Save variables from an entity, load on another map

DrGains

L1: Registered
Dec 2, 2014
27
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?
 

UKCS-Alias

Mann vs Machine... or... Mapper vs Meta?
aa
Sep 8, 2008
1,264
816
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.
 

DrGains

L1: Registered
Dec 2, 2014
27
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:

EArkham

Necromancer
aa
Aug 14, 2009
1,625
2,773
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.
 

A Boojum Snark

Toraipoddodezain Mazahabado
aa
Nov 2, 2007
4,775
7,669
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).
 

DrGains

L1: Registered
Dec 2, 2014
27
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:

DrGains

L1: Registered
Dec 2, 2014
27
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'.
 

EArkham

Necromancer
aa
Aug 14, 2009
1,625
2,773
-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.

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:

DrGains

L1: Registered
Dec 2, 2014
27
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..
 

EArkham

Necromancer
aa
Aug 14, 2009
1,625
2,773
So basically, I should do a test without the counter and just test till I see global is persistant.

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
 

DrGains

L1: Registered
Dec 2, 2014
27
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:

DrGains

L1: Registered
Dec 2, 2014
27
1
Nasty, alrigjt do you know any multi-stage maps or a prefab that has env_global for tf2
 

EArkham

Necromancer
aa
Aug 14, 2009
1,625
2,773
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.
 

DrGains

L1: Registered
Dec 2, 2014
27
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?
 

EArkham

Necromancer
aa
Aug 14, 2009
1,625
2,773
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).