• 🏆 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] Jass Code Help

Status
Not open for further replies.
Level 5
Joined
Feb 22, 2013
Messages
161
JASS:
function Melee_Initialization_Actions takes nothing returns nothing
    
    call FogModifierStart(CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE, gg_rct_Horde_Area, true, false))
    call FogModifierStart(CreateFogModifierRect(Player(1), FOG_OF_WAR_VISIBLE, gg_rct_Alliance_Area, true, false))
    call FogModifierStart(CreateFogModifierRect(Player(2), FOG_OF_WAR_VISIBLE, gg_rct_Alliance_Area, true, false))
    call FogModifierStart(CreateFogModifierRect(Player(10), FOG_OF_WAR_VISIBLE, gg_rct_Horde_Area, true, false))
    
    if GetPlayerSlotState(Player(0)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(0)) == MAP_CONTROL_USER then
        set udg_RedIsPlaying = true
        call BJDebugMsg("Red is playing and is a user.")
    endif
    if GetPlayerSlotState(Player(1)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(1)) == MAP_CONTROL_USER then
        set udg_BlueIsPlaying = true
        call BJDebugMsg("Blue is playing and is a user.")
    endif
    if GetPlayerSlotState(Player(2)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(2)) == MAP_CONTROL_USER then
        set udg_TealIsPlaying = true
        call BJDebugMsg("Teal is playing and is a user.")
    endif
    if GetPlayerSlotState(Player(10)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(10)) == MAP_CONTROL_USER then
        set udg_DarkGreenIsPlaying = true
        call BJDebugMsg("Dark Green is playing and is a user.")
    endif
    
    if udg_RedIsPlaying == false then
        call StartMeleeAI(Player(0), "orc.ai")
    endif
    if udg_BlueIsPlaying == false then
        call StartMeleeAI(Player(1), "human.ai")
    endif
    if udg_TealIsPlaying == false then
        call StartMeleeAI(Player(2), "elf.ai")
    endif
    if udg_DarkGreenIsPlaying == false then
        call StartMeleeAI(Player(10), "undead.ai")
    endif
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    call TriggerAddAction( t, function Melee_Initialization_Actions )
    
    set t = null
endfunction

When I begin the game, it seems like this trigger doesn't run, it's supposed to start at map init, and I have the map init thing checked as well... Is there anything wrong with this?
 
Level 5
Joined
Feb 22, 2013
Messages
161
Because there are no events currently registered. Try this in the init:
JASS:
function InitTrig_Melee_Initialization takes nothing returns nothing
    call Melee_Initialization_Actions()
endfunction

It is supposed to run on map init, that doesn't need event registration
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
The map initialization event provided by the GUI injects the selected trigger into the main function. So no, OP does not need to call from the InitTrig function (which is btw injected too).

Put a debug message in the front. Maybe your main function crashes, which is mostly due to oversizedly initialized arrays.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
I see. You have replaced the trigger identifier with a local variable. How can wc3 know that this trigger object should be connected to the init event? The trigger variable it does try to refer to is the one generated by the trigger page, which is given the same name as the trigger page + prefix and blanks substituted with underscore.

So for trigger page "Melee Initialization" that would be "gg_trg_Melee_Initialization". Also, when using this global variable, do not nullify it.
 
Level 5
Joined
Feb 22, 2013
Messages
161
I see, even though I was taught that you could call a local trigger t and set it null after the function ends... Anyway, changing it back to the default way worked, thanks WaterKnight
 
Level 5
Joined
Feb 22, 2013
Messages
161
I have another question however...

JASS:
function tExpires takes nothing returns nothing	
	call BJDebugMsg("Timer has expired.")
endfunction

function Melee_Initialization takes nothing returns nothing
	local timer t = CreateTimer()
	local timerdialog td = CreateTimerDialog(t)

	call TimerStart(t, 3.00, false, function tExpires)
	call TimerDialogSetTitle(td, "Gate Control In:")
	call TimerDialogDisplay(td, true)
