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

[Trigger] Does this Custom Script work?

Status
Not open for further replies.
Level 3
Joined
Dec 23, 2009
Messages
32
Hey I need some help with custom scripts, I recently saw a tutorial on leaks and decided to make most of my triggers leakfree, though I cant make this trigger leakfree:

Edit: ops sorry I meant that Im quite certain the trigger wont work.. please help the system to know which player it is..

  • Starting Setup Copy
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set InventoryRegion[1] = Red Inventory Drop <gen>
      • Set InventoryRegion[2] = Blue Inventory Drop <gen>
      • Set InventoryRegion[3] = Teal Inventory Drop <gen>
      • Set InventoryRegion[4] = Purple Inventory Drop <gen>
      • Set InventoryRegion[5] = Yellow Inventory Drop <gen>
      • Set InventoryRegion[6] = Orange Inventory Drop <gen>
      • Set InventoryRegion[7] = Grenn Inventory Drop <gen>


  • Inventory Enter
    • Events
      • Player - Player 1 (Red) types a chat message containing -inventory as An exact match
      • Player - Player 2 (Blue) types a chat message containing -inventory as An exact match
      • Player - Player 3 (Teal) types a chat message containing -inventory as An exact match
      • Player - Player 4 (Purple) types a chat message containing -inventory as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -inventory as An exact match
      • Player - Player 6 (Orange) types a chat message containing -inventory as An exact match
      • Player - Player 7 (Green) types a chat message containing -inventory as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units in (Entire map) owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set InvPoint[(Player number of (Triggering player))] = (Position of (Picked unit))
          • Unit - Move (Picked unit) instantly to (Center of InventoryRegion[(Player number of (Triggering player))])
          • Custom script: call DestroyGroup( udg_TempGroup )

  • Player Inventory Leave
    • Events
      • Unit - A unit owned by Player 1 (Red) Acquires an item
      • Unit - A unit owned by Player 2 (Blue) Acquires an item
      • Unit - A unit owned by Player 3 (Teal) Acquires an item
      • Unit - A unit owned by Player 4 (Purple) Acquires an item
      • Unit - A unit owned by Player 5 (Yellow) Acquires an item
      • Unit - A unit owned by Player 6 (Orange) Acquires an item
      • Unit - A unit owned by Player 7 (Green) Acquires an item
    • Conditions
      • (InventoryRegion[(Player number of (Triggering player))] contains (Triggering unit)) Equal to True
    • Actions
      • Unit - Move (Hero manipulating item) instantly to InvPoint[(Player number of (Triggering player))]
      • [COLOR="Red"][B]Custom script: call RemoveLocation (udg_InvPoint[(Player number of (Triggering player))])[/B][/COLOR]
Thanks, Diabloj
 
Level 9
Joined
Jun 7, 2007
Messages
195
Change this:

  • Inventory Enter
    • Events
      • Player - Player 1 (Red) types a chat message containing -inventory as An exact match
      • Player - Player 2 (Blue) types a chat message containing -inventory as An exact match
      • Player - Player 3 (Teal) types a chat message containing -inventory as An exact match
      • Player - Player 4 (Purple) types a chat message containing -inventory as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -inventory as An exact match
      • Player - Player 6 (Orange) types a chat message containing -inventory as An exact match
      • Player - Player 7 (Green) types a chat message containing -inventory as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units in (Entire map) owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set InvPoint[(Player number of (Triggering player))] = (Position of (Picked unit))
          • Unit - Move (Picked unit) instantly to (Center of InventoryRegion[(Player number of (Triggering player))])
          • Custom script: call DestroyGroup( udg_TempGroup )
