Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new event onPlayerTeleport. #3941

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerTriggerInvalidEvent", "eventName, isAdded, isRemote", nullptr, false);
m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false);
m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false);
m_Events.AddEvent("onPlayerTeleport", "", NULL, false);
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CMainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ const std::vector<SIntSetting>& CMainConfig::GetIntSettingList()
{true, true, 50, 100, 400, "ped_syncer_distance", &g_TickRateSettings.iPedSyncerDistance, &CMainConfig::OnTickRateChange},
{true, true, 50, 130, 400, "unoccupied_vehicle_syncer_distance", &g_TickRateSettings.iUnoccupiedVehicleSyncerDistance, &CMainConfig::OnTickRateChange},
{true, true, 0, 30, 130, "vehicle_contact_sync_radius", &g_TickRateSettings.iVehicleContactSyncRadius, &CMainConfig::OnTickRateChange},
{true, true, 50, 100, 500, "player_teleport_alert", &g_TickRateSettings.iPlayerTeleportAlert, &CMainConfig::OnTickRateChange},
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
{false, false, 0, 1, 2, "compact_internal_databases", &m_iCompactInternalDatabases, NULL},
{true, true, 0, 1, 2, "minclientversion_auto_update", &m_iMinClientVersionAutoUpdate, NULL},
{true, true, 0, 0, 100, "server_logic_fps_limit", &m_iServerLogicFpsLimit, NULL},
Expand Down
12 changes: 12 additions & 0 deletions Server/mods/deathmatch/logic/CPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ CPlayer::CPlayer(CPlayerManager* pPlayerManager, class CScriptDebugging* pScript

m_ucBlurLevel = 36; // Default

m_bTeleported = false;
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved

// Sync stuff
m_bSyncingVelocity = false;
m_uiPuresyncPackets = 0;
Expand Down Expand Up @@ -1115,6 +1117,16 @@ void CPlayer::SetPlayerStat(unsigned short usStat, float fValue)
CPed::SetPlayerStat(usStat, fValue);
}

bool CPlayer::GetTeleported()
{
return m_bTeleported;
}

void CPlayer::SetTeleported(bool bState)
{
m_bTeleported = bState;
}

imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
// Calculate weapon range using efficient stuffs
float CPlayer::GetWeaponRangeFromSlot(uint uiSlot)
{
Expand Down
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,12 @@ bool CStaticFunctionDefinitions::SetElementPosition(CElement* pElement, const CV
assert(pElement);
RUN_CHILDREN(SetElementPosition(*iter, vecPosition, bWarp))

if (IS_PLAYER(pElement))
{
CPlayer* pPlayer = static_cast<CPlayer*>(pElement);
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
pPlayer->SetTeleported(true);
}

// Update our position for that entity.
pElement->SetPosition(vecPosition);

Expand Down
10 changes: 10 additions & 0 deletions Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
position.data.vecPosition += vecTempPos;
}

CVector vecPlayerPosition = pSourcePlayer->GetPosition();
float fPlayerDistancePosition = DistanceBetweenPoints3D(vecPlayerPosition, position.data.vecPosition);
if (fPlayerDistancePosition >= g_TickRateSettings.iPlayerTeleportAlert) {
if (!pSourcePlayer->GetTeleported()) {
pSourcePlayer->CallEvent("onPlayerTeleport");
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
}

pSourcePlayer->SetTeleported(false);
}
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved

pSourcePlayer->SetPosition(position.data.vecPosition);

// Player rotation
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/mtaserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
Available range: 0 to 130. Default - 30 -->
<vehicle_contact_sync_radius>30</vehicle_contact_sync_radius>

<!-- This parameter specifies the player position limit change alert.
Available range: 50 to 500. Default - 100 -->
<player_teleport_alert>100</player_teleport_alert>

<!-- This parameter sets the amount of extrapolation that clients will apply to remote vehicles. This can reduce
some of the latency induced location disparency by predicting where the remote vehicles will probably be.
Depending on the gamemode, an incorrect prediction may have a negative effect. Therefore this setting
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/mtaserver.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
Available range: 0 to 130. Default - 30 -->
<vehicle_contact_sync_radius>30</vehicle_contact_sync_radius>

<!-- This parameter specifies the player position limit change alert.
Available range: 50 to 500. Default - 100 -->
<player_teleport_alert>100</player_teleport_alert>

<!-- This parameter sets the amount of extrapolation that clients will apply to remote vehicles. This can reduce
some of the latency induced location disparency by predicting where the remote vehicles will probably be.
Depending on the gamemode, an incorrect prediction may have a negative effect. Therefore this setting
Expand Down
2 changes: 2 additions & 0 deletions Shared/mods/deathmatch/logic/CTickRateSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct CTickRateSettings
iPedSyncerDistance = 100;
iUnoccupiedVehicleSyncerDistance = 130;
iVehicleContactSyncRadius = 30;
iPlayerTeleportAlert = 100;
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
}

int iPureSync;
Expand All @@ -41,6 +42,7 @@ struct CTickRateSettings
int iPedSyncerDistance;
int iUnoccupiedVehicleSyncerDistance;
int iVehicleContactSyncRadius;
int iPlayerTeleportAlert;
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
};

extern CTickRateSettings g_TickRateSettings;