From 089076bb769d5306e81d587fd611c4c687d7bf2d Mon Sep 17 00:00:00 2001
From: black <black@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Fri, 19 Dec 2003 17:54:22 +0000
Subject: [PATCH] Added the console commands edictset and prvm_edictset.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3744 d7cf8633-e32d-0410-b094-e92efae38249
---
 pr_edict.c   | 29 +++++++++++++++++++++++++++++
 prvm_edict.c | 40 +++++++++++++++++++++++++++++++++++++++-
 todo         |  2 +-
 3 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/pr_edict.c b/pr_edict.c
index 89e6f3f1..2a77bac1 100644
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -800,6 +800,34 @@ void ED_WriteGlobals (qfile_t *f)
 	FS_Printf (f,"}\n");
 }
 
+/*
+=============
+ED_EdictSet_f
+
+Console command to set a field of a specified edict
+=============
+*/
+void ED_EdictSet_f(void)
+{
+	edict_t *ed;
+	ddef_t *key;
+
+	if(Cmd_Argc() != 4)
+	{
+		Con_Printf("edictset <edict number> <field> <value>\n");
+		return;
+	}
+	ed = EDICT_NUM(atoi(Cmd_Argv(1)));
+
+	if((key = ED_FindField(Cmd_Argv(2))) == 0)
+	{
+		Con_Printf("Key %s not found !\n", Cmd_Argv(2));
+		return;
+	}
+
+	ED_ParseEpair(ed, key, Cmd_Argv(3));
+}
+
 /*
 =============
 ED_ParseGlobals
@@ -1553,6 +1581,7 @@ void PR_Init (void)
 	Cmd_AddCommand ("edict", ED_PrintEdict_f);
 	Cmd_AddCommand ("edicts", ED_PrintEdicts);
 	Cmd_AddCommand ("edictcount", ED_Count);
+	Cmd_AddCommand ("edictset", ED_EdictSet_f);
 	Cmd_AddCommand ("profile", PR_Profile_f);
 	Cmd_AddCommand ("pr_fields", PR_Fields_f);
 	Cmd_AddCommand ("pr_globals", PR_Globals_f);
diff --git a/prvm_edict.c b/prvm_edict.c
index 45f17c61..daa322d0 100644
--- a/prvm_edict.c
+++ b/prvm_edict.c
@@ -896,7 +896,6 @@ char *PRVM_ED_NewString (const char *string)
 	return new;
 }
 
-
 /*
 =============
 PRVM_ED_ParseEval
@@ -985,6 +984,44 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s)
 	return true;
 }
 
+/*
+=============
+PRVM_ED_EdictSet_f
+
+Console command to set a field of a specified edict
+=============
+*/
+void PRVM_ED_EdictSet_f(void)
+{
+	prvm_edict_t *ed;
+	ddef_t *key;
+
+	if(Cmd_Argc() != 5)
+	{
+		Con_Printf("prvm_edictset <program name> <edict number> <field> <value>\n");
+		return;
+	}
+
+	PRVM_Begin;
+	if(!PRVM_SetProgFromString(Cmd_Argv(1)))
+	{
+		Con_Printf("Wrong program name %s !\n", Cmd_Argv(1));
+		return;
+	}
+
+	ed = PRVM_EDICT_NUM(atoi(Cmd_Argv(2)));
+
+	if((key = PRVM_ED_FindField(Cmd_Argv(3))) == 0)
+	{
+		Con_Printf("Key %s not found !\n", Cmd_Argv(3));
+		return;
+	}
+
+	PRVM_ED_ParseEpair(ed, key, Cmd_Argv(4));
+
+	PRVM_End;
+}
+
 /*
 ====================
 PRVM_ED_ParseEdict
@@ -1635,6 +1672,7 @@ void PRVM_Init (void)
 	Cmd_AddCommand ("prvm_profile", PRVM_Profile_f);
 	Cmd_AddCommand ("prvm_fields", PRVM_Fields_f);
 	Cmd_AddCommand ("prvm_globals", PRVM_Globals_f);
+	Cmd_AddCommand ("prvm_edictset", PRVM_ED_EdictSet_f);
 	// LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others))
 	Cvar_RegisterVariable (&prvm_boundscheck);
 	Cvar_RegisterVariable (&prvm_traceqc);
diff --git a/todo b/todo
index 7196b9b7..1ab5e93b 100644
--- a/todo
+++ b/todo
@@ -210,7 +210,7 @@ d darkplaces: q1bsp trace bug: scrags frequently fly through ceilings - this nee
 1 lhfire: get lhfire_gui build from Tomaz.
 1 lhfire: post lhfire_gui build.
 1 lhfire: prepare example scripts for release.
-2 darkplaces: add a "edictset" command to console to set a single field of an edict to the specified value
+-n darkplaces: add a "edictset" command to console to set a single field of an edict to the specified value
 2 darkplaces: add a flag/effect/whatever for double sided entity rendering (disable cull face for this entity) (yummyluv)
 2 darkplaces: add and document DP_SOUND_DIRECTIONLESSATTNNONE extension
 2 darkplaces: add and document DP_SOUND_STEREOWAV extension
-- 
2.39.5