- Joined
- Apr 3, 2010
- Messages
- 1,889
To help aid myself (and hopefully others) I have created this system to help with indexing players that are in game with this snippet.
It should be able to help with initializing systems that use only playing players and systems that use playing players constantly like an income system or a player multiboard.
It should be able to help with initializing systems that use only playing players and systems that use playing players constantly like an income system or a player multiboard.
Code:
JASS:
library IsPlaying /* v1.0.1.0, created by DeathChef
Description
Keeps track of playing players (cpu's optional) and keeps them
indexed into variables to aid with efficient and
effective coding
Settings
*/
//! textmacro ISPLAYING_SETTINGS
private static constant boolean INCLUDE_CPUS = false
//! endtextmacro
/*
Fields
static integer Count
- Amount of players
integer Id
- Actual player id from index
player Player
- Actual player from index
integer Index
- Index from actual player id
boolean Registered
- Is playing from actual player id
constant static trigger LEAVE_TRIGGER
- Trigger executed when a player leaves
Add this trigger with "TriggerAddAction" to a function
to execute when a player leaves
*/
struct IsPlaying extends array
//! runtextmacro ISPLAYING_SETTINGS()
static constant trigger LEAVE_TRIGGER = CreateTrigger()
readonly static thistype Count = 0
//Use struct index
readonly integer Id
readonly player Player
//Use player id
readonly integer Index
readonly boolean Registered
private static method PlayerLeaves takes nothing returns nothing
local thistype i = GetPlayerId(GetTriggerPlayer())
local thistype thisIndex = i.Index
set i.Index = 0
set i.Registered = false
if thisIndex == Count then
set Count.Player = null
else
set thisIndex.Id = Count.Id
set thisIndex.Player = Count.Player
set thistype[Count.Id].Index = thisIndex
endif
endmethod
private static method onInit takes nothing returns nothing
local player p
local thistype i = 0
loop
set p = Player(i)
static if INCLUDE_CPUS then
if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then
set Count.Id = i
set Count.Player = p
set i.Index = Count
set i.Registered = true
set Count = Count + 1
call TriggerRegisterPlayerEvent(LEAVE_TRIGGER, p, EVENT_PLAYER_LEAVE)
endif
else
if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
set Count.Id = i
set Count.Player = p
set i.Index = Count
set i.Registered = true
set Count = Count + 1
call TriggerRegisterPlayerEvent(LEAVE_TRIGGER, p, EVENT_PLAYER_LEAVE)
endif
endif
exitwhen i == 11
set i = i + 1
endloop
set p = null
call TriggerAddAction(LEAVE_TRIGGER, function thistype.PlayerLeaves)
endmethod
endstruct
endlibrary
JASS:
library IsCpu /* v1.0.1.0, created by DeathChef
Description
Keeps track of playing players (cpu's optional) and keeps them
indexed into variables to aid with efficient and
effective coding
Fields
static integer Count
- Amount of players
integer Id
- Actual player id from index
player Player
- Actual player from index
integer Index
- Index from actual player id
boolean Registered
- Is actual player slot a player
constant static trigger LEAVE_TRIGGER
- Trigger executed when a player leaves
Add this trigger with "TriggerAddAction" to a function
to execute when a player leaves
*/
struct IsCpu extends array
readonly static thistype Count = 0
//Use struct index
readonly integer Id
readonly player Player
//Use player id
readonly integer Index
readonly boolean Registered
private static method onInit takes nothing returns nothing
local player p
local thistype i = 0
loop
set p = Player(i)
if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_COMPUTER then
set Count.Id = i
set Count.Player = p
set i.Index = Count
set i.Registered = true
set Count = Count + 1
endif
exitwhen i == 11
set i = i + 1
endloop
set p = null
endmethod
endstruct
endlibrary
Last edited: