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

TriggerRegisterEvent not starting

Status
Not open for further replies.
Level 3
Joined
Jan 13, 2010
Messages
52
Hey all

can someone tell me why this trigger isnt starting or repeating when the game starts?

Lua:
function Trig_Enemy_Spawn_Conditions()
    return udg_SpawnCap < 500
end

function Trig_Enemy_Spawn_Func004Func002A()
    udg_TempLoc = GetUnitLoc (GetEnumUnit())
    udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[1]
    CreateUnitAtLoc(Player(20), FourCC("n009"), udg_TempLoc, 0.)
    RemoveLocation (udg_TempLoc)
end

function Trig_Enemy_Spawn_Func005Func002A()
    udg_TempLoc = GetUnitLoc (GetEnumUnit())
    if 0 == GetRandomInt(0, 1) then
        CreateUnitAtLoc(Player(20), FourCC("n00B"), udg_TempLoc, 0.)
    else
        CreateUnitAtLoc(Player(21), FourCC("n000"), udg_TempLoc, 0.)
    end
    udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[1]
    RemoveLocation (udg_TempLoc)
end


function Trig_Enemy_Spawn_Actions()
    if udg_SpawnSeconds <= 100 then
        udg_SpawnSeconds = udg_SpawnSeconds + 1
    else
        udg_SpawnSeconds = 0
    end
    DisplayTimedTextToForce(GetForceOfPlayer(Player(0)), 1.1, "Test")
    if UnitAlive(udg_SpawnBuildings[4]) == true and ModuloReal(I2R(udg_SpawnSeconds), 5.00) == 4.00 then
        --// Scorched Spawn
        udg_TempLoc = GetRandomLocInRect (udg_SpawnFields[4])
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[1]
        CreateUnitAtLoc(Player(21), FourCC("n009"), udg_TempLoc, 0.)
        RemoveLocation (udg_TempLoc)
    end
    if CountUnitsInGroup(udg_GravesUnitGroup) > 0 and ModuloReal(I2R(udg_SpawnSeconds), 4.00) == 3.00 then
        --// Scorched Spawn
        ForGroup( udg_GravesUnitGroup, Trig_Enemy_Spawn_Func004Func002A() )
    end
    if CountUnitsInGroup(udg_SewerUnitGroup) > 0 and ModuloReal(I2R(udg_SpawnSeconds), 4.00) == 3.00 then
        --// Canalization Spawn
        ForGroup( udg_SewerUnitGroup, Trig_Enemy_Spawn_Func005Func002A() )
    end
    if UnitAlive(udg_SpawnBuildings[5]) == true and I2R(udg_SpawnSeconds) / 1.50 >= 10 and ModuloReal(I2R(udg_SpawnSeconds), 9.00) == 8.00 then
        --// Fire Spawn
        udg_TempLoc = GetRandomLocInRect (udg_SpawnFields[5])
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[2]
        if 0 == GetRandomInt(0, 1) then
            CreateUnitAtLoc(Player(21), FourCC("n003"), udg_TempLoc, 0.)
        else
            CreateUnitAtLoc(Player(21), FourCC("n002"), udg_TempLoc, 0.)
        end
        RemoveLocation (udg_TempLoc)
    end
    if UnitAlive(udg_SpawnBuildings[2]) == true and ModuloReal(I2R(udg_SpawnSeconds), 14.00) == 13.00 then
        --// Orc Spawn
        udg_TempLoc = GetRandomLocInRect (udg_SpawnFields[2])
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[3]
        CreateUnitAtLoc(Player(22), FourCC("n004"), udg_TempLoc, 0.)
        RemoveLocation (udg_TempLoc)
    end
    if UnitAlive(udg_SpawnBuildings[0]) == true and ModuloReal(I2R(udg_SpawnSeconds), 14.00) == 13.00 then
        --// Portal Spawn
        udg_TempLoc = GetRandomLocInRect (udg_SpawnFields[0])
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[3]
        CreateUnitAtLoc(Player(21), FourCC("n008"), udg_TempLoc, 0.)
        RemoveLocation (udg_TempLoc)
    end
    if IsUnitAliveBJ(udg_SpawnBuildings[3]) == true and ModuloReal(I2R(udg_SpawnSeconds), 19.00) == 18.00 then
        --// Sunken SHip Spawn
        udg_TempLoc = GetRandomLocInRect (udg_SpawnFields[3])
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[4]
        CreateUnitAtLoc(Player(22), FourCC("n007"), udg_TempLoc, 0.)
        RemoveLocation (udg_TempLoc)
    end
    if UnitAlive(udg_SpawnBuildings[6]) == true and ModuloReal(I2R(udg_SpawnSeconds), 19.00) == 18.00 then
        --// Scorched Spawn
        udg_TempLoc = GetRandomLocInRect (udg_SpawnFields[6])
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[4]
        CreateUnitAtLoc(Player(21), FourCC("n006"), udg_TempLoc, 0.)
        RemoveLocation (udg_TempLoc)
    end
    if UnitAlive(udg_SpawnBuildings[1]) == true and ModuloReal(I2R(udg_SpawnSeconds), 25.00) == 24.00  then
        --// Beast Spawn
        udg_TempLoc = GetRandomLocInRect (udg_SpawnFields[1])
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[5]
        CreateUnitAtLoc(Player(23), FourCC("n005"), udg_TempLoc, 0.)
        RemoveLocation (udg_TempLoc)
    end
    if ModuloReal(I2R(udg_SpawnSeconds), 25.00) == 23.00 then
        --// Beast Spawn
        udg_TempLoc = GetPlayerStartLocationLoc (Player(21))
        udg_SpawnCap = udg_SpawnCap + udg_MonsterPointsTierLvl[5]
        CreateUnitAtLoc(Player(23), FourCC("n00A"), udg_TempLoc, 0.)
        RemoveLocation (udg_TempLoc)
    end
    MultiboardSetItemValueBJ( udg_MultiboardGame, 3, 1, I2S(udg_SpawnCap) )
