Skip to content

Commit

Permalink
Add setPedJetPack
Browse files Browse the repository at this point in the history
  • Loading branch information
Dezash committed Jul 19, 2018
1 parent 49e0ce4 commit c4c12fc
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CPedRPCs.cpp
Expand Up @@ -21,6 +21,7 @@ void CPedRPCs::LoadFunctions(void)
AddHandler(SET_PED_ROTATION, SetPedRotation, "SetPedRotation");
AddHandler(GIVE_PED_JETPACK, GivePedJetPack, "GivePedJetPack");
AddHandler(REMOVE_PED_JETPACK, RemovePedJetPack, "RemovePedJetPack");
AddHandler(SET_PED_JETPACK, SetPedJetPack, "SetPedJetPack");
AddHandler(REMOVE_PED_CLOTHES, RemovePedClothes, "RemovePedClothes");
AddHandler(SET_PED_GRAVITY, SetPedGravity, "SetPedGravity");
AddHandler(SET_PED_CHOKING, SetPedChoking, "SetPedChoking");
Expand Down Expand Up @@ -100,6 +101,19 @@ void CPedRPCs::RemovePedJetPack(CClientEntity* pSource, NetBitStreamInterface& b
}
}

void CPedRPCs::SetPedJetPack(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
bool bJetPack;
if (bitStream.ReadBit(bJetPack))
{
CClientPed* pPed = m_pPedManager->Get(pSource->GetID(), true);
if (pPed)
{
pPed->SetHasJetPack(bJetPack);
}
}
}

void CPedRPCs::RemovePedClothes(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
unsigned char ucType;
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/rpc/CPedRPCs.h
Expand Up @@ -23,6 +23,7 @@ class CPedRPCs : public CRPCFunctions
DECLARE_ELEMENT_RPC(SetPedRotation);
DECLARE_ELEMENT_RPC(GivePedJetPack);
DECLARE_ELEMENT_RPC(RemovePedJetPack);
DECLARE_ELEMENT_RPC(SetPedJetPack);
DECLARE_ELEMENT_RPC(RemovePedClothes);
DECLARE_ELEMENT_RPC(SetPedGravity);
DECLARE_ELEMENT_RPC(SetPedChoking);
Expand All @@ -39,4 +40,4 @@ class CPedRPCs : public CRPCFunctions
DECLARE_ELEMENT_RPC(ReloadPedWeapon);
};

#endif
#endif
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp
Expand Up @@ -42,6 +42,7 @@ ADD_ENUM1(SET_PED_ARMOR)
ADD_ENUM1(SET_PED_ROTATION)
ADD_ENUM1(GIVE_PED_JETPACK)
ADD_ENUM1(REMOVE_PED_JETPACK)
ADD_ENUM1(SET_PED_JETPACK)
ADD_ENUM1(REMOVE_PED_CLOTHES)
ADD_ENUM1(SET_PED_GRAVITY)
ADD_ENUM1(SET_PED_CHOKING)
Expand Down
23 changes: 23 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -3898,6 +3898,29 @@ bool CStaticFunctionDefinitions::RemovePedJetPack(CElement* pElement)
return false;
}

bool CStaticFunctionDefinitions::SetPedJetPack(CElement* pElement, bool bJetPack)
{
assert(pElement);
RUN_CHILDREN(SetPedJetPack(*iter, bJetPack))

if (IS_PED(pElement))
{
CPed* pPed = static_cast<CPed*>(pElement);
if (pPed->IsSpawned() && bJetPack != pPed->HasJetPack())
{
pPed->SetHasJetPack(bJetPack);

CBitStream BitStream;
BitStream.pBitStream->WriteBit(bJetPack);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, SET_PED_JETPACK, *BitStream.pBitStream));

return true;
}
}

return false;
}

bool CStaticFunctionDefinitions::SetPedFightingStyle(CElement* pElement, unsigned char ucStyle)
{
assert(pElement);
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -186,6 +186,7 @@ class CStaticFunctionDefinitions
static bool RemovePedClothes(CElement* pElement, unsigned char ucType, const char* szTexture = NULL, const char* szModel = NULL);
static bool GivePedJetPack(CElement* pElement);
static bool RemovePedJetPack(CElement* pElement);
static bool SetPedJetPack(CElement* pElement, bool bJetPack);
static bool SetPedFightingStyle(CElement* pElement, unsigned char ucStyle);
static bool SetPedMoveAnim(CElement* pElement, unsigned int iMoveAnim);
static bool SetPedGravity(CElement* pElement, float fGravity);
Expand Down
28 changes: 28 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Expand Up @@ -54,6 +54,7 @@ void CLuaPedDefs::LoadFunctions(void)
CLuaCFunctions::AddFunction("removePedClothes", RemovePedClothes);
CLuaCFunctions::AddFunction("givePedJetPack", GivePedJetPack);
CLuaCFunctions::AddFunction("removePedJetPack", RemovePedJetPack);
CLuaCFunctions::AddFunction("setPedJetPack", SetPedJetPack);
CLuaCFunctions::AddFunction("setPedFightingStyle", SetPedFightingStyle);
CLuaCFunctions::AddFunction("setPedWalkingStyle", SetPedMoveAnim);
CLuaCFunctions::AddFunction("setPedGravity", SetPedGravity);
Expand Down Expand Up @@ -96,6 +97,7 @@ void CLuaPedDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "removeFromVehicle", "removePedFromVehicle");
lua_classfunction(luaVM, "removeJetPack", "removePedJetPack");
lua_classfunction(luaVM, "doesHaveJetpack", "doesPedHaveJetPack");
lua_classfunction(luaVM, "setJetPack", "setPedJetPack");

lua_classfunction(luaVM, "isDead", "isPedDead");
lua_classfunction(luaVM, "isDucked", "isPedDucked");
Expand Down Expand Up @@ -1238,6 +1240,32 @@ int CLuaPedDefs::RemovePedJetPack(lua_State* luaVM)
return 1;
}

int CLuaPedDefs::SetPedJetPack(lua_State* luaVM)
{
CElement* pElement;
bool bJetPack;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
argStream.ReadBool(bJetPack);

if (!argStream.HasErrors())
{
LogWarningIfPlayerHasNotJoinedYet(luaVM, pElement);

if (CStaticFunctionDefinitions::SetPedJetPack(pElement, bJetPack))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaPedDefs::SetPedFightingStyle(lua_State* luaVM)
{
CElement* pElement;
Expand Down
3 changes: 2 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h
Expand Up @@ -63,6 +63,7 @@ class CLuaPedDefs : public CLuaDefs
LUA_DECLARE(RemovePedClothes);
LUA_DECLARE(GivePedJetPack);
LUA_DECLARE(RemovePedJetPack);
LUA_DECLARE(SetPedJetPack);
LUA_DECLARE(SetPedFightingStyle);
LUA_DECLARE(SetPedMoveAnim);
LUA_DECLARE(SetPedGravity);
Expand All @@ -77,4 +78,4 @@ class CLuaPedDefs : public CLuaDefs
LUA_DECLARE(SetPedHeadless);
LUA_DECLARE(SetPedFrozen);
LUA_DECLARE(reloadPedWeapon);
};
};
1 change: 1 addition & 0 deletions Shared/sdk/net/rpc_enums.h
Expand Up @@ -45,6 +45,7 @@ enum eElementRPCFunctions
SET_PED_ROTATION,
GIVE_PED_JETPACK,
REMOVE_PED_JETPACK,
SET_PED_JETPACK,
REMOVE_PED_CLOTHES,
SET_PED_GRAVITY,
SET_PED_CHOKING,
Expand Down

0 comments on commit c4c12fc

Please sign in to comment.