{
float created_saved_value;
entity e;
-
+
if not(tmp_cvar || tmp_value)
{
dprint("Error: Invalid usage of cvar_settemp(string, string); !\n");
return FALSE;
}
-
+
+ if(!cvar_type(tmp_cvar))
+ {
+ print(sprintf("Error: cvar %s doesn't exist!\n", tmp_cvar));
+ return FALSE;
+ }
+
for(e = world; (e = find(e, classname, "saved_cvar_value")); )
if(e.netname == tmp_cvar)
goto saved; // skip creation
-
+
// creating a new entity to keep track of this cvar
e = spawn();
e.classname = "saved_cvar_value";
e.netname = strzone(tmp_cvar);
e.message = strzone(cvar_string(tmp_cvar));
created_saved_value = TRUE;
-
+
// an entity for this cvar already exists
:saved
-
+
// update the cvar to the value given
cvar_set(tmp_cvar, tmp_value);
-
+
return created_saved_value;
}
{
float i;
entity e;
- while((e = find(world, classname, "saved_cvar_value")))
+ while((e = find(e, classname, "saved_cvar_value")))
{
- cvar_set(e.netname, e.message);
- remove(e);
+ if(cvar_type(e.netname))
+ {
+ cvar_set(e.netname, e.message);
+ remove(e);
+ }
+ else
+ print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", e.netname));
}
-
+
return i;
}