endfunction

This was added to the Initialization trigger as I showed before. The timer expires and everything, but the problem is, is that the timer dialog does not display when the trigger is ran
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
How about the one I suggested? It works.
Wc3 just calls all initializers.

Yes, though it's not exactly the same. First all InitTrigs get called, then initialization-marked triggers executed. So if you want to refer to another global trigger e.g., you would not do that within InitTrig as the target might not be known yet.

You can create the dialog/board handles on init but not display them. More reason to shift init stuff to after the loadscreen.
 
Level 5
Joined
Feb 22, 2013
Messages
161
Ok, I finally got the initialization trigger to work... Now I'm having difficulties with something else... Here's the code:

JASS:
function RedWorkersCantLeavePutback takes nothing returns nothing
    if ( not (GetRectMinX(gg_rct_WorkersCantLeave2) <= GetUnitX(GetEnumUnit())) and (GetUnitX(GetEnumUnit()) <= GetRectMaxX(gg_rct_WorkersCantLeave2)) and (GetRectMinY(gg_rct_WorkersCantLeave2) <= GetUnitY(GetEnumUnit())) and (GetUnitY(GetEnumUnit()) <= GetRectMaxY(gg_rct_WorkersCantLeave2))) then
        call SetUnitX(GetEnumUnit(), GetRectCenterX(gg_rct_WorkerPutBack2))
        call SetUnitY(GetEnumUnit(), GetRectCenterY(gg_rct_WorkerPutBack2))
        
        call DisplayTimedTextToPlayer(Player(0), 0, 0, 3.00, "Workers can not leave the kingdom!")
    endif
endfunction

function DarkGreenWorkersCantLeavePutback takes nothing returns nothing
    if ( not (GetRectMinX(gg_rct_WorkersCantLeave2) <= GetUnitX(GetEnumUnit())) and (GetUnitX(GetEnumUnit()) <= GetRectMaxX(gg_rct_WorkersCantLeave2)) and (GetRectMinY(gg_rct_WorkersCantLeave2) <= GetUnitY(GetEnumUnit())) and (GetUnitY(GetEnumUnit()) <= GetRectMaxY(gg_rct_WorkersCantLeave2))) then
        call SetUnitX(GetEnumUnit(), GetRectCenterX(gg_rct_WorkerPutBack2))
        call SetUnitY(GetEnumUnit(), GetRectCenterY(gg_rct_WorkerPutBack2))
        
        call DisplayTimedTextToPlayer(Player(10), 0, 0, 3.00, "Workers can not leave the kingdom!")
    endif
endfunction

function BlueWorkersCantLeavePutback takes nothing returns nothing
    if ( not (GetRectMinX(gg_rct_WorkersCantLeave) <= GetUnitX(GetEnumUnit())) and (GetUnitX(GetEnumUnit()) <= GetRectMaxX(gg_rct_WorkersCantLeave)) and (GetRectMinY(gg_rct_WorkersCantLeave) <= GetUnitY(GetEnumUnit())) and (GetUnitY(GetEnumUnit()) <= GetRectMaxY(gg_rct_WorkersCantLeave))) then
        call SetUnitX(GetEnumUnit(), GetRectCenterX(gg_rct_WorkerPutBack))
        call SetUnitY(GetEnumUnit(), GetRectCenterY(gg_rct_WorkerPutBack))
        
        call DisplayTimedTextToPlayer(Player(1), 0, 0, 3.00, "Workers can not leave the kingdom!")
    endif
endfunction

function TealWorkersCantLeavePutback takes nothing returns nothing
    if ( not (GetRectMinX(gg_rct_WorkersCantLeave) <= GetUnitX(GetEnumUnit())) and (GetUnitX(GetEnumUnit()) <= GetRectMaxX(gg_rct_WorkersCantLeave)) and (GetRectMinY(gg_rct_WorkersCantLeave) <= GetUnitY(GetEnumUnit())) and (GetUnitY(GetEnumUnit()) <= GetRectMaxY(gg_rct_WorkersCantLeave))) then
        call SetUnitX(GetEnumUnit(), GetRectCenterX(gg_rct_WorkerPutBack))
        call SetUnitY(GetEnumUnit(), GetRectCenterY(gg_rct_WorkerPutBack))
        
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 3.00, "Workers can not leave the kingdom!")
    endif
