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 6 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", "", nullptr, false);

// 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.playerTeleportAlert, &CMainConfig::OnTickRateChange},
{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
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ class CPlayer final : public CPed, public CClient
void SetRedirecting(bool bRedirecting) noexcept { m_bIsRedirecting = bRedirecting; }
bool IsRedirecting() const noexcept { return m_bIsRedirecting; }

bool GetTeleported() const noexcept { return m_teleported; }
void SetTeleported(bool state) noexcept { m_teleported = state; }

protected:
bool ReadSpecialData(const int iLine) override { return true; }

Expand Down Expand Up @@ -465,4 +468,6 @@ class CPlayer final : public CPed, public CClient

ushort m_usPrevDimension;
SString m_strQuitReasonForLog;

bool m_teleported;
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
};
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* player = static_cast<CPlayer*>(pElement);
player->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 playerPosition = pSourcePlayer->GetPosition();
float playerDistancePosition = DistanceBetweenPoints3D(playerPosition, position.data.vecPosition);
if (playerDistancePosition >= g_TickRateSettings.playerTeleportAlert) {
if (!pSourcePlayer->GetTeleported()) {
pSourcePlayer->CallEvent("onPlayerTeleport");
imfelipedev marked this conversation as resolved.
Show resolved Hide resolved
}

pSourcePlayer->SetTeleported(false);
}

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;
playerTeleportAlert = 100;
}

int iPureSync;
Expand All @@ -41,6 +42,7 @@ struct CTickRateSettings
int iPedSyncerDistance;
int iUnoccupiedVehicleSyncerDistance;
int iVehicleContactSyncRadius;
int playerTeleportAlert;
};

extern CTickRateSettings g_TickRateSettings;