• 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.

[Trigger] Make unit drop items each time it's hp lower in percentage

Status
Not open for further replies.
Level 9
Joined
Oct 4, 2006
Messages
132
Ok, its a bit difficult to describe
Sorry for that.

I started a minigame-map today.
The idea is that every player has got a worker, who needs to go into the forest and search for gold, silver and iron ore.
He has to attack them to get items/charges on its ore-item.
The number of charges he acquires depends on the type of ore:
5 for gold, 3 for Silver and 1 for Iron. They are all stored in one item which can have a max of 100charges, then it goes to the next ore-item.

but my problem is, that i don't really know how to trigger when he gets those charges.
I don't like the idea of the source dropping an item on death, for i fear stealing it by other players. no fun that way.

I had the idea of this: if the source drops from over 90% hp to equal or less than 90%, the attacking unit gets the charges. the 3 types got different values of hitpoints, for of course gold is more difficult to mine than iron.
if the sources hp drop now from over 80% under 80% he gets the second charge, and so on.
This way it doesn't really matter if you destroy the mine, for it has 10 loads to give. that way, if somebody is stealing, he won't steal 50 charges (in the case of a goldmine) but only 5, which is a big advantage.

But how could I trigger that percentage-thing? i don't have a clue yet, and i'm not confident that i will get one in time, so I ask you to help me out!

Maybe someone does the trigger(s) for me, or just give me some hints?

I would be very grateful for any sort of help!
it's the last big problem that has to be solved before i can finish the game!


PS: the mines aren't static; they are spawned at the beginning of the game several times, (10 gold, 20 silver and 30 iron)
everytime 1 mine is destroyed, another one of the same type is created somewhere else. maybe this knowledge is helpful for this task =/
 
Well, create 3 units, each having different model to depict the specific resource and have this trigger:

  • Melee Initialization
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Attacked unit)) Equal to Gold
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Attacking unit) has an item of type Gold) Equal to False
            • Then - Actions
              • Set Charges[1] = (Charges[1] + 1)
              • Hero - Create Gold and give it to (Attacking unit)
              • Item - Set charges remaining in (Last created item) to Charges[1]
            • Else - Actions
              • Item - Set charges remaining in (Item carried by (Attacking unit) of type Gold) to Charges[1]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Charges[1] Equal to 5
                • Then - Actions
                  • Set Charges[1] = 0
                • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Attacked unit)) Equal to Silver
            • Then - Actions
              • Set Charges[2] = (Charges[2] + 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Attacking unit) has an item of type Silver) Equal to False
                • Then - Actions
                  • Hero - Create Silver and give it to (Attacking unit)
                  • Item - Set charges remaining in (Last created item) to Charges[2]
                • Else - Actions
                  • Item - Set charges remaining in (Item carried by (Attacking unit) of type Silver) to Charges[2]
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Charges[2] Equal to 3
                    • Then - Actions
                      • Set Charges[2] = 0
                    • Else - Actions
            • Else - Actions
The attacked unit is the resource. Once attacked, the charge for attacking unit increases by 1. When i set the charges back to 0, it is where your unit should return the item (to depict the "return resource" order(, so that you can have an action of type "Unit - Order (attacking unit) to Move to (Point1) [Point1 = (Position of (Your building))]. This is the main idea. Have the units that represent the resources have no hp, so that they never die. You can go on the trigger with the Iron Ore part as well with the same method, having Charges[3] for the Iron ore.
 
Level 9
Joined
Oct 4, 2006
Messages
132
okay, the thing with moving them to another point is pretty nice, i will use it i think =D

but i don't want to make every attack "steal" ressources from the mine, they should do an amount of damage to the mine and if the mines are damaged enough, they kinda drop resources to the worker.

example:

Goldmine has 500hp
10% of 500hp = 50hp
means, the unit will have to first damage the mine till it has only 450 or less hp left, then it acquires the first charge(s) for that mine. another 50 damage done, so the mine has 400 or less, and the next giveaway follows. etc

thats because i want to let damage play a relatively high role, for example, you will have the option of buying some better tools to do more damage and get ressources with lesser attacks than with an old-fashioned rusted pick. you know what i mean?

hmm... maybe... maybe i could use a randomizer, so theres a chance of (A)+(Bonus for Tools)% of getting gold etc... i could make the chances for gold little and the chances for iron relatively high, maybe 10% for gold and e.g. 50% for iron, the standard tool doesn't grant a bonus, but the "better" pick could give maybe 5%...
I'm gonna try this way now..

but please, if somebody has an idea of doing the damage-idea, feel free to help me out =)
 
Well, have this:

  • Map Initialization
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set Recource_Group = ((Units in (Playable Map Area) matching ((Unit-type of (Matching unit) Equal to Gold)) and ((Unit-type) of (Matching unit) Equal to (Silver)) and ((Unit-type) of (Matching unit) Equal to Iron Ore))
    • Unit Group - Pick up every unit in (Resource_Group) and do (Actions)
      • Loop - Actions
        • Set Picked_Resource = (Picked unit)
        • Trigger - Add to Melee2 <gen> the event ((Unit -(Picked_Resource) takes damage))
    • Custom script: call DestroyGroup (udg_Resource_Group)
  • Melee2
  • Events
  • Conditions
    • ((Damage source) is A peon-type unit) Equal to True
  • Actions
    • Set Charges[1] = Charges[1] + 1
    • If/ Then/ Else
      • If (Conditions)
        • (Life of (Picked_Resource)) Less than or Equal to (0.1 * ((Max Life) of (Resource_Picked))
      • Then (Actions)
        • Unit - Set life of (Picked_Resource) to ((Max Life) of (Picked_Resource))
        • Item - Set Charges Remaining of (Item carried by (Damage Source) of type (Gold)) to Charges[1]
Something like this (?)
 
Status
Not open for further replies.
Top