System Multiplayer Ammo System

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
Ammo System by Duderock101

Introduction

You need a good ammo system for any zombie survival maps where you fight with guns. Or maybe you’re making a battle map where you fight with guns. I don’t mind but this system will teach you how to create an ammo system effectively that will work for multiplayer as well as single player. All you need is very limited or higher knowledge of the Variable editor and a basic knowledge of the trigger editor that most who use the WE should have. So let’s get started? What will this ammo system give us?
A unit attacks with a gun and needs ammo (gold). The unit gets ammo from clips (lumber). Run out of gold you use lumber, run out of gold and lumber then you don’t fire, easy and simple.

Triggers

Ok first of all we need to create a variable. I am afraid to say that this system will only work for one unit per player. Now create a unit variable called Main_Unit, it must be array and set the array number to the amount of players that will be controlling an ammo using unit. My map will be having 3 players that control 3 ammo using units so I set the array to 3.
Here is the trigger –

Code:
set vars
    Events
        Map initialization
    Conditions
    Actions
        Set Main_Unit[1] = Marine 0000 <gen>


Ok now to the attacking trigger, we need it to be that when a unit attacks that requires ammo the gold is taken off the right player. If you try and attack and you don’t have any gold you will automatically reload that will pause the firing unit for 4 seconds, you don’t reload instantly in real life now do you? And if you have no lumber the action will stop the unit from dealing any damage.
Here is the trigger –

Code:
Attacking
    Events
        Unit - A unit Is attacked
    Conditions
        (Owner of (Attacking unit)) Not equal to (!=) Player 12 (Brown)
        (Owner of (Attacking unit)) Not equal to (!=) Player 11 (Dark Green)
    Actions
         Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                ((Owner of (Attacking unit)) Current gold) Greater than or equal to (>=) 1
            Then - Actions
                Player - Set (Owner of (Attacking unit)) Current gold to (((Owner of (Attacking unit)) Current gold) - 1)
            Else - Actions
                 Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Owner of (Attacking unit)) Current lumber) Greater than or equal to (>=) 1
                    Then - Actions
                        Unit - Pause (Attacking unit)
                        Player - Set (Owner of (Attacking unit)) Current gold to 50
                        Player - Add -1 to (Owner of (Attacking unit)) Current lumber
                        Game - Display to (Player group((Owner of (Attacking unit)))) for 4.00 seconds the text: Reloading
                        Wait 4.00 seconds
                        Unit - Unpause (Attacking unit)
                    Else - Actions
                        Unit - Order Main_Unit[(Player number of (Owner of (Attacking unit)))] to Stop


Now final trigger is a manual reload. When the designated player clicks the ESC key and if you have lumber then you will pause the unit and reload the weapon using up 1 lumber. Now if you have bullets and you reload you have to take out the clip you already have in your weapon, that also means throwing away any bullets you haven’t used as well I’m afraid so if you use esc key and you have a full clip you still will use up 1 lumber. You could always create a condition yourself if you wanted to I supposed. So for the last time
Here is the trigger –

Code:
Reloading
    Events
        Player - Player 1 (Red) skips a cinematic sequence
        Player - Player 2 (Blue) skips a cinematic sequence
        Player - Player 3 (Teal) skips a cinematic sequence
        Player - Player 4 (Purple) skips a cinematic sequence
        Player - Player 5 (Yellow) skips a cinematic sequence
        Player - Player 6 (Orange) skips a cinematic sequence
        Player - Player 7 (Green) skips a cinematic sequence
        Player - Player 8 (Pink) skips a cinematic sequence
        Player - Player 9 (Gray) skips a cinematic sequence
        Player - Player 10 (Light Blue) skips a cinematic sequence
        Player - Player 11 (Dark Green) skips a cinematic sequence
        Player - Player 12 (Brown) skips a cinematic sequence
    Conditions
        ((Triggering player) Current lumber) Greater than or equal to (>=) 1
    Actions
        Unit - Pause Main_Unit[(Player number of (Triggering player))]
        Player - Set (Triggering player) Current gold to 50
        Player - Add -1 to (Triggering player) Current lumber
        Game - Display to (Player group((Triggering player))) for 4.00 seconds the text: Reloading
        Wait 4.00 seconds
        Unit - Unpause Main_Unit[(Player number of (Triggering player))]


Thanks for reading this and I hope its helped you greatly. These triggers are the basic bone for you to edit yourself so go ahead and edit them if you feel you must. A map will be added shortly unless it’s already there.

Q&A

Q - Why are there not any screen shots?

A - Such a simple system and you still want screen shots? You can tell what it’s supposed to do can’t you?

Q – I thought I was asking the questions?

A – You seem to be at the moment.

Q – It doesn’t work for me! DIS TUT IS SH*T COS IT DON'T W0RK!!!!

A – Oh do shut up, it’s probably because you rushed too soon for your little 5 year old mind to cope. This tut is self explanatory basically, if you can’t get it then you obviously can’t read English.

Q – What does explanatory mean?

A - … Q&A session over…
 

Attachments

  • Ammo System.w3x
    13.2 KB · Views: 266

Leazy

