• 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 Skipping if Slot empty

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
I'm having a problem with this script. If a player is not in a slot (A player is in slot 1 and no one is in 2 but someone is in 3 4 5 and 6 for example) It will create player 1's hero, but no one else. Why is this? How can i fix this?
JASS:
function Trig_Random_Actions takes nothing returns nothing
    local integer i
    set udg_Random[1] = 'Hpal'
    set udg_Random[2] = 'Hamg'
    set udg_Random[3] = 'Hmkg'
    set udg_Random[4] = 'Hblm'
    set udg_Random[5] = 'Obla'
    set udg_Random[6] = 'Ofar'
    set udg_Random[7] = 'Otch'
    set udg_Random[8] = 'Oshd'
    set udg_Random[9] = 'Udea'
    set udg_Random[10] = 'Ulic'
    set udg_Random[11] = 'Udre'
    set udg_Random[12] = 'Ucrl'
    set udg_Random[13] = 'Ekee'
    set udg_Random[14] = 'Emoo'
    set udg_Random[15] = 'Edem'
    set udg_Random[16] = 'Ewar'
    set udg_Random[17] = 'Nalc'
    set udg_Random[18] = 'Nngs'
    set udg_Random[19] = 'Ntin'
    set udg_Random[20] = 'Nbst'
    set udg_Random[21] = 'Nbrn'
    set udg_Random[22] = 'Nfir'
    set udg_Random[23] = 'Npbm'
    set udg_Random[24] = 'Nplh'
    set i = 0
 loop
    exitwhen i > 11
    if GetPlayerSlotState(Player(i))== PLAYER_SLOT_STATE_PLAYING then
    set Hero[i] = CreateUnit(Player(i), udg_Random[GetRandomInt(1, 24)],GetRectCenterX(gg_rct_Hero_Spawn),GetRectCenterY(gg_rct_Hero_Spawn), 260.0)
    endif
    set i = (i + 1)
endloop
    endfunction
//===========================================================================
function InitTrig_Random takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventSingle(t, 0.00)
    call TriggerAddAction( t, function Trig_Random_Actions )
    set t = null
endfunction
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
Because you increase 'i' in the if-section, so it creates an infinite loop if there's an empty player slot.
You need to drag it to under the "endif"

JASS:
loop
    exitwhen i > 11
    if GetPlayerSlotState(Player(i))== PLAYER_SLOT_STATE_PLAYING then
        set Hero[i] = CreateUnitAtLoc(Player(i), udg_Random[GetRandomInt(1, 24)], l, 260.0)
    endif
    set i = i + 1
endloop

Also, use coordinates, not locations. Coordinates are both far easier to handle, and work faster.
(And you never remove the location, so that's a leak. Coordinates don't leak)
 
Level 9
Joined
Apr 23, 2011
Messages
460
It's still not spawning if someone is in a different order. I tried testing with me on slot 1 and a comp on slot 3 (I don't have the user if in atm, i've made sure of that) and its not working still. I checked to see if it worked if i was on slot 1, comp on slot 2 it worked fine.
Edit: updated my script to use
JASS:
GetRectCenterX(gg_rct_Hero_Spawn), GetRectCenterY(gg_rct_Hero_Spawn)
instead. Ty.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
JASS:
function createHeroes takes nothing returns nothing
    local integer i = 0
    local real x = GetRectCenterX(gg_rct_Create_Heroes)
    local real y = GetRectCenterY(gg_rct_Create_Heroes)
    
    loop
        exitwhen i > 11
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            call CreateUnit(Player(i), 'hpea', x, y, 0.)
        endif
        set i = i+1
    endloop
endfunction

This works perfectly fine for me.
I don't know why you should be having any trouble... could you update the script, please?
 
Level 9
Joined
Apr 23, 2011
Messages
460
Okay. I'm done doing World Editor work when im on Codine. Because I have now realized that i have been editing this map for an hour, and not been replacing it in my wacraft 3 folder, where i've been editing it. I'm sorry for wasting your time sir. Pain Pills are a bitch..
 
Status
Not open for further replies.
Top