• 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
452
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 =...

zxmatzx

Advanced OT User
Joined
Dec 1, 2010
Messages
307
Solutions
26
Reaction score
155
Location
Brazil
GitHub
Mateuso8
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.
 
OP
OP
dervin13

dervin13

Active Member
Joined
Apr 26, 2008
Messages
452
Solutions
1
Reaction score
28
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
 

zxmatzx

Advanced OT User
Joined
Dec 1, 2010
Messages
307
Solutions
26
Reaction score
155
Location
Brazil
GitHub
Mateuso8
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

theduck

Member
Joined
Dec 6, 2018
Messages
245
Reaction score
19
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
 

zxmatzx

Advanced OT User
Joined
Dec 1, 2010
Messages
307
Solutions
26
Reaction score
155
Location
Brazil
GitHub
Mateuso8
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())
 

ZeroSkyer

New Member
Joined
May 17, 2019
Messages
28
Solutions
1
Reaction score
2
Location
EEUU
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.
 

zxmatzx

Advanced OT User
Joined
Dec 1, 2010
Messages
307
Solutions
26
Reaction score
155
Location
Brazil
GitHub
Mateuso8
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
 

ZeroSkyer

New Member
Joined
May 17, 2019
Messages
28
Solutions
1
Reaction score
2
Location
EEUU
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
 
Top