Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- IP Alias
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(processId, game, persistent)
- ipalias = table.load("ip.data")
- end
- function OnScriptUnload()
- table.save(ipalias, "ip.data")
- end
- --[[
- function OnNewGame(map)
- end
- --]]
- --[[
- function OnGameEnd(stage)
- end
- --]]
- --[[
- function OnServerChat(player, type, message)
- end
- --]]
- --[[
- function OnServerCommandAttempt(player, command, password)
- --return true
- end
- --]]
- function OnServerCommand(admin, command)
- local cmd, args = cmdsplit(command)
- if cmd == "sv_ipalias" then
- local player_or_ip = args[1]
- if tonumber(player_or_ip) then
- local playerid = tonumber(player_or_ip)
- if playerid > 0 and playerid < 17 then
- local player = rresolveplayer(playerid)
- if getplayer(player) then
- local ip = getip(player)
- local alias = {}
- for name,joins in pairs(ipalias[ip]) do
- table.insert(alias, name)
- end
- table.sort(alias, function(a, b) return ipalias[ip][a] > ipalias[ip][b] end)
- local str = formatlist(alias, 4, 5) -- formatlist(table, rowlength, extra white space)
- respond("Alias list for " .. getname(player) .. " IP " .. ip .. ":")
- hprintf(str)
- respond(str)
- -- Test
- for k,v in pairs(ipalias[ip]) do
- print(k)
- end
- else
- respond("Player " .. player .. " does not exist")
- end
- else
- respond("Player number must be between 1 and 16")
- end
- else
- local ip = player_or_ip
- if ipalias[ip] then
- local alias = {}
- for name,joins in pairs(ipalias[ip]) do
- table.insert(alias, name)
- end
- table.sort(alias, function(a, b) return ipalias[ip][a] > ipalias[ip][b] end)
- local str = formatlist(alias, 4, 5)
- respond("Alias list for IP " .. ip .. ":")
- respond(str)
- else
- respond("Invalid Player ID or IP Address")
- end
- end
- return false
- end
- end
- --[[
- function OnNameRequest(hash, name)
- --return true, name
- end
- --]]
- --[[
- function OnBanCheck(hash, ip)
- --return true
- end
- --]]
- function OnPlayerJoin(player)
- local name = getname(player)
- local ip = getip(player)
- ipalias[ip] = ipalias[ip] or {}
- ipalias[ip][name] = (ipalias[ip][name] or 0) + 1
- end
- --[[
- function OnPlayerLeave(player)
- end
- --]]
- --[[
- function OnPlayerKill(killer, victim, mode)
- -- mode 0: Killed by server
- -- mode 1: Killed by fall damage
- -- mode 2: Killed by guardians
- -- mode 3: Killed by vehicle
- -- mode 4: Killed by killer
- -- mode 5: Betrayed by killer
- -- mode 6: Suicide
- end
- --]]
- --[[
- function OnKillMultiplier(player, multiplier)
- -- Multipliers:
- -- 7: Double Kill
- -- 9: Triple Kill
- -- 10: Killtacular
- -- 11: Killing Spree
- -- 12: Running Riot
- -- 16: Double Kill w/ Score
- -- 15: Triple Kill w/ Score
- -- 14: Killtacular w/ Score
- -- 18: Killing Spree w/ Score
- -- 17: Running Riot w/ Score
- end
- --]]
- --[[
- function OnPlayerSpawn(player)
- end
- --]]
- --[[
- function OnPlayerSpawnEnd(player)
- end
- --]]
- --[[
- function OnWeaponAssignment(player, objId, slot, weapId)
- --return mapId
- end
- --]]
- --[[
- function OnWeaponReload(player, weapId)
- --return true
- end
- --]]
- --[[
- function OnObjectCreationAttempt(mapId, parentId, player)
- --return mapId
- end
- --]]
- --[[
- function OnObjectCreation(objId)
- end
- --]]
- --[[
- function OnObjectInteraction(player, objId, mapId)
- end
- --]]
- --[[
- function OnTeamDecision(team)
- --return team
- end
- --]]
- --[[
- function OnTeamChange(player, old_team, new_team, voluntary)
- --return true
- end
- --]]
- --[[
- function OnDamageLookup(receiver, causer, mapId, tagdata)
- --return true
- end
- --]]
- --[[
- function OnDamageApplication(receiver, causer, mapId, location, backtap)
- --return true
- end
- --]]
- --[[
- function OnVehicleEntry(player, vehiId, seat, mapId, voluntary)
- --return true
- end
- --]]
- --[[
- function OnVehicleEject(player, voluntary)
- --return true
- end
- --]]
- --[[
- function OnClientUpdate(player)
- end
- --]]
- function table.save(t, filename)
- local dir = getprofilepath()
- local file = io.open(dir .. "\\data\\" .. filename, "w")
- local spaces = 0
- local function tab()
- local str = ""
- for i = 1,spaces do
- str = str .. " "
- end
- return str
- end
- local function format(t)
- spaces = spaces + 4
- local str = "{ "
- for k,v in opairs(t) do
- -- Key datatypes
- if type(k) == "string" then
- k = string.format("%q", k)
- elseif k == math.inf then
- k = "1 / 0"
- end
- k = tostring(k)
- -- Value datatypes
- if type(v) == "string" then
- v = string.format("%q", v)
- elseif v == math.inf then
- v = "1 / 0"
- end
- if type(v) == "table" then
- if table.len(v) > 0 then
- str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. format(v) .. ","
- else
- str = str .. "\n" .. tab() .. "[" .. k .. "] = {},"
- end
- else
- str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. tostring(v) .. ","
- end
- end
- spaces = spaces - 4
- return string.sub(str, 1, string.len(str) - 1) .. "\n" .. tab() .. "}"
- end
- file:write("return " .. format(t))
- file:close()
- end
- function table.load(filename)
- local dir = getprofilepath()
- local file = loadfile(dir .. "\\data\\" .. filename)
- if file then
- return file() or {}
- end
- return {}
- end
- function table.len(t)
- local count = 0
- for k,v in pairs(t) do
- count = count + 1
- end
- return count
- end
- function opairs(t)
- local keys = {}
- for k,v in pairs(t) do
- table.insert(keys, k)
- end
- table.sort(keys,
- function(a,b)
- if type(a) == "number" and type(b) == "number" then
- return a < b
- end
- an = string.lower(tostring(a))
- bn = string.lower(tostring(b))
- if an ~= bn then
- return an < bn
- else
- return tostring(a) < tostring(b)
- end
- end)
- local count = 1
- return function()
- if table.unpack(keys) then
- local key = keys[count]
- local value = t[key]
- count = count + 1
- return key,value
- end
- end
- end
- function cmdsplit(str)
- local subs = {}
- local sub = ""
- local ignore_quote, inquote, endquote
- for i = 1,string.len(str) do
- local bool
- local char = string.sub(str, i, i)
- if char == " " then
- if (inquote and endquote) or (not inquote and not endquote) then
- bool = true
- end
- elseif char == "\\" then
- ignore_quote = true
- elseif char == "\"" then
- if not ignore_quote then
- if not inquote then
- inquote = true
- else
- endquote = true
- end
- end
- end
- if char ~= "\\" then
- ignore_quote = false
- end
- if bool then
- if inquote and endquote then
- sub = string.sub(sub, 2, string.len(sub) - 1)
- end
- if sub ~= "" then
- table.insert(subs, sub)
- end
- sub = ""
- inquote = false
- endquote = false
- else
- sub = sub .. char
- end
- if i == string.len(str) then
- if string.sub(sub, 1, 1) == "\"" and string.sub(sub, string.len(sub), string.len(sub)) == "\"" then
- sub = string.sub(sub, 2, string.len(sub) - 1)
- end
- table.insert(subs, sub)
- end
- end
- local cmd = subs[1]
- local args = subs
- table.remove(args, 1)
- return cmd, args
- end
- function formatlist(list, rowlen, space, delimiter)
- local longest = 0
- for _,v in ipairs(list) do
- local len = string.len(v)
- if len > longest then
- longest = len
- end
- end
- local rows = {}
- local row = 1
- local count = 1
- for k,v in ipairs(list) do
- if count % rowlen == 0 or k == #list then
- rows[row] = (rows[row] or "") .. v
- else
- rows[row] = (rows[row] or "") .. v .. spaces(longest - string.len(v) + space, delimiter)
- end
- if count % rowlen == 0 then
- row = row + 1
- end
- count = count + 1
- end
- return table.concat(rows, "\n")
- end
- function spaces(n, delimiter)
- delimiter = delimiter or ""
- local str = ""
- for i = 1, n do
- if i == math.floor(n / 2) then
- str = str .. delimiter
- end
- str = str .. " "
- end
- return str
- end
Advertisement
Add Comment
Please, Sign In to add comment