• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Shoot only if ammo is available

Status
Not open for further replies.
Level 2
Joined
Jul 13, 2018
Messages
7
Hello!

I need help with something. I have an integer variable called "Ammo" and I want some type of units, like the rifleman or the siege engine, to shoot only if the variable is greater than 0 and consume 1 unit of ammo when they shoot (if they don't have ammo, they should run away when they receive damage?). How can I do that with triggers?

Thanks!
 
Level 30
Joined
Feb 18, 2014
Messages
3,623
How do you make this "Ammo' ? Is it an item or something? Anyway, there are many ways you can achieve this : Here's a example on how to make ammo for a single unit.
  • Ammo Single Unit
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Rifleman 0001 <gen>
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Ammo Equal to 0
        • Then - Actions
          • Unit - Order Rifleman 0001 <gen> to Stop
        • Else - Actions
          • Set Ammo = (Ammo - 1)
          • Game - Display to (All players) the text: (Bullets left : + (String(Ammo)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Ammo Equal to -1
            • Then - Actions
              • Unit - Order Rifleman 0001 <gen> to Stop
            • Else - Actions
If you're using this ammo as an item :
  • Ammo Item
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Rifleman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Attacking unit) has an item of type Shotgun Shell) Equal to FALSE
        • Then - Actions
          • Unit - Order (Attacking unit) to Stop
        • Else - Actions
          • Item - Set charges remaining in (Item carried by (Attacking unit) of type Shotgun Shell) to ((Charges remaining in (Item carried by (Attacking unit) of type Shotgun Shell)) - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Charges remaining in (Item carried by (Attacking unit) of type Shotgun Shell)) Equal to 0
            • Then - Actions
              • Item - Remove (Item carried by (Attacking unit) of type Shotgun Shell)
            • Else - Actions
 

Attachments

  • Ammo System.w3x
    18 KB · Views: 16
Status
Not open for further replies.
Top