Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Add grenade history
Browse files Browse the repository at this point in the history
  • Loading branch information
marqdevx committed Apr 16, 2024
1 parent 49899f3 commit 605a096
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
34 changes: 32 additions & 2 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,40 @@ CON_COMMAND_CHAT(last, "Teleport to the last thrown grenade")

ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot());

if(pPlayer->lastThrow_position.x == 0.0f && pPlayer->lastThrow_position.y == 0.0f && pPlayer->lastThrow_position.z == 0.0f){
if(!pPlayer->grenade_throws.Count()){
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "No lineup saved");
return;
}

player->GetPawn()->Teleport(&pPlayer->lastThrow_position, &pPlayer->lastThrow_rotation, nullptr);
player->GetPawn()->Teleport(&pPlayer->grenade_throws[pPlayer->grenade_throws.Count()-1].lastThrow_position, &pPlayer->grenade_throws[pPlayer->grenade_throws.Count()-1].lastThrow_rotation, nullptr);
}

CON_COMMAND_CHAT(back, "Teleport to the selected thrown grenade")
{
if (!player || !g_bEnablePractice)
return;

if (!practiceMode)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Last grenade teleport only available on .pracc mode");
return;
}

ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot());

if(!pPlayer->grenade_throws.Count()){
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "No lineups yet");
return;
}

int target_index = atoi(args[1]);

if(target_index >= pPlayer->grenade_throws.Count()){
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target number out of index");
return;
}

target_index++;

player->GetPawn()->Teleport(&pPlayer->grenade_throws[pPlayer->grenade_throws.Count()-target_index].lastThrow_position, &pPlayer->grenade_throws[pPlayer->grenade_throws.Count()-target_index].lastThrow_rotation, nullptr);
}
18 changes: 12 additions & 6 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ GAME_EVENT_F(grenade_thrown){
if (!practiceMode || !g_bEnablePractice)
return;

CCSPlayerController* pController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pEvent->GetUint64("userid") + 1));

//CCSPlayerController* pController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pEvent->GetUint64("userid") + 1));
CCSPlayerController *pController = (CCSPlayerController *)pEvent->GetPlayerController("userid");

if (!pController)
return;

Expand All @@ -275,10 +276,15 @@ GAME_EVENT_F(grenade_thrown){

CCSPlayerPawnBase* cPlayerBase = (CCSPlayerPawnBase*)pController->GetPawn();
QAngle currentAngle = cPlayerBase->m_angEyeAngles;

//ClientPrintAll( HUD_PRINTTALK, CHAT_PREFIX "Pos: %f, %f, %f", currentPos.x, currentPos.y, currentPos.z);

ZEPlayer *pPlayer = g_playerManager->GetPlayer(pController->GetPlayerSlot());
pPlayer->lastThrow_position = currentPos;
pPlayer->lastThrow_rotation = currentAngle;
t_throw currentThrow;

currentThrow.lastThrow_position = currentPos;
currentThrow.lastThrow_rotation = currentAngle;

pPlayer->grenade_throws.AddToTail(currentThrow);

ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX "Pos: %f, %f, %f", currentThrow.lastThrow_position.x, currentThrow.lastThrow_position.y, currentThrow.lastThrow_position.z);
ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX "Count:%i Pos: %f, %f, %f", pPlayer->grenade_throws.Count(), pPlayer->grenade_throws[pPlayer->grenade_throws.Count()-1].lastThrow_position.x, pPlayer->grenade_throws[pPlayer->grenade_throws.Count()-1].lastThrow_position.y, pPlayer->grenade_throws[pPlayer->grenade_throws.Count()-1].lastThrow_position.z);
}
2 changes: 2 additions & 0 deletions src/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ bool CPlayerManager::OnClientConnected(CPlayerSlot slot, uint64 xuid, const char
ZEPlayer *pPlayer = new ZEPlayer(slot);
pPlayer->SetUnauthenticatedSteamId(new CSteamID(xuid));

pPlayer->grenade_throws.Purge();

std::string ip(pszNetworkID);

// Remove port
Expand Down
13 changes: 6 additions & 7 deletions src/playermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ enum class ETargetType {
CT,
};

struct t_throw{
Vector lastThrow_position;
QAngle lastThrow_rotation;
};

class ZEPlayer
{
public:
Expand All @@ -68,8 +73,6 @@ class ZEPlayer
m_bInGame = false;
m_iMZImmunity = 0; // out of 100
m_flNominateTime = -60.0f;

lastThrow_position = Vector(0,0,0);
}

~ZEPlayer()
Expand Down Expand Up @@ -133,11 +136,7 @@ class ZEPlayer
void CheckAdmin();
void CheckInfractions();



Vector lastThrow_position;
QAngle lastThrow_rotation;

CUtlVector<t_throw> grenade_throws;

private:
bool m_bAuthenticated;
Expand Down

0 comments on commit 605a096

Please sign in to comment.