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: 265

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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top