diff --git a/src/commands.cpp b/src/commands.cpp index ec2470c3..a59419b8 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -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); } \ No newline at end of file diff --git a/src/events.cpp b/src/events.cpp index f4078a4c..d1c1ecbf 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -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; @@ -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); } \ No newline at end of file diff --git a/src/playermanager.cpp b/src/playermanager.cpp index c9113032..59a8424c 100644 --- a/src/playermanager.cpp +++ b/src/playermanager.cpp @@ -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 diff --git a/src/playermanager.h b/src/playermanager.h index 108d1af7..0fc017c8 100644 --- a/src/playermanager.h +++ b/src/playermanager.h @@ -43,6 +43,11 @@ enum class ETargetType { CT, }; +struct t_throw{ + Vector lastThrow_position; + QAngle lastThrow_rotation; +}; + class ZEPlayer { public: @@ -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() @@ -133,11 +136,7 @@ class ZEPlayer void CheckAdmin(); void CheckInfractions(); - - - Vector lastThrow_position; - QAngle lastThrow_rotation; - + CUtlVector grenade_throws; private: bool m_bAuthenticated;