Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pass = 0
- local client_lev = {}
- local sys_level = {}
- --[[
- It must contain a file lev_list.txt where levels are defined
- ex: Admin = 777 !ban, !help, !setlevel, !lev, !ref, !kick, !mute, !unmute, !splat
- There must be a ',' between each commands
- --]]
- --[[ flag list
- 256: "!ref",
- 128: "!ban",
- 64: "!kick",
- 32: "!setlevel",
- 16: "!mute",
- 8: "!unmute",
- 4: "!splat",
- 2: "!lev",
- 1: "!help"
- --]]
- function skip_carac(str, spe, i)
- while (string.sub(str, i, i) == sep) do
- i = i + 1
- end
- return i
- end
- function str_to_wordtab(str, sep)
- local tab = {}
- local len = string.len(str)
- local wend = 1
- local y = 1
- wend = skip_carac(str, sep, wend)
- wstart = wend
- while (wend <= len) do
- local carac = string.sub(str, wend, wend)
- if (carac == sep or wend == len) then
- if (wend == len) then wend = wend + 1 end
- tab[y] = string.sub(str, wstart, wend - 1)
- y = y + 1
- wend = skip_carac(str, sep, wend) + 1
- wstart = wend
- else
- wend = wend + 1
- end
- end
- return tab
- end
- function fill_client_level(tab, maxclients)
- local i = 0
- while (i < maxclients) do
- local cl_guid = string.lower(et.Info_ValueForKey(et.trap_GetUserinfo(i), "cl_guid"))
- if (cl_guid == tab[2]) then
- client_lev[i + 1] = tonumber(tab[3])
- end
- i = i + 1
- end
- end
- function get_pl_levels() -- load client levels
- local maxclients = tonumber((et.trap_Cvar_Get("sv_maxClients")) - 1)
- local file = io.open("pl_levels.txt", "r")
- local line = nil
- local i = 0
- while (i < maxclients) do -- init to 0
- client_lev[i + 1] = 0
- i = i + 1
- end
- if (file ~= nil) then -- load levels
- line = file:read("*line")
- while (line ~= nil) do
- local tab = str_to_wordtab(line, ' ')
- fill_client_level(tab, maxclients)
- line = file:read("*line")
- end
- file:close()
- end
- end
- function et_ClientBegin(clientNum)
- local game = 2
- local gamestate = tonumber(et.trap_Cvar_Get( "gamestate"))
- if (pass == 0) then
- sys_level = get_levels()
- if (sys_level == nil) then et.trap_SendServerCommand(-1, "chat \"FAIL\"") end
- get_pl_levels()
- end
- pass = 1
- if (gamestate == game) then
- local name = string.gsub(et.gentity_get(clientNum, "pers.netname"), "%^$", "^^ ")
- local rank = get_pl_rank_from_lev(client_lev[clientNum + 1])
- et.trap_SendServerCommand(-1, "chat \"^7Welcome to "..name..", ^2"..rank.."\"")
- end
- end
- function epur_name(id) -- remove spaces and color codes
- local name = et.gentity_get(id, "pers.netname")
- if (name == nil) then return nil end
- name = string.gsub(name, "%^$", "^^ ")
- name = string.gsub(name, " ", "")
- name = string.gsub(name, "(^%w)", "")
- return name
- end
- function get_player_info(client)
- local maxclients = tonumber((et.trap_Cvar_Get("sv_maxClients")) - 1)
- local name = nil
- local i = 0
- if (string.find(client, "%a") == nil) then
- name = epur_name(client)
- return client, name
- end
- client = string.gsub(client, " ", "")
- client = string.gsub(client, "(^%w)", "")
- while (i < maxclients) do
- local pl_name = epur_name(i)
- if (pl_name ~= nil) then
- if (pl_name ~= nil and string.find(pl_name, client) ~= nil) then
- return i, pl_name
- end
- end
- i = i + 1
- end
- return -1, nil
- end
- function setlevel(adm, client, lev) -- set the new level of a client
- local ptr = io.open("pl_levels.txt", "r")
- local file = {}
- local i = 1
- local j = 1
- local id = -1 -- players info
- local name = nil
- id, name = get_player_info(client)
- if (id == -1 or name == nil) then
- et.trap_SendServerCommand(adm, "chat \"Player "..client.." doesn't exist\"")
- return -1
- end
- local pl_guid = string.lower(et.Info_ValueForKey(et.trap_GetUserinfo(id), "cl_guid"))
- if (pl_guid == "unknown") then
- et.trap_SendServerCommand(adm, "chat \"Unknown guid\"")
- return -1
- end
- if (ptr ~= nil) then
- line = ptr:read("*l")
- while (line ~= nil) do
- file[i] = line
- i = i + 1
- line = ptr:read("*l")
- end
- ptr:close()
- end
- ptr = io.open("pl_levels.txt", "w")
- while (j < i and string.find(file[j], pl_guid) == nil) do
- j = j + 1
- end
- file[j] = name .. " " .. pl_guid .. " " .. lev
- if (j == i) then
- i = i + 1
- end
- j = 1
- while (j < i) do
- ptr:write(file[j])
- ptr:write("\n")
- j = j + 1
- end
- name = string.gsub(et.gentity_get(id, "pers.netname"), "%^$", "^^ ")
- et.trap_SendServerCommand(-1, "chat \"^7Player ^7"..name.."^7 has been setted to level "..lev.."\"")
- ptr:close()
- return 0
- end
- function checkmuted(client)
- return et.gentity_get(client, "sess.muted", 1)
- end
- function mute_pl(client, id, mu_time) -- time doesnt work yet
- local name = string.gsub(et.gentity_get(id, "pers.netname"), "%^$", "^^ ")
- if (checkmuted(id) == 1) then -- already muted
- et.trap_SendServerCommand(client, "chat \"^2The player is already muted\"")
- return 1
- end
- if (mu_time == nil) then
- mu_time = 600 -- muted time set to 10 mins
- end
- et.gentity_set(id, "sess.muted", 1)
- et.trap_SendServerCommand(-1, "cpm \""..name.."^7 is ^qmuted\"")
- return 1
- end
- function unmute_pl(client, id) -- time doesnt work yet
- local name = string.gsub(et.gentity_get(id, "pers.netname"), "%^$", "^^ ")
- if (checkmuted(id) ~= 1) then -- already muted
- et.trap_SendServerCommand(client, "chat \"^2The player is not muted\"")
- return 1
- end
- et.gentity_set(id, "sess.muted", 0)
- et.trap_SendServerCommand(-1, "cpm \""..name.."^7 is ^qunmuted\"")
- return 1
- end
- function check_levels(id1, id2)
- if (client_lev[id1 + 1] >= client_lev[id2 + 1]) then
- return 1
- else
- et.trap_SendServerCommand(id1, "chat \"You can't use this command on this player because of your level\"")
- return -1
- end
- end
- function ban_pl(client, id, ban_time)
- if (ban_time == nil) then
- ban_time = 6000000
- end
- if (type(ban_time) ~= 'number') then
- et.trap_SendServerCommand(client, "chat \"ban time must be a number\"")
- return 1
- end
- et.trap_DropClient(id, "Banned by admin", ban_time) -- ban for x2 mins
- end
- function help_cmd(client, flag)
- local bits = convert_to_binary(flag)
- local tflag = flag
- local i = 1
- local cmd_list = {
- "!help", -- 1
- "!lev", -- 2
- "!splat", -- 4
- "!unmute", -- 8
- "!mute", -- 16
- "!kick", -- 32
- "!setlevel",-- 64
- "!ban", -- 128
- "!ref" -- 256
- }
- et.trap_SendServerCommand(client, "chat \"\nCommand list^q:\n\"")
- while (cmd_list[i] ~= nil) do
- if (bits[i] == 1) then et.trap_SendServerCommand(client, "chat \""..cmd_list[i].."\"") end
- i = i + 1
- end
- end
- function count_alive_players()
- local alive = 0
- local maxclients = tonumber((et.trap_Cvar_Get( "sv_maxClients" )) -1)
- for i = 0, maxclients, 1 do
- local clientteam = tonumber(et.gentity_get(i, "sess.sessionTeam"))
- if (clientteal == 1 or clientteam == 2) then
- if (tonumber(et.gentity_get(i, "health")) > 0) then alive = alive + 1 end
- end
- end
- return alive
- end
- function splat_cmd(client, id)
- local namep = string.gsub(et.gentity_get(id, "pers.netname"), "%^$", "^^ ")
- local namec = string.gsub(et.gentity_get(client, "pers.netname"), "%^$", "^^ ")
- et.gentity_set(id, "health", -500)
- et.G_globalSound("sound/player/gib.wav")
- et.trap_SendServerCommand(-1, "chat \""..namep.." ^7got ^qSplated ^7by "..namec.."\"")
- if (tonumber(et.trap_Cvar_Get( "gamestate")) == 0 and count_alive_players() == 0) then
- et.trap_SendServerCommand(-1, "chat \"^t-^7Match ended because there was no players alive^t-\"")
- et.trap_SendConsol3eCommand(et.EXEC_APPEND, "ref matchreset")
- end
- end
- function get_level_name(line)
- local pos = string.find(line, '=') -- geting the level name
- local name = nil
- if (pos == nil) then -- no = in the line
- return nil
- elseif (pos == 1) then -- no name
- return nil
- end
- pos = pos - 1
- name = string.sub(line, 1, pos)
- return name
- end
- function get_flag(line)
- local flag = 0
- local pos1, pos2 = 1
- local lev = 0
- local i = 1
- local commands = {}
- local cmd_list = {
- "!help", -- 1
- "!lev", -- 2
- "!splat", -- 4
- "!unmute", -- 8
- "!mute", -- 16
- "!kick", -- 32
- "!setlevel",-- 64
- "!ban", -- 128
- "!ref" -- 256
- }
- pos1, pos2 = string.find(line, "%d+", 1)
- if (pos1 == nil or pos2 == nil) then return nil, 0 end
- lev = tonumber(string.sub(line, pos1, pos2))
- if (lev == nil) then return nil, 0 end -- no level
- pos1, pos2 = string.find(line, '!')
- if (pos1 == nil) then return lev, flag end
- line = string.sub(line, pos1)
- if (line == nil) then return lev, flag end -- no commands
- commands = str_to_wordtab(line, ',') -- Here, ',' is used as separator
- local j = 1
- while (commands[i] ~= nil) do
- j = 1
- while (cmd_list[j] ~= nil and string.find(cmd_list[j], commands[i]) == nil) do
- j = j + 1
- end
- if (cmd_list[j] ~= nil) then
- flag = flag + math.pow(2, j - 1)
- end
- i = i + 1
- end
- return lev, flag
- end
- function get_levels() -- get levels from file
- local levels = {} -- contains Name - level - flag
- local file = io.open("lev_list.txt", "r")
- local line = nil
- local i = 1
- if (file ~= nil) then -- load levels
- line = file:read("*line")
- while (line ~= nil) do
- levels[i] = {} -- create the second dimention to stock the informations
- local name = get_level_name(line)
- if (name == nil) then return nil end
- levels[i][1] = name
- line = string.sub(line, string.find(line, '=') + 1)
- if (line == nil) then return nil end
- line = string.gsub(line, ' ', '') -- take off the spaces
- levels[i][2], levels[i][3] = get_flag(line)
- if (levels[i][2] == nil) then return nil end
- line = file:read("*line")
- i = i + 1
- end
- file:close()
- end
- return levels
- end
- function get_pl_rank_from_lev(pl_level)
- local i = 1
- while (sys_level[i] ~= nil and sys_level[i][2] ~= pl_level) do
- i = i + 1
- end
- if (sys_level[i] ~= nil) then return sys_level[i][1] end
- return "not setted"
- end
- function get_pl_flag_from_lev(pl_level)
- local i = 1
- while (sys_level[i] ~= nil and sys_level[i][2] ~= pl_level) do
- i = i + 1
- end
- if (sys_level[i] ~= nil) then return sys_level[i][3] end
- return 0
- end
- function convert_to_binary(nb)
- local bin = {}
- local i = 1
- local cast = 0
- while (nb > 0) do
- bin[i] = math.mod(nb, 2)
- nb = nb / 2
- cast = math.mod(nb, 1)
- nb = nb - cast
- i = i + 1
- end
- return bin
- end
- function handle_cmd(client, flag, rank, arg, id)
- local bits = convert_to_binary(flag)
- local tflag = flag
- if (bits[9] == 1 and arg[2] == "!ref") then
- et.trap_SendConsoleCommand(et.EXEC_APPEND, "ref referee "..client.."")
- return 1
- elseif (bits[8] == 1 and arg[2] == "!ban") then
- if (check_levels(client, id) == -1) then return -1 end
- ban_pl(client, id, tonumber(arg[4]))
- return 1
- elseif (bits[7] == 1 and string.len(arg[2]) > 2 and string.find("!setlevel", arg[2]) == 1) then -- !setlevel
- if (arg[3] ~= nil and arg[4] ~= nil) then
- if (check_levels(client, id) == -1) then return -1 end
- local ret = 0
- if (tonumber(arg[4]) == nil) then
- et.trap_SendServerCommand(client, "chat \"Invalid level\"")
- return 1
- end
- if (setlevel(client, arg[3], tonumber(arg[4])) == 0) then -- all went good
- get_pl_levels() -- need to refresh the players level
- end
- end
- return 1
- elseif (bits[6] == 1 and arg[2] == "!kick") then
- if (check_levels(client, id) == -1) then return -1 end
- et.trap_DropClient(id, "Kicked by admin", 600) -- kick for 10 mins
- return 1
- elseif (bits[5] == 1 and string.len(arg[2]) > 2 and string.find("!mute", arg[2]) == 1) then
- if (check_levels(client, id) == -1) then return -1 end
- mute_pl(client, id, arg[4])
- return 1
- elseif (bits[4] == 1 and string.len(arg[2]) > 2 and string.find("!unmute", arg[2]) == 1) then
- unmute_pl(client, id)
- return 1
- elseif (bits[3] == 1 and string.len(arg[2]) > 3 and string.find("!splat", arg[2]) == 1) then
- if (check_levels(client, id) == -1) then return -1 end
- splat_cmd(client, id)
- return 1
- elseif (bits[2] == 1 and arg[2] == "!lev" or cmd == "!adm") then
- local cl_name = string.gsub(et.gentity_get(client, "pers.netname"), "%^$", "^^ ")
- et.trap_SendServerCommand(-1, "chat \"^7Player ^7"..cl_name.."^7 is level ^q"..client_lev[client + 1].."^7, rank: ^2"..rank.."\"")
- return 1
- elseif (bits[1] == 1 and string.len(arg[2]) > 2 and string.find("!help", arg[2]) == 1) then
- help_cmd(client, flag)
- return 1
- end
- return 0
- end
- function et_ClientCommand(clientNum, command)
- local argc = et.trap_Argc()
- local i = 0
- local arg = {}
- while (i < argc) do
- arg[i + 1] = et.trap_Argv(i)
- i = i + 1
- end
- if (arg[1] == "say" and arg[2] ~= nil) then
- local id = -1
- local name = nil
- local flag = 0
- local rank = nil
- if (arg[1] == "say" and string.find(arg[2], '!') == 1 and arg[3] ~= nil) then -- it's an admin command
- id, name = get_player_info(arg[3])
- if (id == -1) then
- et.trap_SendServerCommand(clientNum, "chat \"^7Player "..arg[3].."^7 doesn't exist\"")
- return 1
- end
- end
- flag = get_pl_flag_from_lev(client_lev[clientNum + 1])
- rank = get_pl_rank_from_lev(client_lev[clientNum + 1])
- if (handle_cmd(clientNum, flag, rank, arg, id) == 1) then return 1 end
- return 0
- end
- return 0
- end
- function et_ClientConnect(clientNum, firstTime, isBot )
- get_pl_levels() -- need to refresh the players level
- end
- function et_ClientDisconnect(clientNum)
- get_pl_levels() -- need to refresh the players level
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement