]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Implement "ent_remove_all" command. Removes all entities of classname in map
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 25 Jul 2020 15:09:56 +0000 (15:09 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 25 Jul 2020 15:09:56 +0000 (15:09 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12877 d7cf8633-e32d-0410-b094-e92efae38249

sv_ccmds.c

index f6d71256aa6a6c898c9a538cd75db12e2442bedc..f15f2f4b2697055ae60c66812c955fc1e8fc753b 100644 (file)
@@ -1572,6 +1572,35 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
        if(cmd->source == src_client)
                Con_Printf("%s spawned a \"%s\"\n", host_client->name, Cmd_Argv(cmd, 1));
 }
+//static void SV_Ent_Remove()
+
+static void SV_Ent_Remove_All_f(cmd_state_t *cmd)
+{
+       prvm_prog_t *prog = SVVM_prog;
+       int i, rmcount;
+       prvm_edict_t *ed;
+       void (*print)(const char *, ...) = (cmd->source == src_client ? SV_ClientPrintf : Con_Printf);
+
+       for (i = 0, rmcount = 0, ed = PRVM_EDICT_NUM(i); i < prog->num_edicts; i++, ed = PRVM_NEXT_EDICT(ed))
+       {
+               if(!ed->priv.required->free && !strcmp(PRVM_GetString(prog, PRVM_serveredictstring(ed, classname)), Cmd_Argv(cmd, 1)))
+               {
+                       if(!i)
+                       {
+                               print("Cannot remove the world\n");
+                               return;
+                       }
+                       PRVM_ED_ClearEdict(prog, ed);
+                       PRVM_ED_Free(prog, ed);
+                       rmcount++;
+               }
+       }
+
+       if(!rmcount)
+               print("No \"%s\" found\n", Cmd_Argv(cmd, 1));
+       else
+               print("Removed %i of \"%s\"\n", rmcount, Cmd_Argv(cmd, 1));
+}
 
 void SV_InitOperatorCommands(void)
 {
@@ -1625,4 +1654,5 @@ void SV_InitOperatorCommands(void)
        Cmd_AddCommand(CMD_USERINFO, "playerskin", SV_Playerskin_f, "change your player skin number");
 
        Cmd_AddCommand(CMD_CHEAT | CMD_SERVER_FROM_CLIENT, "ent_create", SV_Ent_Create_f, "Creates an entity at the specified coordinate, of the specified classname. If executed from a server, origin has to be specified manually.");
+       Cmd_AddCommand(CMD_CHEAT | CMD_SERVER_FROM_CLIENT, "ent_remove_all", SV_Ent_Remove_All_f, "Removes all entities of the specified classname");
 }