• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need help with item trigger.

Status
Not open for further replies.
Level 9
Joined
Jul 11, 2009
Messages
294
Hi guys,

I need help with this trigger.


When a unit enters a region, if the unit is a smuggler, I want to remove items carried by ((triggering unit) of type "drug") and give gold to the owner of triggering unit depending on how much drug is in the inventory.

For example, if the smuggler enters the region with 3 "drugs", the trigger will remove the 3 drugs in inventory then add 3 x 10gold to the owner of triggering unit.
Whereas if the smuggler enters the region with 6 "drugs", the trigger will remove the 6 drugs in inventory then add 6 x 10gold to the owner of triggering unit.

How can I do so?

Thanks!
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
  • Add gold per drug
    • Events
      • Unit - A unit enters Your_Region
    • Conditions
    • Actions
      • Set u = (Triggering unit)
      • For each (Integer LoopInteger) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by u in slot LoopInteger)) Equal to Drug
            • Then - Actions
              • Set i = (i + 1)
              • Item - Remove (Item carried by u in slot LoopInteger)
            • Else - Actions
      • Player - Add (i x 10) to (Owner of u) Current gold
      • Set u = No unit
LoopInteger and i are integer variables, u is unit variable.
 
Level 9
Joined
Jul 11, 2009
Messages
294
  • Add gold per drug
    • Events
      • Unit - A unit enters Your_Region
    • Conditions
    • Actions
      • Set u = (Triggering unit)
      • For each (Integer LoopInteger) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by u in slot LoopInteger)) Equal to Drug
            • Then - Actions
              • Set i = (i + 1)
              • Item - Remove (Item carried by u in slot LoopInteger)
            • Else - Actions
      • Player - Add (i x 10) to (Owner of u) Current gold
      • Set u = No unit
LoopInteger and i are integer variables, u is unit variable.


It worked after I made some changes to it, thanks! +REP!

However, how can I make the trigger display a text message to the owner of triggering unit saying that "10 gold is added for every drug brought" just once? Because if I add display message under the Then - Actions part, it will trigger 6 messages if 6 drugs are bought. Also, would this work if there are different drugs at different locations?

Thanks!
 
Last edited:
Level 25
Joined
Sep 26, 2009
Messages
2,378
Depends how you want it to work. If any drug type is "sold" for 10 gold, you can add it in the ITE condition block as "Or" condition.

If you sell them for different prices, it would be easiest to make the price calculative - e.g. the "worst" drug type for 10 gold, medium-quality for 15, best quality for 20.
You could the calculate the sum by for example item level.
So the worst drug type would have item level 1, medium level 2 and best level 3, etc.

If the price would be different and non-calculative (e.g. worst for 10 gold, medium for 45 and best for 127 gold), you would need to add more ITEs.
 
Level 9
Joined
Jul 11, 2009
Messages
294
Depends how you want it to work. If any drug type is "sold" for 10 gold, you can add it in the ITE condition block as "Or" condition.

If you sell them for different prices, it would be easiest to make the price calculative - e.g. the "worst" drug type for 10 gold, medium-quality for 15, best quality for 20.
You could the calculate the sum by for example item level.
So the worst drug type would have item level 1, medium level 2 and best level 3, etc.

If the price would be different and non-calculative (e.g. worst for 10 gold, medium for 45 and best for 127 gold), you would need to add more ITEs.

how can I make the trigger display a text message to the owner of triggering unit saying that "10 gold is added for every drug brought" just once? Because if I add display message under the Then - Actions part, it will trigger 6 messages if 6 drugs are bought.

Thanks!
 
Level 9
Joined
Jul 11, 2009
Messages
294
At the end of the trigger make a condition : Is drugs more than one -> Display message.

I'm sorry I don't quite get what you mean, because the trigger itself is already confusing me, sorry bout that cos I've been away from map making for a couple of years.


or check if "i" is greater than 0, which reminds me that I have an error in the trigger - add line
  • Set i = 0
at the start of end of the trigger so you won't get more money each time the trigger fires.

Yeah I fixed that problem by adding Set Itemschool = (Itemschool - 1) under 'Then Actions'
 
Status
Not open for further replies.
Top