|
38 | 38 | extern CEntitySystem *g_pEntitySystem; |
39 | 39 | extern IVEngineServer2 *g_pEngineServer2; |
40 | 40 |
|
| 41 | +extern bool practiceMode; |
| 42 | + |
41 | 43 | void ParseChatCommand(const char *pMessage, CCSPlayerController *pController) |
42 | 44 | { |
43 | 45 | if (!pController) |
@@ -132,6 +134,69 @@ CON_COMMAND_CHAT(unpause, "Request unpause") |
132 | 134 | g_pEngineServer2->ServerCommand("mp_unpause_match"); |
133 | 135 | } |
134 | 136 |
|
| 137 | +CON_COMMAND_CHAT(spawn, "teleport to desired spawn") |
| 138 | +{ |
| 139 | + if (!player) |
| 140 | + return; |
| 141 | + |
| 142 | + if (!practiceMode){ |
| 143 | + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Only available on practice mode"); |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + if (args.ArgC() < 2) |
| 148 | + { |
| 149 | + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !spawn <spawn number>"); |
| 150 | + return; |
| 151 | + } |
| 152 | + |
| 153 | + char teamName[256]; |
| 154 | + if(player->m_iTeamNum == CS_TEAM_T){ |
| 155 | + V_snprintf(teamName, sizeof(teamName), "info_player_terrorist"); |
| 156 | + }else if(player->m_iTeamNum == CS_TEAM_CT){ |
| 157 | + V_snprintf(teamName, sizeof(teamName), "info_player_counterterrorist"); |
| 158 | + }else{ |
| 159 | + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You cannot teleport in spectator!"); |
| 160 | + return; |
| 161 | + } |
| 162 | + |
| 163 | + //Count spawnpoints (info_player_counterterrorist & info_player_terrorist) |
| 164 | + SpawnPoint* spawn = nullptr; |
| 165 | + CUtlVector<SpawnPoint*> spawns; |
| 166 | + while (nullptr != (spawn = (SpawnPoint*)UTIL_FindEntityByClassname(spawn, teamName))) |
| 167 | + { |
| 168 | + if (spawn->m_bEnabled()) |
| 169 | + { |
| 170 | + // ClientPrint(player, HUD_PRINTTALK, "Spawn %i: %f / %f / %f", spawns.Count(), spawn->GetAbsOrigin().x, spawn->GetAbsOrigin().y, spawn->GetAbsOrigin().z); |
| 171 | + spawns.AddToTail(spawn); |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + //Pick and get position of random spawnpoint |
| 176 | + //Spawns selection from 1 to spawns.Count() |
| 177 | + int targetSpawn = atoi(args[1]) - 1; |
| 178 | + int spawnIndex = targetSpawn % spawns.Count(); |
| 179 | + Vector spawnpos = spawns[spawnIndex]->GetAbsOrigin(); |
| 180 | + |
| 181 | + //Here's where the mess starts |
| 182 | + CBasePlayerPawn *pPawn = player->GetPawn(); |
| 183 | + if (!pPawn) |
| 184 | + { |
| 185 | + return; |
| 186 | + } |
| 187 | + if (pPawn->m_iHealth() <= 0) |
| 188 | + { |
| 189 | + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You cannot teleport when dead!"); |
| 190 | + return; |
| 191 | + } |
| 192 | + |
| 193 | + int totalSpawns = spawns.Count(); |
| 194 | + |
| 195 | + pPawn->SetAbsOrigin(spawnpos); |
| 196 | + |
| 197 | + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You have been teleported to spawn. %i/%i", spawnIndex +1, totalSpawns); |
| 198 | +} |
| 199 | + |
135 | 200 | /* |
136 | 201 |
|
137 | 202 | CON_COMMAND_CHAT(getorigin, "get your origin") |
|
0 commit comments