Ir para conteúdo
  • 0

Pergunta

Bom galera, eu queria saber se é póssivel um script que só permita X vocation id atacar esse X monstro (configurado) e o monstro também só podendo atacar essa X vocation.

 

Bom é isso ai, desculpem se não expliquei direito.

 

Agradeço desde já.

Link para o comentário
https://xtibia.com/forum/topic/234873-apenas-x-vocation-id-pode-atacar-x-monstro/
Compartilhar em outros sites

Posts Recomendados

  • 0

Funcionou, obrigado.

Mas enquanto em lua, nenhum resultado o monster ainda ataca o jogador com vocation id diferente da adicionada no script.

mano poderia dizer qual sua idéia com esses script.

  • 0

Obrigado a todos que tentaram de todo jeito me ajudar, principalmente Bruno e Zipter98.

Grato.

mano poderia dizer qual sua idéia com esses script.

Creatserv, meu servidor possui raças com esse script criarei guardas para cada centro da cidade.


@EDIT

 

Zipter, achei um pequeno erro outra vocation sem o id configurado consegue matar o bixo, sendo que apenas os id configurado poderia matar, queria que quando jogadores sem o vocation id configurado aparece um doPlayerSendCancel dizendo "você não pode atacar esta criatura." (OBS: tinha esquecido deste detalhe)

Editado por AdilsonTsunami
  • 0

Ops, é mesmo.

local config = {
    name = "xxx",    --nome do monstro
    vocId = xxx,     --vocation id
}
function onTarget(cid, target)
    local player = isMonster(cid) and isPlayer(target) and target or isPlayer(cid) and isMonster(target) and getCreatureName(target) == config.name and cid or false
    if player then
        if getPlayerVocation(player) ~= config.vocId then
            if isPlayer(cid) then
                doPlayerSendCancel(cid, "você não pode atacar esta criatura.")
            end
            return false
        end
    end
    return true
end
function onStatsChange(cid, attacker, type, combat, value)
    local player = isMonster(attacker) and isPlayer(cid) and cid or isPlayer(attacker) and isMonster(cid) and getCreatureName(cid) == config.name and attacker or false
    if player then
        return getPlayerVocation(player) == config.vocId
    end
    return true
end

PS: O diretório na tag de ambos os creatureevents deve ser o mesmo.

Editado por zipter98
  • 0

Sim, e era para apenas os jogadores que ele foca poder atacar ele, quando outro vocation id não configurado atacar falar aquela mensagem que citei acima.

  • 0

OK, tenta assim:

 

local config = {
    name = "xxx",    --nome do monstro
    vocId = xxx,     --vocation id
}
function onTarget(cid, target)
    if isMonster(cid) and isPlayer(target) then
        if getPlayerVocation(target) ~= config.vocId then
            return false
        end
    elseif isPlayer(cid) and isMonster(target) then
        if getCreatureName(target) == config.name and getPlayerVocation(cid) ~= config.vocId then
            return doPlayerSendCancel(cid, "você não pode atacar esta criatura.") and false
        end
    end
    return true
end
function onStatsChange(cid, attacker, type, combat, value)
    if isMonster(attacker) and isPlayer(cid) then
        if getPlayerVocation(cid) ~= config.vocId then
            return false
        end
    elseif isPlayer(attacker) and isMonster(cid) then
        if getCreatureName(cid) == config.name and getPlayerVocation(attacker) ~= config.vocId then
            return doPlayerSendCancel(attacker, "você não pode atacar esta criatura.") and false
        end
    end
    return true
end
  • 0

 

 <event type="target" name="guarda" event="script" value="guarda.lua"/> 
 <event type="StatsChange" name="guarda" event="script" value="guarda.lua"/>    
Editado por AdilsonTsunami
  • 0

Tags:

<event type="statschange" name="guardaStatsChange" event="script" value="guarda.lua"/>
<event type="target" name="guardaTarget" event="script" value="guarda.lua"/> 
Em login.lua:
registerCreatureEvent(cid, "guardaStatsChange")
registerCreatureEvent(cid, "guardaTarget")
No xml do monstro:
<script>
    <event name="guardaStatsChange"/>
    <event name="guardaTarget"/>
</script>
Editado por zipter98
  • 0

Use este código e informe tudo que for imprimido no console.

local config = {
    name = "xxx",    --nome do monstro
    vocId = xxx,     --vocation id
}
function onTarget(cid, target)
    if isMonster(cid) and isPlayer(target) then
        if getPlayerVocation(target) ~= config.vocId then
            return false
        end
    elseif isPlayer(cid) and isMonster(target) then
        print("[Target] - "..getCreatureName(cid))
        print("[Target] - Vocation ID: [configurada: "..config.vocId.."] / [cid: "..getPlayerVocation(cid).."]")
        if getCreatureName(target) == config.name and getPlayerVocation(cid) ~= config.vocId then
            print("[Target] Cid can't target monster.")
            return doPlayerSendCancel(cid, "você não pode atacar esta criatura.") and false
        end
    end
    return true
end
function onStatsChange(cid, attacker, type, combat, value)
    if isMonster(attacker) and isPlayer(cid) then
        if getPlayerVocation(cid) ~= config.vocId then
            return false
        end
    elseif isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
        print("[StatsChange] - "..getCreatureName(attacker))
        print("[StatsChange] - Vocation ID: [configurada: "..config.vocId.."] / [cid: "..getPlayerVocation(attacker).."]")
        if getCreatureName(cid) == config.name and getPlayerVocation(attacker) ~= config.vocId then
            print("[StatsChange] Cid can't damage monster.")
            return doPlayerSendCancel(attacker, "você não pode atacar esta criatura.") and false
        end
    end
    return true
end
Editado por zipter98
×
×
  • Criar Novo...