Ir para conteúdo
Entre para seguir isso  
izaiasousa

Funções de Lua #3

Recommended Posts

izaiasousa    0
izaiasousa

Funções de scripts de lua #3

 

Olá :style:

 

Mais um tutorial bim bim fodim coloridim para os coloridim :lol:

 

Hoje iremos iniciar mais uma aula de scripts de Lua. Na aula Funções de scripts de Lua #2 vimos a função e as sintaxes de function.

Hoje iremos ver quais as funções, onde ser usada, como e por que de usar GET .

 

Get é usado pra ler uma informação de um jogador (cid) ou um item (item.id). Ele irá ver se o jogador tem certa condição ou um certo item, tende ?

 

Digamos que ele apenas irá ler as informações, os dados sobre o jogador ou item.

 

O jogador tem life maior que 1500 ?

Sim. Então, doPlayerRemoveHealth (cid,-100)

 

O get irá ler as informações do life do jogador nesse caso.

 

Vamos analisar algumas que considero importantes e úteis para você, inciante nessa área!

 

getCreatureHealth

 

Irá ler a quantidade de Life do jogador ou criatura cid.

 

if getCreatureHealth (cid)

 

if getCreatureHealth (cid) >= 500 then -- Se o jogador possuir 500 ou mais de life então.. execute o script, entederam ? ;)

 

 

 

getCreatureMaxHealth

Irá ler a quantidade máxima de life do jogador ou criatura cid.

 

If getCreatureMaxHealth (cid) == 1500 then -- Se a quantidade máxima de vida do jogador é 1500 então ele está preparado para enfrentar o que vier :soudado:

 

 

getPlayerLevel

 

Este irá ler o nível do jogador.

 

if getPlayerLevel (cid) >= 20 then -- Ele irá ver se o jogador tem level igual ou acima de 20 para poder executar o script. :yes:

 

getPlayerMagLevel

 

Este aqui irá ler a quantidade do Magic Level do jogador cid.

 

**Toda vez que eu me referir a jogador, será cid, ok?

 

if getPlayerMagLevel (cid) >= 10 then

 

 

getPlayerMana

 

Irá ver ler a quantidade de Mana que o jogador tem.

 

if getPlayerMana (cid) >= 350 then -- Se o jogador tiver a quantidade de mana maior ou igual à 350 então o script será executado.

 

getCreatureMaxMana

 

Irá ler a quantidade máxima de mana do jogador :)

Igual ao getCreatureMaxHealth.

getPlayerPosition

 

Irá ver a posição do jogador.

 

if getPlayerPosition == frompos then -- Ele irá ver se o jogador esta na posição indicada por frompos. Se ele estiver, então o script irá ser executado.

getPlayerSkill

 

Irá ver os skills do jogador. if getPlayerSkill (cid,0) >= 10 then -- Ele irá ler o skill do jogador. Sabe aqueles valores de doPlayerAddSkillTry ? Eles também servirão aqui. Se o jogador tiver Fist (0) maior ou igual a 10 então o script será executado.

getPlayerVocation

 

Ele irá ler a vocação do jogador.

 

if getPlayerVocation (cid) == 2 then -- Se o jogador for Druid (2) então o script poderá ser executado. Por exemplo, uma porta que só permita entrar uma vocação. :)

 

getPlayerSex

 

Esta função irá ler o sexo do jogador. Se for feminino é 0 e se for masculino será 1.

 

if getPlayerSex (cid) == 1 then -- Ele irá ler o jogador (cid), se ele for do sexo masculino 1 então o script será executado. :w00t:

 

getPlayerSoul

 

Esse irá ler a quantidade de soul do jogador.

 

if getPlayerSoul (cid) >= 100 then -- Irá ler a quantidade de soul do jogador. Se ele tiver soul maior ou igual a 100 então o script será executado.

 

getCreatureName

 

Esse script irá ler o nome da criatura (cid). :louco:

 

if getCreatureName (cid) == Demon then -- Ele irá ler se o nome da criatura escolhida é Demon. Se for o script será executado.

 

getPlayerPremiumDays

 

Ele irá ler a quantidade de dias de premium do jogador.

 

if getPlayerPremiumDays (cid) >= 3 then -- Irá ler os dias de premium do jogador. No exemplo, se for maior ou igual a 3 então o script será executado.

 

getPlayerSlotItem

 

