#Edit, resolvido.
Potion System

tente esse
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, 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) doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE) return true end Pots = { [8704] = Potion:new("health", 50, 100, "all", 8704), [7618] = Potion:new("health", 100, 200, "all", 7618), [7588] = Potion:new("health", 200, 400, {3, 4, 7, 8}, 7588), [7591] = Potion:new("health", 600, 800, {4, 8}, 7591), [8473] = Potion:new("health", 900, 1200, {4, 8}, 8473), [8472] = Potion:new("health", 900, 950, {3, 7}, 8472), [7620] = Potion:new("mana", 90, 150, "all", 7620), [7589] = Potion:new("mana", 190, 250, {1, 2, 5, 6}, 7589), [7590] = Potion:new("mana", 300, 400, {1, 2, 5, 6}, 7590), } function onUse(cid, item, position, itemEx) if not isPlayer(itemEx.uid) then doPlayerSendCancel(cid, "Use only in players.") return true end local Potions = Pots[item.itemid] Potions.uid = item.uid Potions:heal(itemEx.uid) return true end
Scripter em Treinamento
Codigos
Simples Pet Sistema < New
Assim que possivel mais codigos, com criatividade.
Ainda não, eu quero que ele gaste, porém que não fique o empty, assim ainda está infinita.
use
doRemoveItem(uid, 1)
no scripter..
Scripter em Treinamento
Codigos
Simples Pet Sistema < New
Assim que possivel mais codigos, com criatividade.
Como o cara aí disse, deve funcionar assim:
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, 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) 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), [8472] = Potion:new("health", 900, 950, {3, 7}, 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) if not isPlayer(itemEx.uid) then doPlayerSendCancel(cid, "Use only in players.") return true end local Potions = Pots[item.itemid] Potions.uid = item.uid Potions:heal(itemEx.uid) doRemoveItem(item.uid, 1) return true end
Bons tempos...
[Portfólio de scripts]
Tó:
local MIN = 950 local MAX = 1050 local EMPTY_POTION = 7635 local RANGE = -1 local exhaust = createConditionObject(CONDITION_EXHAUST) setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100)) function onUse(cid, item, fromPosition, itemEx, toPosition) if isPlayer(itemEx.uid) == FALSE then return FALSE end if hasCondition(cid, CONDITION_EXHAUST_HEAL) == TRUE then doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED) return TRUE end if(RANGE > 0 and cid ~= itemEx.uid and getDistanceBetween(getThingPosition(cid), getThingPosition(itemEx.uid)) > RANGE) then return FALSE end if doPlayerAddMana(itemEx.uid, math.random(MIN, MAX)) == LUA_ERROR then return FALSE end doAddCondition(cid, exhaust) doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE) doCreatureSay(itemEx.uid, "Aaaah!!!", TALKTYPE_ORANGE_1) doRemoveItem(item.uid, 1) pot_count = getPlayerItemCount(cid, EMPTY_POTION) doPlayerRemoveItem(cid, EMPTY_POTION, pot_count) return TRUE end
#include <iostream>
cout <<"Mano, a brisa é louca o barato é dentro";
Como o cara aí disse, deve funcionar assim:
Spoiler
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,
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)
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),
[8472] = Potion:new("health", 900, 950, {3, 7}, 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)
if not isPlayer(itemEx.uid) then
doPlayerSendCancel(cid, "Use only in players.")
return true
end
local Potions = Pots[item.itemid]
Potions.uid = item.uid
Potions:heal(itemEx.uid)
doRemoveItem(item.uid, 1)
return true
end
Funcionou, porém se uma vocação tenta usar um potion de outra vocação os potions também gastam, não healam, mas ainda assim são gastos, no caso deveria apararecer uma mensagem Only vocation... e tal, e não serem gastos.
tenta aew
local config = {removeOnUse = "yes",usableOnTarget = "yes", -- can be used on target? (fe. healing friend)splashable = "no",realAnimation = "no", -- make text effect visible only for players in range 1x1healthMultiplier = 1.0,manaMultiplier = 1.0}config.removeOnUse = getBooleanFromString(config.removeOnUse)config.usableOnTarget = getBooleanFromString(config.usableOnTarget)config.splashable = getBooleanFromString(config.splashable)config.realAnimation = getBooleanFromString(config.realAnimation)local POTIONS = {[8704] = {empty = 7636, splash = 2, health = {50, 100}}, -- small health potion[7618] = {empty = 7636, splash = 2, health = {100, 200}}, -- health potion[7588] = {empty = 7634, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins"}, -- strong health potion[7591] = {empty = 7635, splash = 2, health = {500, 700}, level = 80, vocations = {4, 8}, vocStr = "knights"}, -- great health potion[8473] = {empty = 7635, splash = 2, health = {800, 1100}, level = 130, vocations = {4, 8}, vocStr = "knights"}, -- ultimate health potion[7620] = {empty = 7636, splash = 7, mana = {90, 170}}, -- mana potion[7589] = {empty = 7634, splash = 7, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion[7590] = {empty = 7635, splash = 7, mana = {500, 800}, level = 80, vocations = {1, 2, 5, 6}, vocStr = "sorcerers and druids"}, -- great mana potion[8472] = {empty = 7635, splash = 3, health = {400, 600}, mana = {230, 380}, level = 80, vocations = {3, 7}, vocStr = "paladins"} -- great spirit potion}local exhaust = createConditionObject(CONDITION_EXHAUST)setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))function onUse(cid, item, fromPosition, itemEx, toPosition)local potion = POTIONS[item.itemid]if(not potion) thenreturn falseendif(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) thenif(not config.splashable) thenreturn falseendif(toPosition.x == CONTAINER_POSITION) thentoPosition = getThingPos(item.uid)enddoDecayItem(doCreateItem(2016, potion.splash, toPosition))doTransformItem(item.uid, potion.empty)return TRUEendif(hasCondition(cid, CONDITION_EXHAUST_HEAL)) thendoPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)return TRUEendif(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) andnot getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES))thendoCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)return TRUEendlocal health = potion.healthif(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) thenreturn falseendlocal mana = potion.manaif(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier))) thenreturn falseenddoSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)if(not realAnimation) thendoCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)elsefor i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) doif(isPlayer(tid)) thendoCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)endendenddoAddCondition(cid, exhaust)if(not potion.empty or config.removeOnUse) thendoRemoveItem(item.uid, 1)return TRUEenddoRemoveItem(item.uid, 0)doPlayerAddItem(cid, potion.empty, 0)doPlayerRemoveItem(cid, potion.empty, getPlayerItemCount(cid, potion.empty))doPlayerAddItem(cid, potion.empty, getPlayerItemCount(cid, potion.empty))return TRUEend
REP+
Mesma coisa, tipo aparece a mensagem This vocation cannot use this potion mas ainda assim o potion é gasto.
Mesma coisa, tipo aparece a mensagem This vocation cannot use this potion mas ainda assim o potion é gasto.
foi mal eu eskeci de arruma um negocio kkk tenta essa dae.
eu arrumei ali em cima.
REP+
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, 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 doPlayerRemoveItem(cid, self.uid, 1) doCreatureSay(cid, "Aaaah...", TALKTYPE_MONSTER) 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), [8472] = Potion:new("health", 900, 950, {3, 7}, 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) if not isPlayer(itemEx.uid) then doPlayerSendCancel(cid, "Use only in players.") return true end local Potions = Pots[item.itemid] Potions.uid = item.uid Potions:heal(itemEx.uid) return true end
Bons tempos...
[Portfólio de scripts]
Omega eu ja postei ali em cima.
REP+
Agora está certo, porém está infinita... não gasta nenhuma.
Agora está certo, porém está infinita... não gasta nenhuma.
mano usa a minha la esta certo e esta gastando.
local config = {
removeOnUse = "yes",usableOnTarget = "yes", -- can be used on target? (fe. healing friend)splashable = "no",realAnimation = "no", -- make text effect visible only for players in range 1x1healthMultiplier = 1.0,manaMultiplier = 1.0}config.removeOnUse = getBooleanFromString(config.removeOnUse)config.usableOnTarget = getBooleanFromString(config.usableOnTarget)config.splashable = getBooleanFromString(config.splashable)config.realAnimation = getBooleanFromString(config.realAnimation)local POTIONS = {[8704] = {empty = 7636, splash = 2, health = {50, 100}}, -- small health potion[7618] = {empty = 7636, splash = 2, health = {100, 200}}, -- health potion[7588] = {empty = 7634, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins"}, -- strong health potion[7591] = {empty = 7635, splash = 2, health = {500, 700}, level = 80, vocations = {4, 8}, vocStr = "knights"}, -- great health potion[8473] = {empty = 7635, splash = 2, health = {800, 1100}, level = 130, vocations = {4, 8}, vocStr = "knights"}, -- ultimate health potion[7620] = {empty = 7636, splash = 7, mana = {90, 170}}, -- mana potion[7589] = {empty = 7634, splash = 7, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion[7590] = {empty = 7635, splash = 7, mana = {500, 800}, level = 80, vocations = {1, 2, 5, 6}, vocStr = "sorcerers and druids"}, -- great mana potion[8472] = {empty = 7635, splash = 3, health = {400, 600}, mana = {230, 380}, level = 80, vocations = {3, 7}, vocStr = "paladins"} -- great spirit potion}local exhaust = createConditionObject(CONDITION_EXHAUST)setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))function onUse(cid, item, fromPosition, itemEx, toPosition)local potion = POTIONS[item.itemid]if(not potion) thenreturn falseendif(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) thenif(not config.splashable) thenreturn falseendif(toPosition.x == CONTAINER_POSITION) thentoPosition = getThingPos(item.uid)enddoDecayItem(doCreateItem(2016, potion.splash, toPosition))doTransformItem(item.uid, potion.empty)return TRUEendif(hasCondition(cid, CONDITION_EXHAUST_HEAL)) thendoPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)return TRUEendif(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) andnot getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES))thendoCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)return TRUEendlocal health = potion.healthif(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) thenreturn falseendlocal mana = potion.manaif(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier))) thenreturn falseenddoSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)if(not realAnimation) thendoCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)elsefor i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) doif(isPlayer(tid)) thendoCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)endendenddoAddCondition(cid, exhaust)if(not potion.empty or config.removeOnUse) thendoRemoveItem(item.uid, 1)return TRUEenddoRemoveItem(item.uid, 0)doPlayerAddItem(cid, potion.empty, 0)doPlayerRemoveItem(cid, potion.empty, getPlayerItemCount(cid, potion.empty))doPlayerAddItem(cid, potion.empty, getPlayerItemCount(cid, potion.empty))return TRUEend
REP+
Usuário acima, embora seu script possa ser funcional, a base que ele forneceu é muito superior e, por favor, use spoilers para postar códigos grandes.
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, 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 false 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) 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), [8472] = Potion:new("health", 900, 950, {3, 7}, 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) if not isPlayer(itemEx.uid) then doPlayerSendCancel(cid, "Use only in players.") return true end local Potions = Pots[item.itemid] Potions.uid = item.uid if Potions:heal(itemEx.uid) then doRemoveItem(item.uid, 1) end return true end
Testa mais esse aqui se quiser manter, agora deve funcionar.
Bons tempos...
[Portfólio de scripts]