Skip to content

Commit

Permalink
Merge pull request ddnet#7230 from furo321/practice-lasttp
Browse files Browse the repository at this point in the history
Add /lasttp
  • Loading branch information
def- authored Sep 21, 2023
2 parents 3ca6008 + a7ef9c7 commit 2c8a798
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/game/ddracechat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
31 changes: 30 additions & 1 deletion src/game/server/ddracechat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/entities/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ class CCharacter : public CEntity
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; }
Expand Down
1 change: 1 addition & 0 deletions src/game/server/gamecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class CGameContext : public IGameServer
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);
Expand Down

0 comments on commit 2c8a798

Please sign in to comment.