Advertising
Lua - team_maxmines dynamically

13.02.2011 - 16:49:53

Here I have a little script, which sets team_maxmines according configured rules based on the number of players currently connected

 Code
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
 
-- ETW-Mines.lua
--by [ETW-FZ] schnoog
--*************************************************************************
-- global variables (initialization
--*************************************************************************
players = 0 -- current number of players
mines   = 0 -- current number of max. allowed mines per tea

--*************************************************************************
-- message functions
--*************************************************************************
function printConsole(id, message) -- prints a message to the console
  et.trap_SendServerCommand(id, "print \"" .. message .. "\n\"")
end

function printChat(id, message) -- prints a message to the chat
  et.trap_SendServerCommand(id, "chat \"" .. message .. "\"") 
end

function printCenter(id, message) -- prints a message to the center
  et.trap_SendServerCommand(id, "cp \"" .. message .. "\"")
end

function printBanner(id, message) -- prints a message to the center
  et.trap_SendServerCommand(id, "bp \"" .. message .. "\"")
end

--*************************************************************************
-- change number of landmines
--*************************************************************************
function setMaxMines() -- sets the number of max. allowed landmines
 
  if players > 8 then
    maxmines = 15
  elseif players > 6 then
    maxmines = 10
  elseif players > 4 then
    maxmines = 8
  else
    maxmines = 5
  end

  if mines ~= maxmines then
    et.trap_Cvar_Set("team_maxmines", maxmines)
   printConsole(-1, "Max. " .. maxmines .. " mines allowed.")
   mines = maxmines
  end
end

--*************************************************************************
-- player connecting
--*************************************************************************
function et_ClientConnect(id, firstTime, isBot) -- is called when a client connects
  players = players + 1
  setMaxMines()
end

--*************************************************************************
-- player disconnection
--*************************************************************************
function et_ClientDisconnect(id) -- client disconnects
  players = players - 1
  setMaxMines()
end



The current setting:
if players > 8 then <- if more than 8 players connected = 15 mines
maxmines = 15
elseif players > 6 then <- more than 6, but less than 9 players connected = 10mines
maxmines = 10
elseif players > 4 then <- more than 4, less than 7 = 8 mines
maxmines = 8
else <- less then 5 players = 5 mines
maxmines = 5
end

  schnoog
First Sergeant

User Pic

Posts: 294
Registred: 08.12.2010
Origin: Südbaden

    

0 approved this posting.




Images by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Powered by IlchBB Forum 3.1 © 2010 Weblösungen Florian Körner