Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8718cc0
Added related functions
TracerDS Jun 3, 2024
58fe7db
Moved `CClientPed::Spawn` to `CClientPlayer` class
TracerDS Jun 4, 2024
fc5f800
Updated code according to reviews
TracerDS Jun 4, 2024
54c341f
Changes `IsSpawned` to `IsDead` in some places
TracerDS Jun 4, 2024
9e65c97
Merge github.com:TracerDS/mtasa-blue into 030624_NewFunction-isPlayer…
TracerDS Jun 22, 2024
30bebc7
Update according to reviews
TracerDS Jun 22, 2024
db6821e
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jun 22, 2024
20c02b3
Update according to reviews
TracerDS Jun 22, 2024
9cd7219
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jun 22, 2024
7939df5
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jun 24, 2024
04a644d
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jun 26, 2024
b9e98e6
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
Dutchman101 Jun 30, 2024
20f25b2
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jul 14, 2024
f2a6011
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jul 14, 2024
2e8adf5
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jul 15, 2024
346f9cc
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jul 15, 2024
4527f01
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jul 16, 2024
467048e
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jul 19, 2024
42536a9
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Jul 31, 2024
82c8767
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Aug 23, 2024
1c84853
Merge branch 'master' into 030624_NewFunction-isPlayerSpawned
TracerDS Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/ClientCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void DumpPlayer(CClientPlayer* pPlayer, FILE* pFile)
fprintf(pFile, "Armor: %f\n", pPlayer->GetArmor());
fprintf(pFile, "On screen: %u\n", pPlayer->IsOnScreen());
fprintf(pFile, "Frozen: %u\n", pPlayer->IsFrozen());
fprintf(pFile, "Respawn state: %i\n", pPlayer->GetRespawnState());
fprintf(pFile, "Respawn state: %u\n", pPlayer->IsSpawned());

fprintf(pFile, "Cur weapon slot: %i\n", static_cast<int>(pPlayer->GetCurrentWeaponSlot()));
fprintf(pFile, "Cur weapon type: %i\n", static_cast<int>(pPlayer->GetCurrentWeaponType()));
Expand Down
54 changes: 0 additions & 54 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,60 +720,6 @@ void CClientPed::SetCurrentRotationNew(float fRotation)
SetRotationRadiansNew(CVector(0, 0, fRotation));
}

void CClientPed::Spawn(const CVector& vecPosition, float fRotation, unsigned short usModel, unsigned char ucInterior)
{
// Remove us from our car
RemoveFromVehicle();
SetVehicleInOutState(VEHICLE_INOUT_NONE);

// Wait for ground
if (m_bIsLocalPlayer)
{
SetFrozenWaitingForGroundToLoad(true);
m_iLoadAllModelsCounter = 10;
}

// Remove any animation
KillAnimation();

// Give him the correct model
SetModel(usModel);

// Detach from any entities
AttachTo(NULL);

// Restore our health before any resurrection calls (::SetHealth/SetInitialState)
// So we don't get recreated more than once
if (m_pPlayerPed)
{
m_pPlayerPed->SetInitialState();
m_fHealth = GetMaxHealth();
m_pPlayerPed->SetHealth(m_fHealth);
m_bUsesCollision = true;
m_pPlayerPed->SetLanding(false);
}
else
{
// Remote ped health/armor was locked during Kill, so make sure it's unlocked
UnlockHealth();
UnlockArmor();
}

// Set some states
SetFrozen(false);
Teleport(vecPosition);
SetCurrentRotationNew(fRotation);
SetHealth(GetMaxHealth());
RemoveAllWeapons();
SetArmor(0);
ResetInterpolation();
SetHasJetPack(false);
SetMoveSpeed(CVector());
SetInterior(ucInterior);
SetFootBloodEnabled(false);
SetIsDead(false);
}

