Skip to content

Commit fe8a534

Browse files
authored
Merge pull request #243 from Dezash/feature/setPedJetPack
Function setPedWearingJetpack
2 parents c2d1a08 + cf1eb95 commit fe8a534

File tree

8 files changed

+82
-17
lines changed

8 files changed

+82
-17
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void CLuaPedDefs::LoadFunctions(void)
2626
CLuaCFunctions::AddFunction("getPedContactElement", GetPedContactElement);
2727
CLuaCFunctions::AddFunction("isPedInVehicle", IsPedInVehicle);
2828
CLuaCFunctions::AddFunction("doesPedHaveJetPack", DoesPedHaveJetPack);
29+
CLuaCFunctions::AddFunction("isPedWearingJetpack", DoesPedHaveJetPack); // introduced in 1.5.5-9.13176
2930
CLuaCFunctions::AddFunction("isPedOnGround", IsPedOnGround);
3031
CLuaCFunctions::AddFunction("getPedTask", GetPedTask);
3132
CLuaCFunctions::AddFunction("getPedSimplestTask", GetPedSimplestTask);
@@ -104,6 +105,7 @@ void CLuaPedDefs::AddClass(lua_State* luaVM)
104105

105106
lua_classfunction(luaVM, "canBeKnockedOffBike", "canPedBeKnockedOffBike");
106107
lua_classfunction(luaVM, "doesHaveJetPack", "doesPedHaveJetPack");
108+
lua_classfunction(luaVM, "isWearingJetpack", "isPedWearingJetpack"); // introduced in 1.5.5-9.13176
107109
lua_classfunction(luaVM, "getAmmoInClip", "getPedAmmoInClip");
108110
lua_classfunction(luaVM, "getAnalogControlState", "getPedAnalogControlState");
109111
lua_classfunction(luaVM, "getAnimation", "getPedAnimation");
@@ -170,6 +172,7 @@ void CLuaPedDefs::AddClass(lua_State* luaVM)
170172
lua_classvariable(luaVM, "vehicleSeat", NULL, "getPedOccupiedVehicleSeat");
171173
lua_classvariable(luaVM, "canBeKnockedOffBike", "setPedCanBeKnockedOffBike", "canPedBeKnockedOffBike");
172174
lua_classvariable(luaVM, "hasJetPack", NULL, "doesPedHaveJetPack");
175+
lua_classvariable(luaVM, "jetpack", NULL, "isPedWearingJetpack"); // introduced in 1.5.5-9.13176
173176
lua_classvariable(luaVM, "armor", NULL, "getPedArmor");
174177
lua_classvariable(luaVM, "cameraRotation", "setPedCameraRotation", "getPedCameraRotation");
175178
lua_classvariable(luaVM, "contactElement", NULL, "getPedContactElement");

Client/mods/deathmatch/logic/rpc/CPedRPCs.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
*
1010
*****************************************************************************/
1111

12-
#ifndef __CPedRPCs_H
13-
#define __CPedRPCs_H
12+
#pragma once
1413

1514
#include "CRPCFunctions.h"
1615

@@ -38,5 +37,3 @@ class CPedRPCs : public CRPCFunctions
3837
DECLARE_ELEMENT_RPC(SetPedFrozen);
3938
DECLARE_ELEMENT_RPC(ReloadPedWeapon);
4039
};
41-
42-
#endif

Server/mods/deathmatch/logic/CResourceChecker.Data.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ namespace
166166
{"setElementCallPropagationEnabled", "1.3.5-9.06118"},
167167
{"isElementCallPropagationEnabled", "1.3.5-9.06118"},
168168
{"getResourceState", "1.3.5-9.06194"},
169+
{"isPedWearingJetpack", "1.5.5-9.13176"},
169170
};
170171

171172
SVersionItem serverFunctionInitList[] = {
@@ -242,6 +243,8 @@ namespace
242243
{"isElementCallPropagationEnabled", "1.3.5-9.06118"},
243244
{"resendPlayerACInfo", "1.5.1-9.07633"},
244245
{"dbPrepareString", "1.5.2"},
246+
{"isPedWearingJetpack", "1.5.5-9.13176"},
247+
{"setPedWearingJetpack", "1.5.5-9.13176"},
245248
};
246249

247250
//
@@ -250,7 +253,12 @@ namespace
250253