end


function InitTrig_Enemy_Spawn()
    gg_trg_Enemy_Spawn = CreateTrigger(  )
    TriggerRegisterTimerEventPeriodic( gg_trg_Enemy_Spawn, 8.00 )
    TriggerAddCondition( gg_trg_Enemy_Spawn, Condition( Trig_Enemy_Spawn_Conditions() ) )
    TriggerAddAction( gg_trg_Enemy_Spawn, Trig_Enemy_Spawn_Actions() )
end
 
Last edited:
I spotted some lines which come up as problematic:

Lua:
function InitTrig_Enemy_Spawn()
    gg_trg_Enemy_Spawn = CreateTrigger(  )
    TriggerRegisterTimerEventPeriodic( gg_trg_Enemy_Spawn, 8.00 )
    TriggerAddCondition( gg_trg_Enemy_Spawn, Condition( Trig_Enemy_Spawn_Conditions() ) )
    TriggerAddAction( gg_trg_Enemy_Spawn, Trig_Enemy_Spawn_Actions() )
end

The following lines should instead look like this:
Lua:
function InitTrig_Enemy_Spawn()
    gg_trg_Enemy_Spawn = CreateTrigger(  )
    TriggerRegisterTimerEventPeriodic( gg_trg_Enemy_Spawn, 8.00 )
    -- Remove the extra pair of parentheses
    TriggerAddCondition( gg_trg_Enemy_Spawn, Condition( Trig_Enemy_Spawn_Conditions ) )
    TriggerAddAction( gg_trg_Enemy_Spawn, Trig_Enemy_Spawn_Actions )
end
 
Level 3
Joined
Jan 13, 2010
Messages
52
Thanks MyPad but sadly this didnt fixed my problem.

And thanks to uncle for the information. I changed it to lua
 
Does you Trigger/InitTrig run at all?
World editor creates a list of such initTrig functions and calls them when the time is right. But that includes only GUI triggers created with Trigger Editor.
Written code put into a script file will not be called automatic, even if you create a InitTrig function.
 
Last edited:
Does you Trigger/InitTrig run at all?
World editor creates a list of such initTrig functions and calls them when the time is right. But that includes only GUI triggers created with Trigger Editor.
Written code put into a script file will not be called automatic, even if you create a InitTrig function.

To support this statement, in Lua mode, you cannot convert triggers to custom text. However, you can create a trigger which runs on melee initialization and call the InitTrig function, as demonstrated below:

  • Enemy Spawn Init
  • Events
    • Game - Melee Initialization
  • Conditions
  • Actions
    • Custom Script: InitTrig_Enemy_Spawn()
Edit:

Watch out for any silent errors in Lua; those are a pain in the ass to debug. You can usually catch them with xpcall(<func>, print)
 
Level 3
Joined
Jan 13, 2010
Messages
52
Oh missed that information. So when i call my trigger once he will run every 8 seconds?

Is there any other Option to not use gui at all?

Thanks both of you and for the debug tip.
 
Oh missed that information. So when i call my trigger once he will run every 8 seconds?

Is there any other Option to not use gui at all?

Thanks both of you and for the debug tip.
Yes, and yes.

If you want to initialize the function at the same time as the normal map initialization time, you might find Bribe's Lua Initializer useful. Otherwise, if you're okay with initializing it on map config, just make sure to assign the generated triggercondition and triggeraction to variables, to avoid garbage collection.
 
Status
Not open for further replies.
Top