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

[Trigger] Why is this trigger causeing lag?

Status
Not open for further replies.
Level 9
Joined
Aug 1, 2008
Messages
453
I'm am trying to make a system that makes it so you can only have 2 of 1 item. And it works just fine, just it causes MAJOR lag. And i have no clue why. Will +rep if you can help me. Heres the trigger
  • Only have 2 of 1 item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
    • Actions
      • Wait 0.05 seconds
      • Item - Remove (Item carried by (Hero manipulating item) of type Claws of Attack +15)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Hero manipulating item) has an item of type Claws of Attack +15) Equal to True
        • Then - Actions
          • Item - Remove (Item carried by (Hero manipulating item) of type Claws of Attack +15)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Hero manipulating item) has an item of type Claws of Attack +15) Equal to True
            • Then - Actions
              • Item - Remove (Item carried by (Hero manipulating item) of type Claws of Attack +15)
              • Game - Display to (All players) the text: WARNING: YOU MAY ON...
              • Set Points[22] = (Center of (Playable map area))
              • Item - Create Claws of Attack +15 at Points[22]
              • Hero - Give (Last created item) to (Hero manipulating item)
              • Item - Create Claws of Attack +15 at Points[22]
              • Hero - Give (Last created item) to (Hero manipulating item)
              • Custom script: call RemoveLocation (udg_Points[22])
            • Else - Actions
              • Set Points[22] = (Center of (Playable map area))
              • Item - Create Claws of Attack +15 at Points[22]
              • Hero - Give (Last created item) to (Hero manipulating item)
              • Item - Create Claws of Attack +15 at Points[22]
              • Hero - Give (Last created item) to (Hero manipulating item)
              • Custom script: call RemoveLocation (udg_Points[22])
        • Else - Actions
          • Set Points[22] = (Center of (Playable map area))
          • Item - Create Claws of Attack +15 at Points[22]
          • Hero - Give (Last created item) to (Hero manipulating item)
          • Custom script: call RemoveLocation (udg_Points[22])
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on (This trigger)
 
  • Angry
Reactions: Rui
Level 3
Joined
May 20, 2008
Messages
66
I think this trigger gives the hero Claw of Attack, but it starts on event Unit Acquires Item ( which is Claw of Attack ), so the trigger repeats itself an unlimited amount of times so... it causes lag.
 
Level 7
Joined
Sep 5, 2006
Messages
334
Like what Zenerik said, your trigger repeats every time it is run.

Item - Create Claws of Attack +15 at Points[22]
Hero - Give (Last created item) to (Hero manipulating item) <-You hero gets item, running the trigger again
Item - Create Claws of Attack +15 at Points[22]
Hero - Give (Last created item) to (Hero manipulating item) <-Same as abrove, runs the trigger again

Also I don't see what your trying to do with this trigger, you remove a item, create another and give it to your hero. Your hero ends up with the same item.
 
Level 11
Joined
Nov 15, 2007
Messages
781
You also don't need the wait. Two units pick up an item within a quarter second of eachother and your trigger will be screwed; rare but I'm sure it'd happen.
 
Level 5
Joined
Jan 25, 2006
Messages
103
This is a very stupid trigger.
What are you trying to achieve Shendoo?
I don't see the reasons for the conditions in the action. If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Hero manipulating item) has an item of type Claws of Attack +15) Equal to True
Then - Actions
Item - Remove (Item carried by (Hero manipulating item) of type Claws of Attack +15)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Hero manipulating item) has an item of type Claws of Attack +15) Equal to True
Makes no sense to me.

AS other people pointed out you have several conditions of the same thing and then several actions of the same thing.
So you are doing this:
acquires item
item manipulated
if has iteam, if hero manipulating do remove
else
repeat
else repeat
else repeat

Essentially 3 triggers that work the same way to remove an item!?
 
Level 9
Joined
Aug 1, 2008
Messages
453
it makes it so the unit can only have 2 of the same item. It removes the item because thats how it is checking the amount of that item they have. Ill have it turn the trigger off at the start and turn it back on at the end. Should fix the bug.
 
Level 11
Joined
Nov 15, 2007
Messages
781
....Well:

  • trigger
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Item - Remove (Item being manipulated)
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to (==) True
        • Then - Actions
          • Item - Create (Item-type of (Item being manipulated)) at (Position of (Triggering unit))
          • Game - Display to (Player group((Owner of (Triggering unit)))) the text: No duplicate items ...
        • Else - Actions
          • Trigger - Turn off (This trigger)
          • Hero - Create (Item-type of (Item being manipulated)) and give it to (Triggering unit)
          • Trigger - Turn on (This trigger)
Of course, I can only make a wild assumption about what you're trying to do. Also, leaks.
 
Level 9
Joined
Aug 1, 2008
Messages
453
im trying to make it so you have have two of the item. Imma just do my way. I have a short question, is it bad if you remove an item that the unit doesn't have? like your remove two of the item but they only have one?
 
Level 7
Joined
Oct 14, 2008
Messages
340
Okay here's a good way of doing it, and fairly easy to understand.

Now I understand that this was
  • only but I think this should be easy enough for you to grasp :P
  • First I'm going to give you a chunk of JASS code, copy and paste this into your map's header (in the trigger window, above all of your triggers on the left column. it has a map icon next to it)
  • [code=jass]
  • function CountItemsByType takes unit u, integer itemId returns integer
    • local integer i = 0
    • local integer q = 1
    • loop
      • if GetItemTypeId(UnitItemInSlot(u, q)) == itemId then
        • set i = i+1
      • endif
      • set q = q+1
      • exitwhen q == 7
    • endloop
    • return i
  • endfunction
  • [/code]
  • Now, once you have this in your map's header, you can count how many items a hero is holding by a specific type. First get your item's raw code, you do this by going to the object editor and pressing ctrl+D, and there's a 4 digit code for every item you have. EXAMPLE: ratf (this is the ID for claws of attack +15) ..now with that info, you can make a trigger like this:
  • [trigger]
  • 2 claws
  • Events
    • Unit - A unit aquires an item
  • Conditions
    • (Item type of (Item being manipulated)) Equal to Claws of Attack +15
  • Actions
    • Custom script: set udg_TempInt = CountItemsByType(GetTriggerUnit(), 'ratf')
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • TempInt Greater than 2
      • Then - Actions
        • Hero - Drop (Item being manipulated) from (Triggering unit)
      • Else - Actions
This trigger will immediately drop any claws of attack +15 picked up by a hero if he already has 2.

If the custom script line is confusing you, let me explain:
For this trigger, I have created a variable called TempInt, it is an integer.
The custom script calls upon the code I asked you to paste in your map's header. Notice the perenthesis () inside you see "GetTriggerUnit()" what this does is it sets the unit who's items you are counting as the unit who triggered this whole bit. then theres a comma "," and you see 'ratf' -this is the raw code for Claws of Attack +15, this custom script will set your variable "TempInt" to the amount of items carried by your hero that are equal to Claws of Attack +15, the rest of the trigger should be pretty easy to figure out.

Hope this didn't confuse you, and I hope I did help.
 
Status
Not open for further replies.
Top