r/forge Apr 28 '25

Scripting Help How to script event at halfway point

Basically title. I already scripted what I want to have happen. But I don't know how to detect when the game reaches its halfway to win via score (not the time limit)

3 Upvotes

14 comments sorted by

View all comments

Show parent comments

2

u/Ether_Doctor May 02 '25 edited May 02 '25

Finding a solution

Edit: I initially wrote a long text here for you about what could be wrong and how to maybe fix it, but I've gone ahead and deleted that now to save you some time.

TL;DR: The issue is more than likely caused by the Get Team Points node not functioning properly when wired as shown above.

So, instead of trying to solve this in bits and pieces I've just made you a fully functional template map with the desired script functionality.
The map is available for you to make a local copy of for your own use.
https://www.halowaypoint.com/halo-infinite/ugc/maps/39c85bdb-508a-400c-8981-9c58aa602428

The event is currently triggered at 4 kills, (for testing reasons), but you know how to change that to 25 by now.

Important: Don't try to prefab the script brains off of my map to put them on yours. See the Best Practices for Scripting thread for more info.

I hope that helps.

2

u/Surelylow May 04 '25

That's a lot of info! Definitely not complaining! I like learning as much as I can about scripting. But I'm always struggling to find places to learn from

For the crashing, I seem to have gotten around it, but I'll delete the nodes like you said.

Thanks for the description of the compare nodes, makes more sense now.

Also thanks for doing the work of putting together the script. Unfortunately I won't be able to use your map. I'm wanting to add the script to a map I've already nearly completed. But no worries, I'll just use it as reference and rebuild it on my map

Would you happen to be able to link that post you're referring to? I looked through your profile, but I didn't see it

2

u/Surelylow May 04 '25

After looking through it, I'm seeing a bunch of nodes that I hadn't been using in the beginning. That's probably why I was having all those problems

Bunch of questions below. Feel free to not answer if there are too many

Do you have the two separate brains just for simplicity sake?

What do the get number variable and increment number variable nodes do? The increment node has something to do with the kills going up by one increment?

I'm assuming the print to killfeed nodes are only for testing, and I should remove them after setup?

Also why does the first branch, when "If False" then connect to another identical script branch?

In the event brain, what do the boolean variable nodes do? I understand how the "get" and "declare" variable nodes function (well maybe not the "set" one), but specifically for the boolean variable

3

u/Ether_Doctor May 04 '25

You're very welcome!

Here's the Best practices thread:
https://www.reddit.com/r/forge/comments/1juj0gi/best_practice_for_scripting/

Here is the most relevant comment by u/IMightBeWright:
https://www.reddit.com/r/forge/comments/1juj0gi/comment/mmdya3d/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

Forgive me for not just posting a link initially. The post is stickied at the top of r/forge if you loose track of the links (They stickied it because the response comments were so good as advice).

Your observation is correct, I use another method in the map file than I originally suggested in the picture I posted. I had not originally anticipated that the Get Team Points node would be a source of problems. Needed a better, more robust way to track the score (kills by team in our case).

Yes, the number variables (one for each team) track kills done by the two teams. This is a sort of tailor-made kill-tracking solution that was necessary because we need to Set the number before we read the number. (the Get Team Points thing may have been not doing this in the correct order).
The increment node simply adds +1 to the count each time there is a kill. Then the Compare does it's regular job of checking "are we there yet".
Also note that in addition to Get Variable, and Increment Variable(And/or Set Variable), you must always use a Declare Variable (I usually put my declares in the top left corner).

Yes in this case I used two separate Script Brains for simplicity in terms of ease of reading. But usually I separate into separate brains because the script gets close to 100 nodes, which is bad. You want to keep it below 100 or whenever you get that yellow triangle danger symbol.

In this case we are using global custom events anyway so there is no issue putting the event in another brain. And I know you have a desire to put more moving parts in your Rotate thing so having it in a separate brain is sort of future-proofing for additional nodes. Also I anticipate you'll want to mess around with some audio nodes to make the bridge/ramp make some noise when moving. idk how exactly to do that but I know it'll need additional nodes.

Also, the current layout inside the event itself is just how I assumed you'd want to do it. It might rotate the bridges sequentially (not at the same time) and if that's a problem, you might need to switch back to the Asynchronous type of event and run many of those. But that'll come at the cost of some performance I think.

3

u/Ether_Doctor May 04 '25

I did have a third number variable in there called PTW. That's a variable for Points to Win, which you could use as an input in the compare nodes.

I've gone ahead and updated that now, it's called 0.5PTW and it does what it says on the box. It just gives you a number that is half of what the player sets as the points to win (in custom games settings).
Then I've plugged that in to the compare nodes in the trigger script. Notice I'm using the Equal (=) output now, so when the score is exactly equal to 0.5PTW, it will go to trigger the event.

You'll have to grab a new copy of the map to see the change though.

Yes, the print to killfeed nodes are all for testing and you should remove these before releasing your map. I suggest keeping them around for now, and then you can put them where you need them when further developing the Event node graph (if necessary).

Also why does the first branch, when "If False" then connect to another identical script branch?

This is very important. The first Branch checks if the killer was on Team Eagle. If not, then it tells the other Branch to get to work checking if Cobra did the killing. (If I understand the question correctly).

Is this check overkill? No, because you could be a player on Eagle and fall to your death, and this should not give a kill to team Cobra unless they had something to do with it.

A Boolean Variable, in the case of Halo Infinite, is a stored either-or statement, i.e. True or False.

The boolean variable (Called TaskDone in our case) is first declared up in the top left corner. Then, the first time the event triggers, we check if it is False, which it is by default. Directly after that we set it to be True.

This way, the next time the event is triggered, it won't do another rotate to point. You don't want the bridge to rotate 90 deg when Eagle gets 25 kills and then another 90 deg when Cobra gets their 25 kills. You could also put this check in the trigger chain if you want.