• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Another Potions Script.

Jano

oturhaN
Joined
Feb 21, 2008
Messages
876
Solutions
1
Reaction score
68
Location
Chile
I was playing with Lua and this what i ve done.

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
potions.lua

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:
Code:
local potions = {
	[8377] = {minH=800,maxH=1000,minM=0,maxM=0,trans=7635,lvl=130,voc={4,8}},
	[7591] = {minH=500,maxH=700,minM=0,maxM=0,trans=7635,lvl=80,voc={4,8}},
	[7588] = {minH=200,maxH=400,minM=0,maxM=0,trans=7634,lvl=50,voc={3,4,7,8}},
	[7618] = {minH=400,maxH=200,minM=0,maxM=0,trans=7636,lvl=8,voc={1,2,3,4,5,6,7,8}},
	[7590] = {minH=0,maxH=0,minM=200,maxM=300,trans=7635,lvl=80,voc={1,2,5,6}},
	[7589] = {minH=0,maxH=0,minM=110,maxM=190,trans=7634,lvl=50,voc={1,2,3,5,6,7}},
	[7620] = {minH=0,maxH=0,minM=70,maxM=130,trans=7636,lvl=8,voc={1,2,3,4,5,6,7,8}},
	[8376] = {minH=200,maxH=400,minM=110,maxM=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 potion = potions[item.itemid]
	if(isInArray(potion.voc, getPlayerVocation(cid)) == TRUE and getPlayerLevel(cid) >= potion.lvl or getPlayerAccess(cid) ~= 0) then
		if(doTargetCombatHealth(0, cid, COMBAT_HEALING, potion.minH, potion.maxH, CONST_ME_MAGIC_BLUE) == LUA_ERROR or doTargetCombatMana(0, cid, potion.minM, potion.maxM, CONST_ME_MAGIC_BLUE) == LUA_ERROR) then
			return FALSE
		end
		doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
		doTransformItem(item.uid, potion.trans)
	else
		doCreatureSay(cid, "This potion can only be consumed by " .. getVocationName(potion.voc) .. " of level " .. potion.lvl .. " or higher.", TALKTYPE_ORANGE_1)
	end
return TRUE
end
Bit shortened ;)
 
Last edited:
hehe nice way, i was thinking in any way to make it more short :p
 
nice script gonna test it on TFS.
 
Last edited:
@Elf

Change

Code:
[7618] = {minH=400,maxH=200,minM=0,maxM=0,trans=7636,lvl=8,voc={1,2,3,4,5,6,7,8}},
to

Code:
[7618] = {minH=100,maxH=200,minM=0,maxM=0,trans=7636,lvl=8,voc={1,2,3,4,5,6,7,8}},
i dint noticed it, you either :p
 
As Elf did won't work. You are passing nil-values to the function.
 
i did all this and i even made a new file in the scipts file for potions.lua and i put in that code....nothing is working please help!!!
 
Back
Top