• 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 Limit 3 IPs for this script

dawnking

Member
Joined
Jun 23, 2016
Messages
176
Reaction score
22
I found a topic with this script here with this same problem, but abandoned

This script to encourage players to make guilds, invite their friends, makers and get a bonus
But what is happen: Some players create their own guild invite 10 mc's and let this 10 mc's open to get bonus alone...

Anybody know a way to if have more then 3 characters on the same IP stop to count?

Code:
<event type="login" name="ExpGuild" event="script" value="exp_guild_login.lua"/>
<event type="logout" name="ExpGuild_out" event="script" value="exp_guild_logout.lua"/>

exp_guild_login.lua
Code:
function getGuildMembersOnline(GuildId)
    local players = {}
    for _, pid in pairs(getPlayersOnline()) do
        if getPlayerGuildId(pid) == tonumber(GuildId) then
            table.insert(players, getPlayerName(pid))
        end
    end
    return #players > 0 and players or false
end
function onLogin(cid)
   local guild_id = getPlayerGuildId(cid)
   local minimo = 1
   local max = 10
   local porcentagem = 1
   -----------------------------------------
   doPlayerSetExperienceRate(cid, 1)
   if guild_id <= 0 then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Join a guild to have experience bonus.")
       return true
   end
   
   if guild_id > 0 then
       local membros_online = table.maxn(getGuildMembersOnline(guild_id))
       local tabela_membros = getGuildMembersOnline(guild_id)
       
       if membros_online <= minimo then
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] To get bonus experience must be over "..minimo.." players online guild.\nGuild of Players Online ["..membros_online.."]")
           return true
       end
   
       if membros_online > minimo then
       for var = 1, #tabela_membros do
           local nomes = getCreatureByName(tabela_membros[var])
           local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00  
           doPlayerSetExperienceRate(nomes, XP)  
           doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] The experience of the guild members was increased to +"..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." joined.")     
       end
       return true
       end
   
   end
   
   
   
   
   
end

exp_guild_logout.lua
Code:
function getGuildMembersOnline(GuildId)
   local players = {}
   for _, pid in pairs(getPlayersOnline()) do
       if getPlayerGuildId(pid) == tonumber(GuildId) then
           table.insert(players, getPlayerName(pid))
       end
   end
   return #players > 0 and players or false
end

function onLogout(cid)
   local guild_id = getPlayerGuildId(cid)
   local membros_online = table.maxn(getGuildMembersOnline(guild_id))
   local tabela_membros = getGuildMembersOnline(guild_id)
   local porcentagem = 1
   local minimo = 1
   -----------------------------------------       
   if guild_id >= 1 then
       for var = 1, #tabela_membros do
           local nomes = getCreatureByName(tabela_membros[var])
           local membros_online = membros_online - 1
           
           if membros_online <= minimo then
               doPlayerSetExperienceRate(nomes, 1.0)   
               doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] No longer does the number of players needed to earn bonus experience - Member "..getCreatureName(cid).." left.")
           end
           
           if membros_online > minimo then
               local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00   
               doPlayerSetExperienceRate(nomes, XP)   
               doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] Experience from guild members has been adjusted to "..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." left.")
           end
       end
   end
   return true   
end
 
You would check the for the ip address within the getGuildMembersOnline function. Instead of using table.insert you should assign their ip as the index of the table. This will only count 1 guild member per ip but then again you could create a nested table with 2 properties which are tables one which holds all the ip's and one which holds all the players and then cycle through the ip's so see how many are unique and if you there is more than 3 stop counting.
 
Yours login script:
Lua:
function onLogin(cid)
   local guild_id = getPlayerGuildId(cid)
   local minimo = 1
   local max = 10
   local porcentagem = 1
   -----------------------------------------
   doPlayerSetExperienceRate(cid, 1)
   if guild_id <= 0 then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Join a guild to have experience bonus.")
       return true
   end
  
   if guild_id > 0 then
       local membros_online = table.maxn(getGuildMembersOnline(guild_id))
       local tabela_membros = getGuildMembersOnline(guild_id)
       local maxlimit_sameIP = 3
       local ips, count = {}, 0
       for _, pid in ipairs(tabela_membros) do
           table.insert(ips, getPlayerIp(pid))
       end
       if #ips > 1 then
           table.sort(ips)
           for i = 1, #ips do
               if ips[i] == ips[i + 1] then
                   count = count + 1
               end
           end
       end
       if count >= maxlimit_sameIP then
           membros_online = membros_online - count
       end
       if membros_online <= minimo then
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] To get bonus experience must be over "..minimo.." players online guild.\nGuild of Players Online ["..membros_online.."]")
           return true
       end
  
       if membros_online > minimo then
       for var = 1, #tabela_membros do
           local nomes = getCreatureByName(tabela_membros[var])
           local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00 
           doPlayerSetExperienceRate(nomes, XP) 
           doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] The experience of the guild members was increased to +"..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." joined.")  
       end
       return true
       end
  
   end
  
  
  
  
  