251254
struct SDeprecatedItem
252255
{
256+
// bRemoved does not mean:
257+
// "has this function been removed yet?"
258+
// bRemoved actually means:
259+
// "is not rename?" (you can't rename removed functions)
253260
bool bRemoved;
261+
254262
SString strOldName;
255263
SString strNewName;
256264
SString strVersion;
@@ -324,6 +332,9 @@ namespace
324332

325333
{false, "getComponentPosition", "will return 3 floats instead of a Vector3", "1.5.5-9.11710"},
326334
{false, "getComponentRotation", "will return 3 floats instead of a Vector3", "1.5.5-9.11710"},
335+
336+
// Ped jetpacks
337+
{false, "doesPedHaveJetPack", "isPedWearingJetpack"},
327338
};
328339

329340
SDeprecatedItem serverDeprecatedList[] = {
@@ -367,8 +378,6 @@ namespace
367378
{false, "setPlayerStat", "setPedStat"},
368379
{false, "addPlayerClothes", "addPedClothes"},
369380
{false, "removePlayerClothes", "removePedClothes"},
370-
{false, "givePlayerJetPack", "givePedJetPack"},
371-
{false, "removePlayerJetPack", "removePedJetPack"},
372381
{false, "setPlayerFightingStyle", "setPedFightingStyle"},
373382
{false, "setPlayerGravity", "setPedGravity"},
374383
{false, "setPlayerChoking", "setPedChoking"},
@@ -377,6 +386,12 @@ namespace
377386
{false, "attachElementToElement", "attachElements"},
378387
{false, "detachElementFromElement", "detachElements"},
379388
{false, "showPlayerHudComponent", "setPlayerHudComponentVisible"},
389+
// Server ped jetpack
390+
{true, "givePlayerJetPack", "Replaced with setPedWearingJetpack. Refer to the wiki for details"},
391+
{true, "removePlayerJetPack", "Replaced with setPedWearingJetpack. Refer to the wiki for details"},
392+
{false, "givePedJetPack", "Replaced with setPedWearingJetpack. Refer to the wiki for details"},
393+
{false, "removePedJetPack", "Replaced with setPedWearingJetpack. Refer to the wiki for details"},
394+
{false, "doesPedHaveJetPack", "isPedWearingJetpack"},
380395
// XML
381396
{false, "xmlNodeGetSubNodes", "xmlNodeGetChildren"},
382397
{false, "xmlCreateSubNode", "xmlCreateChild"},

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,28 @@ bool CStaticFunctionDefinitions::RemovePedJetPack(CElement* pElement)
39023902
return false;
39033903
}
39043904

