Contraption: Random Weapon Box

Discussion in 'Halo and Forge Discussion' started by buddhacrane, Mar 9, 2016.

  1. buddhacrane

    buddhacrane Promethean
    Senior Member

    Messages:
    1,204
    Likes Received:
    116
    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 [Despawn]

    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 [Despawn]

    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 [Spawn]

    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:


    Timer

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

    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
     
    #1 buddhacrane, Mar 9, 2016
    Last edited: Mar 11, 2016
  2. Psychoduck

    Psychoduck Spartan II
    343 Industries Cartographer Forge Critic Senior Member

    Messages:
    1,528
    Likes Received:
    428
    :tedium:
     
    MultiLockOn and Yumudas Beegbut like this.
  3. MartianMallCop

    MartianMallCop Spartan II
    Forge Critic

    Messages:
    803
    Likes Received:
    1,935
    One upping me again as always. :) awesome job
     
    Yumudas Beegbut likes this.
  4. Sn1p3r C

    Sn1p3r C Halo 3 Era
    Creative Force

    Messages:
    379
    Likes Received:
    578
    This is fantastic, buddhacrane! Really excited for part 2.
     
  5. Yumudas Beegbut

    Yumudas Beegbut Spartan I
    Wiki Contributor

    Messages:
    391
    Likes Received:
    349
    This is tight.

    Might want to be explicit about turning each weapon's Respawn property to Off. And what timer objects are, in case someone starts with this one. I think, right?

    Do the (On Message: foxtrot) Multi conditions initially work because foxtrot power is turned on? Is that mechanism potentially a "bug" that could get fixed down the line? I think those two scripts would be future-proofed if you add a (On Power: foxtrot: Toggle) condition and leave Minimum where it is. Or would Toggle make one fire when it's turned off too?

    The only terrible part is waiting one whole script cycle to despawn the switch based on foxtrot instead of (On Interaction), during which time something awful might happen, even though I don't see how anything could and basing the operation around foxtrot is prolly a more flexible and reusable design. So there. :p

    I kinda like the idea of the 2nd crappy weapon. We could add additional weapons to have a weighting system. If it's a rockets sort of day then 3 of maybe 7 weapons could be rockets. Or there could be a booby prize for the last item. I'd say grunt with a plasma nade in each hand, but I can't get the nades to blow with a script. :grunt:
     
    Xandrith likes this.
  6. buddhacrane

    buddhacrane Promethean
    Senior Member

    Messages:
    1,204
    Likes Received:
    116
    What can I say, I do like a challenge :)

    Sounds good, will do!

    In a multi condition, the "On Message", and "Power: Toggle" conditions behave the same - which one you choose to use is just semantics. Either of those conditions would trigger when Foxtrot either receives a Message, or its Power is toggled (either On or Off). So adding the Toggle to this would cause both conditions to fire every time - it would be the same as putting in 2 "On Message: Foxtrot" conditions. The "On Power: Foxtrot: On" in the conditions already makes sure the overall condition doesn't trigger when Foxtrot is turned Off.

    One could argue that the fact multi conditions behave this way is a bug. But I'll worry about it if it ever gets changed, lol.


    EDIT: My mistake (this is what I get for posting replies at work, away from the game, and when I have a terrible memory, lol). In the multi condition, "Power: Toggle" and "On Message" do NOT behave exactly the same. A "Power: Toggle" will ONLY trigger when the Power is toggled, but an "On Message" triggers when a message is received AND ALSO when the Power is turned ON - which is the behaviour my Scripts required.
     
    #6 buddhacrane, Mar 10, 2016
    Last edited: Mar 10, 2016
    Yumudas Beegbut likes this.
  7. Yumudas Beegbut

    Yumudas Beegbut Spartan I
    Wiki Contributor

    Messages:
    391
    Likes Received:
    349
    Heheh, too true. And this setup would only take seconds to update anyways.

    I thought that the Multi (On Message) condition fire for messages or when the power is turned on (not off), but I guess I haven't really tested it (once again). And I definitely haven't tested the Multi (On Power) conditions when messages are sent. And I vaguely recall something about some Multi's firing when Minimum=3 but there's only being 2 conditions used... Like if 2 actions do the same thing then they both count towards Minimum or something.

    Now I've got to test the crap outta the message/power conditions. So many possible combinations and settings that can come into play. Curses! If you guys have any notes that can be quickly shared that'd be great, but don't go to any lengths. I'll post the info when I'm done if it seems like it'll help others.
     
  8. buddhacrane

    buddhacrane Promethean
    Senior Member

    Messages:
    1,204
    Likes Received:
    116
    You are indeed correct. I had a brain fart when I initially replied. I've edited my post to correct myself lol.
     
    Yumudas Beegbut likes this.
  9. Agent Zero85

    Agent Zero85 Spartan I
    Wiki Contributor

    Messages:
    399
    Likes Received:
    432
    Wheres the moving box :(
     
  10. Yumudas Beegbut

    Yumudas Beegbut Spartan I
    Wiki Contributor

    Messages:
    391
    Likes Received:
    349
    Yeah, where's part 2? Where you at, dog? Bird?@buddhacrane
     
  11. Agent Zero85

    Agent Zero85 Spartan I
    Wiki Contributor

    Messages:
    399
    Likes Received:
    432
    Its harder than it looks, i almost got my scripting to work, but in the end i failed, in gonna leave it up to the OP to finish this, if you need help with this hit me up, by the number of times ive had to remake my box im a pro by now.
     
    #11 Agent Zero85, Apr 25, 2016
    Last edited: Apr 26, 2016
  12. Agent Zero85

    Agent Zero85 Spartan I
    Wiki Contributor

    Messages:
    399
    Likes Received:
    432
    Redacted: Wasn't Important, unneeded bump.
     
    #12 Agent Zero85, Apr 25, 2016
    Last edited: Apr 26, 2016

Share This Page