• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

how to check ips

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,209
Solutions
2
Reaction score
154
How to check if there have more than 2 equal IPs connected in game?

LUA:
if player:getIp() >= 2 then
--
end

?

tfs 1.2

thanks
 
Solution
make sure this is all in 1 file, i commented what you should register in creaturescripts.xml
LUA:
local ipTable = {}

function getPlayersConnected(ip)
    return ipTable[ip] or 0
end

--<event type="login" name="ip counter login" script="x.lua"/>
function onLogin(player)
    local ip = player:getIp()
    ipTable[ip] = ipTable[ip] and ipTable[ip] + 1 or 1
    return true
end

--<event type="logout" name="ip counter logout" script="x.lua"/>
function onLogout(player)
    local ip = player:getIp()
    ipTable[ip] = ipTable[ip] and ipTable[ip] - 1 or nil
    return true
end

to get amount of ips connected:
LUA:
if getPlayersConnected(player:getIp()) >= 2 then
    --
end
make sure this is all in 1 file, i commented what you should register in creaturescripts.xml
LUA:
local ipTable = {}

function getPlayersConnected(ip)
    return ipTable[ip] or 0
end

--<event type="login" name="ip counter login" script="x.lua"/>
function onLogin(player)
    local ip = player:getIp()
    ipTable[ip] = ipTable[ip] and ipTable[ip] + 1 or 1
    return true
end

--<event type="logout" name="ip counter logout" script="x.lua"/>
function onLogout(player)
    local ip = player:getIp()
    ipTable[ip] = ipTable[ip] and ipTable[ip] - 1 or nil
    return true
end

to get amount of ips connected:
LUA:
if getPlayersConnected(player:getIp()) >= 2 then
    --
end
 
Solution
make sure this is all in 1 file, i commented what you should register in creaturescripts.xml
LUA:
local ipTable = {}

function getPlayersConnected(ip)
    return ipTable[ip] or 0
end

--<event type="login" name="ip counter login" script="x.lua"/>
function onLogin(player)
    local ip = player:getIp()
    ipTable[ip] = ipTable[ip] and ipTable[ip] + 1 or 1
    return true
end

--<event type="logout" name="ip counter logout" script="x.lua"/>
function onLogout(player)
    local ip = player:getIp()
    ipTable[ip] = ipTable[ip] and ipTable[ip] - 1 or nil
    return true
end

to get amount of ips connected:
LUA:
if getPlayersConnected(player:getIp()) >= 2 then
    --
end

Its for talkactions, I can use this function inside talkactions too right?
 
yes, getPlayersConnected(ip) is global, so you can use it anywhere

hey, how to add +1 IP and remove -1, if player enter/leave from teleport or dead in some event pvp?

I need remove the function from login/logout and make an check in movements
 
just add an onDeath function to that same file and register it in creaturescripts
copy the code from inside onLogout to onDeath and itll -1 for deaths
dont know what you mean for movements
 
Back
Top