• 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 Question about anti mc

dervin13

Active Member
Joined
Apr 26, 2008
Messages
458
Solutions
1
Reaction score
28
Is it possible to create a script that prohibit players with same ip to attack the same player?
 
Solution
Sorry but I think I was not clear, I'm trying something like if I try to attack a guy with my 2 characters It wouldn't be possible, just with one. I try something with your script that helps but I want something that it's not necessary to logout like this one

Code:
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            if #getPlayersByIPAddress(self:getIp()) > 2 then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
Try this:
Put Game.getPlayersByIPAddress in you lib/core/game.lua if you don't have the function.
Lua:
function Game.getPlayersByIPAddress(ip, mask)
    if not mask then mask = 0xFFFFFFFF end
    local masked =...
Is it possible to create a script that prohibit players with same ip to attack the same player?
Always post your server version...
This is for TFS 1.x:
In events/scripts/creature.lua:
Lua:
function Creature:onTargetCombat(target)
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            if self:getIp() == target:getIp() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
end
You already have the function Creature:onTargetCombat(target) just add the code.
In events/events.xml be sure <event class="Creature" method="onTargetCombat" enabled="1" /> that enabled = 1, this should work.
 
Always post your server version...
This is for TFS 1.x:
In events/scripts/creature.lua:
Lua:
function Creature:onTargetCombat(target)
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            if self:getIp() == target:getIp() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
end
You already have the function Creature:onTargetCombat(target) just add the code.
In events/events.xml be sure <event class="Creature" method="onTargetCombat" enabled="1" /> that enabled = 1, this should work.

Sorry but I think I was not clear, I'm trying something like if I try to attack a guy with my 2 characters It wouldn't be possible, just with one. I try something with your script that helps but I want something that it's not necessary to logout like this one

Code:
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            if #getPlayersByIPAddress(self:getIp()) > 2 then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
 
Sorry but I think I was not clear, I'm trying something like if I try to attack a guy with my 2 characters It wouldn't be possible, just with one. I try something with your script that helps but I want something that it's not necessary to logout like this one

Code:
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            if #getPlayersByIPAddress(self:getIp()) > 2 then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
Try this:
Put Game.getPlayersByIPAddress in you lib/core/game.lua if you don't have the function.
Lua:
function Game.getPlayersByIPAddress(ip, mask)
    if not mask then mask = 0xFFFFFFFF end
    local masked = bit.band(ip, mask)
    local result = {}
    local players, player = Game.getPlayers()
    for i = 1, #players do
        player = players[i]
        if bit.band(player:getIp(), mask) == masked then
            result[#result + 1] = player
        end
    end
    return result
end
And this in events/scripts/creature.lua
Lua:
function Creature:onTargetCombat(target)
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            local playersByIp = Game.getPlayersByIPAddress(self:getIp())
            if #playersByIp > 1 then
                for i = 1, #playersByIp do
                    if playersByIp[i] ~= self and playersByIp[i]:getTarget() == target then
                        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                    end
                end
            end
        end
    end
end
Tested.
 
Last edited:
Solution
Try this:
Put Game.getPlayersByIPAddress in you lib/core/game.lua if you don't have the function.
Lua:
function Game.getPlayersByIPAddress(ip, mask)
    if not mask then mask = 0xFFFFFFFF end
    local masked = bit.band(ip, mask)
    local result = {}
    local players, player = Game.getPlayers()
    for i = 1, #players do
        player = players[i]
        if bit.band(player:getIp(), mask) == masked then
            result[#result + 1] = player
        end
    end
    return result
end
And this in events/scripts/creature.lua
Lua:
function Creature:onTargetCombat(target)
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            local playersByIp = Game.getPlayersByIPAddress(self:getIp())
            if #playersByIp > 1 then
                for i = 1, #playersByIp do
                    if playersByIp[i] ~= self and playersByIp[i]:getTarget() == target then
                        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                    end
                end
            end
        end
    end
end
Tested.
this would affect the player who is using tibia mc on hunt and has 1 char in pvp because that will count all his char would be interesting to count only the char that is in pvp
 
this would affect the player who is using tibia mc on hunt and has 1 char in pvp because that will count all his char would be interesting to count only the char that is in pvp
You are wrong. With this playersByIp[i]:getTarget() == target i check if have a player in playersByIp table that is attacking the target(that have to be a Player, because i check in line 3 with target:isPlayer())
 
You are wrong. With this playersByIp[i]:getTarget() == target i check if have a player in playersByIp table that is attacking the target(that have to be a Player, because i check in line 3 with target:isPlayer())
Brother a question, how can I increase from 1 to 2? In other words, allow 2 players with the same IP and block the third.
 
Brother a question, how can I increase from 1 to 2? In other words, allow 2 players with the same IP and block the third.
Lua:
function Creature:onTargetCombat(target)
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            local playersByIp = Game.getPlayersByIPAddress(self:getIp())
            local pCount = 0
            if #playersByIp > 1 then
                for i = 1, #playersByIp do
                    if playersByIp[i] ~= self and playersByIp[i]:getTarget() == target and pCount >= 2 then --Change the '2' to the count that you want allow to atk the same target.
                        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                    end
                    pCount = pCount + 1
                end
            end
        end
    end
end
Try this
 
Lua:
function Creature:onTargetCombat(target)
    if self and target then
        if self:isPlayer() and target:isPlayer() then
            local playersByIp = Game.getPlayersByIPAddress(self:getIp())
            local pCount = 0
            if #playersByIp > 1 then
                for i = 1, #playersByIp do
                    if playersByIp[i] ~= self and playersByIp[i]:getTarget() == target and pCount >= 2 then --Change the '2' to the count that you want allow to atk the same target.
                        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                    end
                    pCount = pCount + 1
                end
            end
        end
    end
end
Try this
Thanks for answering, I tried it and it did not work, it is still as before
 
Back
Top