void CClientPed::ResetInterpolation()
{
m_ulBeginRotationTime = 0;
Expand Down
11 changes: 3 additions & 8 deletions Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,6 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

void Teleport(const CVector& vecPosition);

// This function spawns/respawns this ped in any location. This will force a recreation
// and restoration of initial state. This will also remove all weapons, unfreeze,
// remove jetpack, etc...
void Spawn(const CVector& vecPosition, float fRotation, unsigned short usModel, unsigned char ucInterior);

void ResetInterpolation();

float GetCurrentRotation();
Expand Down Expand Up @@ -292,8 +287,8 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
void StealthKill(CClientPed* pPed);
void BeHit(CClientPed* pClientPedAttacker, ePedPieceTypes hitBodyPart, int hitBodySide, int weaponId);

int GetRespawnState() const noexcept { return m_pRespawnState; };
void SetRespawnState(int iRespawnState) noexcept { m_pRespawnState = iRespawnState; };
int IsSpawned() const noexcept { return m_bIsSpawned; }
void SetSpawned(const bool bSpawned) noexcept { m_bIsSpawned = bSpawned; }

CWeapon* GiveWeapon(eWeaponType weaponType, unsigned int uiAmmo, bool bSetAsCurrent = false);
bool SetCurrentWeaponSlot(eWeaponSlot weaponSlot);
Expand Down Expand Up @@ -614,7 +609,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
CTaskManager* m_pTaskManager;
CPad* m_pPad;
bool m_bIsLocalPlayer;
int m_pRespawnState;
bool m_bIsSpawned;
unsigned long m_ulModel;
CMatrix m_matFrozen;
bool m_bRadioOn;
Expand Down
55 changes: 55 additions & 0 deletions Client/mods/deathmatch/logic/CClientPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,61 @@ bool CClientPlayer::IsOnMyTeam(CClientPlayer* pPlayer)
return false;
}

void CClientPlayer::Spawn(const CVector& vecPosition, float fRotation, unsigned short usModel, unsigned char ucInterior)
{
// Remove us from our car
RemoveFromVehicle();
SetVehicleInOutState(VEHICLE_INOUT_NONE);

// Wait for ground
if (m_bIsLocalPlayer)
{
SetFrozenWaitingForGroundToLoad(true);
m_iLoadAllModelsCounter = 10;
}

// Remove any animation
KillAnimation();

// Give him the correct model
SetModel(usModel);

// Detach from any entities
AttachTo(NULL);

// Restore our health before any resurrection calls (::SetHealth/SetInitialState)
// So we don't get recreated more than once
if (m_pPlayerPed)
{
m_pPlayerPed->SetInitialState();
m_fHealth = GetMaxHealth();
m_pPlayerPed->SetHealth(m_fHealth);
m_bUsesCollision = true;
m_pPlayerPed->SetLanding(false);
}
else
{
// Remote ped health/armor was locked during Kill, so make sure it's unlocked
UnlockHealth();
UnlockArmor();
}

// Set some states
SetSpawned(true);
SetFrozen(false);
Teleport(vecPosition);
SetCurrentRotationNew(fRotation);
SetHealth(GetMaxHealth());
RemoveAllWeapons();
SetArmor(0);
ResetInterpolation();
SetHasJetPack(false);
SetMoveSpeed(CVector());
SetInterior(ucInterior);
SetFootBloodEnabled(false);
SetIsDead(false);
}

void CClientPlayer::Reset()
{
// stats
Expand Down
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class CClientPlayer final : public CClientPed

unsigned short GetLatency() { return m_usLatency; }
void SetLatency(unsigned short usLatency) { m_usLatency = (m_usLatency + usLatency) / 2; }

// This function spawns/respawns this ped in any location. This will force a recreation
// and restoration of initial state. This will also remove all weapons, unfreeze,
// remove jetpack, etc...
void Spawn(const CVector& vecPosition, float fRotation, unsigned short usModel, unsigned char ucInterior);

unsigned long GetLastPuresyncTime() { return m_ulLastPuresyncTime; }
void SetLastPuresyncTime(unsigned long ulLastPuresyncTime) { m_ulLastPuresyncTime = ulLastPuresyncTime; }
Expand Down
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"isPlayerHudComponentVisible", IsPlayerHudComponentVisible},
{"getPlayerMoney", GetPlayerMoney},
{"getPlayerWantedLevel", GetPlayerWantedLevel},
{"hasPlayerSpawned", ArgumentParser<HasPlayerSpawned>},

// Player set funcs
{"showPlayerHudComponent", ShowPlayerHudComponent},
Expand Down Expand Up @@ -309,6 +310,13 @@ int CLuaPlayerDefs::GetPlayerWantedLevel(lua_State* luaVM)
return 1;
}


bool CLuaPlayerDefs::HasPlayerSpawned(CClientPlayer* player)
{
return player->IsSpawned();
}


