• 🏆 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!

How to "shrink" this trigger?

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,137
Hello everone. I am bit of confused because it item system of Warcraft III. As you know if you try to pick item and check the item in the trigger, game immediately realizes you have the item and counting it in trigger.

I have created system like this. I want to prevent players to get more than 1 of the items i have specified. I know it looks bit of complex but i believe there is the easy way to do that instead of create variables like this.

  • Sadece1AdetAncestralTouch
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Ancestral Staff
              • AncestralTouchInt[(Player number of (Owner of (Triggering unit)))] Equal to 1
              • ((Triggering unit) has an item of type Ancestral Staff) Equal to True
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Triggering unit)
          • Set AncestralTouchInt[(Player number of (Owner of (Triggering unit)))] = 0
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Ancestral Staff
              • AncestralTouchInt[(Player number of (Owner of (Triggering unit)))] Equal to 0
        • Then - Actions
          • Set AncestralTouchInt[(Player number of (Owner of (Triggering unit)))] = (AncestralTouchInt[(Player number of (Triggering player))] + 1)
        • Else - Actions

  • Sadece1AdetBirak
    • Events
      • Unit - A unit Loses an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Steel Shield
        • Then - Actions
          • Set SteelShieldInt[(Player number of (Owner of (Triggering unit)))] = 0
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Iron Plate
        • Then - Actions
          • Set IronPlateInt[(Player number of (Owner of (Triggering unit)))] = 0
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Ancestral Staff
        • Then - Actions
          • Set AncestralTouchInt[(Player number of (Owner of (Triggering unit)))] = 0
        • Else - Actions

It is working well. But i don't know i feel i screwed everything up. I believe there is lot of more easy way to do that.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,539
1) "And - All (Conditions) are true" is unnecessary. By default all conditions need to be met.

2) Since you're using If Then Else statements you can use the Else to make it more efficient:
If Item = Steel Shield, ELSE if Item equal to Iron Plate, ELSE if Item equal to Ancestral staff.

3) You can Turn off triggers temporarily to prevent them from running. I'm not sure if you want or need to do this:
Turn off Sadece1AdetBirak, Drop Item, Turn on Sadece1AdetBirak.

Anyway, all of that aside, an easier solution would be to Loop through the unit's inventory and count how many Items it has of the type that it just acquired.

A unit acquires an item -> Loop from 1 to 6 -> If ITEM-TYPE of Item carried by triggering unit in Slot (Loop) Equal to ITEM-TYPE of Item being manipulated -> Then Increase ItemCounter by 1.

Once you've looped over all 6 item slots, check the value of ItemCounter. If ItemCounter is > 1 then you know that the unit has 2+ of these items so you should Drop the item being manipulated. Don't forget to reset ItemCounter to 0 before running the loop again.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
In addition to the solution Uncle posted, before running the loop to count the items you should check if the item type should be limited to only 1. It is usually desired to restrict equipment or powerful items to 1 copy, and not necessarily every item type such as consumables.

Such a check could be an enormous "Or - any condition is true" block which check if the acquired item type is equal to one of the restricted types. If you want a more efficient/scaleable custom script solution then a hashtable (or Lua table) could be used to map the integer item type id to a boolean or integer value representing the item being limited to 1.
 
Status
Not open for further replies.
Top