Contraption: Random Weapon Box

bubuddhacraneMar 09 2016101.6K11
    Halo and Forge Discussion

Edit: I've had to rework the Scripting because it turns out that the Scripting engine becomes unreliable as the map/scripting becomes more complex. Messages that are meant to fire one after another start to fire at the same time instead, which broke my logic. On the plus side, you're no longer forced to have an odd number of weapons in the box!

This will be a 2-part post. In the first part I'm going to explain how to create a stationary weapon box, which spawns you a random weapon every time you activate it, until it runs out of weapons (due to weapon spawning limitations). In the second part (coming later) I'll explain how to turn that stationary weapon box into one that moves - just like in COD Zombies.

Many of you may be aware that ForgeHub already provided a tutorial on how to create a random weapon box. My version is different though, for the following reasons:

  • It won't give you duds - Forgehub's version could give you nothing at all if the box tried to give you a weapon that it had already spawned in. My version is guaranteed to give you a weapon until it runs out completely.

  • It won't give you 2 weapons at once - Forgehub's version could sometimes give you 2 weapons from one pull of the box. My version only give you one weapon per pull, every time.

On with the show! Here's how to create a stationary random weapon box. Note that in my example I'm using a weapon count of 5:

To allow a choice of 5 random options, we need 10 Scripts:

Script 1: Initially enables option 1 at the start, and then again every 1 second
Condition (Timer) (Initial Delay: 0.00) (Repeat Delay: 1.00)
Action [PowerSet: Alpha: On]

Script 2: Disables option 1 0.10 seconds after it's been enabled
Condition (Timer) (Initial Delay: 0.10) (Repeat Delay: 1.00)
Action [PowerSet: Alpha: Off]

Script 3: Enables option 2 0.10 seconds after option 1 has been disabled
Condition (Timer) (Initial Delay: 0.20) (Repeat Delay: 1.00)
Action [PowerSet: Bravo: On]

Script 4: Disables option 2 0.10 seconds after it's been enabled.
Condition (Timer) (Initial Delay: 0.30) (Repeat Delay: 1.00)
Action [PowerSet: Bravo: Off]

Script 5: Enables option 3 0.10 seconds after option 2 has been disabled
Condition (Timer) (Initial Delay: 0.40) (Repeat Delay: 1.00)
Action [PowerSet: Charlie: On]

Script 6: Disables option 3 0.10 seconds after it's been enabled.
Condition (Timer) (Initial Delay: 0.50) (Repeat Delay: 1.00)
Action [PowerSet: Charlie: Off]

Script 7: Enables option 4 0.10 seconds after option 3 has been disabled
Condition (Timer) (Initial Delay: 0.60) (Repeat Delay: 1.00)
Action [PowerSet: Delta: On]

Script 8: Disables option 4 0.10 seconds after it's been enabled.
Condition (Timer) (Initial Delay: 0.70) (Repeat Delay: 1.00)
Action [PowerSet: Delta: Off]

Script 9: Enables option 5 0.10 seconds after option 4 has been disabled
Condition (Timer) (Initial Delay: 0.80) (Repeat Delay: 1.00)
Action [PowerSet: Echo: On]

Script 10: Disables option 5 0.10 seconds after it's been enabled.
Condition (Timer) (Initial Delay: 0.90) (Repeat Delay: 1.00)
Action [PowerSet: Echo: Off]

What's happening here is that we're creating a roulette of Timers; which means that we're cycling from one Power Channel to the next as quick as the Timers allow, and only one Power Channel will be active at a time (with a 0.10 second gap between each switchover to ensure that we don't get any quirky behaviour as we transition from one channel to the next).

The process of building these Timers is to just keep adding 0.10 to the Initial Delay as we add each Script; and then the Repeat Delay is 0.10 + the highest Initial Delay you ended up with. Bear this process in mind if you want to have a different number of options than 5.

Setup a switch to control how we choose one of the 5 random options. It needs 2 Scripts, and a respawn delay:

Script 1: Activate the switch to turn on Foxtrot
Condition (OnInteraction)
Action [PowerSet: Foxtrot: On]

Script 2: Despawn the switch after it's activated, so that it can't be used again until after a specified respawn delay
Condition (OnInteraction)
Action

Additional Object Setttings
- Respawn: On, Timer: x- where 'x' is whatever delay, in seconds, you want before allowing the switch to be activated again.

Give the switch a respawn time of whatever delay you want, to control when players are allowed to activate the switch again.

We want each weapon to be one of the random choices, and to only spawn in when the player hits the switch. To do this, each weapon will require 3 Scripts. I'm not going to show the Scripts for every weapon here - just give each weapon the same Scripting, but switch out Alpha for Bravo/Charlie/Delta/Echo on each weapon.

Script 1: Start the game with the weapon despawned
Condition (OnRoundStart)
Action

Script 2: Spawn this weapon when the switch is activated, if the randomiser has picked this weapon to be "The One" (Note: Change Alpha to Bravo/Charlie/Delta/Echo for the other weapons)
Condition (OnMulti: Minimum=2) (OnPower: Foxtrot: On) (OnPower: Alpha: On)
Action

Script 3: Reset the switch's activation channel (this also acts as a flag that a weapon has successfully spawned in)
Condition (OnSpawn)
Action [PowerSet: Foxtrot: Off]

Additional Object Settings:
- Respawn: Off
- Only let the Scripts handle the spawning.

The way this works is that the weapon will only spawn when its matching Power Channel is On at the same time the Switch's Power Channel is on. So depending on when the player hits the switch will dictate which weapon Power Channel will happen to be On at that given moment.

Because the Switch's Power Channel stays On until a weapon has spawned in, this prevents the box from giving duds; and because we've allowed a 0.10 second gap between each weapon's Power Channel being On, we won't get more than one weapon spawning in at a time.

We need to add a Timeout Timer that forces the Foxtrot Power Channel to Off, if there are no more weapons left in the box; otherwise as soon as we're out of weapons, the Switch will never be able to activate again (for when weapons have finally despawned off the map)

A note on Timers: A Timer allows us to add delays to our Scripts. To set one up, we use any old object, and make use of its spawning to trigger a delay in our Scripts. Watch the ForgeHub tutorial for more info on Timers:
https://www.youtube.com/watch?v=nkgPoxsO8GE

Timer

Script 1: When the switch is activated, kick off this Timer.
Condition (OnPower: Foxtrot: On)
Action

Script 2: Make sure we reset the Switch's Power Channel after this Timer expires.
Condition (OnSpawn)
Action [PowerSet: Foxtrot: Off]

Additional Object Setttings
- Respawn: On, Timer: 2 - after despawning, respawn back in after a 2 second delay (this delay needs to be longer than it takes the randomiser roulette Timer to complete a full cycle of all the channels).

Quite a lot of information to process there, to be fair!

To see all this in action, check out the demo map on my fileshare (GT: BuddhaCrane) called "Script: Rnd Wpn Box".

Part 2 - Moving Box: Coming later in the week