int CLuaPlayerDefs::ShowPlayerHudComponent(lua_State* luaVM)
{
// bool showPlayerHudComponent ( string component, bool show )
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(GetPlayerTeam);
LUA_DECLARE(GetPlayerMoney);
LUA_DECLARE(GetPlayerWantedLevel);
static bool HasPlayerSpawned(CClientPlayer* player);

// Player set
LUA_DECLARE(ShowPlayerHudComponent);
Expand Down
12 changes: 4 additions & 8 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,6 @@ void CGame::Packet_PlayerWasted(CPlayerWastedPacket& Packet)
CPlayer* pPlayer = Packet.GetSourcePlayer();
if (pPlayer && !pPlayer->IsDead())
{
pPlayer->SetSpawned(false);
pPlayer->SetIsDead(true);
pPlayer->SetHealth(0.0f);
pPlayer->SetArmor(0.0f);
Expand Down Expand Up @@ -2995,8 +2994,8 @@ void CGame::Packet_Vehicle_InOut(CVehicleInOutPacket& Packet)
FAIL_TRAILER,
} failReason = FAIL_INVALID;

// Is he spawned? (Fix for #2335)
if (!pPed->IsSpawned())
// Is he dead? (Fix for #2335)
if (pPed->IsDead())
{
CVehicleInOutPacket Reply(PedID, VehicleID, 0, VEHICLE_ATTEMPT_FAILED);
pPlayer->Send(Reply);
Expand Down Expand Up @@ -3735,8 +3734,8 @@ void CGame::Packet_VehicleTrailer(CVehicleTrailerPacket& Packet)
CPlayer* pPlayer = Packet.GetSourcePlayer();
if (pPlayer && pPlayer->IsJoined())
{
// Spawned?
if (pPlayer->IsSpawned())
// Alive?
if (!pPlayer->IsDead())
{
// Grab the vehicle with the chosen ID
ElementID ID = Packet.GetVehicle();
Expand Down Expand Up @@ -4296,9 +4295,6 @@ void CGame::PlayerCompleteConnect(CPlayer* pPlayer)

// Send him the join details
pPlayer->Send(CPlayerConnectCompletePacket());

// The player is spawned when he's connected, just the Camera is not faded in/not targetting
pPlayer->SetSpawned(true);
}

void CGame::Lock()
Expand Down
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/CPickup.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class CPickup final : public CElement, private CColCallback
bool CanUse(class CPlayer& Player, bool bOnfootCheck = true);
void Use(class CPlayer& Player);

bool IsSpawned() { return m_bSpawned; }
void SetSpawned(bool bSpawned) { m_bSpawned = bSpawned; }
bool IsSpawned() const noexcept { return m_bSpawned; }
void SetSpawned(bool bSpawned) noexcept { m_bSpawned = bSpawned; }

CColShape* GetColShape() { return m_pCollision; }
void SetEnabled(bool bEnabled)
Expand Down
3 changes: 1 addition & 2 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2136,8 +2136,8 @@ CPed* CStaticFunctionDefinitions::CreatePed(CResource* pResource, unsigned short
}

pPed->SetPosition(vecPosition);
pPed->SetIsDead(false);
pPed->SetSpawned(true);
pPed->SetIsDead(false);
pPed->SetHealth(100.0f);
pPed->SetSyncable(bSynced);

Expand Down Expand Up @@ -3722,7 +3722,6 @@ bool CStaticFunctionDefinitions::KillPed(CElement* pElement, CElement* pKiller,
}

// Update the ped
pPed->SetSpawned(false);
pPed->SetIsDead(true);
pPed->SetHealth(0.0f);
pPed->SetArmor(0.0f);
Expand Down
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"resendPlayerModInfo", ResendPlayerModInfo},
{"resendPlayerACInfo", ResendPlayerACInfo},
{"getPlayerScriptDebugLevel", ArgumentParser<GetPlayerScriptDebugLevel>},
{"hasPlayerSpawned", ArgumentParser<HasPlayerSpawned>},

// Player set funcs
{"setPlayerMoney", SetPlayerMoney},
Expand Down Expand Up @@ -1459,6 +1460,11 @@ unsigned int CLuaPlayerDefs::GetPlayerScriptDebugLevel(CPlayer* const player)
return player->GetScriptDebugLevel();
}

bool CLuaPlayerDefs::HasPlayerSpawned(CPlayer* player)
{
return player->IsSpawned();
}

int CLuaPlayerDefs::BindKey(lua_State* luaVM)
{
CPlayer* pPlayer;
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(GetPlayerVersion);
LUA_DECLARE(GetPlayerACInfo);
static unsigned int GetPlayerScriptDebugLevel(CPlayer* const player);
static bool HasPlayerSpawned(CPlayer* player);

// Player set functions
LUA_DECLARE(SetPlayerMoney);
Expand Down