1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  4. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  5. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Do you have good ideas for new contests? If so, please open new threads in the Contest Submission sub-forum to discuss them.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Why is this trigger causeing lag?

Discussion in 'Triggers & Scripts' started by Shendoo2, Mar 15, 2009.

  1. Shendoo2

    Shendoo2

    Joined:
    Aug 1, 2008
    Messages:
    464
    Resources:
    0
    Resources:
    0
    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)
     
  2. Zenerik

    Zenerik

    Joined:
    May 20, 2008
    Messages:
    66
    Resources:
    0
    Resources:
    0
    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.
     
  3. Meticulous

    Meticulous

    Joined:
    Nov 15, 2007
    Messages:
    779
    Resources:
    0
    Resources:
    0
    This is not a good trigger... :sad:
     
  4. chenlimin

    chenlimin

    Joined:
    Sep 5, 2006
    Messages:
    332
    Resources:
    0
    Resources:
    0
    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.
     
  5. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    805
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    maybe move "Trigger - Turn off (This trigger)" right below that Wait.
     
  6. Kingz

    Kingz

    Joined:
    Jun 5, 2008
    Messages:
    2,470
    Resources:
    6
    Spells:
    5
    Tutorials:
    1
    Resources:
    6
    It runs indefinetly...
    Also there are quality item systems on the Hive so why not just take one?
     
  7. Meticulous

    Meticulous

    Joined:
    Nov 15, 2007
    Messages:
    779
    Resources:
    0
    Resources:
    0
    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.
     
  8. SlickR

    SlickR

    Joined:
    Jan 25, 2006
    Messages:
    112
    Resources:
    5
    Maps:
    5
    Resources:
    5
    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!?
     
  9. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,929
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Trigger falls into an infinate loop, be lucky it does not crash the game.
     
  10. Shendoo2

    Shendoo2

    Joined:
    Aug 1, 2008
    Messages:
    464
    Resources:
    0
    Resources:
    0
    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.
     
  11. SlickR

    SlickR

    Joined:
    Jan 25, 2006
    Messages:
    112
    Resources:
    5
    Maps:
    5
    Resources:
    5
    there is a better way of checking how many items one has, but whatever!
     
  12. Shendoo2

    Shendoo2

    Joined:
    Aug 1, 2008
    Messages:
    464
    Resources:
    0
    Resources:
    0
    how to check how many of the ONE item the unit has? I would like to know. Would make my job a lot easier.
     
  13. Meticulous

    Meticulous

    Joined:
    Nov 15, 2007
    Messages:
    779
    Resources:
    0
    Resources:
    0
    ....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.
     
  14. Shendoo2

    Shendoo2

    Joined:
    Aug 1, 2008
    Messages:
    464
    Resources:
    0
    Resources:
    0
    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?
     
  15. Meticulous

    Meticulous

    Joined:
    Nov 15, 2007
    Messages:
    779
    Resources:
    0
    Resources:
    0
    Nothing will happen if you try to remove something that doesn't exist.
     
  16. Shendoo2

    Shendoo2

    Joined:
    Aug 1, 2008
    Messages:
    464
    Resources:
    0
    Resources:
    0
    k thank you.
     
  17. Maximilianx

    Maximilianx

    Joined:
    Oct 14, 2008
    Messages:
    334
    Resources:
    0
    Resources:
    0
    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)
    • [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
    • [/jass]
    • 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.
     
  18. Shendoo2

    Shendoo2

    Joined:
    Aug 1, 2008
    Messages:
    464
    Resources:
    0
    Resources:
    0
    actually it works if the the has more than 3 =P changed it though. Thanks for the help, ill probably use your way instead of mine. +rep

    Fixed it Thanks for the help.
     
    Last edited: Mar 18, 2009