Hey,
i have worked today on an exploit fix in Lua. During this i came across a task to count number of connected players at the server. I found no direct field to do this in Lua. Also, my task went somewhat a different road, namely to count the number of players on each team.
Here is my solution:
function getTeamInfo()
local temp = et.trap_GetConfigstring( 0 )
temp = et.Info_ValueForKey( temp, "P" )
local team_free_cnt, team_ax_cnt, team_al_cnt, team_spec_cnt = 0, 0, 0, 0
for i = 1, #temp do
if (string.sub( temp, i, i ) == "0" ) then
team_free_cnt = team_free_cnt + 1
end
if (string.sub( temp, i, i ) == "1" ) then
team_ax_cnt = team_ax_cnt + 1
end
if (string.sub( temp, i, i ) == "2" ) then
team_al_cnt = team_al_cnt + 1
end
if (string.sub( temp, i, i ) == "3" ) then
team_spec_cnt = team_spec_cnt + 1
end
end
return team_free_cnt, team_ax_cnt, team_al_cnt, team_spec_cnt
end
As you can see, i use the P info var from the server. Do you happen to know a better way?
Otherwise, feel free to use this script. It counts the number of players on each team. In ET, there are 4 teams actually:
typedef enum {
TEAM_FREE,
TEAM_AXIS,
TEAM_ALLIES,
TEAM_SPECTATOR,
TEAM_NUM_TEAMS
} team_t;
The script above does count the number of players in each team. You can rewrite it to something like this
function CheckActivePlayers()
local temp = et.trap_GetConfigstring( 0 )
temp = et.Info_ValueForKey( temp, "P" )
local team_ax_cnt, team_al_cnt = 0, 0
for i = 1, #temp do
if (string.sub( temp, i, i ) == "1" ) then
team_ax_cnt = team_ax_cnt + 1
end
if (string.sub( temp, i, i ) == "2" ) then
team_al_cnt = team_al_cnt + 1
end
end
if team_ax_cnt > 0 or team_al_cnt > 0 then
return 0
end
return 1
end
… to check if there is a player currently in team allies or in team axis.
So yeah, both a giveaway and a question in one thread. Hope someone has a workaround to not work with the serverinfo P stuff …
And i have not read a switch statement in Lua so far, so i think it is not in. After all, the code lands in Lua itself, which may decide what to do.
Sooner or later there will probably be some updated combinedfixes.lua or something, don’t really know yet, or how it is done. Will see, will see. Until then one can use the Lua script, until mods catch up in fixing it in the C code.