You can change this now in User CP.
Reaction score
50
Fun & Easy system. Although, I suggest to use other test units than peasants... they run away and it's anoying :p Make a unit with endless HP based on the target doodad model or something :D Also, try to change the icon of gold & lumber and the tooltip, this is not so important but will make the system more interesting I think =)
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Why monopolize gold and lumber usage for something that could be with a lot of other less useful objects. Lumber might not be an issue but most maps uses gold. If it has to be displayed at the very top of the screen, why not use lumber and food instead?
 

Flare

Stops copies me!
Reaction score
662
why not use lumber and food instead?
Why not use food alone? Current food used could be number of rounds remaining in current clip, and maximum food could be the number of remaining clips.

Unless, of course, food was needed for some other reason. Perhaps a multiboard alternative?

Code:
(Player group((Triggering player)))
That leaks - you could use the Display Text To Player (if it's available in the GUI), or store Player group (Triggering player) in a player group variable and use that
 

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
hehe, thx for comments. About using food and lumber well, if you haven't noticed most games use gold and lumber, i have given you the basics all you need to do is change the triggers a bit. Not too hard humm?

About the leaks, i wasn't sure if it leaked, aint a master of leaks im afriad, i know the code to remove leaks but i won't have time today im afraid, perhaps if you post the leaks then i could fix it buyt thats mean asking u to do my work so only if you wanna help. :shades:
 

Exide

I am amazingly focused right now!
Reaction score
448
First system I see around here in a while that isn't jibberish (coded in vJass). :thup:
+rep.

I want some screenshots, though. :p
 

psychophat

New Member
Reaction score
0
Is there a way to have different ammo system per hero/class. Using your Ammo System?

eg.
hero1(sniper) 1 lumber = 10 rounds
hero2(gunner) 1 lumber = 100 rounds
hero3(scout) 1 lumber = 30 rounds
etc.

Apologies I'm very new to this, please help.
 

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
hadn't thought about that... hmm well anyway i am sure theres away around it but i am busy...
 

psychophat

New Member
Reaction score
0
Got passed that issue, but need help on another thing.

Using the ammo system encountered an issue and don't know how to fix.

Code:
set vars
    Events
        Map initialization
    Conditions
    Actions
        Set Main_Unit[1] = Marine 0000 <gen>

Using a tavern to select the hero, the system works "if there is lumber" but if there is no lumber the hero is still able to attack.

Marine 0000 <gen> is not anymore selectable since, hero's are being selected from a tavern.

Any ideas how to fix?
 

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
the lumber is the clips, the gold is the ammo. It will attack if theres gold...


Marine 0000 <gen> is not anymore selectable since, hero's are being selected from a tavern.

Please refrase the question
 

psychophat

New Member
Reaction score
0
Issue in the code below is, without the code below the system still fires without gold or lumber.

Code #1
Code:
set vars
    Events
        Map initialization
    Conditions
    Actions
        Set Main_Unit[1] = Blood Mage 0036 <gen>

It says 'Attacking unit' it applies to even the creeps/neutral hostile. The neutral hostiles don't attack/fire at all since Ammo System is no longer specified to 'Set Main_Unit[1] = Blood Mage 0036 <gen>'. It now becomes global, system works on player controlled units but for neutrals it doesn't work because they have no gold or lumber.

Code #2
Code:
Attacking
    Events
        Unit - A unit Is attacked
    Conditions
        (Owner of (Attacking unit)) Not equal to Player 12 (Brown)
        (Owner of (Attacking unit)) Not equal to Player 11 (Dark Green)
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                ((Owner of (Attacking unit)) Current gold) Greater than or equal to 1
            Then - Actions
                Player - Set (Owner of (Attacking unit)) Current gold to (((Owner of (Attacking unit)) Current gold) - 1)
            Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Owner of (Attacking unit)) Current lumber) Greater than or equal to 1
                    Then - Actions
                        Unit - Pause (Attacking unit)
                        Player - Set (Owner of (Attacking unit)) Current gold to 60
                        Player - Add -1 to (Owner of (Attacking unit)) Current lumber
                        Game - Display to (Player group((Owner of (Attacking unit)))) for 1.00 seconds the text: Reloading...
                        Wait 2.50 seconds
                        Unit - Unpause (Attacking unit)
                    Else - Actions
                        Unit - Order Main_Unit[(Player number of (Owner of (Attacking unit)))] to Stop

But when you add this code the issue with Code #1 is fixed (no longer attacks without gold). But the same as well with the neutral hostiles.

Code #3
Code:
No Ammo
    Events
        Unit - A unit Is attacked
    Conditions
        ((Owner of (Attacking unit)) Current gold) Equal to 0
    Actions
        Unit - Order (Attacking unit) to Stop

Changing the 'Attacking unit' to 'Ordering unit' or to something else makes Code #2 work but now the same problem starts again that if there is no more gold and lumber the Hero can still attack.

Can you help fix this?
 

duderock101

Check out my 2 Player Co-op RPG!
Reaction score
71
perhaps add the condition to the long trigger (code #2), attacking unit eqaul to Main_Unit [1] and if there are multiple units then add all the main units then change the trigger so it is compatible for multiplayer
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top