int CLuaPedDefs::GiveWeapon ( lua_State* luaVM ) { // bool giveWeapon ( ped thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] ) CElement* pElement; eWeaponType weaponType; ushort usAmmo; bool bSetAsCurrent; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pElement ); argStream.ReadEnumStringOrNumber ( weaponType ); argStream.ReadNumber ( usAmmo, 30 ); argStream.ReadBool ( bSetAsCurrent, false ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::GiveWeapon ( pElement, weaponType, usAmmo, bSetAsCurrent ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetWeaponAmmo ( lua_State* luaVM ) { // bool setWeaponAmmo ( player thePlayer, int weapon, int totalAmmo, [int ammoInClip = 0] ) CElement* pElement; eWeaponType weaponType; ushort usAmmo; ushort usAmmoInClip; CCustomWeapon * pWeapon = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pElement ); if ( !argStream.HasErrors () ) { if ( pElement->GetType () != CElement::WEAPON ) { argStream.ReadEnumStringOrNumber ( weaponType ); argStream.ReadNumber ( usAmmo ); argStream.ReadNumber ( usAmmoInClip, 0 ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponAmmo ( pElement, weaponType, usAmmo, usAmmoInClip ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } else { pWeapon = static_cast <CCustomWeapon *> ( pElement ); argStream.ReadNumber ( usAmmo ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponAmmo ( pWeapon, usAmmo ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetSlotFromWeapon ( lua_State* luaVM ) { eWeaponType weaponType; CScriptArgReader argStream ( luaVM ); argStream.ReadEnumStringOrNumber( weaponType ); if ( !argStream.HasErrors ( ) ) { char cSlot = CWeaponNames::GetSlotFromWeapon ( weaponType ); if ( cSlot >= 0 ) lua_pushnumber ( luaVM, cSlot ); else lua_pushboolean ( luaVM, false ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaWorldDefs::getJetpackWeaponEnabled ( lua_State* luaVM ) { eWeaponType weaponType; bool bEnabled; CScriptArgReader argStream ( luaVM ); argStream.ReadEnumStringOrNumber ( weaponType ); if ( !argStream.HasErrors() ) { if ( CStaticFunctionDefinitions::GetJetpackWeaponEnabled ( weaponType, bEnabled ) ) { lua_pushboolean ( luaVM, bEnabled ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::CreateWeapon ( lua_State* luaVM ) { CVector vecPos; eWeaponType weaponType; CScriptArgReader argStream ( luaVM ); argStream.ReadEnumStringOrNumber ( weaponType ); argStream.ReadNumber ( vecPos.fX ); argStream.ReadNumber ( vecPos.fY ); argStream.ReadNumber ( vecPos.fZ ); if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource (); if ( pResource ) { CClientWeapon * pWeapon = CStaticFunctionDefinitions::CreateWeapon ( *pResource, weaponType, vecPos ); if ( pWeapon ) { CElementGroup * pGroup = pResource->GetElementGroup(); if ( pGroup ) { pGroup->Add ( ( CClientEntity* ) pWeapon ); } lua_pushelement ( luaVM, pWeapon ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPedDefs::TakeWeapon ( lua_State* luaVM ) { // bool takeWeapon ( player thePlayer, int weaponId [, int ammo ] ) CElement* pElement; eWeaponType weaponType; ushort usAmmo; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pElement ); argStream.ReadEnumStringOrNumber ( weaponType ); argStream.ReadNumber ( usAmmo, 9999 ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::TakeWeapon ( pElement, weaponType, usAmmo ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetOriginalWeaponProperty ( lua_State* luaVM ) { eWeaponSkill eWepSkill = WEAPONSKILL_STD; eWeaponType eWep = WEAPONTYPE_UNARMED; eWeaponProperty eProp = WEAPON_INVALID_PROPERTY; CScriptArgReader argStream ( luaVM ); argStream.ReadEnumStringOrNumber ( eWep ); argStream.ReadEnumStringOrNumber ( eWepSkill ); argStream.ReadEnumString ( eProp ); if ( !argStream.HasErrors () ) { switch ( eProp ) { case WEAPON_WEAPON_RANGE: case WEAPON_TARGET_RANGE: case WEAPON_ACCURACY: case WEAPON_FIRING_SPEED: case WEAPON_LIFE_SPAN: case WEAPON_SPREAD: case WEAPON_MOVE_SPEED: // Get only case WEAPON_REQ_SKILL_LEVEL: case WEAPON_ANIM_LOOP_START: case WEAPON_ANIM_LOOP_STOP: case WEAPON_ANIM_LOOP_RELEASE_BULLET_TIME: case WEAPON_ANIM2_LOOP_START: case WEAPON_ANIM2_LOOP_STOP: case WEAPON_ANIM2_LOOP_RELEASE_BULLET_TIME: case WEAPON_ANIM_BREAKOUT_TIME: case WEAPON_RADIUS: { float fWeaponInfo = 0.0f; if ( CStaticFunctionDefinitions::GetOriginalWeaponProperty ( eProp, eWep, eWepSkill, fWeaponInfo ) ) { lua_pushnumber ( luaVM, fWeaponInfo ); return 1; } break; } case WEAPON_DAMAGE: case WEAPON_MAX_CLIP_AMMO: case WEAPON_FLAGS: case WEAPON_ANIM_GROUP: case WEAPON_FIRETYPE: case WEAPON_MODEL: case WEAPON_MODEL2: case WEAPON_SLOT: case WEAPON_AIM_OFFSET: case WEAPON_SKILL_LEVEL: case WEAPON_DEFAULT_COMBO: case WEAPON_COMBOS_AVAILABLE: { int sWeaponInfo = 0; if ( CStaticFunctionDefinitions::GetOriginalWeaponProperty ( eProp, eWep, eWepSkill, sWeaponInfo ) ) { lua_pushinteger ( luaVM, sWeaponInfo ); return 1; } break; } case WEAPON_FIRE_OFFSET: { CVector vecWeaponInfo; if ( CStaticFunctionDefinitions::GetOriginalWeaponProperty ( eProp, eWep, eWepSkill, vecWeaponInfo ) ) { lua_pushnumber ( luaVM, vecWeaponInfo.fX ); lua_pushnumber ( luaVM, vecWeaponInfo.fY ); lua_pushnumber ( luaVM, vecWeaponInfo.fZ ); return 3; } break; } case WEAPON_FLAG_AIM_NO_AUTO: case WEAPON_FLAG_AIM_ARM: case WEAPON_FLAG_AIM_1ST_PERSON: case WEAPON_FLAG_AIM_FREE: case WEAPON_FLAG_MOVE_AND_AIM: case WEAPON_FLAG_MOVE_AND_SHOOT: case WEAPON_FLAG_TYPE_THROW: case WEAPON_FLAG_TYPE_HEAVY: case WEAPON_FLAG_TYPE_CONSTANT: case WEAPON_FLAG_TYPE_DUAL: case WEAPON_FLAG_ANIM_RELOAD: case WEAPON_FLAG_ANIM_CROUCH: case WEAPON_FLAG_ANIM_RELOAD_LOOP: case WEAPON_FLAG_ANIM_RELOAD_LONG: case WEAPON_FLAG_SHOT_SLOWS: case WEAPON_FLAG_SHOT_RAND_SPEED: case WEAPON_FLAG_SHOT_ANIM_ABRUPT: case WEAPON_FLAG_SHOT_EXPANDS: { MinServerReqCheck ( argStream, MIN_SERVER_REQ_WEAPON_PROPERTY_FLAG, "flag name is being used" ); if ( !argStream.HasErrors () ) { bool bEnable; if ( CStaticFunctionDefinitions::GetOriginalWeaponPropertyFlag ( eProp, eWep, eWepSkill, bEnable ) ) { lua_pushboolean ( luaVM, bEnable ); return 1; } } break; } default: { argStream.SetCustomError ( "unsupported weapon property at argument 3" ); break; } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetWeaponProperty ( lua_State* luaVM ) { // bool setWeaponProperty ( int weaponID/string weaponName, string weaponSkill, string property/int property, int/float theValue ) eWeaponSkill eWepSkill = WEAPONSKILL_STD; eWeaponType eWep = WEAPONTYPE_BRASSKNUCKLE; eWeaponProperty eProp = WEAPON_ACCURACY; CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsUserData () ) { CCustomWeapon * pWeapon; eWeaponProperty weaponProperty; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWeapon ); argStream.ReadEnumString ( weaponProperty ); if ( !argStream.HasErrors () ) { if ( weaponProperty == WEAPON_DAMAGE ) { short sData = 0; argStream.ReadNumber ( sData ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, sData ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else { float fData = 0.0f; argStream.ReadNumber ( fData ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, fData ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } else { argStream.ReadEnumStringOrNumber ( eWep ); argStream.ReadEnumStringOrNumber ( eWepSkill ); argStream.ReadEnumString ( eProp ); if ( !argStream.HasErrors () ) { switch ( eProp ) { case WEAPON_WEAPON_RANGE: case WEAPON_TARGET_RANGE: case WEAPON_ACCURACY: case WEAPON_MOVE_SPEED: case WEAPON_ANIM_LOOP_START: case WEAPON_ANIM_LOOP_STOP: case WEAPON_ANIM_LOOP_RELEASE_BULLET_TIME: case WEAPON_ANIM2_LOOP_START: case WEAPON_ANIM2_LOOP_STOP: case WEAPON_ANIM2_LOOP_RELEASE_BULLET_TIME: case WEAPON_ANIM_BREAKOUT_TIME: { float fWeaponInfo = 0.0f; argStream.ReadNumber ( fWeaponInfo ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponProperty ( eProp, eWep, eWepSkill, fWeaponInfo ) ) { lua_pushboolean ( luaVM, true ); return 1; } } break; } case WEAPON_DAMAGE: case WEAPON_MAX_CLIP_AMMO: case WEAPON_FLAGS: { int sWeaponInfo = 0; argStream.ReadNumber ( sWeaponInfo ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponProperty ( eProp, eWep, eWepSkill, sWeaponInfo ) ) { lua_pushboolean ( luaVM, true ); return 1; } } break; } case WEAPON_FLAG_AIM_NO_AUTO: case WEAPON_FLAG_AIM_ARM: case WEAPON_FLAG_AIM_1ST_PERSON: case WEAPON_FLAG_AIM_FREE: case WEAPON_FLAG_MOVE_AND_AIM: case WEAPON_FLAG_MOVE_AND_SHOOT: case WEAPON_FLAG_TYPE_THROW: case WEAPON_FLAG_TYPE_HEAVY: case WEAPON_FLAG_TYPE_CONSTANT: case WEAPON_FLAG_TYPE_DUAL: case WEAPON_FLAG_ANIM_RELOAD: case WEAPON_FLAG_ANIM_CROUCH: case WEAPON_FLAG_ANIM_RELOAD_LOOP: case WEAPON_FLAG_ANIM_RELOAD_LONG: case WEAPON_FLAG_SHOT_SLOWS: case WEAPON_FLAG_SHOT_RAND_SPEED: case WEAPON_FLAG_SHOT_ANIM_ABRUPT: case WEAPON_FLAG_SHOT_EXPANDS: { MinServerReqCheck ( argStream, MIN_SERVER_REQ_WEAPON_PROPERTY_FLAG, "flag name is being used" ); bool bEnable; argStream.ReadBool ( bEnable ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponPropertyFlag ( eProp, eWep, eWepSkill, bEnable ) ) { lua_pushboolean ( luaVM, true ); return 1; } } break; } default: { argStream.SetCustomError ( "unsupported weapon property at argument 3" ); break; } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } // Failed lua_pushboolean ( luaVM, false ); return 1; }