fixed bot detection and simplified code

This commit is contained in:
Remy Marquis 2017-03-06 21:23:38 +01:00
parent a172ad86c3
commit f2b2cbad20

View file

@ -3,10 +3,8 @@
Description: Ensure the server is connected to IRC - see irc_* cvars. Set irc_mode flag 1 and 2. Description: Ensure the server is connected to IRC - see irc_* cvars. Set irc_mode flag 1 and 2.
]]-- ]]--
modname ="IRC announcer" modname = "IRC announcer"
version ="0.2" version = "0.3"
usecolor = 0
function et_InitGame() function et_InitGame()
et.RegisterModname(modname.." "..version) et.RegisterModname(modname.." "..version)
@ -58,40 +56,38 @@ function getTeamInfo()
return team_free_cnt, team_ax_cnt, team_al_cnt, team_spec_cnt return team_free_cnt, team_ax_cnt, team_al_cnt, team_spec_cnt
end end
function getHumanBotInfo() function getBotInfo()
local cs = et.trap_GetConfigstring(0) local cs = et.trap_GetConfigstring(0)
local bots = et.Info_ValueForKey(cs, "omnibot_playing") local bots_cnt = et.Info_ValueForKey(cs, "omnibot_playing")
return bots return bots_cnt
end end
function et_ClientConnect(_clientNum, _firstTime, _isBot) function et_ClientConnect(_clientNum, _firstTime, _isBot)
if _isBot then -- skip bots
return if _isBot == 1 then return end
end
if _firstTime then if _firstTime == 1 then
local clientname
-- note pers.netname is empty on first connect -- note pers.netname is empty on first connect
if usecolor then clientname = ircColorStr(et.Info_ValueForKey(et.trap_GetUserinfo(_clientNum), "name"))
local clientname = ircColorStr(et.Info_ValueForKey(et.trap_GetUserinfo(_clientNum), "name")) -- clientname = et.Q_CleanStr(et.Info_ValueForKey(et.trap_GetUserinfo(_clientNum), "name"))
else
local clientname = et.Q_CleanStr(et.Info_ValueForKey(et.trap_GetUserinfo(_clientNum), "name"))
end
-- iterate through clients and count them -- get player type and team count
local free, axis, allies, spec = 0, 0, 0, 0 local free, axis, allies, spec = 0, 0, 0, 0
free, axis, allies, spec = getTeamInfo() free, axis, allies, spec = getTeamInfo()
-- count humans players -- count humans players
local bots, humans = 0, 0 local bots, humans = 0, 0
bots = getHumanBotInfo() bots = getBotInfo()
if bots then if bots then
humans = free + axis + allies + spec - bots humans = free + axis + allies + spec - bots
else else
humans = free + axis + allies + spec humans = free + axis + allies + spec
end end
-- float to int conversion
humans = math.floor(humans) humans = math.floor(humans)
-- current player is connecting but doesn't show up in the total yet -- current player is connecting but doesn't show up in the total yet
@ -99,24 +95,19 @@ function et_ClientConnect(_clientNum, _firstTime, _isBot)
humans = humans + 1 humans = humans + 1
-- send message -- send message
if usecolor then local msg = "irc_say \"" .. clientname .. " connected to server. Playing now:^7 " .. humans .. "^9(+" .. bots .. ")\""
local msg = "irc_say \"" .. clientname .. " connected to server. Playing now:^7 " .. humans .. "^9(+" .. bots .. ")\"" et.trap_SendConsoleCommand(et.EXEC_NOW , ircColorStr(msg))
et.trap_SendConsoleCommand(et.EXEC_NOW , ircColorStr(msg)) -- local msg = "irc_say \"" .. clientname .. " connected to server. Playing now: " .. humans .. "(+" .. bots .. ")\""
else -- et.trap_SendConsoleCommand(et.EXEC_NOW , msg)
local msg = "irc_say \"" .. clientname .. " connected to server. Playing now: " .. humans .. "(+" .. bots .. ")\""
et.trap_SendConsoleCommand(et.EXEC_NOW , msg)
end
end end
end end
-- function et_ClientDisconnect(_clientNum) -- function et_ClientDisconnect(_clientNum)
-- if usecolor then -- local clientname = ircColorStr(et.gentity_get(_clientNum ,"pers.netname"))
-- local clientname = ircColorStr(et.gentity_get(_clientNum ,"pers.netname")) -- local msg = "irc_say \"" .. clientname .. " disconnected from server\""
-- local msg = "irc_say \"" .. clientname .. " disconnected from server\"" -- et.trap_SendConsoleCommand(et.EXEC_NOW , ircColorStr(msg))
-- et.trap_SendConsoleCommand(et.EXEC_NOW , ircColorStr(msg)) --
-- else -- local clientname = et.Q_CleanStr(et.gentity_get(_clientNum ,"pers.netname"))
-- local clientname = et.Q_CleanStr(et.gentity_get(_clientNum ,"pers.netname")) -- local msg = "irc_say \"" .. clientname .. " disconnected from server\""
-- local msg = "irc_say \"" .. clientname .. " disconnected from server\"" -- et.trap_SendConsoleCommand(et.EXEC_NOW , msg)
-- et.trap_SendConsoleCommand(et.EXEC_NOW , msg)
-- end
-- end -- end