Modifying entity spawnflags / keyvalues with a script file
Quote from innocentive on December 16, 2012, 5:42 amI haven't been successful with my searches in this forum so i'm just asking away: How can I modify a spawnflag of an entity, or any other keyvalue of an entity for that matter, through vscript?
I've been looking at the KeyValues Class and found this site: http://wiki.alliedmods.net/KeyValues_(S ... _Scripting).
I still have no clue as to how to address the various keyvalues properly. This vscript command:
if (KvJumpToKey(EntityGroup[2], "enabled"))
produces the following error message:
AN ERROR HAS OCCURED [the index 'KvJumpToKey' does not exist]
Does that mean that the entity itself cannot be addressed as the 'holder' of the keyvalues? I have Basic knowledge of C++ and have only started to look into vscripting a couple of days ago so please forgive me if I'm totally blind here. Any help would be greatly appreciated.
I haven't been successful with my searches in this forum so i'm just asking away: How can I modify a spawnflag of an entity, or any other keyvalue of an entity for that matter, through vscript?
I've been looking at the KeyValues Class and found this site: http://wiki.alliedmods.net/KeyValues_(S ... _Scripting).
I still have no clue as to how to address the various keyvalues properly. This vscript command:
if (KvJumpToKey(EntityGroup[2], "enabled"))
produces the following error message:
AN ERROR HAS OCCURED [the index 'KvJumpToKey' does not exist]
Does that mean that the entity itself cannot be addressed as the 'holder' of the keyvalues? I have Basic knowledge of C++ and have only started to look into vscripting a couple of days ago so please forgive me if I'm totally blind here. Any help would be greatly appreciated.
Quote from innocentive on December 16, 2012, 7:40 amOk, I searched on and found the CScriptKeyValue commands as well as GetModelKeyValues (I really was blind!
). However, this set of commands provides read-only features ... any chance that there is a way to modify keyvalues?
Ok, I searched on and found the CScriptKeyValue commands as well as GetModelKeyValues (I really was blind! ). However, this set of commands provides read-only features ... any chance that there is a way to modify keyvalues?
Quote from FelixGriffin on December 16, 2012, 9:48 amNot as far as I know. Model KeyValues are meant to hold information about what the model can do, you can't usually change them after the model is compiled. The first page you were looking at is for editing the game's C++ itself.
What you're looking for is the second (undocumented) use of AddOutput. You can use it to change any keyvalues you want, although for some (such as changing to a non-precached model) it might not be a smooth change.
Instead of the string with all of the colons specifying an output, use AddOutput > KeyValue Value. For example, to make a cube become invisible when a button is pressed, OnPressed > cube > AddOutput > rendermode 10.
Note: If you're doing this from the console, you need to wrap the "KeyValue Value" bit in quotes or it will complain.
Spawnflags I'm not sure about, but you should be able to change them (albeit all at once) with AddOutput spawnflags 42 (or whatever).
Not as far as I know. Model KeyValues are meant to hold information about what the model can do, you can't usually change them after the model is compiled. The first page you were looking at is for editing the game's C++ itself.
What you're looking for is the second (undocumented) use of AddOutput. You can use it to change any keyvalues you want, although for some (such as changing to a non-precached model) it might not be a smooth change.
Instead of the string with all of the colons specifying an output, use AddOutput > KeyValue Value. For example, to make a cube become invisible when a button is pressed, OnPressed > cube > AddOutput > rendermode 10.
Note: If you're doing this from the console, you need to wrap the "KeyValue Value" bit in quotes or it will complain.
Spawnflags I'm not sure about, but you should be able to change them (albeit all at once) with AddOutput spawnflags 42 (or whatever).
Quote from innocentive on December 16, 2012, 2:37 pmI think I found another approach to what I want to achieve. The easiest (and maybe also safest?) way to edit keyvalues in vscript should be the EntFire function if I'm not mistaken. In addition with the autocomplete of the ingame console command ent_fire that shows you all the available actions it seems like a very powerful and efficient tool. Have to try that in more detail.
However, EntFire doesn't touch spawnflags so I will try your suggestion. Thanks for your input!!!
I think I found another approach to what I want to achieve. The easiest (and maybe also safest?) way to edit keyvalues in vscript should be the EntFire function if I'm not mistaken. In addition with the autocomplete of the ingame console command ent_fire that shows you all the available actions it seems like a very powerful and efficient tool. Have to try that in more detail.
However, EntFire doesn't touch spawnflags so I will try your suggestion. Thanks for your input!!!
Quote from FelixGriffin on December 16, 2012, 4:25 pmHm? What I'm referring to uses the EntFire function. Something like EntFire("object","addoutput","spawnflags 42",0.0,null); or such. The VDC on AddOutput explains the different ways you can do this.
Hm? What I'm referring to uses the EntFire function. Something like EntFire("object","addoutput","spawnflags 42",0.0,null); or such. The VDC on AddOutput explains the different ways you can do this.
Quote from innocentive on December 16, 2012, 4:37 pmOk, got it ... I kinda travelled on the same road as you but just didn't see that. As I said, I'm just trying to get a hold of vscripting for hammer for a couple of days now and it's such a mess with all the different sources of reference and lists of implemented commands that it took me a while to see that EntFire is what I needed ... which probably is hammer 101 for most long-term users.
Thanks for the AddOutput hint. Will be trying that tomorrow!
Ok, got it ... I kinda travelled on the same road as you but just didn't see that. As I said, I'm just trying to get a hold of vscripting for hammer for a couple of days now and it's such a mess with all the different sources of reference and lists of implemented commands that it took me a while to see that EntFire is what I needed ... which probably is hammer 101 for most long-term users.
Thanks for the AddOutput hint. Will be trying that tomorrow!
Quote from FelixGriffin on December 16, 2012, 8:54 pmYeah, the information you really want for vscripting is from the VDC List of Portal 2 Script Commands and the Squirrel Reference Manual. You should also look at scripts other people have made to avoid reinventing the wheel, most people here are happy to share scripts with attribution.
Yeah, the information you really want for vscripting is from the VDC List of Portal 2 Script Commands and the Squirrel Reference Manual. You should also look at scripts other people have made to avoid reinventing the wheel, most people here are happy to share scripts with attribution.

