Modifying entity spawnflags / keyvalues with a script file

Avatar
innocentive
52 Posts
Posted Dec 16, 2012
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.

Advertisement
Registered users don’t see ads! Register now!
Avatar
innocentive
52 Posts
Posted Dec 16, 2012
Replied 1 hour later
Ok, I searched on and found the CScriptKeyValue commands as well as GetModelKeyValues (I really was blind! :angrysquare: ). However, this set of commands provides read-only features ... any chance that there is a way to modify keyvalues?
Avatar
FelixGriffin
2,680 Posts
Posted Dec 16, 2012
Replied 2 hours later
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).

Avatar
innocentive
52 Posts
Posted Dec 16, 2012
Replied 4 hours later
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!!! :thumbup:

Avatar
FelixGriffin
2,680 Posts
Posted Dec 16, 2012
Replied 1 hour later
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. :wink:
Avatar
innocentive
52 Posts
Posted Dec 16, 2012
Replied 12 minutes later
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!

Avatar
FelixGriffin
2,680 Posts
Posted Dec 16, 2012
Replied 4 hours later
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.
Avatar
ChickenMobile
2,460 Posts
Posted Dec 17, 2012
Replied 22 hours later
  • 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.

    """"""

    Avatar
    FelixGriffin
    2,680 Posts
    Posted Dec 17, 2012
    Replied 1 hour later
    The only exception I can think of is changing targetname or classname, for certain filters or an env_entity_something.
    Avatar
    innocentive
    52 Posts
    Posted Dec 18, 2012
    Replied 6 hours later

    ChickenMobile 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?

    Avatar
    josepezdj
    2,386 Posts
    Posted Dec 18, 2012
    Replied 18 minutes later
    Rand0mnumbers made a couple of awesome video tutorials about vscripting (apart from another bunch of useful tutorials). I think they will be useful for you, check:

    nfL3x8XylGc

    WqkkBEkMyIs

    Avatar
    innocentive
    52 Posts
    Posted Dec 18, 2012
    Replied 2 minutes later
    Thanks! Will check them out soon... :smile:
    Avatar
    FelixGriffin
    2,680 Posts
    Posted Dec 18, 2012
    Replied 13 hours later
    To find out what EntFire can do, you can read that entity's page on the VDC, that lists all inputs and outputs. Or create an entity of that type in Hammer and click HELP.

    Just wondering...you do understand inputs and outputs, right? You learned those before you started VScripting?

    Avatar
    innocentive
    52 Posts
    Posted Dec 18, 2012
    Replied 19 minutes later
    Totally ... I think I can say that I understand Hammer's IO System pretty well. The thing is that I want to change the launch direction of a trigger_catapult ingame according to the behaviour of the player. As far as I can see there is no way to do that with the IO of Hammer. True, I don't need to write directly into the KeyValues, I can do that with EntFire and I'm grateful for you pointing that out. It just took me quite long to find the correct action to feed Entfire with for the target. As far as I know there's no respective reference listing all actions you can fire for any given entity. I understand that Hammer and VDC don't list all KeyValues but maybe I'm wrong about that.

    It would be so much more efficient if you could just access the KeyValues ... that's all.

    Avatar
    Brainstone
    401 Posts
    Posted Dec 18, 2012
    Replied 32 minutes later
    Give your trigger_catapult the input setlaunchtarget <targetname>. Not listed anywhere, but actually works. Some guys on the forum found this out once. I stumbled upon it and used it. Works perfectly.

    As launchtarget you can take preferably info_targets, but !player is possible, too. In my map (a bossfight), I parented a point_template to the player, which created static info_targets, which were then shot by bombss a short period of time afterwards.

    Avatar
    FelixGriffin
    2,680 Posts
    Posted Dec 18, 2012
    Replied 1 hour later
    Ah, okay. Just checking. And there is a list, as I said, on the VDC page for each entity. Anything EntFire does can be done with an output, so you can change KeyValues that way too.

    Also, remember that the catapult only applies a force once. If bombs target the player, for example, the player can dodge, because it won't keep correcting them. This wrecked a big section of a map once when I didn't count on player movement.

    Avatar
    innocentive
    52 Posts
    Posted Dec 18, 2012
    Replied 56 minutes later
    I haven't found such list on VDC ... we're talking about developer.valvesoftware.com, right?

    Let's just take the trigger_catapult as an example: when I check the corresponding page on VDC, I see multiple entries. Looking at the keyvalues of a trigger_catapult in Hammer will show quite a lot in SmartEdit but once you turn it off there's just about half of the keyvalues left. So this is where you start trying what would be the right key value combination to work with. On top of that, and not necessarily making things easier, there's the autocomplete of the ingame console on the ent_fire command. I've gone through the trouble of compiling the list of 'actions' the Portal 2 console offers for a trigger_catapult entity:

    addcontext
    addoutput
    alpha
    alternativesorting
    callscriptfunction
    clearcontext
    clearparent
    color
    disable
    disabledamageforces
    disabledraw
    disabledrawinfastreflection
    disablereceivingflashlight
    disableshadow
    dispatchresponse
    enable
    enabledamageforces
    enabledraw
    enabledrawinfastreflection
    enablereceivingflashlight
    enableshadow
    endtouch
    fireuser1
    fireuser2
    fireuser3
    fireuser4
    kill
    killhierarchy
    removecontext
    removepaint
    runscriptcode
    runscriptfile
    setdamagefilter
    setexactvelocitychoicetype
    setlaunchtarget
    setlocalangles
    setlocalorigin
    setparent
    setparentattachment
    setparentattachmentmainoffset
    setphysicsspeed
    setplayerspeed
    setteam
    starttouch
    toggle
    touchtest
    use

    You see that there are substantial differences between all 'lists' either on VDC or in Hammer or in Portal 2 console. I thought it would be easy to go to the source and make sense of this all ... look into the entity keyvalues themselves instead of looking into secondary sources.

    Have I made myself clear now? Is there a way to access (read-only) the Entity keyvalue keys and preferably also their values through vscript or whatever else?

    Avatar
    innocentive
    52 Posts
    Posted Dec 18, 2012
    Replied 9 minutes later

    Brainstone wrote:
    Give your trigger_catapult the input setlaunchtarget . Not listed anywhere, but actually works. Some guys on the forum found this out once. I stumbled upon it and used it. Works perfectly.

    As launchtarget you can take preferably info_targets, but !player is possible, too. In my map (a bossfight), I parented a point_template to the player, which created static info_targets, which were then shot by bombss a short period of time afterwards.

    Thanks for that tip ... but I don't want the trigger_catapult to aim at the player and I had already found 'setlaunchtarget' as you can see in my previous post. Believe me when I say there's no way you can achieve what I want with the IO system of Hammer because (a) there is no particular target to catapult to, and (b) I need to stay in Charge of the flight route which is not possible with Launch targets. In fact I need vector calculations with coordinates that are set by actions of the player. I wish I could be more clear but i don't wanna give my idea away.

    Thanks again!

    Advertisement
    Registered users don’t see ads! Register now!
    Avatar
    FelixGriffin
    2,680 Posts
    Posted Dec 18, 2012
    Replied 3 hours later
    Those are all the commands the game recognizes for the entity, not all of them work on that one (they're inherited and do nothing, such as Alpha). Also, KVs only show with SmartEdit off if their value is non-default.