end
If it works put my part of script to your logout script
 
Last edited:
Yours login script:
Lua:
function onLogin(cid)
   local guild_id = getPlayerGuildId(cid)
   local minimo = 1
   local max = 10
   local porcentagem = 1
   -----------------------------------------
   doPlayerSetExperienceRate(cid, 1)
   if guild_id <= 0 then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Join a guild to have experience bonus.")
       return true
   end
 
   if guild_id > 0 then
       local membros_online = table.maxn(getGuildMembersOnline(guild_id))
       local tabela_membros = getGuildMembersOnline(guild_id)
       local maxlimit_sameIP = 3
       local ips, count = {}, 0
       for _, pid in ipairs(tabela_membros) do
           table.insert(ips, getPlayerIp(pid))
       end
       if #ips > 1 then
           table.sort(ips)
           for i = 1, #ips do
               if ips[i] == ips[i + 1] then
                   count = count + 1
               end
           end
       end
       if count >= maxlimit_sameIP then
           membros_online = membros_online - count
       end
       if membros_online <= minimo then
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] To get bonus experience must be over "..minimo.." players online guild.\nGuild of Players Online ["..membros_online.."]")
           return true
       end
 
       if membros_online > minimo then
       for var = 1, #tabela_membros do
           local nomes = getCreatureByName(tabela_membros[var])
           local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00
           doPlayerSetExperienceRate(nomes, XP)
           doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] The experience of the guild members was increased to +"..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." joined.") 
       end
       return true
       end
 
   end
 
 
 
 
 
end
If it works put my part of script to your logout script


When i use this script and try to login 2 character at the same guild, the second one get kicked on the second he login!
 
Any error pop up? Before my edit the script was working correctly? Probably smth other making this kick.

I'm sorry
Here is the error when i use your script:
Code:
[0:3:34.493] [Error - CreatureScript Interface]
[0:3:34.493] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[0:3:34.493] Description:
[0:3:34.493] (internalGetPlayerInfo) Player not found when requesting player info #28
[0:3:45.446] Paladin has logged in.

[0:3:45.447] [Error - CreatureScript Interface]
[0:3:45.447] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[0:3:45.447] Description:
[0:3:45.447] (internalGetPlayerInfo) Player not found when requesting player info #28

[0:3:45.447] [Error - CreatureScript Interface]
[0:3:45.447] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[0:3:45.447] Description:
[0:3:45.447] (internalGetPlayerInfo) Player not found when requesting player info #28

[0:3:45.447] [Error - CreatureScript Interface]
[0:3:45.447] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[0:3:45.447] Description:
[0:3:45.447] attempt to compare two boolean values
[0:3:45.447] stack traceback:
[0:3:45.447]    [C]: in function 'sort'
[0:3:45.447]    data/creaturescripts/scripts/exp_guild_login.lua:22: in function <data/creaturescripts/scripts/exp_guild_login.lua:1>
 
Try this one:
Lua:
function onLogin(cid)
   local guild_id = getPlayerGuildId(cid)
   local minimo = 1
   local max = 10
   local porcentagem = 1
   -----------------------------------------
   doPlayerSetExperienceRate(cid, 1)
   if guild_id <= 0 then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Join a guild to have experience bonus.")
   elseif guild_id > 0 then
       local membros_online = table.maxn(getGuildMembersOnline(guild_id))
       local tabela_membros = getGuildMembersOnline(guild_id)
       local maxlimit_sameIP = 3
       local ips, count = {}, 0
       for _, pid in ipairs(getCreatureByName(tabela_membros)) do
           table.insert(ips, getPlayerIp(pid))
       end
      print(#tabela_membros .." total online, ".. #ips .." amount of IP's, 1: ".. ips[1] ..", 2: ".. ips[2])
       if #ips > 1 then
           table.sort(ips)
          print(#tabela_membros .." total online, ".. #ips .." amount of IP's, 1: ".. ips[1] ..", 2: ".. ips[2])
           for i = 1, #ips do
               if ips[i] == ips[i + 1] then
                   count = count + 1
               end
           end
       end
       if count >= maxlimit_sameIP then
           membros_online = membros_online - count
       end
       if membros_online <= minimo then
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] To get bonus experience must be over "..minimo.." players online guild.\nGuild of Players Online ["..membros_online.."]")
       elseif membros_online > minimo then
          for var = 1, #tabela_membros do
              local nomes = getCreatureByName(tabela_membros[var])
              local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00
              doPlayerSetExperienceRate(nomes, XP)
              doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] The experience of the guild members was increased to +"..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." joined.") 
          end
       end
   end
