From: cloudwalk Date: Sat, 25 Jul 2020 15:09:56 +0000 (+0000) Subject: Implement "ent_remove_all" command. Removes all entities of classname in map X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=05ac5cdc0d6ec20ec53fc8f17603d92a2e10fe92;p=xonotic%2Fdarkplaces.git Implement "ent_remove_all" command. Removes all entities of classname in map git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12877 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/sv_ccmds.c b/sv_ccmds.c index f6d71256..f15f2f4b 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -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"); }