From a7ef9c7c6f285d3283be4269197042790824421d Mon Sep 17 00:00:00 2001 From: furo Date: Thu, 21 Sep 2023 21:02:55 +0200 Subject: [PATCH] Add /lasttp --- src/game/ddracechat.h | 1 + src/game/server/ddracechat.cpp | 31 +++++++++++++++++++++++++++- src/game/server/entities/character.h | 2 ++ src/game/server/gamecontext.h | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/game/ddracechat.h b/src/game/ddracechat.h index da7f50c70..957c44385 100644 --- a/src/game/ddracechat.h +++ b/src/game/ddracechat.h @@ -61,6 +61,7 @@ CHAT_COMMAND("timer", "?s['gametimer'|'broadcast'|'both'|'none'|'cycle']", CFGFL CHAT_COMMAND("r", "", CFGFLAG_CHAT | CFGFLAG_SERVER, ConRescue, this, "Teleport yourself out of freeze (use sv_rescue 1 to enable this feature)") CHAT_COMMAND("rescue", "", CFGFLAG_CHAT | CFGFLAG_SERVER, ConRescue, this, "Teleport yourself out of freeze (use sv_rescue 1 to enable this feature)") CHAT_COMMAND("tp", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTele, this, "Teleport yourself to player or to where you are spectating if no player name is given") +CHAT_COMMAND("lasttp", "", CFGFLAG_CHAT | CFGFLAG_SERVER, ConLastTele, this, "Teleport yourself to the last location you teleported to.") CHAT_COMMAND("teleport", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTele, this, "Teleport yourself to player or to where you are spectating if no player name is given") CHAT_COMMAND("unsolo", "", CFGFLAG_CHAT, ConPracticeUnSolo, this, "Puts you out of solo part") CHAT_COMMAND("undeep", "", CFGFLAG_CHAT, ConPracticeUnDeep, this, "Puts you out of deep freeze") diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 629adf951..dcca83ad1 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -1523,12 +1523,41 @@ void CGameContext::ConTele(IConsole::IResult *pResult, void *pUserData) return; Pos = pChrTo->m_Pos; } - + pChr->LastTelePos = Pos; pSelf->Teleport(pChr, Pos); pChr->UnFreeze(); pChr->Core()->m_Vel = vec2(0, 0); } +void CGameContext::ConLastTele(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) + return; + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + CCharacter *pChr = pPlayer->GetCharacter(); + if(!pChr) + return; + + CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams; + int Team = Teams.m_Core.Team(pResult->m_ClientID); + if(!Teams.IsPractice(Team)) + { + pSelf->SendChatTarget(pPlayer->GetCID(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled."); + return; + } + if(!pChr->LastTelePos.x) + { + pSelf->SendChatTarget(pPlayer->GetCID(), "You haven't previously teleported. Use /tp before using this command."); + return; + } + pSelf->Teleport(pChr, pChr->LastTelePos); + pChr->UnFreeze(); + pChr->Core()->m_Vel = vec2(0, 0); +} + void CGameContext::ConPracticeUnSolo(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 89dc031c4..8870ef636 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -217,6 +217,8 @@ public: int m_SpawnTick; int m_WeaponChangeTick; + vec2 LastTelePos; + // Setters/Getters because i don't want to modify vanilla vars access modifiers int GetLastWeapon() { return m_LastWeapon; } void SetLastWeapon(int LastWeap) { m_LastWeapon = LastWeap; } diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 801a28137..e8b84df63 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -448,6 +448,7 @@ private: static void ConSetTimerType(IConsole::IResult *pResult, void *pUserData); static void ConRescue(IConsole::IResult *pResult, void *pUserData); static void ConTele(IConsole::IResult *pResult, void *pUserData); + static void ConLastTele(IConsole::IResult *pResult, void *pUserData); static void ConPracticeUnSolo(IConsole::IResult *pResult, void *pUserData); static void ConPracticeUnDeep(IConsole::IResult *pResult, void *pUserData); static void ConProtectedKill(IConsole::IResult *pResult, void *pUserData);