Aqui ele irá ler, verificar se naquele slot ali tem um item. Se tiver o script será executado. No Funções de Lua #9 irei falar mais sobre ele. Ele será fundamental em uma função lá :rolleyes:

 

getPlayerSlotItem (cid,slot)

 

Slot é o lugar onde fica o item. Tipo.. Plate armor fica no lugar da armadura, certo ? Então no slot de armaduras!

 

Mas no parametro aqui não funciona assim :cry:

 

Será na base de numeração. Segue uma Lista para que você memorize quais são.

 

1 = capacete

2 = colar

3 = mochila

4 = armadura

5 = mão esquerda

6 = mão direita

7 = pernas

8 = botas

9 = anel

10 = costas (munição)

getPlayerStamina

 

Irá ler a quantidade de stamina do jogador cid.

getPlayerStamina(cid)

 

 

-----------

Atividade Para casa :ras:

 

Crie um script com as seguintes características :

 

•Faça um baú com Unique Id;

• O jogador deve ter o level maior que 100 para poder abrir;

•Deve ser Sorcerer ou Druid;

•Deve ter a mana maior ou igual à 500;

•Quando ele abrir, ele irá receber a mensagem de Quest completada!

•Irá aparecer dois dragons;

•Irá aparecer a mensagem "Ops!";

 

--------------

Bem, este é o tutorial Funções dos scripts de Lua #3!

Espero que isso tenha te ajudado , assim como me ajudou

Até Funções de scripts de Lua #4 (4ª temporada)

 

Editado por izaiasousa

Compartilhar este post


Link para o post
Flatronez    1
Flatronez

Movido.

 

aprovadog.png

Compartilhar este post


Link para o post
-Fark-    0
-Fark-

não consegui fazer >.<

 

function onUse(cid, item, frompos, item2, topos)
if item.uid == 5432 then
queststatus = getPlayerStorageValue(cid,5432)
getPlayerLevel (cid) >= 100 then
getPlayerVocation (cid) == 2 then
   getPlayerMana (cid) >= 500 then
if queststatus == -1 or queststatus == 0 then
item_uid = doPlayerRemoveItem(cid,2160,100)
item_uid = doPlayerAddItem(cid,2160,300)
setPlayerStorageValue(cid,5432,1)
doPlayerSendTextMessage(cid,22,"Quest Completada")
doSummonCreature (Dragon,{x=1015,y=1023,z=7})

else
doPlayerSendTextMessage(cid,22,"Ops!")
end
else
return 0
end
return 1
end

 

erro:

[24/06/2010 08:29:47] [Error - LuaScriptInterface::loadFile] data/actions/scripts/Fark/atividade_2.lua:4: unexpected symbol near '>='
[24/06/2010 08:29:47] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/Fark/atividade_2.lua)
[24/06/2010 08:29:47] data/actions/scripts/Fark/atividade_2.lua:4: unexpected symbol near '>='
[24/06/2010 08:29:47] [Error - LuaScriptInterface::loadFile] data/actions/scripts/Fark/atividade.lua:3: unexpected symbol near 'then'
[24/06/2010 08:29:47] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/Fark/atividade.lua)
[24/06/2010 08:29:47] data/actions/scripts/Fark/atividade.lua:3: unexpected symbol near 'then'

Compartilhar este post


Link para o post
izaiasousa    0
izaiasousa
não consegui fazer >.<

 

function onUse(cid, item, frompos, item2, topos)
if item.uid == 5432 then
queststatus = getPlayerStorageValue(cid,5432)
getPlayerLevel (cid) >= 100 then
getPlayerVocation (cid) == 2 then
   getPlayerMana (cid) >= 500 then
if queststatus == -1 or queststatus == 0 then
item_uid = doPlayerRemoveItem(cid,2160,100)
item_uid = doPlayerAddItem(cid,2160,300)
setPlayerStorageValue(cid,5432,1)
doPlayerSendTextMessage(cid,22,"Quest Completada")
doSummonCreature (Dragon,{x=1015,y=1023,z=7})

else
doPlayerSendTextMessage(cid,22,"Ops!")
end
else
return 0
end
return 1
end

erro:

[24/06/2010 08:29:47] [Error - LuaScriptInterface::loadFile] data/actions/scripts/Fark/atividade_2.lua:4: unexpected symbol near '>='
[24/06/2010 08:29:47] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/Fark/atividade_2.lua)
[24/06/2010 08:29:47] data/actions/scripts/Fark/atividade_2.lua:4: unexpected symbol near '>='
[24/06/2010 08:29:47] [Error - LuaScriptInterface::loadFile] data/actions/scripts/Fark/atividade.lua:3: unexpected symbol near 'then'
[24/06/2010 08:29:47] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/Fark/atividade.lua)
[24/06/2010 08:29:47] data/actions/scripts/Fark/atividade.lua:3: unexpected symbol near 'then'

 

Olha

 

getPlayerLevel (cid) >= 100 then -- O get apenas vai pegar a informação do jogador!

getPlayerVocation (cid) == 2 then -- O get só pega a informação do jogador!

getPlayerMana (cid) >= 500 then -- O get só pega informação do jogador!

 

Aqui no caso ficaria assim

 

local level = getPlayerLevel(cid)

local vocation = getPlayerVocation (cid)

local mana = getPlayerMana (cid)

local queststatus = getPlayerStorageValue (cid,5432)

 

function onUse(cid, item, frompos, item2, topos)

if item.uid == 5432 and level >= 0 and queststatus < 0 and mana >=500 and vocation == 2 then

doPlayerRemoveItem(cid,2160,100)

doPlayerAddItem(cid,2160,300)

setPlayerStorageValue(cid,5432,1)

doPlayerSendTextMessage(cid,22,"Quest Completada")

doSummonCreature (Dragon,{x=1015,y=1023,z=7})

Else

doPlayerSendTextMessage (cid,22,"Você não tem as condições necessarias para fazer a quest")

end

else

doPlayerSendTextMessage (cid,22,"ops!")

end

return 0

end

end

Eu criei variáveis em local para receber o level, a mana, o storagevalue e a vocation do jogador. Depois verificamos se é a condição ou não. Senão me engano o Dragon tem que estar entre aspas né ? :w00t:

Acho que só isso, se tiver outro erro me avisa.

Compartilhar este post


Link para o post
Mickfern    32
Mickfern

Bom, deixa eu ver se eu entendi, a função "get" só serve para verificar algo ?

Tipo if item.uid == 1345 then... ?

Se for isto, acho que entendi, eu nunca tinha usado algumas dessas funções antes... mas acho que vou começar usar.

Compartilhar este post


Link para o post
XCabulozoX    0
XCabulozoX

HIHI muito bom adoro seus tutorias =D

Compartilhar este post


Link para o post
izaiasousa    0
izaiasousa

O get irá ler o que foi determinado pra ela e irá retornar com o valor.

 

local Level = getPlayerLevel(cid) -- Aqui a variavel Level recebe o valor do level do jogador.

if level >= 30 then -- O get diz ao script o level do jogador (retorna). Se for maior ou igual a 30 então o script será executado.

 

Espero que tenha entedido :soudado:

 

=D

Compartilhar este post


Link para o post
Sir DeeD    0
Sir DeeD

Como disse nas aulas passadas, suas aulas sao

muito exclarecedoras. Voce esta de Parabens

por fazer aulas de otima qualidade e facil intendimento.

Obrigado.

Compartilhar este post


Link para o post
godmasterlord    0
godmasterlord

Errei uhul!! \,,/

 

function onUse(cid,item,frompos,item2,topos)
if getPlayerLevel(cid) >= 100 then
 if getPlayerVocation(cid) == 1 or 2 then
  if getPlayerMana(cid) >= 500 then
   doPlayerSendCancel(cid,"A quest foi completada!")
   doSummonCreature(demon,frompos)
   doPlayerSendCancel(cid,"Ops!")
end     
end     

 

Erro >

INFO: Starting OTScript Debug.lua
ERROR: teste .lua:10: 'end' expected (to close 'if' at line 2) near '<eof>'
INFO: Stopping OTScript Debug.lua

Compartilhar este post


Link para o post
izaiasousa    0
izaiasousa

Ta faltando um end pro if aí Godmaster~

Compartilhar este post


Link para o post
Dran Kron    0
Dran Kron

Por favor uma correção :3

 

local mana = getPlayerMana (cid)
local level	= getPlayerLevel (cid)
local vocation = getPlayerVocation ( cid)
local queststatus = getPlayerStorageValue (cid, 8000)
local dragonpos = {x=100, y=100, z=7}
local chest = item.uid

function onUse (cid,item,frompos,item2,topos)
if  chest == 1234 mana >= 500 and level >= 100 and queststatus < 0 and vocation == 1 then
	doPlayerAddItem (cid, 2160, 1)
	setPlayerStorageValue (cid, 8000, 1)
	doSendTextMessage (cid, "Quest Completada!", 22)
	doSummonCreature (2, "Dragon", dragonpos)
	doCreatureSay (cid, "Omg!", 2)		
elseif
	queststatus >= 1
	doSendTexMessage (cid, "Você já fez essa Quest.", 22)

end
end	

Compartilhar este post


Link para o post
PoRaI    0
PoRaI
Por favor uma correção :3

 

local mana = getPlayerMana (cid)
local level	= getPlayerLevel (cid)
local vocation = getPlayerVocation ( cid)
local queststatus = getPlayerStorageValue (cid, 8000)
local dragonpos = {x=100, y=100, z=7}
local chest = item.uid

function onUse (cid,item,frompos,item2,topos)
if  chest == 1234 mana >= 500 and level >= 100 and queststatus < 0 and vocation == 1 then
	doPlayerAddItem (cid, 2160, 1)
	setPlayerStorageValue (cid, 8000, 1)
	doSendTextMessage (cid, "Quest Completada!", 22)
	doSummonCreature (2, "Dragon", dragonpos)
	doCreatureSay (cid, "Omg!", 2)		
elseif
	queststatus >= 1
	doSendTexMessage (cid, "Você já fez essa Quest.", 22)

end
end	

 

Está bastante errado, o certo seria:

function onUse(cid, item, frompos, item2, topos)

local mana = getCreatureMana(cid)

local level = getPlayerLevel(cid)

local vocation = getPlayerVocation(cid)

local queststatus = getPlayerStorageValue(cid, 8000)

local dragonpos = {x=100, y=100, z=7}

local chest = item.uid

 

if chest == 1234 and mana >= 500 and level >= 100 and queststatus < 0 and vocation == 1 then

doPlayerAddItem(cid, 2160, 1)

setPlayerStorageValue(cid, 8000, 1)

doPlayerSendTextMessage(cid, 22, "Quest Completada!")

doSummonCreature (2, "Dragon", dragonpos)

doCreatureSay(cid, "Omg!", 1)

elseif queststatus >= 1 then

doPlayerSendTextMessage(cid, 22, "Você ja fez esta Quest!")

end

end

Compartilhar este post


Link para o post
Dran Kron    0
Dran Kron

Acho que getPlayerMana tava certo...

 

 

getPlayerMana

 

Irá ver ler a quantidade de Mana que o jogador tem.

 

if getPlayerMana (cid) >= 350 then -- Se o jogador tiver a quantidade de mana maior ou igual à 350 então o script será executado.

Compartilhar este post


Link para o post
polons    0
polons

SE ESTIVER ERRADO CORRIGAN E MANDE POR MIN PARA PM

function onUse(cid, item, frompos, item2, topos)

item.uid = 8796

queststatus = getPlayerStorageValue(cid,10285)

if getPlayerLevel (cid) >= 100 then

if getPlayerVocation (cid) == 1 or 2 then

if getPlayerMana (cid) >= 500 then

end

else

doPlayerSendTextMessage(cid, 23,"Quest Completada!")

doSummonCreature (Dragon,{x=1808,y=600,z=7},2)

doPlayerSendTextMessage(cid, 23,"Ops!")

end

end

 

oBRIGADO!

Compartilhar este post


Link para o post
J John    0
J John

@izaiasousa

 

ta faltando 2 'end'

[color="blue"]function onUse[/color](cid,item,frompos,item2,topos)
[color="red"] if getPlayerLevel[/color](cid) >= 100 then
 [color="lime"]if getPlayerVocation[/color](cid) == 1 or 2 then
 [color="purple"] if getPlayerMana[/color](cid) >= 500 then
   doPlayerSendCancel(cid,"A quest foi completada!")
   doSummonCreature(demon,frompos)
   doPlayerSendCancel(cid,"Ops!")
[color="blue"]end[/color]    
[color="red"]end[/color]
[color="lime"]end[/color]
[color="purple"]end[/color]

 

- 3 para os 'ifs' e 1 para a 'function onUse'

 

Estou errado?

Editado por J John

Compartilhar este post


Link para o post
iuniX    4
iuniX

J John. Eu sei que você está querendo participar. Mas por favor, verifique as datas e pare de reviver tópicos antigos. Vou ser obrigado a reportar se isso continuar...

Tópico fechado para evitar futuros transtornos.

 

Att. iuniX~

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×