Quote from ChickenMobile on December 17, 2012, 7:16 pm
- Flags can be changed through an output using the ent_fire [name] addoutput "spawnflags [#]" command.
- Changing the flags of triggers and brush entities will work.
- You can change the flags of certain point entities that can be created through the console. E.g. ent_create env_shooter. This includes physic models.
- Changing the keyvalues can cause errors or even crashes when the entity relies on this single state. I can't tell you what exact entities, but there are a few.
EntFire("[name]", "addoutput", "spawnflags [number]", [delay])
However I wouldn't rely on changing the keyvalues for your mapping solution. Usually the only reason why you would want to change the keyvalues is if you want to script and create things inside the game. A single state of flags is only what you need as you can create other entities to fulfil your solution.
- Flags can be changed through an output using the ent_fire [name] addoutput "spawnflags [#]" command.
- Changing the flags of triggers and brush entities will work.
- You can change the flags of certain point entities that can be created through the console. E.g. ent_create env_shooter. This includes physic models.
- Changing the keyvalues can cause errors or even crashes when the entity relies on this single state. I can't tell you what exact entities, but there are a few.
EntFire("[name]", "addoutput", "spawnflags [number]", [delay])
However I wouldn't rely on changing the keyvalues for your mapping solution. Usually the only reason why you would want to change the keyvalues is if you want to script and create things inside the game. A single state of flags is only what you need as you can create other entities to fulfil your solution.
Quote from FelixGriffin on December 17, 2012, 8:32 pmThe only exception I can think of is changing targetname or classname, for certain filters or an env_entity_something.
The only exception I can think of is changing targetname or classname, for certain filters or an env_entity_something.
Quote from innocentive on December 18, 2012, 2:37 amChickenMobile wrote:However I wouldn't rely on changing the keyvalues for your mapping solution. Usually the only reason why you would want to change the keyvalues is if you want to script and create things inside the game. A single state of flags is only what you need as you can create other entities to fulfil your solution.That's great advice and I already thought of the alternative solution to just add multiple entities with different spawnflags and to switch between them. However, the amount of actions available with EntFire for each entity is poorly documented in the VDC. At least I couldn't find any overview of what actions are available for each entity and on top of that it would be great to have an explanation of what some of the actions do. So far I always check in the console with the ent_fire command and autocomplete which is a bit annoying ... is there another documentation of this?
That's great advice and I already thought of the alternative solution to just add multiple entities with different spawnflags and to switch between them. However, the amount of actions available with EntFire for each entity is poorly documented in the VDC. At least I couldn't find any overview of what actions are available for each entity and on top of that it would be great to have an explanation of what some of the actions do. So far I always check in the console with the ent_fire command and autocomplete which is a bit annoying ... is there another documentation of this?