• 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 for ip

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
Can someone help me limit only 1 character that can win? Because my server allows to log more than 1 character in the same account and the staff is registering several and earning double tibia coins.


Lua:
function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do   
        accountID = player:getAccountId()       
        if (os.time() - player:getStorageValue(_TOKENS_LH.sto_online)) >= _TOKENS_LH.time * 60 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Voce recebeu ".. _TOKENS_LH.token_qnt .. " tibia coins!")       
             player:setStorageValue(_TOKENS_LH.sto_online, os.time())
             db.asyncQuery('UPDATE `accounts` SET `coins` = `coins` + "'.. _TOKENS_LH.token_qnt .. '"  WHERE `id` = '.. accountID)           
        end       
    end

    return true
end
 
You can make only one character online per account from your Config.lua
onePlayerOnlinePerAccount = false
change
false to True.


or

Try this
Lua:
function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do   
        accountID = player:getAccountId()   
  local Info = db.getResult("SELECT `lockmc` FROM `accounts` WHERE `id` = " .. accountID .. " LIMIT 1")
        local mc= Info:getDataInt("lockmc")        
        if (os.time() - player:getStorageValue(_TOKENS_LH.sto_online)) >= _TOKENS_LH.time * 60 and mc <1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Voce recebeu ".. _TOKENS_LH.token_qnt .. " tibia coins!")       
             player:setStorageValue(_TOKENS_LH.sto_online, os.time())
             db.asyncQuery('UPDATE `accounts` SET `coins` = `coins` + "'.. _TOKENS_LH.token_qnt .. '"  WHERE `id` = '.. accountID)           
             db.asyncQuery('UPDATE `accounts` SET `lockmc`= 1 WHERE `id`=' .. accountID)           
        end       
    end

    return true
end
on Event Start you should Add this line
Lua:
    db.asyncQuery('UPDATE `accounts`  SET  `lockmc`= 0 )
 
You can make only one character online per account from your Config.lua
onePlayerOnlinePerAccount = false
change
false to True.


or

Try this
Lua:
function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do  
        accountID = player:getAccountId()  
  local Info = db.getResult("SELECT `lockmc` FROM `accounts` WHERE `id` = " .. accountID .. " LIMIT 1")
        local mc= Info:getDataInt("lockmc")       
        if (os.time() - player:getStorageValue(_TOKENS_LH.sto_online)) >= _TOKENS_LH.time * 60 and mc <1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Voce recebeu ".. _TOKENS_LH.token_qnt .. " tibia coins!")      
             player:setStorageValue(_TOKENS_LH.sto_online, os.time())
             db.asyncQuery('UPDATE `accounts` SET `coins` = `coins` + "'.. _TOKENS_LH.token_qnt .. '"  WHERE `id` = '.. accountID)          
             db.asyncQuery('UPDATE `accounts` SET `lockmc`= 1 WHERE `id`=' .. accountID)          
        end      
    end

    return true
end
on Event Start you should Add this line
Lua:
    db.asyncQuery('UPDATE `accounts`  SET  `lockmc`= 0 )

Is there a way to validate this without using queries?
 
You can edit this code to ur TFS version

then Winner can be one account without MC
 
Is there a way to validate this without using queries?
This queries not alot won't make you any lag it just for some seconds on the end of the event and the start so you won't worry about it .
you can check if same ip won't join the event.. or
in same account don't join the event too. but it requires query
 
Lua:
local function has_value (tab, val)
    for index, value in ipairs(tab) do
        if value == val then
            return true
        end
    end

    return false
end

function onThink(interval, lastExecution)   
    for _, player in pairs(Game.getPlayers()) do           
        local ip, flag = {}       
        accountID = player:getAccountId()
        table.insert(ip, player:getIp())
        if ip then
            if #ip >= 1 then
                for i = 1, #ip do
                
                    flag = has_value(ip,ip[i])   
                        
                    
                    if (os.time() - player:getStorageValue(_TOKENS_LH.sto_online)) >= _TOKENS_LH.time * 60 and flag == true then
                        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Voce recebeu ".. _TOKENS_LH.token_qnt .. " tibia coins!")       
                        player:setStorageValue(_TOKENS_LH.sto_online, os.time())
                        db.asyncQuery('UPDATE `accounts` SET `coins` = `coins` + "'.. _TOKENS_LH.token_qnt .. '"  WHERE `id` = '.. accountID)           
                    end                       
                end
            end
        end   
    end

    return true
end

Can someone help me to check if it has more than 1 equal value?

Because what I've managed to do so far ... it will always return true.
 
Back
Top