Sigoles
Discord: @sigoles
- Joined
- Nov 20, 2015
- Messages
- 1,209
- Solutions
- 2
- Reaction score
- 154
this script work only the first time, after no work anymore:
How it should work: If player lost connection (with IP 0.0.0.0) the monsters stop attack and remove the player after some seconds
creature.lua
login.lua
TFS 1.2
thanks
How it should work: If player lost connection (with IP 0.0.0.0) the monsters stop attack and remove the player after some seconds
creature.lua
LUA:
local function removeCombatProtection(cid)
local player = Player(cid)
if not player then
return true
end
local time = 0
if player:isMage() then
time = 10
elseif player:isPaladin() then
time = 20
else
time = 30
end
player:setStorageValue(Storage.combatProtectionStorage, 2)
addEvent(function(cid)
local player = Player(cid)
if not player then
return
end
player:setStorageValue(Storage.combatProtectionStorage, 0)
player:remove()
end, time * 1000, cid)
end
function Creature:onTargetCombat(target)
if not self then
return true
end
if target:isPlayer() then
if self:isMonster() then
local protectionStorage = target:getStorageValue(Storage.combatProtectionStorage)
if target:getIp() == 0 then -- If player is disconnected, monster shall ignore to attack the player
if protectionStorage <= 0 then
addEvent(removeCombatProtection, 30 * 1000, target.uid)
target:setStorageValue(Storage.combatProtectionStorage, 1)
elseif protectionStorage == 1 then
self:searchTarget()
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
end
return true
end
if protectionStorage >= os.time() then
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
end
end
end
return true
end
login.lua
LUA:
local function onMovementRemoveProtection(cid, oldPosition, time)
local player = Player(cid)
if not player then
return true
end
local playerPosition = player:getPosition()
if (playerPosition.x ~= oldPosition.x or playerPosition.y ~= oldPosition.y or playerPosition.z ~= oldPosition.z) or player:getTarget() then
player:setStorageValue(Storage.combatProtectionStorage, 0)
return true
end
addEvent(onMovementRemoveProtection, 1000, cid, oldPosition, time - 1)
end
if player:getStorageValue(Storage.combatProtectionStorage) <= os.time() then
player:setStorageValue(Storage.combatProtectionStorage, os.time() + 10)
onMovementRemoveProtection(playerId, player:getPosition(), 10)
end
TFS 1.2
thanks
Last edited by a moderator: