HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS: Quick simple system trouble

11-01-2006, 07:22 PM#1
Fulla
K what I want to do eventually is>

I have X number of beacons across the map.
I want to randomly shuffle them i.e. share them amongst the players PLAYING.

So I thought id run a loop with a local player array setting them to the active players like so

Collapse JASS:
function Trig_RandomOwner_Check takes integer temp returns boolean
    return (GetPlayerSlotState(ConvertedPlayer(temp)) == PLAYER_SLOT_STATE_PLAYING )
endfunction

function Trig_RandomOwner_Actions takes nothing returns nothing
    local player array owner
    local integer temp = 0
    loop
        exitwhen temp == 12
        if Trig_RandomOwner_Check(temp) then
        set owner[temp] = ConvertedPlayer(temp)
        call DisplayTextToForce(GetPlayersAll(), "1")
        else
        call DisplayTextToForce(GetPlayersAll(), "2") 
        endif
        set temp = temp + 1
    endloop        
endfunction

//===========================================================================
function InitTrig_RandomOwner takes nothing returns nothing
    set gg_trg_RandomOwner = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_RandomOwner, 1.00 )
    call TriggerAddAction( gg_trg_RandomOwner, function Trig_RandomOwner_Actions )
endfunction

This causes a crash? ;/

I was hoping to get something like this

player array 0 = player 0 (active)
player 1 inactive
player 2 inactive
player 3 inactive
player array 1 = player 4 (active)
etc.

Then I count how many players active in the game & run a loop.
Sharing beacons amongst the active players.

- Why does this crash?
- Is this a good method to do it?

thx
11-01-2006, 07:47 PM#2
Captain Griffen
ConvertedPlayer(temp)

Should be:

Player(temp)

You are passing 0 to ConvertedPlayer, which crashes (no player -1).
11-01-2006, 09:23 PM#3
Chuckle_Brother
Verily, keep in mind that with Player, you should only go up to 11.
11-01-2006, 09:34 PM#4
Captain Griffen
He does only go up to 11. He goes from 0 to 11.
11-01-2006, 09:42 PM#5
Fulla
ok I managed to get that part working.

Now part 2 crashes again :-(

Collapse JASS:
function Trig_RandomOwner_Count takes nothing returns boolean
    return (GetPlayerSlotState(GetFilterPlayer()) == PLAYER_SLOT_STATE_PLAYING)
endfunction

function Trig_RandomOwner_Check takes integer ppl returns boolean
    return (GetPlayerSlotState(Player(ppl)) == PLAYER_SLOT_STATE_PLAYING)
endfunction

function Trig_RandomOwner_Group takes nothing returns nothing
    call SetUnitOwner(GetEnumUnit(), udg_owner[udg_number], true)
endfunction

function Trig_RandomOwner_Actions takes nothing returns nothing
    local integer temp = 1
    local integer ppl = 0
    local integer count = CountPlayersInForceBJ(GetPlayersMatching(Condition(function Trig_RandomOwner_Count)))
    loop
        exitwhen temp == 13
        if Trig_RandomOwner_Check(ppl) then
        set udg_owner[temp] = Player(ppl)
        call DisplayTextToForce(GetPlayersAll(), "1")
        else
        call DisplayTextToForce(GetPlayersAll(), "2") 
        endif
        set temp = temp + 1
        set ppl = ppl + 1
    endloop
    set temp = 1
    loop
        exitwhen temp == 5 // currently there are only 4 regions on map
        if udg_number > count then
        set udg_number = 1
        endif
        call ForGroupBJ(GetUnitsInRectAll(udg_R_Towns[temp]), function Trig_RandomOwner_Group)
        set temp = temp + 1
        set udg_number = udg_number + 1
    endloop        
endfunction

//===========================================================================
function InitTrig_RandomOwner takes nothing returns nothing
    set gg_trg_RandomOwner = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_RandomOwner, 1.00 )
    call TriggerAddAction( gg_trg_RandomOwner, function Trig_RandomOwner_Actions )
endfunction

Should be distributing units within each rect amongst the active human players.

thx for any help again.

EDIT: Got it working now, edited code above.
11-01-2006, 11:56 PM#6
Fulla
Ok, the above now all works, id like to move onto 'part 3'
Asking a dif question.

Currently is goes like this:
E.g. Player 1 / Player 2 / Player 3 are active

Region 1 - Goes to ppl 1
Region 2 - Goes to ppl 2
Region 3 - Goes to ppl 3
Region 4 - Goes to ppl 1
Region 5 - Goes to ppl 2
etc. etc.

Id like to make it random thou
So instead of going from rect 1-X in order
it goes through them randomly.

I have no idea how to do this?
Id understand how to do it if it was units instead of rects via group checks.

Advice needed :D
11-02-2006, 05:46 AM#7
ArchWorm
Quote:
Originally Posted by Fulla
d understand how to do it if it was units instead of rects via group checks.
And what's the problem, then? Create some units that represent the regions and do it like you said.
11-02-2006, 10:41 AM#8
Fulla
I dont quite understand sorry.
How could you link units + regions?
11-02-2006, 12:46 PM#9
ArchWorm
That's very easy:
1. Create a unit
2. Set its UserData to handle index of the region.
3. Then jump beetween units with group funcs.