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

[JASS] GUI Specific Unit Event Possible with udg Variable?

Status
Not open for further replies.
Level 18
Joined
Mar 16, 2008
Messages
721
There is no GUI option to have a specific unit event for a unit who's variable isn't set yet. So I was wondering it it would be possible to convert the trigger to JASS and replace that with udg variable? So the unit I want to track take damage for is udg_Red_King but its variable isn't set until the player chooses a hero, during the game. So GUI won't let me select that variable for this event type. I used WE to convert to custom text on that GUI trigger below but I replaced the variable. Will this work or is there some reason why GUI doesn't have that option?

JASS:
function Trig_AI_Red_King_Pages_Stop_Actions takes nothing returns nothing
    call SetUnitOwner( udg_Red_King, Player(0), false )
    call EnableTrigger( gg_trg_AI_Red_Receive_Gold )
    call StartTimerBJ( udg_king_vendor_timer[1], false, 255.00 )
    call DisableTrigger( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_AI_Red_King_Pages_Stop takes nothing returns nothing
    set gg_trg_AI_Red_King_Pages_Stop = CreateTrigger(  )
    call DisableTrigger( gg_trg_AI_Red_King_Pages_Stop )
    call TriggerRegisterUnitEvent( gg_trg_AI_Red_King_Pages_Stop, udg_Red_King, EVENT_UNIT_DAMAGED )
    call TriggerAddAction( gg_trg_AI_Red_King_Pages_Stop, function Trig_AI_Red_King_Pages_Stop_Actions )
endfunction
 
For the second question, the GUI World Editor doesn't allow you to register a global unit variable to a specific unit event since it assumes that the value of the variable at the point is null, and who would want to register a null object to a specific unit event? You can circumvent this somewhat by adding the desired event as follows:

  • Event
    • Game - Map Initialization
  • Conditions
  • Actions
    • Comment - -------- This action may not possibly exist --------
    • Trigger - Add the following event to <your_trigger>: Red_King takes damage
As for the first question .. yes, you can do so.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
Yes the event would never fire if you used a null unit variable. Looks like you just need a Damage Detection System; there are a few here and the recommended one is DamageEngine. Then in a “any unit takes damage” trigger you would just check if the damaged unit was equal to the Red King

You could also just add the event to the trigger dynamically after the Red King variable has been set. Trigger - Add to YOUR_TRIG <gen> the event - Red King takes damage
 
Level 18
Joined
Mar 16, 2008
Messages
721
weird is an understatement, i'm going crazy :xxd:

don't feel to obliged to help with this one cuz it's somewhat minor but thanks as usual :thumbs_up: my map wouldn't have come this far without ur help!

pretty much this trigger orders AI hero to go to vendor, but I want it to be canceled if he's in combat / takes damage. That was my hope for the JASS trigger, because the specific unit event takes damage doesn't work with GUI.

Starts
  • AI Red King Pages Pt1
    • Events
      • Time - king_vendor_timer[1] expires
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Red_King is alive) Equal to True
          • (Owner of Red_King) Not equal to Neutral Passive
          • (Owner of Red_King) Not equal to Player 13 (Maroon)
          • (Player 1 (Red) Current gold) Greater than 10000
          • (Hero level of Red_King) Less than 50
        • Then - Actions
          • Trigger - Turn off AI Red Receive Gold <gen>
          • Trigger - Turn on AI Red King Pages Stop <gen>
          • Countdown Timer - Start king_pages_timer[1] as a One-shot timer that will expire in 120.00 seconds
          • Unit - Change ownership of Red_King to Player 13 (Maroon) and Retain color
          • Unit - Order Red_King to Move To King_Vendor_Red
        • Else - Actions
          • Countdown Timer - Start king_vendor_timer[1] as a One-shot timer that will expire in 255.00 seconds
