From 6e4b03ff86b61b4c557d22c323fcf25a81d3fadd Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Tue, 14 Oct 2014 21:17:07 +0400 Subject: [PATCH] Lua Pickup functions (CLuaFunctionDefinitions) --- mta-mono/src/lua/CLuaFunctionDefinitions.cpp | 177 +++++++++++++++++++ mta-mono/src/lua/CLuaFunctionDefinitions.h | 16 ++ 2 files changed, 193 insertions(+) diff --git a/mta-mono/src/lua/CLuaFunctionDefinitions.cpp b/mta-mono/src/lua/CLuaFunctionDefinitions.cpp index cec6222..d3c317c 100644 --- a/mta-mono/src/lua/CLuaFunctionDefinitions.cpp +++ b/mta-mono/src/lua/CLuaFunctionDefinitions.cpp @@ -4811,3 +4811,180 @@ bool CLuaFunctionDefinitions::SetRadarAreaFlashing( lua_State* pLuaVM, void* pUs return false; } + +// Pickup create/destroy funcs +void* CLuaFunctionDefinitions::CreatePickup( lua_State* pLuaVM, float fX, float fY, float fZ, unsigned char ucType, double dFive, unsigned long ulRespawnInterval, double dSix ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushNumber( fX ); + pLuaArguments.PushNumber( fY ); + pLuaArguments.PushNumber( fZ ); + + pLuaArguments.PushNumber( ucType ); + pLuaArguments.PushNumber( dFive ); + + pLuaArguments.PushNumber( ulRespawnInterval ); + pLuaArguments.PushNumber( dSix ); + + if( pLuaArguments.Call( pLuaVM, "createPickup", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return pLuaArgument.GetLightUserData(); + } + + return NULL; +} + +// Pickup get funcs +unsigned char CLuaFunctionDefinitions::GetPickupType( lua_State* pLuaVM, void* pUserData ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + + if( pLuaArguments.Call( pLuaVM, "getPickupType", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return static_cast< unsigned char >( pLuaArgument.GetNumber() ); + } + + return 0; +} + +unsigned char CLuaFunctionDefinitions::GetPickupWeapon( lua_State* pLuaVM, void* pUserData ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + + if( pLuaArguments.Call( pLuaVM, "getPickupWeapon", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return static_cast< unsigned char >( pLuaArgument.GetNumber() ); + } + + return 0; +} + +float CLuaFunctionDefinitions::GetPickupAmount( lua_State* pLuaVM, void* pUserData ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + + if( pLuaArguments.Call( pLuaVM, "getPickupAmount", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return static_cast< float >( pLuaArgument.GetNumber() ); + } + + return 0.0f; +} + +unsigned short CLuaFunctionDefinitions::GetPickupAmmo( lua_State* pLuaVM, void* pUserData ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + + if( pLuaArguments.Call( pLuaVM, "getPickupAmmo", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return static_cast< unsigned short >( pLuaArgument.GetNumber() ); + } + + return 0; +} + +unsigned long CLuaFunctionDefinitions::GetPickupRespawnInterval( lua_State* pLuaVM, void* pUserData ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + + if( pLuaArguments.Call( pLuaVM, "getPickupRespawnInterval", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return static_cast< unsigned short >( pLuaArgument.GetNumber() ); + } + + return 0; +} + +bool CLuaFunctionDefinitions::IsPickupSpawned( lua_State* pLuaVM, void* pUserData ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + + if( pLuaArguments.Call( pLuaVM, "isPickupSpawned", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return pLuaArgument.GetBoolean(); + } + + return false; +} + +// Pickup set funcs +bool CLuaFunctionDefinitions::SetPickupType( lua_State* pLuaVM, void* pUserData, unsigned char ucType, double dThree, double dFour ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + pLuaArguments.PushNumber( ucType ); + pLuaArguments.PushNumber( dThree ); + pLuaArguments.PushNumber( dFour ); + + if( pLuaArguments.Call( pLuaVM, "setPickupType", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return pLuaArgument.GetBoolean(); + } + + return false; +} + +bool CLuaFunctionDefinitions::SetPickupRespawnInterval( lua_State* pLuaVM, void* pUserData, unsigned long ulInterval ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + pLuaArguments.PushNumber( ulInterval ); + + if( pLuaArguments.Call( pLuaVM, "setPickupRespawnInterval", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return pLuaArgument.GetBoolean(); + } + + return false; +} + +bool CLuaFunctionDefinitions::UsePickup( lua_State* pLuaVM, void* pUserData, void* pPlayer ) +{ + CLuaArguments pLuaArguments; + + pLuaArguments.PushUserData( pUserData ); + pLuaArguments.PushUserData( pPlayer ); + + if( pLuaArguments.Call( pLuaVM, "usePickup", 1 ) ) + { + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + return pLuaArgument.GetBoolean(); + } + + return false; +} + diff --git a/mta-mono/src/lua/CLuaFunctionDefinitions.h b/mta-mono/src/lua/CLuaFunctionDefinitions.h index 584466c..c5c3f96 100644 --- a/mta-mono/src/lua/CLuaFunctionDefinitions.h +++ b/mta-mono/src/lua/CLuaFunctionDefinitions.h @@ -369,6 +369,22 @@ public: static bool SetRadarAreaSize ( lua_State* pLuaVM, void* pUserData, float fSizeX, float fSizeY ); static bool SetRadarAreaColor ( lua_State* pLuaVM, void* pUserData, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, unsigned char ucAlpha ); static bool SetRadarAreaFlashing ( lua_State* pLuaVM, void* pUserData, bool bFlashing ); + + // Pickup create/destroy funcs + static void* CreatePickup ( lua_State* pLuaVM, float fX, float fY, float fZ, unsigned char ucType, double dFive, unsigned long ulRespawnInterval = 30000, double dSix = 50 ); + + // Pickup get funcs + static unsigned char GetPickupType ( lua_State* pLuaVM, void* pUserData ); + static unsigned char GetPickupWeapon ( lua_State* pLuaVM, void* pUserData ); + static float GetPickupAmount ( lua_State* pLuaVM, void* pUserData ); + static unsigned short GetPickupAmmo ( lua_State* pLuaVM, void* pUserData ); + static unsigned long GetPickupRespawnInterval ( lua_State* pLuaVM, void* pUserData ); + static bool IsPickupSpawned ( lua_State* pLuaVM, void* pUserData ); + + // Pickup set funcs + static bool SetPickupType ( lua_State* pLuaVM, void* pUserData, unsigned char ucType, double dThree, double dFour ); + static bool SetPickupRespawnInterval ( lua_State* pLuaVM, void* pUserData, unsigned long ulInterval ); + static bool UsePickup ( lua_State* pLuaVM, void* pUserData, void* pPlayer ); // Explosion funcs // static int CreateExplosion ( lua_State* luaVM );