game: add spawn entity by coordinates

This commit is contained in:
Denis Pauk 2022-08-08 13:30:06 +03:00
parent 021d6480d6
commit 2a8a2f390a
3 changed files with 58 additions and 1 deletions

View File

@ -28,6 +28,9 @@ original clients (Vanilla Quake II) commands are still in place.
* **teleport <x y z>**: Teleports the player to the given coordinates.
* **spawnentity classname x y z <angle_x angle_y angle_z> <flags>**:
Spawn new entity of `classname` at `x y z` coordinates.
* **listmaps**: Lists available maps for the player to load. Maps from
loaded pak files will be listed first followed by maps placed in
the current game's maps folder.

View File

@ -612,6 +612,7 @@ CL_InitLocal(void)
Cmd_AddCommand("weapprev", NULL);
Cmd_AddCommand("listentities", NULL);
Cmd_AddCommand("teleport", NULL);
Cmd_AddCommand("spawnentity", NULL);
Cmd_AddCommand("cycleweap", NULL);
}

View File

@ -1276,6 +1276,55 @@ Cmd_Teleport_f(edict_t *ent)
gi.linkentity(ent);
}
edict_t* G_Spawn(void);
void ED_CallSpawn(edict_t* ent);
static void
Cmd_SpawnEntity_f(edict_t *ent)
{
if (!ent)
{
return;
}
if ((deathmatch->value || coop->value) && !sv_cheats->value)
{
gi.cprintf(ent, PRINT_HIGH,
"You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
if (gi.argc() < 5 || gi.argc() > 9)
{
gi.cprintf(ent, PRINT_HIGH,
"Usage: spawnentity classname x y z <angle_x angle_y angle_z> <flags>\n");
return;
}
ent = G_Spawn();
// set position
ent->s.origin[0] = atof(gi.argv(2));
ent->s.origin[1] = atof(gi.argv(3));
ent->s.origin[2] = atof(gi.argv(4));
// angles
if (gi.argc() >= 8)
{
ent->s.angles[0] = atof(gi.argv(5));
ent->s.angles[1] = atof(gi.argv(6));
ent->s.angles[2] = atof(gi.argv(7));
}
// flags
if (gi.argc() >= 9)
{
ent->spawnflags = atoi(gi.argv(8));
}
ent->classname = strdup(gi.argv(1));
ED_CallSpawn(ent);
}
void
Cmd_ListEntities_f(edict_t *ent)
{
@ -1818,6 +1867,10 @@ ClientCommand(edict_t *ent)
{
Cmd_Teleport_f(ent);
}
else if (Q_stricmp(cmd, "spawnentity") == 0)
{
Cmd_SpawnEntity_f(ent);
}
else if (Q_stricmp(cmd, "listentities") == 0)
{
Cmd_ListEntities_f(ent);