Save variables from an entity, load on another map

Discussion in 'Mapping Questions & Discussion' started by DrGains, Dec 3, 2014.

  1. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    Hey guys, Im working on a large jump story map and I need to find a way to save variables from a math_counter and logic_auto to something and then onmapstart load those variables have them set to the entities. I already tried looking for a console script command and there doesnt seem to be a "varname {integer}" command. -If im wrong about this I would know how to save/load, badically just a pointeserver input after touching trigger and logic_auto on the onmapstart output. Anyway, is there a work-around here? Perhaps a client-sided addon or a formatted file like .cfg or .ini thaf can be freely written on and executed?
     
  2. UKCS-Alias

    aa UKCS-Alias Mann vs Machine... or... Mapper vs Meta?

    Messages:
    1,264
    Positive Ratings:
    748
    A few questions:
    - Does it involve multiple maps (i dont even know if map transitions are possible) or is it a single map with multiple rounds?
    - Is it ment to be local only (does it allow sv_cheats for example) or is it server sided?
    - How much values does it involve? Is it just 2 counters? Is there a max var size? (for example 2 counters of 5 possible numbers)

    Also, if it would allow a map to write anything to the disc then that potential could be a security risk. So if that would be possible im sure valve would at some point fix it.

    If it would send a var to the next map its the same story as that could potentialy be a security risk for cheating.

    If its ment as a point to save your status you could just have some sort of password and force the player to answer it by standing on 4 tiles in a 4 rows of digits (allowing 10000 options). Or maybe give them a teleport in the first place. People interested in the story in that case will just start at 1.

    A general idea on where you are using it for is important to know to come up with ideas to solve it. If its not possible to do it then at least alternatives can be provided.
     
  3. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    Hey thanks for the reply.
    -It does involve multiple maps. The transitions would be as easy as having a pointserver command executed by a trigger_once "map mapname_pt2".
    -It will use atleast 4 values:
    -Drexen's timer: minutes (up to 59), seconds (up to 59), milliseconds (up to 99)
    -A math_counter used to determine what weapons to strip based off of a seperate trigger_multiple (up to 639)
    -Then possibly 1 or 2 more math_counter's (values probably going as high as 32)
    -I dont mind sv_cheats being used, especially if it follows something along the lines of: "sv_cheats 1; write var1 00; sv_cheats 0" ('write obviously being a made up command)
    -It is meant to do nothing more than save values from map to map. I would rather not have player manually enter values by buttons or trigger-on-touch.
    -One last note that could be added is jump_ maps have a community around then dedicated to speedruns.
     
    Last edited: Dec 3, 2014
  4. Crash

    aa Crash func_nerd

    Messages:
    3,064
    Positive Ratings:
    4,550
    I have a feeling you'll need a server-side plugin to do what you're looking for.
     
  5. EArkham

    aa EArkham Necromancer

    Messages:
    1,555
    Positive Ratings:
    2,157
    You can use an env_global to transfer values from one round to another round within the same map. I do not believe any counter values you place on a env_global will be persistant to a new map, but you could test it to be sure. For transfering values from one map to another map you're probably going to need a plugin as Crash said.

    Typically all logic and entities are "reset" on map start/load, so those won't hold a value from one map to another. The value has to be stored somewhere, so that leaves cookies, a database, or possibly a custom client field.

    If env_global doesn't work (and I doubt it will from my experience with it), personally I'd just go with a plugin that stores to a database. Then you can display "fastest speeds this week" on a web site or whatever as well as in game.
     
    • Thanks Thanks x 1
  6. A Boojum Snark

    aa A Boojum Snark Toraipoddodezain Mazahabado

    Messages:
    4,767
    Positive Ratings:
    5,508
    I am going to second what Earkham said, try the env_global and look into the info on how to use it in single player, as its entire purpose is transferring entity information between maps (I didn't even know it could be used for rounds within a map).
     
    • Thanks Thanks x 1
  7. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    Alright, looks like env_global might work. However, in my hammer editor no env_global shows up in the list. I searched through my game definition files it does show up in base.fgd as an @BassClass (EnvGlobal), but there is no @PointClass (env_global) allocated to it, on top of that env_global isn't listed in the AutoVisGroups of the tf.fgd or tf-abs.fgd (which my hammer is directed to). So I could use a fix here of some kind

    I checked another forum (http://forums.steampowered.com/forums/showthread.php?t=2593863) that has a working solution for CS:S, but I need one for tf2 (since the definition could be completely different).
    So, would I be able to either get someones @PointClass of this, or the >common/Team Fortress 2/bin .fgd's, or even an updater for the .fgd's (tf-abs didnt add it, fantastic resource though!)?
    But if Im looking at all of this wrongly, how would I go about fixing this.
     
    Last edited: Dec 3, 2014
  8. A Boojum Snark

    aa A Boojum Snark Toraipoddodezain Mazahabado

    Messages:
    4,767
    Positive Ratings:
    5,508
    Open halflife2.fgd and find the env_global definition, and copy that over. It is in there since it is really only meant for singleplayer.
     
  9. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    So I managed to get the entity working, I might be close to either figuring it out, or finding out it's impossible. These are the current steps taken:

    -trigger_once[A]: OnStartTouch | counter_Digit_01 | FireUser1
    -math_counter[counter_Digit_01]: OnUser1 | var_Digit_01 | SetCounter
    -trigger_once[A]: OnStartTouch | servercommand | Command | changelevel jump_story_ch2_a1 | Delayed

    -Map Changes...

    -logic_auto: OnMapSpawn | var_Digit_01 | FireUser1
    -env_global[var_Digit_01]: OnUser1 | counter_Digit_01 | SetValue
    -logic_auto: OnMapSpawn | relay_start | Trigger | Delayed

    So I think there are a few possible reasons why it's not working yet:
    -env_global only works with transitions, not changelevels. The only way to use a transition (changelevel2 "map_name") is by running the game in single player.
    -SetValue needs to have a parameter override in order for it to actually set a value, I left it at <none>.
    -env_global on the 2nd map sets value back to 0 on map start up (as if the initial value overrides the set saved value.
    *These are all just thoughts, not definite reasons

    ++: 'Initial State' on both maps are set to On, did not touch 'Global State to Set'.
     
  10. EArkham

    aa EArkham Necromancer

    Messages:
    1,555
    Positive Ratings:
    2,157
    You actually need to set a value. On my multistage stuff (this was for a different source game, not TF2, so I can't say if this will even work the same), I was using logic like this on the final "win" trigger for stage 1:

    Code:
    OnStartTouch -> round_control (name of env_global) -> AddOutput -> globalstate round1
    OnStartTouch -> round_control -> TurnOn
    OnStartTouch -> round_control -> AddOutput -> globalstate round2
    OnStartTouch -> round_control -> TurnOff
    Then using logic_auto entities with GlobalStateToRead set to round2 and firing outputs with OnNewGame.

    I'm not really clear on why I was doing the TurnOn before changing the globalstate and then TurnOff after. Maybe I needed to make sure it always had a "default" custom value first, or maybe an env_global needs to be "off" before it will persist, or maybe it's just leftover code from experimenting. I honestly can't remember.

    [EDIT] Strike all of that. I forgot: you have to turn on the state. So basically what I was doing was setting round1 as the globalstate and turning that on, then setting round2 as the globalstate and turning that one off. So this is in fact not the logic from the end of stage1 trigger, it's the one that sets it to stage1 on a FAIL to win of stage1 (essentially saying restart the same level).

    But even still, this is a lot simpler than what you're trying to do. I was basically just setting toggles to determine which stage of the map the players were supposed to be in; and I was only doing this because there was no equivalent of the TF2 logic that normally handles multistage maps.

    What you might try now is AddOutput -> globalstate <some number>, then TurnOn. Then on the new map try checking with a logic_auto for GlobalStateToRead <some_number> and show a sprite or something if the value is there to see if it carries over.

    I still feel like your strongest solution to this is to use a plugin and database. Then you'll be able to track time per player as well as whatever other info you want.
     
    Last edited: Dec 4, 2014
  11. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    So basically, I should do a test without the counter and just test till I see global is persistant. Then add counter variables and somehow pull the globalstate <num> to the counters.
    So this just adds 1 question:
    -How do you pull/send values inbetween math_counter and env_global? Is there something in the math counters like: !Value <num> or a math_counter_name Value <num> that I could be using?

    ++I wont be able to test for another 1 1/2 hours..
     
  12. EArkham

    aa EArkham Necromancer

    Messages:
    1,555
    Positive Ratings:
    2,157
    Yup. Until you confirm the value will be persistant, there's no reason to plug in all the other logic. If you do confirm it, then you can pass the value of the math_counter like so:

    On a trigger_multiple at the end of your course, use an output like OnTouchStart -> <name_of_math_counter> -> GetValue.

    Then on the math_counter: OnGetValue -> <name_of_env_global> SetCounter <none> (if the parameter is none, then it should pass the math_counter's current value).

    This is off memory though, just play with it to confirm. BoojamSnark is the resident entity genius so I'll leave it to him if I'm misremembering.

    And again I think you'd be better off using a plugin + database for real power in handling this. :p
     
  13. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    Finally got to trying it.. no go.

    These are my outputs:
    -map 1, trigger_once: [var_Digit_01 is my env_global entity]
    Code:
    OnStartTocuh | var_Digit_01 | AddOutput | globalstate 0 | 0.00
    OnStartTouch | var_Digit_01 | TurnOn | | 0.01
    OnStartTouch | var_Digit_01 | AddOutput | globalstate 7 | 0.02
    OnStartTouch | var_Digit_01 | TurnOff | | 0.03
    OnStartTouch | servercommand | Command | changlelevel jump_story_ch2_a1 | 0.04
    -map 2, logic_auto:
    Code:
    Global State to Read | 7
    Code:
    OnMapSpawn | relay_GlobalSpeedRun_start | Trigger | | 0.05
    I don't really see any problems in this, I now have all Intial State's set to Off, thoughts?

    *OnNewGame, doesnt change anything
    *I dont want the values to be ran through a server, since each player needs to have their own path (math_counter: weapons obtained, doors unlocked, change level once 1 player is at the end of the map instead of having other people forcefully moving along with the player touching a trigger)
     
    Last edited: Dec 4, 2014
  14. EArkham

    aa EArkham Necromancer

    Messages:
    1,555
    Positive Ratings:
    2,157
    I'm out of ideas at this point, sorry.
     
  15. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    Nasty, alrigjt do you know any multi-stage maps or a prefab that has env_global for tf2
     
  16. EArkham

    aa EArkham Necromancer

    Messages:
    1,555
    Positive Ratings:
    2,157
    I'm afraid not. The map I was doing all this experimentation on was for Zombie Panic! Source as a proof of concept, and we never released any functional multistage maps before the team faded away.

    TF2 handles multistage without env_global. You can look at BoojamSnark's gamemode library. Should be all the entities you need in that.
     
  17. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    Buddy from the jump community had been working on this a while back, still figuring out the logic behind it. Here's his vmf's if anyone's interested: https://www.dropbox.com/s/qu3s6uwo1o6mrf1/globals.rar?dl=0. The maps work fine, and it allows you to go back and forth. Also the counter value in the env_global is bugged for tf2.
     
  18. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    So everything was working fine, then there must have been an update: either tf2, hammer, or abs resource tool.. When trying to give env_global an imput from something else there is no longer a TurnOn / TurnOff option. Also there env_global has this [OBSOLETE] picture instead of that grey cube. What the h* happend?
     
  19. EArkham

    aa EArkham Necromancer

    Messages:
    1,555
    Positive Ratings:
    2,157
    Updates will often reset the FGD. Go back and check to see if you need to repaste in the env_global entry.

    Also, technically the FGD is just an interface for mappers... the entity should still function correctly unless the update changed something with env_global itself (unlikely, as it's a default source entity).
     
  20. DrGains

    DrGains L1: Registered

    Messages:
    21
    Positive Ratings:
    1
    Thanks man, youre really helpful