To this:

  • Inventory Enter
    • Events
      • Player - Player 1 (Red) types a chat message containing -inventory as An exact match
      • Player - Player 2 (Blue) types a chat message containing -inventory as An exact match
      • Player - Player 3 (Teal) types a chat message containing -inventory as An exact match
      • Player - Player 4 (Purple) types a chat message containing -inventory as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -inventory as An exact match
      • Player - Player 6 (Orange) types a chat message containing -inventory as An exact match
      • Player - Player 7 (Green) types a chat message containing -inventory as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units in (Entire map) owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set InvPoint[(Player number of (Triggering player))] = (Position of (Picked unit))
          • Unit - Move (Picked unit) instantly to (Center of InventoryRegion[(Player number of (Triggering player))])
          • Custom script: RemoveLocation( udg_InvPoint[GetConvertedPlayerId(GetTriggerPlayer())] )
      • Custom script: call DestroyGroup( udg_TempGroup )
 
  • Player Inventory Leave
    • Actions
      • Custom script: call RemoveLocation( udg_InvPoint[ GetPlayerId( GetTriggerPlayer( ) ) + 1 ] )
You cannot use the text that is displayed by the GUI inside JASS.
If you create a GUI function and convert it to JASS you'll see that it does something different. I recommend you read some basic JASS tutorials.
 
Level 3
Joined
Dec 23, 2009
Messages
32
Sorry I dident quite understand that Dragoon... dosent Furiontti's trigger solve the problem?
Edit: I just noticed you removed the location when the player was inside the ''inventory'' so I just changed where the script was but it still works ofc :)
ReEdit: When I save the map the WE comes up saying that the system was expecting a '' ' '' are you sure you entered the script 100% correctly?
 
Last edited:
Create another point-variable, name it Point. Do what I do (note that I change the type of unit group that you pick to a "Matching Condition" type):
  • Inventory Enter
    • Events
      • Player - Player 1 (Red) types a chat message containing -inventory as An exact match
      • Player - Player 2 (Blue) types a chat message containing -inventory as An exact match
      • Player - Player 3 (Teal) types a chat message containing -inventory as An exact match
      • Player - Player 4 (Purple) types a chat message containing -inventory as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -inventory as An exact match
      • Player - Player 6 (Orange) types a chat message containing -inventory as An exact match
      • Player - Player 7 (Green) types a chat message containing -inventory as An exact match
    • Conditions
    • Actions
      • Set Point = (Center of InventoryRegion[(Player number of (Triggering player))])
      • Set TempGroup = (Units owned by (Triggering player) Matching Condition(Matching Unit is Unit Type Hero))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: set udg_InvPoint[GetPlayerId(GetTriggerPlayer())] = GetUnitLoc( GetEnumUnit() )
          • Unit - Move (Picked unit) instantly to (Point)
      • Custom script: call GroupClear( udg_TempGroup )
      • Custom script: call DestroyGroup( udg_TempGroup )
      • Custom script: call RemoveLocation( udg_Point )
Also, in this one, replace the condition you already had for this modified condition here:

  • Player Inventory Leave
    • Events
      • Unit - A unit owned by Player 1 (Red) Acquires an item
      • Unit - A unit owned by Player 2 (Blue) Acquires an item
      • Unit - A unit owned by Player 3 (Teal) Acquires an item
      • Unit - A unit owned by Player 4 (Purple) Acquires an item
      • Unit - A unit owned by Player 5 (Yellow) Acquires an item
      • Unit - A unit owned by Player 6 (Orange) Acquires an item
      • Unit - A unit owned by Player 7 (Green) Acquires an item
    • Conditions
      • (InventoryRegion[(Player number of Player( Owner of (Triggering Unit)))] contains (Triggering unit)) Equal to True
    • Actions
      • Custom script: call SetUnitPositionLoc( GetTriggerUnit() , udg_InvPoint[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))] )
      • Custom script: call RemoveLocation( udg_InvPoint[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))] )
 
Last edited:
  • Player Inventory Leave
    • Actions
      • Custom script: call RemoveLocation( udg_InvPoint[ GetPlayerId( GetTriggerPlayer( ) ) + 1 ] )
You cannot use the text that is displayed by the GUI inside JASS.
If you create a GUI function and convert it to JASS you'll see that it does something different. I recommend you read some basic JASS tutorials.

there is nothing in that action that is using the text entered...
 
Level 3
Joined
Dec 23, 2009
Messages
32
Thanks alot bribe :D You also deleted another leak :)
But for future leak improvements.. do I need
Custom script: call GroupClear( udg_TempGroup )
before
Custom script: call DestroyGroup( udg_TempGroup ) ?
and one last thing.. would you mind writeing some custom script commands? couse I really dont know any else than those you just showed :S
 
