I was playing with Lua and this what i ve done.
add this function in your global.lua
potions.lua
add this function in your global.lua
PHP:
function getVocationsName(array)
if #array == 2 then
if isInArray(array, 4) == TRUE then
return "knights"
elseif isInArray(array, 3) == TRUE then
return "paladins"
end
elseif #array == 4 then
if isInArray(array, 1) == TRUE then
return "sorcerers and druids"
elseif isInArray(array, 3) == TRUE then
return "knights and paladins"
end
elseif #array == 6 then
return "sorcerers, druids and paladins"
elseif #array == 8 then
return "players with vocation"
end
end
PHP:
local HealthPotions = {
[8377] = {min=800,max=1000,trans=7635,lvl=130,voc={4,8}},
[7591] = {min=500,max=700,trans=7635,lvl=80,voc={4,8}},
[7588] = {min=200,max=400,trans=7634,lvl=50,voc={3,4,7,8}},
[7618] = {min=100,max=200,trans=7636,lvl=8,voc={1,2,3,4,5,6,7,8}}
}
local ManaPotions = {
[7590] = {min=200,max=300,trans=7635,lvl=80,voc={1,2,5,6}},
[7589] = {min=110,max=190,trans=7634,lvl=50,voc={1,2,3,5,6,7}},
[7620] = {min=70,max=130,trans=7636,lvl=8,voc={1,2,3,4,5,6,7,8}}
}
local BothPotions = {
[8376] = {hmin=200,hmax=400,mmin=110,mmax=190,trans=7635,lvl=80,voc={3,7}},
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if itemEx.uid ~= cid or itemEx.itemid ~= 1 then
return TRUE
end
local HealthP = HealthPotions[item.itemid]
local ManaP = ManaPotions[item.itemid]
local BothP = BothPotions[item.itemid]
if HealthP then
if isInArray(HealthP.voc, getPlayerVocation(cid)) == TRUE and getPlayerLevel(cid) >= HealthP.lvl or getPlayerGroupId(cid) >= 2 then
if(doTargetCombatHealth(0, cid, COMBAT_HEALING, HealthP.min, HealthP.max, CONST_ME_MAGIC_BLUE) == LUA_ERROR) then
return FALSE
end
doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
doTransformItem(item.uid, HealthP.trans)
else
doCreatureSay(cid, "This potion can only be consumed by " .. getVocationsName(HealthP.voc) .. " of level " .. HealthP.lvl .. " or higher.", TALKTYPE_ORANGE_1)
end
elseif ManaP then
if isInArray(ManaP.voc, getPlayerVocation(cid)) == TRUE and getPlayerLevel(cid) >= ManaP.lvl or getPlayerGroupId(cid) >= 2 then
if(doTargetCombatMana(0, cid, ManaP.min, ManaP.max, CONST_ME_MAGIC_BLUE) == LUA_ERROR) then
return FALSE
end
doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
doTransformItem(item.uid, ManaP.trans)
else
doCreatureSay(cid, "This potion can only be consumed by " .. getVocationsName(ManaP.voc) .. " of level " .. ManaP.lvl .. " or higher.", TALKTYPE_ORANGE_1)
end
elseif BothP then
if isInArray(BothP.voc, getPlayerVocation(cid)) == TRUE and getPlayerLevel(cid) >= BothP.lvl or getPlayerGroupId(cid) >= 2 then
if(doTargetCombatHealth(0, cid, COMBAT_HEALING, BothP.hmin, BothP.hmax, CONST_ME_MAGIC_BLUE) == LUA_ERROR or doTargetCombatMana(0, cid, BothP.mmin, BothP.max, CONST_ME_MAGIC_BLUE) == LUA_ERROR) then
return FALSE
end
doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
doTransformItem(item.uid, BothP.trans)
else
doCreatureSay(cid, "This potion can only be consumed by " .. getVocationsName(BothP.voc) .. " of level " .. BothP.lvl .. " or higher.", TALKTYPE_ORANGE_1)
end
end
return TRUE
end
Last edited: