Skip to content

Commit 314dcf8

Browse files
committed
Add setPedAnimationSpeed
bool setPedAnimationProgress ( ped thePed, string anim, float speed ) Allows you to set the speed of any running animation from 0.0 - 1.0. It can be also used to fix swimming speed for higher fps.
2 parents 8c66cfe + 898427a commit 314dcf8

File tree

14 files changed

+151
-0
lines changed

14 files changed

+151
-0
lines changed

Client/game_sa/CAnimBlendAssociationSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CAnimBlendAssociationSA : public CAnimBlendAssociation
6363
float GetBlendAmount() { return m_pInterface->fBlendAmount; }
6464
void SetBlendAmount(float fAmount) { m_pInterface->fBlendAmount = fAmount; }
6565
void SetCurrentProgress(float fProgress);
66+
void SetCurrentSpeed(float fSpeed) { m_pInterface->fSpeed = fSpeed; }
6667
void SetAnimID(short sAnimID) { m_pInterface->sAnimID = sAnimID; }
6768
void SetAnimGroup(short sAnimGroup) { m_pInterface->sAnimGroup = sAnimGroup; }
6869
void SetFlags(short sFlags) { m_pInterface->sFlags = sFlags; }

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,27 @@ bool CStaticFunctionDefinitions::SetPedAnimationProgress(CClientEntity& Entity,
21872187
return false;
21882188
}
21892189

2190+
bool CStaticFunctionDefinitions::SetPedAnimationSpeed(CClientEntity& Entity, const SString& strAnimName, float fSpeed)
2191+
{
2192+
RUN_CHILDREN(SetPedAnimationSpeed(**iter, strAnimName, fSpeed))
2193+
2194+
if (IS_PED(&Entity))
2195+
{
2196+
CClientPed& Ped = static_cast<CClientPed&>(Entity);
2197+
if (!strAnimName.empty())
2198+
{
2199+
auto pAnimAssociation = g_pGame->GetAnimManager()->RpAnimBlendClumpGetAssociation(Ped.GetClump(), strAnimName);
2200+
if (pAnimAssociation)
2201+
{
2202+
pAnimAssociation->SetCurrentSpeed(fSpeed);
2203+
return true;
2204+
}
2205+
}
2206+
}
2207+
2208+
return false;
2209+
}
2210+
21902211
bool CStaticFunctionDefinitions::SetPedMoveAnim(CClientEntity& Entity, unsigned int iMoveAnim)
21912212
{
21922213
RUN_CHILDREN(SetPedMoveAnim(**iter, iMoveAnim))

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class CStaticFunctionDefinitions
170170
static bool SetPedAnimation(CClientEntity& Entity, const SString& strBlockName, const char* szAnimName, int iTime, int iBlend, bool bLoop,
171171
bool bUpdatePosition, bool bInterruptable, bool bFreezeLastFrame);
172172
static bool SetPedAnimationProgress(CClientEntity& Entity, const SString& strAnimName, float fProgress);
173+
static bool SetPedAnimationSpeed(CClientEntity& Entity, const SString& strAnimName, float fSpeed);
173174
static bool SetPedMoveAnim(CClientEntity& Entity, unsigned int iMoveAnim);
174175
static bool AddPedClothes(CClientEntity& Entity, const char* szTexture, const char* szModel, unsigned char ucType);
175176
static bool RemovePedClothes(CClientEntity& Entity, unsigned char ucType);

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ void CLuaPedDefs::LoadFunctions(void)
6767
CLuaCFunctions::AddFunction("setPedCanBeKnockedOffBike", SetPedCanBeKnockedOffBike);
6868
CLuaCFunctions::AddFunction("setPedAnimation", SetPedAnimation);
6969
CLuaCFunctions::AddFunction("setPedAnimationProgress", SetPedAnimationProgress);
70+
CLuaCFunctions::AddFunction("setPedAnimationSpeed", SetPedAnimationSpeed);
7071
CLuaCFunctions::AddFunction("setPedWalkingStyle", SetPedMoveAnim);
7172
CLuaCFunctions::AddFunction("addPedClothes", AddPedClothes);
7273
CLuaCFunctions::AddFunction("removePedClothes", RemovePedClothes);
@@ -150,6 +151,7 @@ void CLuaPedDefs::AddClass(lua_State* luaVM)
150151
lua_classfunction(luaVM, "setAnalogControlState", "setPedAnalogControlState");
151152
lua_classfunction(luaVM, "setAnimation", "setPedAnimation");
152153
lua_classfunction(luaVM, "setAnimationProgress", "setPedAnimationProgress");
154+
lua_classfunction(luaVM, "setAnimationSpeed", "setPedAnimationSpeed");
153155
lua_classfunction(luaVM, "setCameraRotation", "setPedCameraRotation");
154156
lua_classfunction(luaVM, "setControlState", "setPedControlState");
155157
lua_classfunction(luaVM, "warpIntoVehicle", "warpPedIntoVehicle");
@@ -2018,6 +2020,36 @@ int CLuaPedDefs::SetPedAnimationProgress(lua_State* luaVM)
20182020
return 1;
20192021
}
20202022

2023+
int CLuaPedDefs::SetPedAnimationSpeed(lua_State* luaVM)
2024+
{
2025+
CClientEntity* pEntity;
2026+
SString strAnimName;
2027+
float fSpeed;
2028+
2029+
CScriptArgReader argStream(luaVM);
2030+
argStream.ReadUserData(pEntity);
2031+
argStream.ReadString(strAnimName, "");
2032+
argStream.ReadNumber(fSpeed, 1.0f);
2033+
2034+
if (!argStream.HasErrors())
2035+
{
2036+
if (!strAnimName.empty() && fSpeed >= 0.0f && fSpeed <= 1.0f)
2037+
{
2038+
if (CStaticFunctionDefinitions::SetPedAnimationSpeed(*pEntity, strAnimName, fSpeed))
2039+
{
2040+
lua_pushboolean(luaVM, true);
2041+
return 1;
2042+
}
2043+
}
2044+
}
2045+
else
2046+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2047+
2048+
// Failed
2049+
lua_pushboolean(luaVM, false);
2050+
return 1;
2051+
}
2052+
20212053
int CLuaPedDefs::SetPedMoveAnim(lua_State* luaVM)
20222054
{
20232055
// Verify the argument

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class CLuaPedDefs : public CLuaDefs
6969
LUA_DECLARE(SetPedCanBeKnockedOffBike);
7070
LUA_DECLARE(SetPedAnimation);
7171
LUA_DECLARE(SetPedAnimationProgress);
72+
LUA_DECLARE(SetPedAnimationSpeed);
7273
LUA_DECLARE(SetPedMoveAnim);
7374
LUA_DECLARE(SetPedWeaponSlot);
7475
LUA_DECLARE(GivePedWeapon);

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void CPedRPCs::LoadFunctions(void)
3131
AddHandler(SET_PED_DOING_GANG_DRIVEBY, SetPedDoingGangDriveby, "SetPedDoingGangDriveby");
3232
AddHandler(SET_PED_ANIMATION, SetPedAnimation, "SetPedAnimation");
3333
AddHandler(SET_PED_ANIMATION_PROGRESS, SetPedAnimationProgress, "SetPedAnimationProgress");
34+
AddHandler(SET_PED_ANIMATION_SPEED, SetPedAnimationSpeed, "SetPedAnimationSpeed");
3435
AddHandler(SET_PED_ON_FIRE, SetPedOnFire, "SetPedOnFire");
3536
AddHandler(SET_PED_HEADLESS, SetPedHeadless, "SetPedHeadless");
3637
AddHandler(SET_PED_FROZEN, SetPedFrozen, "SetPedFrozen");
@@ -317,6 +318,36 @@ void CPedRPCs::SetPedAnimationProgress(CClientEntity* pSource, NetBitStreamInter
317318
}
318319
}
319320

321+
void CPedRPCs::SetPedAnimationSpeed(CClientEntity* pSource, NetBitStreamInterface& bitStream)
322+
{
323+
char szAnimName[64];
324+
unsigned char ucAnimSize;
325+
float fSpeed;
326+
327+
if (bitStream.Read(ucAnimSize))
328+
{
329+
CClientPed* pPed = m_pPedManager->Get(pSource->GetID(), true);
330+
if (pPed)
331+
{
332+
if (ucAnimSize > 0)
333+
{
334+
if (bitStream.Read(szAnimName, ucAnimSize))
335+
{
336+
szAnimName[ucAnimSize] = 0;
337+
if (bitStream.Read(fSpeed))
338+
{
339+
auto pAnimAssociation = g_pGame->GetAnimManager()->RpAnimBlendClumpGetAssociation(pPed->GetClump(), szAnimName);
340+
if (pAnimAssociation)
341+
{
342+
pAnimAssociation->SetCurrentSpeed(fSpeed);
343+
}
344+
}
345+
}
346+
}
347+
}
348+
}
349+
}
350+
320351
void CPedRPCs::SetPedOnFire(CClientEntity* pSource, NetBitStreamInterface& bitStream)
321352
{
322353
bool bIsOnFire;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CPedRPCs : public CRPCFunctions
3232
DECLARE_ELEMENT_RPC(SetPedDoingGangDriveby);
3333
DECLARE_ELEMENT_RPC(SetPedAnimation);
3434
DECLARE_ELEMENT_RPC(SetPedAnimationProgress);
35+
DECLARE_ELEMENT_RPC(SetPedAnimationSpeed);
3536
DECLARE_ELEMENT_RPC(SetPedOnFire);
3637
DECLARE_ELEMENT_RPC(SetPedHeadless);
3738
DECLARE_ELEMENT_RPC(SetPedFrozen);

Client/sdk/game/CAnimBlendAssociation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class CAnimBlendAssociation
3737
virtual float GetBlendAmount() = 0;
3838
virtual void SetBlendAmount(float fAmount) = 0;
3939
virtual void SetCurrentProgress(float fProgress) = 0;
40+
virtual void SetCurrentSpeed(float fSpeed) = 0;
4041
virtual void SetAnimID(short sAnimID) = 0;
4142
virtual void SetAnimGroup(short sAnimGroup) = 0;
4243
virtual void SetFlags(short sFlags) = 0;

Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ADD_ENUM1(REMOVE_PED_FROM_VEHICLE)
5252
ADD_ENUM1(SET_PED_DOING_GANG_DRIVEBY)
5353
ADD_ENUM1(SET_PED_ANIMATION)
5454
ADD_ENUM1(SET_PED_ANIMATION_PROGRESS)
55+
ADD_ENUM1(SET_PED_ANIMATION_SPEED)
5556
ADD_ENUM1(SET_PED_ON_FIRE)
5657
ADD_ENUM1(SET_PED_HEADLESS)
5758
ADD_ENUM1(SET_PED_FROZEN)

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,6 +4366,33 @@ bool CStaticFunctionDefinitions::SetPedAnimationProgress(CElement* pElement, con
43664366
return false;
43674367
}
43684368

4369+
bool CStaticFunctionDefinitions::SetPedAnimationSpeed(CElement* pElement, const char* szAnimName, float fSpeed)
4370+
{
4371+
assert(pElement);
4372+
RUN_CHILDREN(SetPedAnimationSpeed(*iter, szAnimName, fSpeed))
4373+
4374+
if (IS_PED(pElement))
4375+
{
4376+
CPed* pPed = static_cast<CPed*>(pElement);
4377+
if (pPed->IsSpawned() && szAnimName)
4378+
{
4379+
CBitStream BitStream;
4380+
if (szAnimName)
4381+
{
4382+
unsigned char ucAnimSize = (unsigned char)strlen(szAnimName);
4383+
4384+
BitStream.pBitStream->Write(ucAnimSize);
4385+
BitStream.pBitStream->Write(szAnimName, ucAnimSize);
4386+
BitStream.pBitStream->Write(fSpeed);
4387+
}
4388+
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, SET_PED_ANIMATION_SPEED, *BitStream.pBitStream));
4389+
4390+
return true;
4391+
}
4392+
}
4393+
return false;
4394+
}
4395+
43694396
bool CStaticFunctionDefinitions::SetPedOnFire(CElement* pElement, bool bIsOnFire)
43704397
{
43714398
assert(pElement);

0 commit comments

Comments
 (0)