Oh, I mixed the events up. Well, Bribe fixed it again.

As for "custom script commands". Custom Script simply allows you inside GUI to call JASS functions directly.

For example this:

JASS:
function Trigger01_Conditions takes nothing returns boolean
    return GetUnitTypeId( GetTriggerUnit(  ) ) == 'Hpal'
endfunction

function Trigger01_Actions takes nothing returns nothing
    local unit dummy = CreateUnit( GetOwningPlayer( GetTriggerUnit(  ) ), 'hpea', GetUnitX( GetTriggerUnit(  ) ), GetUnitY( GetTriggerUnit(  ) ), 0 )
    call UnitApplyTimedLife( dummy, 'BTLF', 2. )
    call IssueImmediateOrder( dummy, "stomp" )
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Trigger01 takes nothing returns nothing
    set gg_trg_Trigger01 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Trigger01, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Trigger01, Condition( function Trigger01_Conditions ) )
    call TriggerAddAction( gg_trg_Trigger01, function Trigger01_Actions )
endfunction
is the same as this:
  • Trigger02
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Paladin
    • Actions
      • Custom script: local unit dummy = CreateUnit( GetOwningPlayer( GetTriggerUnit( ) ), 'hpea', GetUnitX( GetTriggerUnit( ) ), GetUnitY( GetTriggerUnit( ) ), 0 )
      • Custom script: call UnitApplyTimedLife( dummy, 'BTLF', 2. )
      • Custom script: call IssueImmediateOrder( dummy, "stomp" )
      • Custom script: set dummy = null
That's why I recommended you to read some basic JASS tutorials. As this way you would also learn how to use custom script.
 
I doubt that, Adiktuz. Groups are made with CreateGroup(g) and DestroyGroup(g)... yet they are enumerated/cleared with seperate functions. If enumeration isn't tied to the Creation, I highly doubt it's tied to the destruction.

I think they separated enumeration to enable modifying the group after creation... I think its logical that it is already cleared when destroyed... anyway just opinion... ^^
 
Every handle that's assigned to a unit has to be cleared manually after the unit dies, including special effects and hashtables. You can removeunit, explodeunit, killunit, but none of those kill the things attached to it.

The same way handles are assigned to units, I think units to group. So if you need to remove the handles from units in addition to its death/removal, most likely need to remove the units from the group in additiona to its destruction.
 
Every handle that's assigned to a unit has to be cleared manually after the unit dies, including special effects and hashtables. You can removeunit, explodeunit, killunit, but none of those kill the things attached to it.

The same way handles are assigned to units, I think units to group. So if you need to remove the handles from units in addition to its death/removal, most likely need to remove the units from the group in additiona to its destruction.

its just that I never saw someone clearing the group before using destroy group...
 
Well, is there a way to test it?

JASS:
scope ClearOrNot initializer init
globals
    private integer i
    private integer j
    private unit u
    private group g
    private trigger T
    private timer t = CreateTimer()
endglobals
 
function control1 takes nothing returns nothing
    set i = 1
    loop
        set j = 1
        set g = CreateGroup()
        loop
            set u = CreateUnit(Player(0), 'hfoo', 0,0,0)
            call GroupAddUnit(g,u)
            call RemoveUnit(u)
        set j = j + 1
        exitwhen i > 1000
        endloop
        call GroupClear(g)
        call DestroyGroup(g)
    set i = i + 1
    exitwhen i > 1000
    endloop
    call TimerStart(t,0.3,true,null)
    call DisableTrigger(T2)
endfunction
 
private function control2 takes nothing returns nothing
    set i = 1
    loop
        set j = 1
        set g = CreateGroup()
        loop
            set u = CreateUnit(Player(0), 'hfoo', 0,0,0)
            call GroupAddUnit(g,u)
            call RemoveUnit(u)
        set j = j + 1
        exitwhen i > 1000
        endloop
        call GroupClear(g)
        call DestroyGroup(g)
    set i = i + 1
    exitwhen i > 1000
    endloop
    call TimerStart(t,0.3,true,null)
    call DisableTrigger(T1)
endfunction
endscope
 
