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

Commit

Permalink
Add spawn command (#8)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
marqdevx and marqdevx authored Oct 29, 2023
1 parent 97b7428 commit fbf11df
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ This plugin adds the minimum requirements for competitive teams that need a more
- [ ] include map name
- Practice
- [X] Map
- [ ] Spawns
- [X] Spawns
- [ ] Only show competitive spawns
- [ ] Remove smokes
- [ ] Move to spec
- [ ] Noclip
Expand Down
7 changes: 6 additions & 1 deletion src/adminsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extern CEntitySystem *g_pEntitySystem;

CAdminSystem* g_pAdminSystem;

bool practiceMode = false;

CUtlMap<uint32, FnChatCommandCallback_t> g_CommandList(0, 0, DefLessFunc(uint32));

CON_COMMAND_F(c_reload_admins, "Reload admin config", FCVAR_SPONLY | FCVAR_LINKED_CONCOMMAND)
Expand Down Expand Up @@ -84,8 +86,9 @@ CON_COMMAND_CHAT(scrim, "Scrim mode")
return;
}



practiceMode = false;

char buf[256];
//V_snprintf(buf, sizeof(buf), "exec %s", args[1]);

Expand All @@ -111,6 +114,8 @@ CON_COMMAND_CHAT(pracc, "Practice mode")
return;
}

practiceMode = true;

char buf[256];
//V_snprintf(buf, sizeof(buf), "exec %s", args[1]);

Expand Down
65 changes: 65 additions & 0 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
extern CEntitySystem *g_pEntitySystem;
extern IVEngineServer2 *g_pEngineServer2;

extern bool practiceMode;

void ParseChatCommand(const char *pMessage, CCSPlayerController *pController)
{
if (!pController)
Expand Down Expand Up @@ -132,6 +134,69 @@ CON_COMMAND_CHAT(unpause, "Request unpause")
g_pEngineServer2->ServerCommand("mp_unpause_match");
}

CON_COMMAND_CHAT(spawn, "teleport to desired spawn")
{
if (!player)
return;

if (!practiceMode){
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Only available on practice mode");
return;
}

if (args.ArgC() < 2)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !spawn <spawn number>");
return;
}

char teamName[256];
if(player->m_iTeamNum == CS_TEAM_T){
V_snprintf(teamName, sizeof(teamName), "info_player_terrorist");
}else if(player->m_iTeamNum == CS_TEAM_CT){
V_snprintf(teamName, sizeof(teamName), "info_player_counterterrorist");
}else{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You cannot teleport in spectator!");
return;
}

//Count spawnpoints (info_player_counterterrorist & info_player_terrorist)
SpawnPoint* spawn = nullptr;
CUtlVector<SpawnPoint*> spawns;
while (nullptr != (spawn = (SpawnPoint*)UTIL_FindEntityByClassname(spawn, teamName)))
{
if (spawn->m_bEnabled())
{
// ClientPrint(player, HUD_PRINTTALK, "Spawn %i: %f / %f / %f", spawns.Count(), spawn->GetAbsOrigin().x, spawn->GetAbsOrigin().y, spawn->GetAbsOrigin().z);
spawns.AddToTail(spawn);
}
}

//Pick and get position of random spawnpoint
//Spawns selection from 1 to spawns.Count()
int targetSpawn = atoi(args[1]) - 1;
int spawnIndex = targetSpawn % spawns.Count();
Vector spawnpos = spawns[spawnIndex]->GetAbsOrigin();

//Here's where the mess starts
CBasePlayerPawn *pPawn = player->GetPawn();
if (!pPawn)
{
return;
}
if (pPawn->m_iHealth() <= 0)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You cannot teleport when dead!");
return;
}

int totalSpawns = spawns.Count();

pPawn->SetAbsOrigin(spawnpos);

ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You have been teleported to spawn. %i/%i", spawnIndex +1, totalSpawns);
}

/*
CON_COMMAND_CHAT(getorigin, "get your origin")
Expand Down

0 comments on commit fbf11df

Please sign in to comment.