• 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] Item ability lagg

Status
Not open for further replies.
Level 15
Joined
Oct 18, 2008
Messages
1,591
I use this code for a socket system-the problem is, the first time when I run this trigger for a type of SocketGem it makes a 1 second lagg. After that if I use that type of gem it runs smoothly, but for the first time it's not good... Why does it do it? (I know that the mana and HP part doesn't work and I'll work on that problem :))
  • For each (Integer A) from 1 to GemTypesNumber, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to GemTypes[(Integer A)]
        • Then - Actions
          • For each (Integer B) from 1 to SocketedItemTypesNumber, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of UsedGem) Equal to SockedtedItemTypes[(Integer B)]
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load 1 of UsedGemID from CurrentSocketsUsed) Less than SocketsMax[(Integer B)]
                    • Then - Actions
                      • Hashtable - Save ((Load 1 of UsedGemID from CurrentSocketsUsed) + 1) as 1 of UsedGemID in CurrentSocketsUsed
                      • Hashtable - Save (Integer A) as (Load 1 of UsedGemID from CurrentSocketsUsed) of UsedGemID in SocketedGems
                      • Item - Remove (Item being manipulated)
                      • For each (Integer X) from 1 to TotalBonusTypes, do (Actions)
                        • Loop - Actions
                          • Set Bonuses[X] = 0
                      • For each (Integer X) from 1 to 6, do (Actions)
                        • Loop - Actions
                          • For each (Integer Y) from 1 to (Load 1 of (Key (Item carried by (Triggering unit) in slot X)) from CurrentSocketsUsed), do (Actions)
                            • Loop - Actions
                              • For each (Integer C) from 1 to GemTypesNumber, do (Actions)
                                • Loop - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • (Load Y of (Key (Item carried by (Triggering unit) in slot X)) from SocketedGems) Equal to C
                                    • Then - Actions
                                      • For each (Integer Z) from 1 to TotalBonusTypes, do (Actions)
                                        • Loop - Actions
                                          • Set Bonuses[Z] = (Bonuses[Z] + (Load Z of C from SocketGemBonuses))
                                    • Else - Actions
                      • Wait 0.10 seconds -- Tried using this to reduce lagg without a succes...
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Bonuses[1] Greater than 0
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Strength Bonus for (Triggering unit)) Equal to 0
                            • Then - Actions
                              • Unit - Add Strength Bonus to (Triggering unit)
                            • Else - Actions
                          • Unit - Set level of Strength Bonus for (Triggering unit) to Bonuses[1]
                        • Else - Actions
                          • Unit - Remove Strength Bonus from (Triggering unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Bonuses[2] Greater than 0
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Agility Bonus for (Triggering unit)) Equal to 0
                            • Then - Actions
                            • Else - Actions
                              • Unit - Add Agility Bonus to (Triggering unit)
                          • Unit - Set level of Agility Bonus for (Triggering unit) to Bonuses[2]
                        • Else - Actions
                          • Unit - Remove Agility Bonus from (Triggering unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Bonuses[3] Greater than 0
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Intelligence Bonus for (Triggering unit)) Equal to 0
                            • Then - Actions
                              • Unit - Add Intelligence Bonus to (Triggering unit)
                            • Else - Actions
                          • Unit - Set level of Intelligence Bonus for (Triggering unit) to Bonuses[3]
                        • Else - Actions
                          • Unit - Remove Intelligence Bonus from (Triggering unit)
                      • Set SocketTempInt = ((Bonuses[4] - 50) / 100)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • SocketTempInt Greater than 0
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Life Bonus (100) for (Triggering unit)) Equal to 0
                            • Then - Actions
                              • Unit - Add Life Bonus (100) to (Triggering unit)
                            • Else - Actions
                          • Unit - Set level of Life Bonus (100) for (Triggering unit) to SocketTempInt
                        • Else - Actions
                          • Unit - Remove Life Bonus (100) from (Triggering unit)
                      • Set SocketTempInt = (Bonuses[4] mod 100)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • SocketTempInt Greater than 0
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Mana Bonus (1) for (Triggering unit)) Equal to 0
                            • Then - Actions
                              • Unit - Add Life Bonus (1) to (Triggering unit)
                            • Else - Actions
                          • Unit - Set level of Life Bonus (1) for (Triggering unit) to SocketTempInt
                        • Else - Actions
                          • Unit - Remove Life Bonus (1) from (Triggering unit)
                      • Set SocketTempInt = ((Bonuses[5] - 49) / 100)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • SocketTempInt Greater than 0
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Mana Bonus (100) for (Triggering unit)) Equal to 0
                            • Then - Actions
                              • Unit - Add Mana Bonus (100) to (Triggering unit)
                            • Else - Actions
                          • Unit - Set level of Mana Bonus (100) for (Triggering unit) to SocketTempInt
                        • Else - Actions
                          • Unit - Remove Mana Bonus (100) from (Triggering unit)
                      • Set SocketTempInt = (Bonuses[5] mod 100)
                      • Game - Display to (All players) the text: (String(SocketTempInt))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • SocketTempInt Greater than 0
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Mana Bonus (1) for (Triggering unit)) Equal to 0
                            • Then - Actions
                              • Unit - Add Mana Bonus (1) to (Triggering unit)
                            • Else - Actions
                          • Unit - Set level of Mana Bonus (1) for (Triggering unit) to SocketTempInt
                        • Else - Actions
                          • Unit - Remove Mana Bonus (1) from (Triggering unit)
                      • Unit - Remove Movement Speed Bonus from (Triggering unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Bonuses[6] Greater than 0
                        • Then - Actions
                          • Unit - Add Movement Speed Bonus to (Triggering unit)
                          • Unit - Set level of Movement Speed Bonus for (Triggering unit) to Bonuses[6]
                        • Else - Actions
                    • Else - Actions
                      • Game - Display to (Player group((Owner of (Triggering unit)))) the text: You can't put more ...
                • Else - Actions
        • Else - Actions
 
You might want to use "Skip remaining actions" in the end of each loop (in the loop).
You have four if/then/else that include the same condition: SocketTempInt Greater than 0. Nest them with each other.
Wait is not needed, lag woun't stop with its presence in the code :p
Finally, save the Triggering unit to a variable and refer to it with the variable, since you are repeatedly using it.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Fix the player group leak: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/

Preload the abilities, at map initialization, add/remove all abilities that you use in this system to a dummy unit.

I suggest you use hashtables and store stuff with item type id's. That way you don't need to loop to get SocketsMax or Integer A values, you can just load them with a single line. Much more efficient solution, not to mention that the trigger will also look 2.2 times cleaner.

Example:
  • Custom script: Set udg_SocketMax = LoadInteger(udg_hashtable, GetItemTypeId(GetOrderTargetItem()), 0)
 
Level 15
Joined
Oct 18, 2008
Messages
1,591
I use 4 sockettempInt Greater than 0 because between them I change socket temp int ^^ And I'm lazy to rewrite the code with more variables xD
Oh, and skip really helped ;) Forgot to put it there xD

Maker- I don't understand you... I already use hashtables for those ^^ And I use loops because I need to transform an item to it's sockets then I have to get the gems in them then look up the gem type out of an array ;) Oh yeah Player Group leak ;)
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
I already use hashtables for those ^^

Clearly not since you're looping through an array.

And I use loops because I need to transform an item to it's sockets then I have to get the gems in them then look up the gem type out of an array ;)

The point is that you should not use an array, use hashtable instead. Then there's no need for looping through all the item types.

Once I also used to loop through arrays to get some value, but then I realized the use of hashtables and keying data for item type id's/whatever. Life got better.
 
Level 15
Joined
Oct 18, 2008
Messages
1,591
The problem is the guy who I am making this for :) He'll clearly not understand hashtables xD And this system will be imported, which means I will suffer more ^^

And I'm getting closer to hashtables atm too ^^

EDIT: ATM This one causes me problems:

  • Then - Actions
    • Set SocketTempInt = ((Bonuses[4] - 50) / 100)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • SocketTempInt Greater than 0
      • Then - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Level of Bonus Damage Book (100) for SocketTempUnit) Equal to 0
          • Then - Actions
            • Unit - Add Damage Bonus Book (100) to SocketTempUnit
            • Player - Disable Bonus Damage Book (100) for (Owner of SocketTempUnit)
          • Else - Actions
        • Unit - Set level of Damage Bonus (100) for (Triggering unit) to SocketTempInt
      • Else - Actions
        • Unit - Remove Bonus Damage Book (100) from SocketTempUnit
        • Player - Enable Bonus Damage Book (100) for (Owner of SocketTempUnit)
    • Set SocketTempInt = (Bonuses[4] mod 100)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • SocketTempInt Greater than 0
      • Then - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Level of Bonus Damage Book (1) for SocketTempUnit) Equal to 0
          • Then - Actions
            • Unit - Add Bonus Damage Book (1) to SocketTempUnit
            • Player - Disable Bonus Damage Book (1) for (Owner of SocketTempUnit)
          • Else - Actions
        • Game - Display to (All players) the text: (String(SocketTempInt))
        • Unit - Set level of Damage Bonus (1) for SocketTempUnit to SocketTempInt
      • Else - Actions
        • Unit - Remove Damage Bonus (1) from SocketTempUnit
        • Player - Enable Bonus Damage Book (1) for (Owner of SocketTempUnit)
It absolutely bugs xD Gives crazy bonus damages without a reason :( Debug trigger gives back 10 when it makes +20...
 
Status
Not open for further replies.
Top