end
Past this one what pops in console.
 
Try this one:
Lua:
function onLogin(cid)
   local guild_id = getPlayerGuildId(cid)
   local minimo = 1
   local max = 10
   local porcentagem = 1
   -----------------------------------------
   doPlayerSetExperienceRate(cid, 1)
   if guild_id <= 0 then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Join a guild to have experience bonus.")
   elseif guild_id > 0 then
       local membros_online = table.maxn(getGuildMembersOnline(guild_id))
       local tabela_membros = getGuildMembersOnline(guild_id)
       local maxlimit_sameIP = 3
       local ips, count = {}, 0
       for _, pid in ipairs(getCreatureByName(tabela_membros)) do
           table.insert(ips, getPlayerIp(pid))
       end
      print(#tabela_membros .." total online, ".. #ips .." amount of IP's, 1: ".. ips[1] ..", 2: ".. ips[2])
       if #ips > 1 then
           table.sort(ips)
          print(#tabela_membros .." total online, ".. #ips .." amount of IP's, 1: ".. ips[1] ..", 2: ".. ips[2])
           for i = 1, #ips do
               if ips[i] == ips[i + 1] then
                   count = count + 1
               end
           end
       end
       if count >= maxlimit_sameIP then
           membros_online = membros_online - count
       end
       if membros_online <= minimo then
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] To get bonus experience must be over "..minimo.." players online guild.\nGuild of Players Online ["..membros_online.."]")
       elseif membros_online > minimo then
          for var = 1, #tabela_membros do
              local nomes = getCreatureByName(tabela_membros[var])
              local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00
              doPlayerSetExperienceRate(nomes, XP)
              doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] The experience of the guild members was increased to +"..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." joined.")
          end
       end
   end
end
Past this one what pops in console.

Now i cant even login 1 character...
When i try print this:
Code:
[14:9:52.602] Druid has logged in.

[14:9:52.678] [Error - CreatureScript Interface]
[14:9:52.678] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[14:9:52.679] Description:
[14:9:52.679] data/creaturescripts/scripts/exp_guild_login.lua:15: bad argument #1 to 'ipairs' (table expected, got nil)
[14:9:52.679] stack traceback:
[14:9:52.679]    [C]: in function 'ipairs'
[14:9:52.679]    data/creaturescripts/scripts/exp_guild_login.lua:15: in function <data/creaturescripts/scripts/exp_guild_login.lua:1>
[14:9:52.824] Druid has logged out.
 
Now i cant even login 1 character...
When i try print this:
Code:
[14:9:52.602] Druid has logged in.

[14:9:52.678] [Error - CreatureScript Interface]
[14:9:52.678] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[14:9:52.679] Description:
[14:9:52.679] data/creaturescripts/scripts/exp_guild_login.lua:15: bad argument #1 to 'ipairs' (table expected, got nil)
[14:9:52.679] stack traceback:
[14:9:52.679]    [C]: in function 'ipairs'
[14:9:52.679]    data/creaturescripts/scripts/exp_guild_login.lua:15: in function <data/creaturescripts/scripts/exp_guild_login.lua:1>
[14:9:52.824] Druid has logged out.

Because the ipairs is excepting a table as the error says, not sure why it's saying nil insted of integer / number but test this;
Lua:
for _, pid in ipairs(tabela_membros) do
    table.insert(ips, getPlayerIp(getCreatureByName(pid)))
end
 