3905+
bool CStaticFunctionDefinitions::SetPedWearingJetpack(CElement* pElement, bool bJetPack)
3906+
{
3907+
assert(pElement);
3908+
RUN_CHILDREN(SetPedWearingJetpack(*iter, bJetPack))
3909+
3910+
if (IS_PED(pElement))
3911+
{
3912+
CPed* pPed = static_cast<CPed*>(pElement);
3913+
if (pPed->IsSpawned() && bJetPack != pPed->HasJetPack())
3914+
{
3915+
pPed->SetHasJetPack(bJetPack);
3916+
3917+
CBitStream BitStream;
3918+
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, bJetPack ? GIVE_PED_JETPACK : REMOVE_PED_JETPACK, *BitStream.pBitStream));
3919+
3920+
return true;
3921+
}
3922+
}
3923+
3924+
return false;
3925+
}
3926+
39053927
bool CStaticFunctionDefinitions::SetPedFightingStyle(CElement* pElement, unsigned char ucStyle)
39063928
{
39073929
assert(pElement);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class CStaticFunctionDefinitions
186186
static bool RemovePedClothes(CElement* pElement, unsigned char ucType, const char* szTexture = NULL, const char* szModel = NULL);
187187
static bool GivePedJetPack(CElement* pElement);
188188
static bool RemovePedJetPack(CElement* pElement);
189+
static bool SetPedWearingJetpack(CElement* pElement, bool bJetPack);
189190
static bool SetPedFightingStyle(CElement* pElement, unsigned char ucStyle);
190191
static bool SetPedMoveAnim(CElement* pElement, unsigned int iMoveAnim);
191192
static bool SetPedGravity(CElement* pElement, float fGravity);

Server/mods/deathmatch/logic/lua/CLuaManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,5 +375,9 @@ void CLuaManager::LoadCFunctions(void)
375375
CLuaCFunctions::AddFunction("xmlFindSubNode", CLuaXMLDefs::xmlNodeFindChild);
376376
CLuaCFunctions::AddFunction("attachElementToElement", CLuaElementDefs::attachElements);
377377
CLuaCFunctions::AddFunction("detachElementFromElement", CLuaElementDefs::detachElements);
378+
// Deprecated since 1.5.5-9.13176
379+
CLuaCFunctions::AddFunction("doesPedHaveJetPack", CLuaPedDefs::DoesPedHaveJetPack);
380+
CLuaCFunctions::AddFunction("givePedJetPack", CLuaPedDefs::GivePedJetPack);
381+
CLuaCFunctions::AddFunction("removePedJetPack", CLuaPedDefs::RemovePedJetPack);
378382
// ** END OF BACKWARDS COMPATIBILITY FUNCS. **
379383
}

Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void CLuaPedDefs::LoadFunctions(void)
3030
CLuaCFunctions::AddFunction("getPedTotalAmmo", GetPedTotalAmmo);
3131
CLuaCFunctions::AddFunction("getPedWeapon", GetPedWeapon);
3232
CLuaCFunctions::AddFunction("getPedClothes", GetPedClothes);
33-
CLuaCFunctions::AddFunction("doesPedHaveJetPack", DoesPedHaveJetPack);
33+
CLuaCFunctions::AddFunction("isPedWearingJetpack", DoesPedHaveJetPack); // introduced in 1.5.5-9.13176
3434
CLuaCFunctions::AddFunction("isPedOnGround", IsPedOnGround);
3535
CLuaCFunctions::AddFunction("getPedFightingStyle", GetPedFightingStyle);
3636
CLuaCFunctions::AddFunction("getPedWalkingStyle", GetPedMoveAnim);
@@ -52,8 +52,7 @@ void CLuaPedDefs::LoadFunctions(void)
5252
CLuaCFunctions::AddFunction("setPedStat", SetPedStat);
5353
CLuaCFunctions::AddFunction("addPedClothes", AddPedClothes);
5454
CLuaCFunctions::AddFunction("removePedClothes", RemovePedClothes);
55-
CLuaCFunctions::AddFunction("givePedJetPack", GivePedJetPack);
56-
CLuaCFunctions::AddFunction("removePedJetPack", RemovePedJetPack);
55+
CLuaCFunctions::AddFunction("setPedWearingJetpack", SetPedWearingJetpack); // introduced in 1.5.5-9.13176
5756
CLuaCFunctions::AddFunction("setPedFightingStyle", SetPedFightingStyle);
5857
CLuaCFunctions::AddFunction("setPedWalkingStyle", SetPedMoveAnim);
5958
CLuaCFunctions::AddFunction("setPedGravity", SetPedGravity);
@@ -95,27 +94,26 @@ void CLuaPedDefs::AddClass(lua_State* luaVM)
9594
lua_classfunction(luaVM, "removeClothes", "removePedClothes");
9695
lua_classfunction(luaVM, "removeFromVehicle", "removePedFromVehicle");
9796
lua_classfunction(luaVM, "removeJetPack", "removePedJetPack");
98-
lua_classfunction(luaVM, "doesHaveJetpack", "doesPedHaveJetPack");
97+
lua_classfunction(luaVM, "doesHaveJetpack", "doesPedHaveJetPack"); // deprecated in 1.5.5-9.13176
9998

10099
lua_classfunction(luaVM, "isDead", "isPedDead");
101100
lua_classfunction(luaVM, "isDucked", "isPedDucked");
102101
lua_classfunction(luaVM, "isInWater", "isPedInWater");
103102
lua_classfunction(luaVM, "isOnGround", "isPedOnGround");
104103
lua_classfunction(luaVM, "isInVehicle", "isPedInVehicle");
105-
106104
lua_classfunction(luaVM, "isOnFire", "isPedOnFire");
107105
lua_classfunction(luaVM, "isChoking", "isPedChoking");
108106
lua_classfunction(luaVM, "isDoingGangDriveby", "isPedDoingGangDriveby");
109107
lua_classfunction(luaVM, "isFrozen", "isPedFrozen");
110108
lua_classfunction(luaVM, "isHeadless", "isPedHeadless");
109+
lua_classfunction(luaVM, "isWearingJetpack", "isPedWearingJetpack"); // introduced in 1.5.5-9.13176
111110

