HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Finding Open/Closed/Computer slots

01-23-2010, 12:17 AM#1
Fluff
I'm trying to write a trigger that checks if a player slot is either Open, Closer, or a Computer. If it is one of these (i.e. not human filled) then I want the leaderboard to do something.

This trigger only works for Computer (Easy), Computer (Normal, and Computer (Insane):

Trigger:
Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
((Picked player) controller) Not equal to User
((Picked player) slot status) Not equal to Is playing
Collapse Then - Actions
Multiboard - Set the text for Multiboard item in column 2, row ((Player number of (Picked player)) + 1) to -----
Else - Actions

I tried adding some things to check the player name, thinking that might be a good way to do it since the open/closed slot's player name is "Player#"

Trigger:
Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
((Picked player) controller) Not equal to User
((Picked player) slot status) Not equal to Is playing
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 1
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 1
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 2
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 3
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 4
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 5
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 6
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 7
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 8
(Substring((Name of (Picked player)), 11, 19)) Equal to Player 9
(Substring((Name of (Picked player)), 11, 20)) Equal to Player 10
(Substring((Name of (Picked player)), 11, 20)) Equal to Player 11
(Substring((Name of (Picked player)), 11, 20)) Equal to Player 12
Collapse Then - Actions
Multiboard - Set the text for Multiboard item in column 2, row ((Player number of (Picked player)) + 1) to -----
Else - Actions

Note: I used looked at the string from 11 to 19 because there is a 10 character color code slapped on the beginning from an earlier trigger. (I don't think that in GUI the first character is 0...?) It goes to 19 because there is a space right after the player name as well due to my name changing trigger.

Anyway, I don't think Open or Closed slots even technically have player names since they don't show up in the Allies menu. So how can I detect them?

And I know the trigger could be written more cleanly. I can fix it up and/or rewrite in JASS after I get it to work.
01-23-2010, 12:36 AM#2
Themerion
What about a for loop from 1 to 12?

Pseudo:
for each integer A from 1 to 12:
   If (Player(A) Slot status = playing) and (Player(A) Controller = user) then
      // Real player - do nothing
   else
      // BAM!
   endif
01-23-2010, 12:39 AM#3
Fluff
In a sense, it does loop from 1-12 because it does it for each player. I know the trigger fires correctly because it will work if the player is set to a computer. The problem is that my conditions can't identify an Open or Closed slot.

EDIT: Yeah, I tried that but couldn't get it to work.
01-23-2010, 03:22 AM#4
Ammorth
Collapse JASS:
    function blah takes nothing returns nothing
        local integer i = 0
        local player p = null
        loop
            exitwhen i >= bj_MAX_PLAYERS
            set p = Player(i)
            if not (GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER) then
                // do what you want here
            endif
            set i = i + 1
        endloop
        return Player(0)
    endfunction

this is what I use, and also what Themerion posted. It should work.
01-23-2010, 04:28 AM#5
Fluff
Yes!

Thank you, both. That worked perfectly.
01-23-2010, 09:09 AM#6
TheWye
Ammorth, why do you need to return Player(0) in your code?
01-23-2010, 09:48 AM#7
Ammorth
It was a copy/paste from a function I was using, but the function returned a player and I forgot to remove it...
01-23-2010, 11:09 AM#8
TheWye
Oh alright then. I thought this involved another one of those bug-exploiting tricks or something..