NA

elseif ou if?

Por narutomaniacos, 14 de fev. de 2014 em Scripts

spell
resolvido
script
6
1.1k
narutomaniacosN
14 de fevereiro de 2014 às 18:52

Bom Tenho um spell de transform Porém da o erro iomh.png

Eu Sempre tive essa duvida Onde Colocar If e onde colocar Elseif.

 

Script:

 

 

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
local condition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(condition, CONDITION_PARAM_TICKS, 86400000)
addOutfitCondition(condition, 0, 71, 0, 0, 0, 0)
setCombatCondition(combat, condition)
ext = 1000
function onCastSpell(cid, var)
-- Transformar
if getPlayerVocation(cid) == 398 then
if getPlayerLevel(cid) >= 50 then
doPlayerSetVocation(cid,399)
doSetOutfit(cid,"495")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 8)
else
doPlayerSendCancel(cid, "You need level 50 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
elseif getPlayerVocation(cid) == 399 then
if getPlayerLevel(cid) >= 100 then
doPlayerSetVocation(cid,400)
doSetOutfit(cid,"496")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 32)
else
doPlayerSendCancel(cid, "You need level 100 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
elseif getPlayerVocation(cid) == 400 then
if getPlayerLevel(cid) >= 150 then
doPlayerSetVocation(cid,401)
doSetOutfit(cid,"497")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 32)
else
doPlayerSendCancel(cid, "You need level 150 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
else
doPlayerSendCancel(cid, "Voce nao pode se transformar.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
elseif getPlayerVocation(cid) == 401 then
if getPlayerLevel(cid) >= 200 then
doPlayerSetVocation(cid,402)
doSetOutfit(cid,"498")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 32)
else
doPlayerSendCancel(cid, "You need level 200 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
return true
end

Editado Fevereiro 14 por narutomaniacos

KilluaK
14 de fevereiro de 2014 às 19:28

Área incorreta. Tópico movido para Pedidos e Dúvidas - Scripting.

 

Aqui está a correção do seu script:

 

 


local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
local condition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(condition, CONDITION_PARAM_TICKS, 86400000)
addOutfitCondition(condition, 0, 71, 0, 0, 0, 0)
setCombatCondition(combat, condition)
 
ext = 1000
 
function onCastSpell(cid, var)
 
 
-- Transformar
if getPlayerVocation(cid) == 398 then
if getPlayerLevel(cid) >= 50 then
doPlayerSetVocation(cid,399)
doSetOutfit(cid,"495")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 8)
else
doPlayerSendCancel(cid, "You need level 50 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
 
elseif getPlayerVocation(cid) == 399 then
if getPlayerLevel(cid) >= 100 then
doPlayerSetVocation(cid,400)
doSetOutfit(cid,"496")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 32)
else
doPlayerSendCancel(cid, "You need level 100 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
 
elseif getPlayerVocation(cid) == 400 then
if getPlayerLevel(cid) >= 150 then
doPlayerSetVocation(cid,401)
doSetOutfit(cid,"497")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 32)
else
doPlayerSendCancel(cid, "You need level 150 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end
 
elseif getPlayerVocation(cid) == 401 then
if getPlayerLevel(cid) >= 200 then
doPlayerSetVocation(cid,402)
doSetOutfit(cid,"498")
addEvent(tran,ext,cid)
doSendMagicEffect(getPlayerPosition(cid), 32)
else
doPlayerSendCancel(cid, "You need level 200 to the next transform.")
doSendMagicEffect(getPlayerPosition(cid), 2)
end

end 
return true
end

Quanto a sua dúvida:

Entendendo "if" como "se" e "elseif" como "se não, mas" facilita tudo. O if vc vai usar para uma primeira condição e o elseif pode vir dentro do if, exemplo de um script traduzido:

se pegarLevelDoPlayer(cid) == 20 então
     teleporteOPlayer(cid, pos)
     se não mas pegarLevelDoPlayer(cid) == 30 então
     teleporteOPlayer(cid, pos2)
end

O mesmo script em LUA:

if getPlayerLevel(cid) == 20 then
     doTeleportThing(cid, pos)
     elseif getPlayerLevel(cid) == 30 then
     doTeleportThing(cid, pos2)
end

Espero que dê pra entender.

Editado Fevereiro 14 por Killua

LegnusL
14 de fevereiro de 2014 às 20:05

Lembrando que para o 'elseif', como uma condição secundária, não se é necessário aplicar um 'end'.

Que do contrário, sempre se deve aplicar um end pra cada condição (ifs), e um a mais, para se fechar a função do script.

14 de fevereiro de 2014 às 20:12

ops , n tinha visto as respostas

desculpa ..

Editado Fevereiro 14 por DuuhCarvalho

narutomaniacosN
16 de fevereiro de 2014 às 22:08

Obrigado a todos Principalmente ao @Killua Rep+

KilluaK
16 de fevereiro de 2014 às 22:42

Que bom que ajudei (:


Tópico movido para a seção de dúvidas e pedidos resolvidos.