private function init takes nothing returns nothing
    set T1 = CreateTrigger()
    call TriggerAddAction(T1,function control1)
    call TriggerRegisterTimerExpireEvent(T1,t,true)
    call TriggerRegisterPlayerChatEvent(T1,Player(0),"no clear",true)
    set T2 = CreateTrigger()
    call TriggerAddAction(T2,function control1)
    call TriggerRegisterTimerExpireEvent(T2,t,true)
    call TriggerRegisterPlayerChatEvent(T2,Player(0),"with clear",true)
endfunction

1000 groups being assigned 1000 units each, one method simply destroys them, the other method clears them then destroys them.

Although I don't know the best way to actually initiate & compare these tests...
 
Last edited:
Well, is there a way to test it?

JASS:
function Set1000UnitsToGroup takes nothing returns nothing
local integer i = 1
local unit u
local group g = CreateGroup()
loop
    set u = CreateUnit(Player(0), 'hfoo', 0,0,0)
    call GroupAddUnit(g,u)
    call RemoveUnit(u)
    set i = i + 1
    exitwhen i > 1000
endloop
call DestroyGroup(g)
set g = null
set u = null
endfunction
function Make1000Groups takes nothing returns nothing
    local integer i = 1
    loop
        call Set1000UnitsToGroup()
        set i = i + 1
        exitwhen i > 1000
    endloop
endfunction

JASS:
function Set1000UnitsToGroup takes nothing returns nothing
local integer i = 1
local unit u
local group g = CreateGroup()
loop
    set u = CreateUnit(Player(0), 'hfoo', 0,0,0)
    call GroupAddUnit(g,u)
    call RemoveUnit(u)
    set i = i + 1
    exitwhen i > 1000
endloop
call GroupClear(g)
call DestroyGroup(g)
set g = null
set u = null
endfunction
function Make1000Groups takes nothing returns nothing
    local integer i = 1
    loop
        call Set1000UnitsToGroup()
        set i = i + 1
        exitwhen i > 1000
    endloop
endfunction

1000 groups being assigned 1000 units each, one method simply destroys them, the other method clears them then destroys them.

Although I don't know the best way to actually initiate & compare these tests...

maybe try running them over and over again and see if it would crash?
 
Ok, I've established the code. I'm not able to test it on this computer; hopefully someone who's bored can (requires Jass NewGen).

JASS:
scope ClearOrNot initializer init
globals
    private integer i
    private integer j
    private unit u
    private group g
    private trigger T1
    private trigger T2
    private timer t = CreateTimer()
endglobals
 
function control1 takes nothing returns nothing
    set i = 1
    loop
        set j = 1
        set g = CreateGroup()
        loop
            set u = CreateUnit(Player(0), 'hfoo', 0,0,0)
            call GroupAddUnit(g,u)
            call RemoveUnit(u)
        set j = j + 1
        exitwhen i > 1000
        endloop
        call GroupClear(g)
        call DestroyGroup(g)
    set i = i + 1
    exitwhen i > 1000
    endloop
    call TimerStart(t,0.3,false,null)
    call DisableTrigger(T2)
endfunction
 
private function control2 takes nothing returns nothing
    set i = 1
    loop
        set j = 1
        set g = CreateGroup()
        loop
            set u = CreateUnit(Player(0), 'hfoo', 0,0,0)
            call GroupAddUnit(g,u)
            call RemoveUnit(u)
        set j = j + 1
        exitwhen i > 1000
        endloop
        call GroupClear(g)
        call DestroyGroup(g)
    set i = i + 1
    exitwhen i > 1000
    endloop
    call TimerStart(t,0.3,false,null)
    call DisableTrigger(T1)
endfunction
endscope
 
private function init takes nothing returns nothing
    set T1 = CreateTrigger()
    call TriggerAddAction(T1,function control1)
    call TriggerRegisterTimerExpireEvent(T1,t,true)
    call TriggerRegisterPlayerChatEvent(T1,Player(0),"no clear",true)
    set T2 = CreateTrigger()
    call TriggerAddAction(T2,function control1)
    call TriggerRegisterTimerExpireEvent(T2,t,true)
    call TriggerRegisterPlayerChatEvent(T2,Player(0),"with clear",true)
endfunction
 
Status
Not open for further replies.
Top