O motivo, é porque um é onCombat (para enviar o cancel caso o jogador tente usar uma spell em área), e o outro é onTarget (como o próprio nome sugere, enviar um cancel caso o jogador tente targetar o monstro).
E sobre sua outra pergunta, que eu saiba, não (a outra pergunta que me refiro, é a terceira). Como os dois scripts são distintos em relação à função main, deve-se criar para cada uma tag diferente, e, consequentemente, um registro diferente no login.lua. E, também, mesmo ambos os scripts só tendo como diferença, por exemplo, o nome do monstro, será necessário registrar uma tag diferente, tanto em creaturescripts.xml quando em login.lua.
Ou, você pode criar um único arquivo .lua com 3 funções dentro (login, combat e target). Por exemplo,
function onCombat(cid, target) local pos = {x = 1056, y = 1056, z = 7} --Posição que o player terá que estar. local name = "nome" --Nome do monstro. if isPlayer(cid) then if getCreatureName(target) == name then if getThingPos(cid).x ~= pos.x or getThingPos(cid).y ~= pos.y or getThingPos(cid).z ~= pos.z then doPlayerSendCancel(cid, "Você não pode atacar na posição que se encontra!") return false end end end return true end function onTarget(cid, target) local pos = {x = 1056, y = 1056, z = 7} --Posição que o player terá que estar. local name = "nome" --Nome do monstro. if isPlayer(cid) then if getCreatureName(target) == name then if getThingPos(cid).x ~= pos.x or getThingPos(cid).y ~= pos.y or getThingPos(cid).z ~= pos.z then doPlayerSendCancel(cid, "Você não pode atacar na posição que se encontra!") return false end end end return true end function onLogin(cid) registerCreatureEvent(cid, "AttackPos") registerCreatureEvent(cid, "AttackPosTwo") return true end
Aí depois, bastaria registrar as três tags no creaturescripts.xml. (já que o registro do login.lua, já foi feito dentro do arquivo, na função onLogin.)<event type="target" name="AttackPos" event="script" value="cantattack.lua"/> <event type="combat" name="AttackPosTwo" event="script" value="cantattack.lua"/> <event type="login" name="AttackPosLogin" event="script" value="cantattack.lua"/>
Você não entendeu, como são três monstros diferentes, sugeri colocar os três em um arquivo só, algo como isso:
function onCombat(cid, target)
local pos = {
[1] = {x = 35, y = 66, z = 7},
[2] = {x = 36, y = 66, z = 7},
}
local name = "Easy"
if isPlayer(cid) and getCreatureName(target) == name then
if getThingPos(cid) ~= pos then
doPlayerSendCancel(cid, "You must be in the mark to attack!")
return false
end
end
return true
end
function onTarget(cid, target)
local pos = {
[1] = {x = 35, y = 66, z = 7},
[2] = {x = 36, y = 66, z = 7},
}
local name = "Easy"
if isPlayer(cid) then
if getCreatureName(target) == name then
if getThingPos(cid).x ~= pos.x or getThingPos(cid).y ~= pos.y or getThingPos(cid).z ~= pos.z then
doPlayerSendCancel(cid, "You must be in the mark to attack!")
return false
end
end
end
return true
end
function onCombat(cid, target)
local pos = {
[1] = {x = 33, y = 68, z = 7},
[2] = {x = 34, y = 68, z = 7},
}
local name = "Medium"
if isPlayer(cid) and getCreatureName(target) == name then
if getThingPos(cid) ~= pos then
doPlayerSendCancel(cid, "You must be in the mark to attack!")
return false
end
end
return true
end
function onTarget(cid, target)
local pos = {
[1] = {x = 33, y = 68, z = 7},
[2] = {x = 34, y = 68, z = 7},
}
local name = "Medium"
if isPlayer(cid) then
if getCreatureName(target) == name then
if getThingPos(cid).x ~= pos.x or getThingPos(cid).y ~= pos.y or getThingPos(cid).z ~= pos.z then
doPlayerSendCancel(cid, "You must be in the mark to attack!")
return false
end
end
end
return true
end
function onCombat(cid, target)
local pos = {
[1] = {x = 31, y = 70, z = 7},
[2] = {x = 32, y = 70, z = 7},
}
local name = "Hard"
if isPlayer(cid) and getCreatureName(target) == name then
if getThingPos(cid) ~= pos then
doPlayerSendCancel(cid, "You must be in the mark to attack!")
return false
end
end
return true
end
function onTarget(cid, target)
local pos = {
[1] = {x = 31, y = 70, z = 7},
[2] = {x = 32, y = 70, z = 7},
}
local name = "Hard"
if isPlayer(cid) then
if getCreatureName(target) == name then
if getThingPos(cid).x ~= pos.x or getThingPos(cid).y ~= pos.y or getThingPos(cid).z ~= pos.z then
doPlayerSendCancel(cid, "You must be in the mark to attack!")
return false
end
end
end
return true
end
function onLogin(cid)
registerCreatureEvent(cid, "AttackPos")
registerCreatureEvent(cid, "AttackPosTwo")
return true
end
<event type="target" name="AttackPos" event="script" value="cantattack.lua"/> <event type="combat" name="AttackPosTwo" event="script" value="cantattack.lua"/> <event type="login" name="AttackPosLogin" event="script" value="cantattack.lua"/>






info
Grupo: Herói
Registrado: 20/09/12
Posts: 2.6k
Reputação: +1.1k
Gênero: Masculino
O motivo, é porque um é onCombat (para enviar o cancel caso o jogador tente usar uma spell em área), e o outro é onTarget (como o próprio nome sugere, enviar um cancel caso o jogador tente targetar o monstro).
E sobre sua outra pergunta, que eu saiba, não (a outra pergunta que me refiro, é a terceira). Como os dois scripts são distintos em relação à função main, deve-se criar para cada uma tag diferente, e, consequentemente, um registro diferente no login.lua. E, também, mesmo ambos os scripts só tendo como diferença, por exemplo, o nome do monstro, será necessário registrar uma tag diferente, tanto em creaturescripts.xml quando em login.lua.
Ou, você pode criar um único arquivo .lua com 3 funções dentro (login, combat e target). Por exemplo,
function onCombat(cid, target) local pos = {x = 1056, y = 1056, z = 7} --Posição que o player terá que estar. local name = "nome" --Nome do monstro. if isPlayer(cid) then if getCreatureName(target) == name then if getThingPos(cid).x ~= pos.x or getThingPos(cid).y ~= pos.y or getThingPos(cid).z ~= pos.z then doPlayerSendCancel(cid, "Você não pode atacar na posição que se encontra!") return false end end end return true end function onTarget(cid, target) local pos = {x = 1056, y = 1056, z = 7} --Posição que o player terá que estar. local name = "nome" --Nome do monstro. if isPlayer(cid) then if getCreatureName(target) == name then if getThingPos(cid).x ~= pos.x or getThingPos(cid).y ~= pos.y or getThingPos(cid).z ~= pos.z then doPlayerSendCancel(cid, "Você não pode atacar na posição que se encontra!") return false end end end return true end function onLogin(cid) registerCreatureEvent(cid, "AttackPos") registerCreatureEvent(cid, "AttackPosTwo") return true end<event type="target" name="AttackPos" event="script" value="cantattack.lua"/> <event type="combat" name="AttackPosTwo" event="script" value="cantattack.lua"/> <event type="login" name="AttackPosLogin" event="script" value="cantattack.lua"/>Editado Dezembro 3 por zipter98