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

Commit fbf11df

Browse files
authored
Add spawn command (#8)
* Add spawn selector * Add `spawn` command * Avoid crash if spawn number is empty * Not allow spawn if not in a team * Update spawn roadmap --------- Co-authored-by: marqdevx <[email protected]>
1 parent 97b7428 commit fbf11df

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ This plugin adds the minimum requirements for competitive teams that need a more
3434
- [ ] include map name
3535
- Practice
3636
- [X] Map
37-
- [ ] Spawns
37+
- [X] Spawns
38+
- [ ] Only show competitive spawns
3839
- [ ] Remove smokes
3940
- [ ] Move to spec
4041
- [ ] Noclip

src/adminsystem.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extern CEntitySystem *g_pEntitySystem;
3535

3636
CAdminSystem* g_pAdminSystem;
3737

38+
bool practiceMode = false;
39+
3840
CUtlMap<uint32, FnChatCommandCallback_t> g_CommandList(0, 0, DefLessFunc(uint32));
3941

4042
CON_COMMAND_F(c_reload_admins, "Reload admin config", FCVAR_SPONLY | FCVAR_LINKED_CONCOMMAND)
@@ -84,8 +86,9 @@ CON_COMMAND_CHAT(scrim, "Scrim mode")
8486
return;
8587
}
8688

87-
8889

90+
practiceMode = false;
91+
8992
char buf[256];
9093
//V_snprintf(buf, sizeof(buf), "exec %s", args[1]);
9194

@@ -111,6 +114,8 @@ CON_COMMAND_CHAT(pracc, "Practice mode")
111114
return;
112115
}
113116

117+
practiceMode = true;
118+
114119
char buf[256];
115120
//V_snprintf(buf, sizeof(buf), "exec %s", args[1]);
116121

src/commands.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
extern CEntitySystem *g_pEntitySystem;
3939
extern IVEngineServer2 *g_pEngineServer2;
4040

41+
extern bool practiceMode;
42+
4143
void ParseChatCommand(const char *pMessage, CCSPlayerController *pController)
4244
{
4345
if (!pController)
@@ -132,6 +134,69 @@ CON_COMMAND_CHAT(unpause, "Request unpause")
132134
g_pEngineServer2->ServerCommand("mp_unpause_match");
133135
}
134136

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+
135200
/*
136201
137202
CON_COMMAND_CHAT(getorigin, "get your origin")

0 commit comments

Comments
 (0)