Perfeito Luck , toma o rep , bjos
- Fórum
- OTServ
- Recursos
- Scripting
- Actions e Talkactions
- Potion System (Meu Primeiro Script em OOP)
Potion System (Meu Primeiro Script em OOP)
Por LuckOake, 24 de jan. de 2013 em Actions e Talkactions
info
Grupo: Banidos
Registrado: 11/01/13
Posts: 576
Reputação: +109
Char no Tibia: Darashia del Shee

info
Grupo: Visconde
Registrado: 12/09/10
Posts: 416
Reputação: +160
Char no Tibia: Draky Lucas

cara muito bem feito o script, parabens, sério!
oww.. me tira uma dúvida? (tou tentando entender ele certo
)
na função:
function Potion:new(type, healmin, healmax, vocations, emptyid, uid)
você está atribuindo o uid = 0 sempre, então nao é desnecessario esse uid? ![]()
(só por curiosidade mesmo)
e novamente, parabens! rep+ merecido!
info
Grupo: Infante
Registrado: 04/03/11
Posts: 1.6k
Reputação: +393
Char no Tibia: No Have

cara muito bem feito o script, parabens, sério! oww.. me tira uma dúvida? (tou tentando entender ele certo) na função:
você está atribuindo o uid = 0 sempre, então nao é desnecessario esse uid?function Potion:new(type, healmin, healmax, vocations, emptyid, uid)(só por curiosidade mesmo) e novamente, parabens! rep+ merecido!
Eu falei com o luck sobre isto.
Ele falo que erá para ficar mais bonito.
info
Grupo: Príncipe
Registrado: 19/08/10
Posts: 4k
Reputação: +1.1k
Gênero: Masculino

eh q o UID vem depois neh...
Potions.uid = item.uid
@topic
muito bom luck! para quem tava sem ideias fico um otimo script e bem limpo ^^ parabens... -falta eu aprender isso kk sei fazer isso em java mas em .lua nem tanto ^^-
Editado Janeiro 27 por Slicer
info
Grupo: Marquês
Registrado: 22/07/12
Posts: 1.1k
Reputação: +400
Gênero: Masculino
Char no Tibia: Luck Oake

@Topic
Valeus galera, tô começando a pegar o jeito de OOP, mas ainda preciso treinar muito ![]()
@DrakyLucas
cara muito bem feito o script, parabens, sério!
oww.. me tira uma dúvida? (tou tentando entender ele certo
)
na função:
functionPotion:new(type, healmin, healmax, vocations, emptyid, uid)você está atribuindo o uid = 0 sempre, então nao é desnecessario esse uid?
(só por curiosidade mesmo)
e novamente, parabens! rep+ merecido!
Eu coloquei o UID por questão de organização mesmo, pra eu não me perder quando eu editar o script ![]()





info
Grupo: Marquês
Registrado: 22/07/12
Posts: 1.1k
Reputação: +400
Gênero: Masculino
Char no Tibia: Luck Oake
Olá galera
Graças ao meu mestre Oneshot eu consegui aprender a poderosa Programação Orientada a Objetos, ou Oriented-object Programming (OOP), e fiz meu primeiro sistema com ela, um sistema de Potions.
Script (potions.lua):
local Potion = { type = "", healmin = 0, healmax = 0, vocations = {}, emptyid = 0, } function Potion:new(type, healmin, healmax, vocations, emptyid, uid) local potions = { type = type, healmin = tonumber(healmin), healmax = tonumber(healmax), vocations = vocations, emptyid = tonumber(emptyid), uid = 0, } return setmetatable(potions, {__index = self}) end function Potion:heal(cid) if self.vocations ~= "all" and not isInArray(self.vocations, getPlayerVocation(cid)) then doPlayerSendCancel(cid, "This vocation cannot use this potion.") return true elseif self.type == "health" then doCreatureAddHealth(cid, math.random(self.healmin, self.healmax)) elseif self.type == "mana" then doPlayerAddMana(cid, math.random(self.healmin, self.healmax)) end doCreatureSay(cid, "Aaaah...", TALKTYPE_MONSTER) doTransformItem(self.uid, self.emptyid) doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE) return true end Pots = { [8704] = Potion:new("health", 50, 100, "all", 7636), [7618] = Potion:new("health", 100, 200, "all", 7636), [7588] = Potion:new("health", 200, 400, {3, 4, 7, 8}, 7634), [7591] = Potion:new("health", 600, 800, {4, 8}, 7635), [8473] = Potion:new("health", 900, 1200, {4, 8}, 7635), [7620] = Potion:new("mana", 90, 150, "all", 7636), [7589] = Potion:new("mana", 190, 250, {1, 2, 5, 6}, 7634), [7590] = Potion:new("mana", 300, 400, {1, 2, 5, 6}, 7635), } function onUse(cid, item, position, itemEx) local Potions = Pots[item.itemid] Potions.uid = item.uid Potions:heal(itemEx.uid) return true endTag (actions.xml):
Configurando:
Para configurar, edite aqui:
Pots = { [8704] = Potion:new("health", 50, 100, "all", 7636), [7618] = Potion:new("health", 100, 200, "all", 7636), [7588] = Potion:new("health", 200, 400, {3, 4, 7, 8}, 7634), [7591] = Potion:new("health", 600, 800, {4, 8}, 7635), [8473] = Potion:new("health", 900, 1200, {4, 8}, 7635), [7620] = Potion:new("mana", 90, 150, "all", 7636), [7589] = Potion:new("mana", 190, 250, {1, 2, 5, 6}, 7634), [7590] = Potion:new("mana", 300, 400, {1, 2, 5, 6}, 7635), }Traduzindo:
[item_id] = Potion:new("tipo de cura", minimo, máximo, {vocações que podem usar}, empty flask),Créditos: