DA

[Resolvido] Erro no script

Por danilonogueira, 26 de jan. de 2019 em Resolvidos

8
1.9k
26 de janeiro de 2019 às 18:16

Olá, meu servidor é RealServer 3.1 p/ OT 8.6 e estou fazendo uma quest que dê Skills de acordo com a vocação.

Segue o Script

 

function onUse(cid, item)

if item.uid == 32114 then
if getPlayerStorageValue(cid, 32114) <= 0 then
    if getPlayerVocation(cid) == 1 or if getPlayerVocation(cid) == 2 or if getPlayerVocation(cid) == 5 or if getPlayerVocation(cid) == 6 then
        doPlayerSetMagic(cid, getPlayerMagLevel(cid)+12)
        doPlayerSendCancel(cid, "You have found a +12 ML.")
        setPlayerStorageValue(cid, 32114, 1)
    elseif getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7 then
        doPlayerAddSkillTry(cid, 4, getPlayerSkill(cid, 4) + 12)
        doPlayerSendCancel(cid, "You have found +12 of Distance Skills.")
        setPlayerStorageValue(cid, 32114, 1)
    else
        doPlayerAddSkillTry(cid, 0, getPlayerSkill(cid, 0) + 12)
        doPlayerAddSkillTry(cid, 1, getPlayerSkill(cid, 1) + 12)
        doPlayerAddSkillTry(cid, 2, getPlayerSkill(cid, 2) + 12)
        doPlayerAddSkillTry(cid, 3, getPlayerSkill(cid, 3) + 12)
        doPlayerAddSkillTry(cid, 5, getPlayerSkill(cid, 5) + 12)
        doPlayerSendCancel(cid, "You have found +12 of some Skills.")
        setPlayerStorageValue(cid, 32114, 1)
    end
else
return doPlayerSendCancel(cid, "This is empty.")
end
return TRUE
end

Porém, ao abrir o server está aparecendo que contém um erro (""chest.lua:5: unexpected symbol near 'if' "") e eu já mexi tanto que não consigo achar o bendito erro.

 

Alguém poderia me ajudar?

valakasV
26 de janeiro de 2019 às 21:18

não tem como postar o erro completo não ou só aparece isso ?

27 de janeiro de 2019 às 08:53

Tem sim 

 

[Error - LuaScriptInterface::loadFile] data/actions/scripts/quests/dwarves/chest.lua:5: unexpected symbol near 'if'
[Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests/dwarves/chest.lua)
data/actions/scripts/quests/dwarves/chest.lua:5: unexpected symbol near 'if'

 

Parece ser algo simples, questão de fechar ou abrir sintaxe, mas não consigo achar ?‍♂️

 

Kuro o ShinigaK
27 de janeiro de 2019 às 11:00

Eae cara beleza? o erro foi o seguinte na quarta linha do script você colocou varios if olha só :

if getPlayerVocation(cid) == 1 or if getPlayerVocation(cid) == 2 or if getPlayerVocation(cid) == 5 or if getPlayerVocation(cid) == 6 then

Não precisa colocar "or if ", apenas o primeiro if já serve para a linha toda, o certo seria assim :

if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 then

 

Outra coisa, você já vai colocar um uid na quest pelo mapa editor, acredito que não precisar colocar ele no script também, eu pelo menos não coloco :

if item.uid == 32114 then

 

E aqui esta o script funcionando :

 

function onUse(cid, item)

if getPlayerStorageValue(cid, 32114) <= 0 and getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 then
        doPlayerSetMagic(cid, getPlayerMagLevel(cid)+12)
        doPlayerSendCancel(cid, "You have found a +12 ML.")
        setPlayerStorageValue(cid, 32114, 1)
		
    if getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7 then
        doPlayerAddSkillTry(cid, 4, getPlayerSkill(cid, 4) + 12)
        doPlayerSendCancel(cid, "You have found +12 of Distance Skills.")
        setPlayerStorageValue(cid, 32114, 1)
    else
        doPlayerAddSkillTry(cid, 0, getPlayerSkill(cid, 0) + 12)
        doPlayerAddSkillTry(cid, 1, getPlayerSkill(cid, 1) + 12)
        doPlayerAddSkillTry(cid, 2, getPlayerSkill(cid, 2) + 12)
        doPlayerAddSkillTry(cid, 3, getPlayerSkill(cid, 3) + 12)
        doPlayerAddSkillTry(cid, 5, getPlayerSkill(cid, 5) + 12)
        doPlayerSendCancel(cid, "You have found +12 of some Skills.")
        setPlayerStorageValue(cid, 32114, 1)
    end
else
return doPlayerSendCancel(cid, "This is empty.")
end
end

 

Editado Janeiro 27 por Pinpao

27 de janeiro de 2019 às 18:58

Puxa, valeu Pinpao. Na hora de abrir o server já sumiu aquele erro que eu havia postado. Muito obrigado.

Só na hora de abrir o baú, o char em vez de receber a recompensa (ML, no caso) ele só abre o baú que está vazio, e no Prompt aparece isso:

 

[Error - Action Interface]
data/actions/scripts/quests/dwarves/chest.lua:onUse
Description:
data/actions/scripts/quests/dwarves/chest.lua:4: attempt to call global 'doPlayerSetMagic' (a nil value)
stack traceback:
        data/actions/scripts/quests/dwarves/chest.lua:4: in function <data/actions/scripts/quests/dwarves/chest.lua:1>

 

Só acontece isso com os MS e ED... com os EK e RP está dando certinho.

 

Fiz outros testes e os skills dos EK e RP não adicionam na medida do parâmetro do script (tentei como estava "12", tentei "8" e não adiciona corretamente). Com +12 ele começou adicionando uns 16, daí eu zerei o Store 32114 no BD e fiz de novo, daí adicionou 10, na terceira vez adicionou 5.. estranho isso.

Talvez seja melhor criar um item que Dê ML (ou skill) ao usá-lo e fazer a quest dar uma quantidade desse item para o player. Pode ser que ajude no problema da quantidade de skill.

Kuro o ShinigaK
27 de janeiro de 2019 às 19:10
function onUse(cid, item)

if getPlayerStorageValue(cid, 32114) <= 0 and getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 then
        doPlayerSetMagic(cid, 12)
        doPlayerSendCancel(cid, "You have found a +12 ML.")
        setPlayerStorageValue(cid, 32114, 1)
		
    if getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7 then
        doPlayerAddSkillTry(cid, 4, 12)
        doPlayerSendCancel(cid, "You have found +12 of Distance Skills.")
        setPlayerStorageValue(cid, 32114, 1)
    else
        doPlayerAddSkillTry(cid, 0, 12)
        doPlayerAddSkillTry(cid, 1, 12)
        doPlayerAddSkillTry(cid, 2, 12)
        doPlayerAddSkillTry(cid, 3, 12)
        doPlayerAddSkillTry(cid, 5, 12)
        doPlayerSendCancel(cid, "You have found +12 of some Skills.")
        setPlayerStorageValue(cid, 32114, 1)
    end
else
return doPlayerSendCancel(cid, "This is empty.")
end
end

 

Você usou a função " doPlayerSetMagic" para adicionar ML, mas desconheço essa função 

Editado Janeiro 27 por Pinpao

28 de janeiro de 2019 às 09:18
Melhor resposta

Obrigado mais uma vez.

Para que o Script funcionasse dando exatamente o que eu precisava, tive que deixar "rateSkill = 1.0" e "rateMagic = 1.0" no config.lua. Além disso, tive que colocar 8 linhas de +1 skill para dar 8 skills, dessa forma:

 

function onUse(cid, item)

if item.uid == 32114 then

if getPlayerStorageValue(cid, 32114) <= 0 then
    if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 then
        doPlayerAddMagLevel(cid, 1)
    doPlayerAddMagLevel(cid, 1)
    doPlayerAddMagLevel(cid, 1)
    doPlayerAddMagLevel(cid, 1)
    doPlayerAddMagLevel(cid, 1)
    doPlayerAddMagLevel(cid, 1)
    doPlayerAddMagLevel(cid, 1)
    doPlayerAddMagLevel(cid, 1)
        doPlayerSendCancel(cid, "You have found a +8 ML.")
        setPlayerStorageValue(cid, 32114, 1)
        
        elseif getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7 then
        doPlayerAddSkill(cid,4,1)
    doPlayerAddSkill(cid,4,1)
    doPlayerAddSkill(cid,4,1)
    doPlayerAddSkill(cid,4,1)
    doPlayerAddSkill(cid,4,1)
    doPlayerAddSkill(cid,4,1)
    doPlayerAddSkill(cid,4,1)
    doPlayerAddSkill(cid,4,1)
        doPlayerSendCancel(cid, "You have found +8 of Distance Skills.")
        setPlayerStorageValue(cid, 32114, 1)
        else
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,0,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,1,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,2,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,3,1)
    doPlayerAddSkill(cid,5,1)
    doPlayerAddSkill(cid,5,1)
    doPlayerAddSkill(cid,5,1)
    doPlayerAddSkill(cid,5,1)
    doPlayerAddSkill(cid,5,1)
    doPlayerAddSkill(cid,5,1)
    doPlayerAddSkill(cid,5,1)
    doPlayerAddSkill(cid,5,1)
        doPlayerSendCancel(cid, "You have found +8 of some Skills.")
        setPlayerStorageValue(cid, 32114, 1)
    end
else
return doPlayerSendCancel(cid, "This is empty.")
end
end
end

 

 

Ficou extenso, mas funcionou perfeitamente.

Obrigado a todos pela ajuda. (y)

1 mês depois...
MarshmelloM
14 de fevereiro de 2019 às 16:23
A questão neste tópico de suporte foi respondida e/ou o autor do tópico resolveu o problema. Este tópico está fechado e foi movido para Suporte - Resolvidos. Se você tiver outras dúvidas, crie um novo tópico.