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

[Solved] Trigger name?

Status
Not open for further replies.
Level 7
Joined
Sep 16, 2016
Messages
185
So, I made this by having the idea of; when someone writes -spartacus, a voice will start. Which works, but it overlaps. I could use PolledWait to avoid the tracks overlapping, but I really dislike PolledWait. So what I did was so that when this function plays the sound, it disables the trigger. Then a timer which has 15 seconds, once it runs out it calls to my other function which is called "EnableThisTrigger" that enables the disabled trigger. So that when writing -spartacus again, it will play the sound.

My purpose is that, when people write -spartacus, the sound will only play once every 15 seconds.

And yes, right now only a player with the name "null" can use this, but pay that no mind.

JASS:
function EnableThisTrigger takes nothing returns nothing
        local integer i = 0

        loop
            call DisplayTimedTextToPlayer(Player(i), 0, 0, 60, "It has been fifteen seconds since EnableThisTrigger was executed.")
            set i = i + 1
            exitwhen i == bj_MAX_PLAYERS
        endloop

        call EnableTrigger(name of the trigger of castauraforwolkern2)
endfunction
function CastAuraForWolkern2 takes nothing returns nothing
        local player TrigPlayer = GetTriggerPlayer()
        local integer ip = GetPlayerId(TrigPlayer)
        local timer t = CreateTimer()

        if GetPlayerName(TrigPlayer)== "null" then
            set SpartacusVoice = CreateSound("null\\KoreWaSpartacusDeAru.mp3", false, false, true, 12700, 12700, "DefaultEAXON")

            set bj_lastPlayedSound = SpartacusVoice

            if SpartacusVoice != null then
                call StartSound(SpartacusVoice)
            endif

              call DisableTrigger( - name of this functions trigger)
            call TimerStart(t, 15.00, false, function EnableThisTrigger)
          
        endif
        set TrigPlayer = null
        set t = null
    endfunction                                                             
function AuraForWolkern2Init takes nothing returns nothing
local trigger t=CreateTrigger()
local integer i=0
loop
call TriggerRegisterPlayerChatEvent(t, Player(i), "-spartacus", true)
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
call TriggerAddAction(t,function CastAuraForWolkern2)
set t=null
endfunction

Thanks.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
First of all trigger!=function.
A trigger consists of actions, conditions and events. Actions and conditions contain functions.
In your case you have a local trigger, that is created at map initialization. You want to disable this trigger, so it's event cannot fire and thus the action (CastAuraForWolkern2) is not exectued.
Since it is a local trigger, it is difficult to refer to it. You can use GetTriggeringTrigger(), but this won't work on your other function (EnableThisTrigger ), because it is called by a timer and not by an event.
You have 3 options.
1. store your trigger in a global variable
2. store your trigger in a hashtable
3. use a different method. For example a global boolean instead of enabling/disabling the trigger
 
Level 7
Joined
Sep 16, 2016
Messages
185
First of all trigger!=function.
A trigger consists of actions, conditions and events. Actions and conditions contain functions.
In your case you have a local trigger, that is created at map initialization. You want to disable this trigger, so it's event cannot fire and thus the action (CastAuraForWolkern2) is not exectued.
Since it is a local trigger, it is difficult to refer to it. You can use GetTriggeringTrigger(), but this won't work on your other function (EnableThisTrigger ), because it is called by a timer and not by an event.
You have 3 options.
1. store your trigger in a global variable
2. store your trigger in a hashtable
3. use a different method. For example a global boolean instead of enabling/disabling the trigger

Thanks for the amazing reply, I tried using a global variable, but I don't know how to link that one to "CastAuraForWolkern2". :/

About GetTriggeringTrigger, I did that one at first, but realized it was futile since I still had to call for the trigger when I wanted to enable it from "EnableThisTrigger"

Can you help me how to "store the trigger in a global variable"?
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
Declare a new variable, and assign that trigger to it.

Either:
Sem título.png


Or

JASS:
globals
    trigger YourTrigger
endglobals
NOTE: This one requires JassHelper (WEX or JNGP)

Then:

JASS:
function AuraForWolkern2Init takes nothing returns nothing
    local integer i=0
    set udg_YourTrigger = CreateTrigger()
 
    loop
        call TriggerRegisterPlayerChatEvent(udg_YourTrigger, Player(i), "-spartacus", true)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
    call TriggerAddAction(udg_YourTrigger, function CastAuraForWolkern2)
endfunction

JASS:
// Enable or Disable
// Do note that GUI variables require the "udg_" prefix
call EnableTrigger(udg_YourTrigger) // For GUI-declared variables
call EnableTrigger(YourTrigger)     // For JASS-declared variables
 
Level 7
Joined
Sep 16, 2016
Messages
185
Have been talking to Jampion on Discord, which helped me greatly.

I thank you as well BloodSoul for the easy to follow guide.

Rep+ on you both.
 
Status
Not open for further replies.
Top