• 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!

Lua [TFS 0.X] Find player by IP

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
Hello everybody,

I want to find a player searching by ip, to help me to check some things in my server, but talkaction its not response a correct value. I search my ip and other players, result its empty, no errors in console. Follow talkaction:

Lua:
function onSay(cid, words, param, channel)

str = "Ip:\n\n"

for _, pid in ipairs(getPlayersOnline()) do

if getPlayerIp(pid) == param then

str = str .. getPlayerIp(pid) .. " - Nome do Player [(".. getPlayerName(pid) ..")] Level ["..getPlayerLevel(pid).."]\n"

end

end

doShowTextDialog(cid, 1397, str)

return true

end

using: /ip xxx.xxx.xxx.xxx
 
Solution
getPlayerIp returns an int. Then, first you need to convert the Ip param to an int. Also, you could use getPlayersByIP.

Here's how I'd use:
Lua:
function onSay(cid, words, param, channel)
    if tonumber(param) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Param must be an Ip with dots (e.g. 127.0.0.1).")
        return true
    end

    param = doConvertIpToInteger(doRevertIp(param))

    local str = ""
    for player_number, player in ipairs(getPlayersByIP(param)) do
        str = str ..
            '# ' .. player_number ..
            '\nName: ' .. getPlayerName(player) ..
            '\nLevel: ' .. getPlayerLevel(player) .. '\n\n'
    end

    if str == "" then
        doPlayerSendTextMessage(cid...
getPlayerIp returns an int. Then, first you need to convert the Ip param to an int. Also, you could use getPlayersByIP.

Here's how I'd use:
Lua:
function onSay(cid, words, param, channel)
    if tonumber(param) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Param must be an Ip with dots (e.g. 127.0.0.1).")
        return true
    end

    param = doConvertIpToInteger(doRevertIp(param))

    local str = ""
    for player_number, player in ipairs(getPlayersByIP(param)) do
        str = str ..
            '# ' .. player_number ..
            '\nName: ' .. getPlayerName(player) ..
            '\nLevel: ' .. getPlayerLevel(player) .. '\n\n'
    end

    if str == "" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There are no players online with this Ip.")
        return true
    end

    doShowTextDialog(cid, 1397, str)
    return true
end
 
Solution
Back
Top