kind of elaborate but pretty much does item crafting specific to this map
  • AI Red King Pages Pt2
    • Events
      • Unit - A unit enters Red Ftn <gen>
    • Conditions
      • (Entering unit) Equal to Red_King
      • (Owner of (Entering unit)) Equal to Player 13 (Maroon)
    • Actions
      • -------- ------------------------ --------
      • -------- PAWN ITEMS BELOW ILV 5 --------
      • -------- ------------------------ --------
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item: (Item carried by Red_King in slot (Integer A))'s Integer Field: Level ('ilev')) Less than 5
            • Then - Actions
              • Set VariableSet pawn_item_red = (Item carried by Red_King in slot (Integer A))
              • Custom script: call UnitDropItemTarget(udg_Red_King, udg_pawn_item_red, udg_king_library[1])
              • Wait 1.00 seconds
              • Set VariableSet pawn_item_red = No item
            • Else - Actions
      • -------- ------------------------ --------
      • -------- ------TOMES------ --------
      • -------- ------------------------ --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Red Ftn <gen> contains Red_Prince) Equal to False
          • (Player 1 (Red) Current gold) Greater than 1800
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of items carried by Red_King) Equal to 6
              • (Red_King has an item of type Page of Royal Literature) Equal to False
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Red_King has an item of type Royal Orb of Fire) Equal to True
                • Then - Actions
                  • Unit - Order Red_King to move (Item carried by Red_King of type Royal Orb of Fire) to inventory slot 1.
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Red_King has an item of type Artifact Shard) Equal to True
                • Then - Actions
                  • Unit - Order Red_King to move (Item carried by Red_King of type Artifact Shard) to inventory slot 2.
                • Else - Actions
              • Hero - Drop the item from slot 6 of Red_King.
            • Else - Actions
          • Player - Add 1800 to Player 13 (Maroon).Current gold
          • Player - Add -1800 to Player 1 (Red).Current gold
          • Wait 2.00 seconds
          • Custom script: call IssueNeutralImmediateOrderById(Player(12), udg_king_library[1], 'tkno')
          • Wait 2.00 seconds
        • Else - Actions
      • -------- ------------------------ --------
      • -------- UNCOMMONS --------
      • -------- ------------------------ --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Item: (Item carried by Red_King in slot 1)'s Integer Field: Level ('ilev')) Equal to 6
              • (Item: (Item carried by Red_King in slot 2)'s Integer Field: Level ('ilev')) Equal to 6
              • (Item: (Item carried by Red_King in slot 3)'s Integer Field: Level ('ilev')) Equal to 6
              • (Item: (Item carried by Red_King in slot 4)'s Integer Field: Level ('ilev')) Equal to 6
              • (Item: (Item carried by Red_King in slot 5)'s Integer Field: Level ('ilev')) Equal to 6
              • (Item: (Item carried by Red_King in slot 6)'s Integer Field: Level ('ilev')) Equal to 6
              • (Item: (Item carried by Red_King in slot 1)'s Integer Field: Level ('ilev')) Equal to 7
              • (Item: (Item carried by Red_King in slot 2)'s Integer Field: Level ('ilev')) Equal to 7
              • (Item: (Item carried by Red_King in slot 3)'s Integer Field: Level ('ilev')) Equal to 7
              • (Item: (Item carried by Red_King in slot 4)'s Integer Field: Level ('ilev')) Equal to 7
              • (Item: (Item carried by Red_King in slot 5)'s Integer Field: Level ('ilev')) Equal to 7
              • (Item: (Item carried by Red_King in slot 6)'s Integer Field: Level ('ilev')) Equal to 7
        • Then - Actions
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item: (Item carried by Red_King in slot (Integer A))'s Integer Field: Level ('ilev')) Not equal to 6
                • Then - Actions
                  • Set VariableSet dropped_items_red_king[(Integer A)] = (Item carried by Red_King in slot (Integer A))
                  • Unit - Order Red_King to drop dropped_items_red_king[(Integer A)] at King_Vendor_Red
                  • Wait 0.50 seconds
                • Else - Actions
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item: (Item carried by Red_King in slot (Integer A))'s Integer Field: Level ('ilev')) Equal to 6
                  • (Player 1 (Red) Current gold) Greater than 1250
                • Then - Actions
                  • Player - Add 1250 to Player 13 (Maroon).Current gold
                  • Player - Add -1250 to Player 1 (Red).Current gold
                  • Wait 1.00 seconds
                  • Custom script: call IssueNeutralImmediateOrderById(Player(12), udg_king_library[1], 'I015')
                  • Wait 2.00 seconds
                • Else - Actions
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • Hero - Give dropped_items_red_king[(Integer A)] to Red_King
              • Set VariableSet dropped_items_red_king[(Integer A)] = No item
          • Wait 0.50 seconds
          • -------- ------------------------ --------
          • -------- ------RARES------ --------
          • -------- ------------------------ --------
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item: (Item carried by Red_King in slot (Integer A))'s Integer Field: Level ('ilev')) Not equal to 7
                • Then - Actions
                  • Set VariableSet dropped_items_red_king[(Integer A)] = (Item carried by Red_King in slot (Integer A))
                  • Unit - Order Red_King to drop dropped_items_red_king[(Integer A)] at King_Vendor_Red
                  • Wait 0.50 seconds
                • Else - Actions
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item: (Item carried by Red_King in slot (Integer A))'s Integer Field: Level ('ilev')) Equal to 7
                  • (Player 1 (Red) Current gold) Greater than 2750
                • Then - Actions
                  • Player - Add 2750 to Player 13 (Maroon).Current gold
                  • Player - Add -2750 to Player 1 (Red).Current gold
                  • Wait 1.00 seconds
                  • Custom script: call IssueNeutralImmediateOrderById(Player(12), udg_king_library[1], 'I007')
                  • Wait 2.00 seconds
                • Else - Actions
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • Hero - Give dropped_items_red_king[(Integer A)] to Red_King
              • Set VariableSet dropped_items_red_king[(Integer A)] = No item
          • Wait 0.50 seconds
        • Else - Actions
      • -------- ------------------------ --------
      • -------- ORBS and SHARDS --------
      • -------- ------------------------ --------
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Item carried by Red_King in slot (Integer A))) Equal to Artifact Shard
                      • (artifact_red is owned) Equal to True
                      • (artifact_blue is owned) Equal to True
                      • (artifact_teal is owned) Equal to True
                      • (artifact_purp is owned) Equal to True
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Item carried by Red_King in slot (Integer A))) Equal to Royal Orb of Fire
                      • (artifact_red is owned) Equal to True
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Item carried by Red_King in slot (Integer A))) Equal to Royal Orb of Water
                      • (artifact_blue is owned) Equal to True
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Item carried by Red_King in slot (Integer A))) Equal to Royal Orb of Wind
                      • (artifact_teal is owned) Equal to True
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Item carried by Red_King in slot (Integer A))) Equal to Royal Orb of Ice
                      • (artifact_purp is owned) Equal to True
            • Then - Actions
              • Set VariableSet pawn_item_red = (Item carried by Red_King in slot (Integer A))
              • Custom script: call UnitDropItemTarget(udg_Red_King, udg_pawn_item_red, udg_king_library[1])
              • Wait 1.00 seconds
              • Set VariableSet pawn_item_red = No item
            • Else - Actions
      • Item - Pick every item in Red Ftn <gen> and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Picked item)) Equal to Artifact Shard
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (artifact_red is owned) Equal to False
                          • (artifact_blue is owned) Equal to False
                          • (artifact_teal is owned) Equal to False
                          • (artifact_purp is owned) Equal to False
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Picked item)) Equal to Royal Orb of Fire
                      • (artifact_red is owned) Equal to False
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Picked item)) Equal to Royal Orb of Water
                      • (artifact_blue is owned) Equal to False
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Picked item)) Equal to Royal Orb of Wind
                      • (artifact_teal is owned) Equal to False
                  • And - All (Conditions) are true
                    • Conditions
                      • (Item-type of (Picked item)) Equal to Royal Orb of Ice
                      • (artifact_purp is owned) Equal to False
            • Then - Actions
              • Hero - Give (Picked item) to Red_King
            • Else - Actions
      • Countdown Timer - Pause king_pages_timer[1]
      • Unit - Change ownership of Red_King to Player 1 (Red) and Retain color
      • Countdown Timer - Start king_vendor_timer[1] as a One-shot timer that will expire in 255.00 seconds
      • Trigger - Turn off AI Red King Pages Stop <gen>
      • Trigger - Turn on AI Red Receive Gold <gen>
this one is incase the hero gets stuck or something un-expected happens
  • AI Red King Pages reset
    • Events
      • Time - king_pages_timer[1] expires
    • Conditions
    • Actions
      • Unit - Change ownership of Red_King to Player 1 (Red) and Retain color
      • Trigger - Turn on AI Red Receive Gold <gen>
      • Countdown Timer - Pause king_pages_timer[1]
      • Countdown Timer - Start king_vendor_timer[1] as a One-shot timer that will expire in 255.00 seconds
here's the one that would stop this system from moving forward if the hero takes damage but it doesn't fire for the reasons Pyro explained above:
JASS:
function Trig_AI_Red_King_Pages_Stop_Actions takes nothing returns nothing
    call SetUnitOwner( udg_Red_King, Player(0), false )
    call PauseTimerBJ( true, udg_king_pages_timer[1] )
    call EnableTrigger( gg_trg_AI_Red_Receive_Gold )
    call StartTimerBJ( udg_king_vendor_timer[1], false, 255.00 )
    call DisableTrigger( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_AI_Red_King_Pages_Stop takes nothing returns nothing
    set gg_trg_AI_Red_King_Pages_Stop = CreateTrigger(  )
    call DisableTrigger( gg_trg_AI_Red_King_Pages_Stop )
    call TriggerRegisterUnitEvent( gg_trg_AI_Red_King_Pages_Stop, udg_Red_King, EVENT_UNIT_DAMAGED )
    call TriggerAddAction( gg_trg_AI_Red_King_Pages_Stop, function Trig_AI_Red_King_Pages_Stop_Actions )
endfunction
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
You put a wait inside an integer a loop. That could be a big issue if something overwrites the min/max/current value of integer a (which is itself just a global variable you can't set directly in GUI) because you used a different inter A loop while that one with a wait in it was executing. In general you should never do this.

I see no reason you can't just remove the wait in your loop because I think the unit can sell items instantly if it's in range. If you feel you still need it, make a unique integer variable you use only for this one specific loop, and then do the GUI For each integer <variable>... instead of Integer A. This will avoid there being a possible issue.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
A wait outright doesn't work in a ForGroup() or ForForce() callback. What happens here is more subtle; it works, but it working can cause confusion and strange bugs.
Edit: are u sure A isn’t a local variable?
Absolutely. Convert it to JASS and see how it looks. It will use bj_forLoopAIndex and bj_forLoopAIndexEnd. These are globals and will be overwritten by any other integer A loop that runs while the one with waits is running.
 
Level 18
Joined
Mar 16, 2008
Messages
721
ok this is not the original topic of this thread but is this trigger ok? I replaced 'Integer A' with a udg gui variable 'integer_A_red_prince'?

  • AI Red Enchant pt2
    • Events
      • Unit - A unit enters Red Ftn <gen>
    • Conditions
      • (Entering unit) Equal to Red_Prince
      • (Owner of (Entering unit)) Equal to Player 13 (Maroon)
    • Actions
      • -------- ------------------------ --------
      • -------- PAWN ITEMS BELOW ILV 5 --------
      • -------- ------------------------ --------
      • For each (Integer integer_A_red_prince) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item: (Item carried by Red_Prince in slot integer_A_red_prince)'s Integer Field: Level ('ilev')) Less than 5
            • Then - Actions
              • Set VariableSet pawn_item_red = (Item carried by Red_Prince in slot integer_A_red_prince)
              • Custom script: call UnitDropItemTarget(udg_Red_Prince, udg_pawn_item_red, udg_king_library[1])
              • Wait 1.00 seconds
              • Set VariableSet pawn_item_red = No item
            • Else - Actions
      • ...
i'd assume the 'for' action will handle changing the variable so i'd never need a command to set it to anything
 
Last edited:
Status
Not open for further replies.
Top