Lua:
function onLogin(cid)
   local guild_id = getPlayerGuildId(cid)
   local minimo = 1
   local max = 10
   local porcentagem = 1
   -----------------------------------------
   doPlayerSetExperienceRate(cid, 1)
   if guild_id <= 0 then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] Join a guild to have experience bonus.")
   elseif guild_id > 0 then
       local membros_online = table.maxn(getGuildMembersOnline(guild_id))
       local tabela_membros = getGuildMembersOnline(guild_id)
       local maxlimit_sameIP = 3
       local ips, count = {}, 0
       for _, pid in pairs(getPlayersOnline()) do
           if getPlayerGuildId(pid) == guild_id then
               table.insert(ips, getPlayerIp(pid))
           end
       end
       if #ips > 1 then
           table.sort(ips)
          print(#tabela_membros .." total online, ".. #ips .." amount of IP's, 1: ".. ips[1] ..", 2: ".. ips[2])
           for i = 1, #ips do
               if ips[i] == ips[i + 1] then
                   count = count + 1
               end
           end
       end
       if count >= maxlimit_sameIP then
           membros_online = membros_online - count
       end
       if membros_online <= minimo then
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED,"[GUILD] To get bonus experience must be over "..minimo.." players online guild.\nGuild of Players Online ["..membros_online.."]")
       elseif membros_online > minimo then
          for var = 1, #tabela_membros do
              local nomes = getCreatureByName(tabela_membros[var])
              local XP = (membros_online <= 10) and (membros_online / 100) + 1.00 or (10/100) + 1.00
              doPlayerSetExperienceRate(nomes, XP)
              doPlayerSendTextMessage(nomes, MESSAGE_STATUS_CONSOLE_RED, "[GUILD] The experience of the guild members was increased to +"..membros_online*porcentagem.."% - Member "..getCreatureName(cid).." joined.")
          end
       end
   end
end
 
Last edited:
Still not logging:
Code:
[8:36:56.704] Noguild has logged in.
[8:36:56.826] Noguild has logged out.
[8:37:03.574] Noguild has logged in.
[8:37:03.697] Noguild has logged out.
[8:37:11.861] Inaguild has logged in.

[8:37:11.863] [Error - CreatureScript Interface]
[8:37:11.863] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[8:37:11.863] Description:
[8:37:11.863] data/creaturescripts/scripts/exp_guild_login.lua:20: attempt to concatenate field '?' (a nil value)
[8:37:11.863] stack traceback:
[8:37:11.863]    data/creaturescripts/scripts/exp_guild_login.lua:20: in function <data/creaturescripts/scripts/exp_guild_login.lua:1>
[8:37:11.983] Inaguild has logged out.
 
Still not logging:
Code:
[8:36:56.704] Noguild has logged in.
[8:36:56.826] Noguild has logged out.
[8:37:03.574] Noguild has logged in.
[8:37:03.697] Noguild has logged out.
[8:37:11.861] Inaguild has logged in.

[8:37:11.863] [Error - CreatureScript Interface]
[8:37:11.863] data/creaturescripts/scripts/exp_guild_login.lua:onLogin
[8:37:11.863] Description:
[8:37:11.863] data/creaturescripts/scripts/exp_guild_login.lua:20: attempt to concatenate field '?' (a nil value)
[8:37:11.863] stack traceback:
[8:37:11.863]    data/creaturescripts/scripts/exp_guild_login.lua:20: in function <data/creaturescripts/scripts/exp_guild_login.lua:1>
[8:37:11.983] Inaguild has logged out.

Lua:
print(#tabela_membros .." total online, ".. #ips .." amount of IP's, 1: ".. ips[1] ..", 2: ".. ips[2])

The table "ips" is most likely empty, move this line to below
Lua:
if #ips > 1 then
 
Code:
local xml = io.open(getDataDir().."monster/monsters.xml", "r")
local monsters = false
if xml then
   local text = xml:read("*all")
   xml:close()
   monsters = {}
   for monstername in text:gmatch('name="(.-)"') do
       table.insert(monsters, monstername)
   end
end

function onLogin(cid)

   if monsters and isInArray(monsters, getCreatureName(cid)) then
       return false
   end

return true
end
 
If you remove the lane from creaturescipts.xml which contains to your script (this one which we made), you can normally login?
 
put "return true" before last "end"

Now is logging script is almost working, just this problems:
When 4 player login on the same IP for him show:
Code:
[GUILD] To get bonus experience must be over 1 players online guild.
Guild of Players Online [1]

And do not show nothing to the others members...

Could you help to give a warning, exp still 3x because of limit of 3 IPs, for him and all others players from the guild ?

And when it logout show this message to the others:
Code:
11:05 [GUILD] The experience of the guild members was increased to +2% - Member Elite Knight joined.
11:05 [GUILD] The experience of the guild members was increased to +3% - Member Master Sorcerer joined.
11:06 [GUILD] Experience from guild members has been adjusted to 3% - Member Royal Paladin left.
11:06 [GUILD] Experience from guild members has been adjusted to 3% - Member Royal Paladin left.
 
Back
Top