112111
lua_classfunction(luaVM, "getArmor", "getPedArmor");
113112
lua_classfunction(luaVM, "getFightingStyle", "getPedFightingStyle");
114113
lua_classfunction(luaVM, "getGravity", "getPedGravity");
115114
lua_classfunction(luaVM, "getStat", "getPedStat");
116115
lua_classfunction(luaVM, "getWeaponSlot", "getPedWeaponSlot");
117116
lua_classfunction(luaVM, "getWalkingStyle", "getPedWalkingStyle");
118-
119117
lua_classfunction(luaVM, "getAmmoInClip", "getPedAmmoInClip");
120118
lua_classfunction(luaVM, "getOccupiedVehicle", "getPedOccupiedVehicle");
121119
lua_classfunction(luaVM, "getWeapon", "getPedWeapon");
@@ -136,9 +134,9 @@ void CLuaPedDefs::AddClass(lua_State* luaVM)
136134
lua_classfunction(luaVM, "setStat", "setPedStat");
137135
lua_classfunction(luaVM, "setWeaponSlot", "setPedWeaponSlot");
138136
lua_classfunction(luaVM, "setWalkingStyle", "setPedWalkingStyle");
139-
140137
lua_classfunction(luaVM, "setAnimation", "setPedAnimation");
141138
lua_classfunction(luaVM, "setAnimationProgress", "setPedAnimationProgress");
139+
lua_classfunction(luaVM, "setWearingJetpack", "setPedWearingJetpack"); // introduced in 1.5.5-9.13176
142140

143141
lua_classvariable(luaVM, "inVehicle", NULL, "isPedInVehicle");
144142
lua_classvariable(luaVM, "ducked", NULL, "isPedDucked");
@@ -160,12 +158,10 @@ void CLuaPedDefs::AddClass(lua_State* luaVM)
160158
GetPedOccupiedVehicle); // what about removePedFromVehicle?
161159
lua_classvariable(luaVM, "dead", "killPed", "isPedDead"); // Setting this to any value will still kill the ped. Should we special case this?
162160
lua_classvariable(luaVM, "walkingStyle", "setPedWalkingStyle", "getPedWalkingStyle");
161+
lua_classvariable(luaVM, "jetpack", "setPedWearingJetpack", "isPedWearingJetpack"); // introduced in 1.5.5-9.13176
163162
// lua_classvariable ( luaVM, "stats", "setPedStat", "getPedStat", CLuaOOPDefs::SetPedStat, CLuaOOPDefs::GetPedStat ); // table
164163
// lua_classvariable ( luaVM, "controlState", "setPedControlState", "getPedControlState", CLuaOOPDefs::SetPedControlState, CLuaOOPDefs::GetPedControlState
165164
// ); // TODO: .controlState["control"] = value
166-
// This commented code will syntax error, a new method has to be implemented to support this
167-
// lua_classvariable ( luaVM, "jetpack", {"removePedJetPack","givePedJetPack}, "doesPedHaveJetPack", CLuaOOPDefs::SetJetpackActive, "doesPedHaveJetPack" );
168-
// // very specialised!
169165

170166
lua_registerclass(luaVM, "Ped", "Element");
171167
}
@@ -1238,6 +1234,32 @@ int CLuaPedDefs::RemovePedJetPack(lua_State* luaVM)
12381234
return 1;
12391235
}
12401236

1237+
int CLuaPedDefs::SetPedWearingJetpack(lua_State* luaVM)
1238+
{
1239+
CElement* pElement;
1240+
bool bJetPack;
1241+
1242+
CScriptArgReader argStream(luaVM);
1243+
argStream.ReadUserData(pElement);
1244+
argStream.ReadBool(bJetPack);
1245+
1246+
if (!argStream.HasErrors())
1247+
{
1248+
LogWarningIfPlayerHasNotJoinedYet(luaVM, pElement);
1249+
1250+
if (CStaticFunctionDefinitions::SetPedWearingJetpack(pElement, bJetPack))
1251+
{
1252+
lua_pushboolean(luaVM, true);
1253+
return 1;
1254+
}
1255+
}
1256+
else
1257+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
1258+
1259+
lua_pushboolean(luaVM, false);
1260+
return 1;
1261+
}
1262+
12411263
int CLuaPedDefs::SetPedFightingStyle(lua_State* luaVM)
12421264
{
12431265
CElement* pElement;

Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CLuaPedDefs : public CLuaDefs
6363
LUA_DECLARE(RemovePedClothes);
6464
LUA_DECLARE(GivePedJetPack);
6565
LUA_DECLARE(RemovePedJetPack);
66+
LUA_DECLARE(SetPedWearingJetpack);
6667
LUA_DECLARE(SetPedFightingStyle);
6768
LUA_DECLARE(SetPedMoveAnim);
6869
LUA_DECLARE(SetPedGravity);
@@ -77,4 +78,4 @@ class CLuaPedDefs : public CLuaDefs
7778
LUA_DECLARE(SetPedHeadless);
7879
LUA_DECLARE(SetPedFrozen);
7980
LUA_DECLARE(reloadPedWeapon);
80-
};
81+
};

0 commit comments

Comments
 (0)