Try this: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
Game.getPlayersByIPAddress
in you lib/core/game.lua
if you don't have the function.function Game.getPlayersByIPAddress(ip, mask)
if not mask then mask = 0xFFFFFFFF end
local masked =...
Always post your server version...Is it possible to create a script that prohibit players with same ip to attack the same player?
events/scripts/creature.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
Creature:onTargetCombat(target)
just add the code.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:
Inevents/scripts/creature.lua
:
You already have the functionLua: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
Creature:onTargetCombat(target)
just add the code.
Inevents/events.xml
be sure<event class="Creature" method="onTargetCombat" enabled="1" />
thatenabled = 1
, this should work.
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: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
Game.getPlayersByIPAddress
in you lib/core/game.lua
if you don't have the function.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
events/scripts/creature.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
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 pvpTry this:
PutGame.getPlayersByIPAddress
in youlib/core/game.lua
if you don't have the function.
And this inLua: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
events/scripts/creature.lua
Tested.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
You are wrong. With thisthis 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
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.You are wrong. With thisplayersByIp[i]:getTarget() == target
i check if have a player inplayersByIp
table that is attacking the target(that have to be a Player, because i check in line 3 withtarget: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.
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
Thanks for answering, I tried it and it did not work, it is still as beforeTry thisLua: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
Sorry, i cant test ATM... I suggest you to create a new thread to solve your problem.Thanks for answering, I tried it and it did not work, it is still as before
I have - Lua - Check Multiclient (https://otland.net/threads/check-multiclient.277140/)Sorry, i cant test ATM... I suggest you to create a new thread to solve your problem.