• 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 Action?!

Status
Not open for further replies.
Level 16
Joined
Jul 21, 2008
Messages
1,121
Can someone, please, make this trigger leakless using HandleVars (not vJASS). I am having troubles with destroying trigger actions.

Note: Trigger below is simple votekick system.

JASS:
function KickEnd takes nothing returns nothing
	local trigger t = GetTriggeringTrigger()
	local integer i = GetHandleInt(t, "i")
	local integer p = GetHandleInt(t, "p")
	local dialog d = GetClickedDialog()

	if (GetTriggerEventId()==EVENT_GAME_TIMER_EXPIRED) then

		if ((2*i) >= CountPlayersInForceBJ(udg_HumanGroup)) then
			call LeaverRemove(ConvertedPlayer(p))
		endif	    	

       	call FlushHandleLocals(t)        
	call DestroyTrigger(t)
    	call DialogClear(d)
	call DialogDestroy(d)

	endif

	if (GetTriggerEventId()!=EVENT_GAME_TIMER_EXPIRED and udg_DialogButton==GetClickedButton()) then
		set i = i + 1
		call SetHandleInt(t,"i",i)
	endif

	set d = null
	set t = null
endfunction

function Trig_KickStart_Actions takes nothing returns nothing
	local trigger t
	local dialog d
	local integer a
	local integer p
	local integer i

	if ((StringLength(GetEventPlayerChatString())==7) or (StringLength(GetEventPlayerChatString())==8)) then
    	set p = S2I(SubStringBJ(GetEventPlayerChatString(), 7, StringLength(GetEventPlayerChatString())))
		if (p<=1 or p>10) then
			return
		endif

		set d = DialogCreate()
        call DialogClear(d)
    	call DialogSetMessage( d, ( "Do you want to kick|n Player " + GetPlayerName(ConvertedPlayer(S2I(SubStringBJ(GetEventPlayerChatString(), 7, StringLength(GetEventPlayerChatString()))))) ) )
    	
		set udg_DialogButton = DialogAddButton( d, "Yes", 1 )
    		call DialogAddButton( d, "No", 2 )

		set t = CreateTrigger()
		set i = 0

		call SetHandleInt(t, "i", i)
        call SetHandleInt(t, "p", p)		
	
   		call TriggerRegisterDialogEvent( t, d )
    	call TriggerRegisterTimerEventSingle( t, 15.00 )
    	set z = TriggerAddAction( t, function KickEnd )	
    	call SetHandleHandle(t, "z", z)
 
    	set a = 1
	    loop
        exitwhen a > 10
        	if ( IsPlayerInForce(ConvertedPlayer(a), udg_HumanGroup) ) then
           			call DialogDisplay( ConvertedPlayer(a), d,true  )
        	endif
       		set a=a+1
    	endloop

	endif

	set d = null
	set t = null
    set z = null
endfunction

//===========================================================================
function InitTrig_KickStart takes nothing returns nothing
    set gg_trg_KickStart = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_KickStart, Player(0), "-kick ", false )
    call TriggerAddAction( gg_trg_KickStart, function Trig_KickStart_Actions )
endfunction

Thanks in advance!
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
For that you need to add another "get" function in your handle vars code (you can add it where the other "get"s are):

JASS:
function GetHandleTriggerAction takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

And I see you attached the triggeraction on the trigger, so the only thing you have to do now is get that triggeraction in the KickEnd function. Make sure you remove the action before flushing the handles:

JASS:
call TriggerRemoveAction(t, GetHandleTriggerAction(t, "z"))
call FlushHandleLocals(t)
call DestroyTrigger(t)
call DialogClear(d)
call DialogDestroy(d)


Just one question.... Where do you declare the "z" variable in Trig_KickStart_Actions? I can't seem to find it atm.

Btw, if something else doesn't work in the code, you can just point it out as well.
 
Status
Not open for further replies.
Top