Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
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
5 changes: 0 additions & 5 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
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;
SetPlayerSpawned(true);
}

// 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 CClientPlayer::Reset()
{
// stats
Expand Down
10 changes: 10 additions & 0 deletions Client/mods/deathmatch/logic/CClientPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ 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);

bool IsPlayerSpawned() const noexcept { return m_bHasPlayerSpawned; }
void SetPlayerSpawned(const bool bSetSpawned) noexcept { m_bHasPlayerSpawned = bSetSpawned; }

unsigned long GetLastPuresyncTime() { return m_ulLastPuresyncTime; }
void SetLastPuresyncTime(unsigned long ulLastPuresyncTime) { m_ulLastPuresyncTime = ulLastPuresyncTime; }
Expand Down Expand Up @@ -116,6 +124,8 @@ class CClientPlayer final : public CClientPed
uchar m_ucPrevBulletSyncOrderCounter;

private:
bool m_bHasPlayerSpawned{false};

bool m_bIsLocalPlayer;
SString m_strNick;

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->IsPlayerSpawned();
}


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
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CMapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ void CMapManager::SpawnPlayer(CPlayer& Player, const CVector& vecPosition, float
}

// Update the player data
Player.SetPlayerSpawned(true);
Player.SetSpawned(true);
Player.SetHealth(Player.GetMaxHealth());
Player.SetIsDead(false);
Expand Down
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class CPlayer final : public CPed, public CClient
bool IsJoined() { return m_bIsJoined; }
void SetJoined() { m_bIsJoined = true; }

bool IsPlayerSpawned() const noexcept { return m_bHasPlayerSpawned; }
void SetPlayerSpawned(const bool bSetSpawned) noexcept { m_bHasPlayerSpawned = bSetSpawned; }

bool SubscribeElementData(CElement* pElement, const std::string& strName);
bool UnsubscribeElementData(CElement* pElement, const std::string& strName);
bool UnsubscribeElementData(CElement* pElement);
Expand Down Expand Up @@ -465,4 +468,6 @@ class CPlayer final : public CPed, public CClient

ushort m_usPrevDimension;
SString m_strQuitReasonForLog;

bool m_bHasPlayerSpawned;
};
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->IsPlayerSpawned();
}

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