AD
pedido

Apenas X vocation id pode atacar X monstro

By AdilsonHacker, 18 de jun. de 2015 in Scripts

resolvido
script
48
6k
zipter98Z
21 de junho de 2015 às 02:43

Foi mal, é o sono. Códigos corrigidos.

Edited Junho 21 by zipter98

CreatservC
21 de junho de 2015 às 09:23

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.

AdilsonHackerA
22 de junho de 2015 às 01:40

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)

Edited Junho 22 by AdilsonTsunami

zipter98Z
22 de junho de 2015 às 13:32

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.

Edited Junho 22 by zipter98

AdilsonHackerA
23 de junho de 2015 às 12:24

Zipter, infelizmente nada aconteceu, o jogador sem a vocation id adicionada no script ainda consegue atacar o monstro.

 

zipter98Z
23 de junho de 2015 às 14:31

E o monstro, ele foca apenas os jogadores com a vocation id configurada?

AdilsonHackerA
23 de junho de 2015 às 14:54

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.

zipter98Z
23 de junho de 2015 às 15:19

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
AdilsonHackerA
23 de junho de 2015 às 15:47

Mesma coisa, não da erros no console mais também não pega. Continua outra vocation id atacando o monstro.

zipter98Z
23 de junho de 2015 às 16:08

Como ficaram as tags e o registro em login.lua?

AdilsonHackerA
23 de junho de 2015 às 16:13

 

 <event type="target" name="guarda" event="script" value="guarda.lua"/> 
 <event type="StatsChange" name="guarda" event="script" value="guarda.lua"/>    

Edited Junho 23 by AdilsonTsunami

zipter98Z
23 de junho de 2015 às 17:03

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>

Edited Junho 23 by zipter98

AdilsonHackerA
24 de junho de 2015 às 01:01

Mesma coisa, nada acontece.


@up

zipter98Z
24 de junho de 2015 às 19:04

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

Edited Junho 24 by zipter98

AdilsonHackerA
24 de junho de 2015 às 21:42

wl4mz5.png