Help with math logic Created 13 years ago2011-09-15 12:06:12 UTC by Tetsu0 Tetsu0

Created 13 years ago2011-09-15 12:06:12 UTC by Tetsu0 Tetsu0

Posted 13 years ago2011-09-15 12:06:12 UTC Post #298967
Sort of a vague thread, i know. But I'm having trouble with some math logic things in source.

Here's what I'm trying to do: I have a number of keys in a level, when you get a key it adds 1 to a math_counter. I also have a number of locked doors in my level. When you approach a locked door, and you have at least one key, the door should open permanently and subtract 1 from the math_counter.

I know how to set up the math_counter and I've used logic_cases before, but is there any way to get the math_counter to send it's value to the logic_case? (and from there open a door)

So is this possible?: (pseudo-code)
On trigger >> logic_case >> getvalue >> math_counter
Case1 - open door, subtract 1 from math_counter
Case2 - open door, subtract 1 from math_counter
Case3 - open door, subtract 1 from math_counter

If anyone has ever played Zelda, that's the key system I'm trying to re-create. Any key can unlock any door, but you can only use a given key once.
Tetsu0 Tetsu0Positive Chaos
Posted 13 years ago2011-09-15 13:00:52 UTC Post #298969
hmm... maybe this will work:
place a trigger_once around every key and a math_counter.
let's name the trigger key1_trigger
when you pick up a key its trigger will add 1 to the key's counter.
the counter will hit max on 1 and will activate all doors' masters(which will unlock them).when you open a door it will first kill its own master resulting in permanent unlock.then it will subtract from all keys' counters 1,they will hit min(0) and will deactivate all masters,but since the opened door's master is gone it will not lock anymore.
Haven't tested it but try
And I don't think it's possible to have the math_counter to send its value to any entity,sorry :(
Posted 13 years ago2011-09-15 13:08:52 UTC Post #298970
Wouldn't that limit the amount of keys you could have at once to 1 though?

Just wondering, I know nothing about Source.
Jessie JessieTrans Rights <3
Posted 13 years ago2011-09-15 13:11:48 UTC Post #298971
Scotch is right :-/
im going to keep futzing with it.
i wish hammer had a script editor.
that'd be SO much easier
Tetsu0 Tetsu0Positive Chaos
Posted 13 years ago2011-09-15 13:16:20 UTC Post #298972
no.you will just place a math_counter for each key.and a master for each door.no limit at input/outputs :)
Posted 13 years ago2011-09-15 13:18:02 UTC Post #298973
if you really want i'll try that system just to save you some time :)
Posted 13 years ago2011-09-15 13:53:07 UTC Post #298974
alright. now i get it haha. makes sense.. its a bit more complex than i would have hoped but that should work =]
right now, this is a simple part of my map, so i can just link one key to each door but when there's an option i'll certainly use that method.
Tetsu0 Tetsu0Positive Chaos
Posted 13 years ago2011-09-15 16:15:34 UTC Post #298978
NOTE:If you want to make this system work you'll have to get somewhere an obsolete entity as the goddamn doors don't accept ONLY that type of master.
I tried a couple of differrent systems,but, unfortunately, they don't work.
Posted 13 years ago2011-09-15 16:51:50 UTC Post #298980
You could make the math counter trigger a relay once it reaches a specific value which allows you to open doors, and as soon as you open a door it'd subtract from the math counter leaving it up for retriggering
Should be rather simple :)

I made an examplemap about counters but I'm not sure how much it covers, and I used a ton of them in my "Nanofight" map. They sure open up a lot of doors, no pun intended
Madcow MadcowSpy zappin my udder
Posted 13 years ago2011-09-19 15:39:09 UTC Post #298981
I have an idea.. i could just lock the doors when the value is minimum.. right?

yeah i figured it out:

Math_Counter
  • Max Value: 1
  • Name: key_count
Outputs
  • On Hit Max >> Door01 >> Unlock
  • On Hit Max >> Door02 >> Unlock
Math_Counter
  • Max Value: 1000
  • Name: key_count
Outputs
  • On Hit Min >> Door01 >> Lock
  • On Hit Min >> Door02 >> Lock
Door01/02
  • Delay before close: -1
Outputs
  • On Open >> key_count >> Subtract >> 1
Trigger_Once(key trigger)
Outputs
  • On Trigger >> key_count >> add >> 1
So the first math counter only counts to 1. So no matter how many keys you get, so long as you have 1, it unlocks all the doors.
The second math counter only locks all the doors once it has reach it's minimum value. ( I have it set to 1000 because I'm never going to have that many keys in a level, and the value needs to be more than zero or else the "on max" and "on min" won't work)

Other than that the doors need only one output: subtract from counter, and source itself handles the locking/ unlocking. So long as they open and stay open ( delay before close: -1) everything's flawless.
Tetsu0 Tetsu0Positive Chaos
You must be logged in to post a response.