endfunction

function BlueCantLeaveForWorkers takes nothing returns nothing
    local group g = CreateGroup()
    
    set bj_groupEnumTypeId = 'hpea'
    call GroupEnumUnitsOfPlayer(g, Player(1), filterGetUnitsOfTypeIdAll)
    
    call ForGroup(g, function BlueWorkersCantLeavePutback)
endfunction

function TealCantLeaveForWorkers takes nothing returns nothing
    local group g = CreateGroup()
    
    set bj_groupEnumTypeId = 'ewsp'
    call GroupEnumUnitsOfPlayer(g, Player(2), filterGetUnitsOfTypeIdAll)
    
    call ForGroup(g, function TealWorkersCantLeavePutback)
endfunction

function RedCantLeaveForWorkers takes nothing returns nothing
    local group g = CreateGroup()
    
    set bj_groupEnumTypeId = 'opeo'
    call GroupEnumUnitsOfPlayer(g, Player(0), filterGetUnitsOfTypeIdAll)
    
    call ForGroup(g, function RedWorkersCantLeavePutback)
endfunction

function DarkGreenCantLeaveForWorkers takes nothing returns nothing
    local group g = CreateGroup()
    
    set bj_groupEnumTypeId = 'uaco'
    call GroupEnumUnitsOfPlayer(g, Player(10), filterGetUnitsOfTypeIdAll)
    
    call ForGroup(g, function DarkGreenWorkersCantLeavePutback)
endfunction

//===========================================================================
function InitTrig_Worker_Units_Cant_Leave takes nothing returns nothing
    set gg_trg_Worker_Units_Cant_Leave = CreateTrigger(  )
    
    call DisableTrigger(gg_trg_Worker_Units_Cant_Leave)
    call TriggerRegisterTimerEvent(gg_trg_Worker_Units_Cant_Leave, 0.25, true)
    call TriggerAddAction( gg_trg_Worker_Units_Cant_Leave, function BlueCantLeaveForWorkers )
    call TriggerAddAction( gg_trg_Worker_Units_Cant_Leave, function TealCantLeaveForWorkers )
    call TriggerAddAction( gg_trg_Worker_Units_Cant_Leave, function RedCantLeaveForWorkers )
    call TriggerAddAction( gg_trg_Worker_Units_Cant_Leave, function DarkGreenCantLeaveForWorkers )
endfunction

functions BlueCantLeaveForWorkers and TealCantLeaveForWorkers work but when it's Red or Dark Green nothing happens... The idea is that when a worker leaves a region it moves the worker back into the region, that whole thing works for Blue and Teal, but not for Red or Dark Green.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
The not is only covering the first condition.

Do not multiply functions for every player. It only creates a big mess. Use arrays and data assignments instead to specify.

Like:

JASS:
set playerPickId[0] = 'opeo'
set playerPickId[1] = 'hpea'
set playerPickId[2] = 'ewsp'
set playerPickId[10] = 'uaco'

set kingdomRegion[0] = gg_rct_WorkerPutBack2
set kingdomRegion[1] = gg_rct_WorkerPutBack
set kingdomRegion[2] = gg_rct_WorkerPutBack
set kingdomRegion[10] = gg_rct_WorkerPutBack2

Also avoid bjs.
 
Level 5
Joined
Feb 22, 2013
Messages
161
Then how can I make a function that tells when a unit of a specific type leaves a region? I understand the use of arrays and stuff, but I'm not sure about the creation of the function without using the bj_groupEnumTypeId, which you said to avoid...
 
Status
Not open for further replies.
Top