• 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!

Action Buying backpack of potions by a lever, best script :D

Hermes

dziwki kola gramy w lola
Joined
Nov 17, 2007
Messages
1,867
Reaction score
14
Location
Poland
Hi there!

I know that there are many released scripts for this action, but I noticed that every sucks, because when player does not have money he receives empty backpack.

I have modified it a bit (took me 5 seconds lmao) and I have decided to release it, someone might need it xd:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local container = 0
	local cost = 6200
	local potion_id = 8473
	local backpack_id = 2000
	if(item.itemid == 1945) then
		if(doPlayerRemoveMoney(cid, cost) == TRUE) then
			doTransformItem(item.uid, item.itemid+1)
			container = doPlayerAddItem(cid, backpack_id, 1)
			for i = 1, 20 do
				doAddContainerItem(container, potion_id)
			end
		else
			doPlayerSendCancel(cid,"Sorry, you don't have enough money.")
		end
	elseif(item.itemid == 1946) then
		doTransformItem(item.uid, item.itemid-1)
	end
return TRUE
end

also you can use more advanced version aswell (thanks to josejunior23):
Code:
local config = {
	--[actionid] = {backpack_id = ID OF BACKPACK, potion_id = ID OF POTION, cost = COST OF BP WITH POTIONS
	[1522] = {backpack_id = 2000, potion_id = 8473, cost = 6000}, -- example with ultimate health potion
	[1517] = {backpack_id = 2001, potion_id = 7590, cost = 4000} -- example with great mana potion
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local container = 0
	if(item.itemid == 1945) then    
		if(doPlayerRemoveMoney(cid, CONFIG[item.actionid].cost) == TRUE) then
			doTransformItem(item.uid, item.itemid+1)
			container = doPlayerAddItem(cid, CONFIG[item.actionid].backpack_id, 1)
			for i = 1, 20 do
				doAddContainerItem(container, CONFIG[item.actionid].potion_id)
			end
		else
			doPlayerSendCancel(cid, "Sorry, you don't have enough money.")
		end
	elseif(item.itemid == 1946) then
		doTransformItem(item.uid, item.itemid-1)
	end
	return TRUE
end

It's working for me like a charm ;>

Regards,
Hermes

@updated, 22.04, bugfix
 
Last edited:
Lua:
local CONFIG = {
    [1522]={backpack_id = 2000, potion_id = 8473, cost = 6000}, -- ultimate health pot
    [1517]={backpack_id = 2001, potion_id = 7590, cost = 6000} -- great mana potion
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local container = 0
 	if item.itemid == 1945 then	
		if doPlayerRemoveMoney(cid, CONFIG[item.actionid].cost) == 1 then
		doTransformItem(item.uid, item.itemid+1)
		container = doPlayerAddItem(cid, CONFIG[item.actionid].backpack_id, 1)
		for i = 1, 20 do
				doAddContainerItem(container, CONFIG[item.actionid].potion_id)
         end
       else
			doPlayerSendCancel(cid,"Sorry, you don't have enough money.")
		end
	elseif item.itemid == 1946 then
		doTransformItem(item.uid, item.itemid-1)
	end
return TRUE
end


based on yours xD
 
Last edited:
PHP:
-- by Keraxel // for otland.net.pl
local config = {
effect = 39,
aolPrice = 4000
}
local prices = {
--[runeId] = {cost, charges, backpackColor, count},
--POTIONS--
[7618] = {800, 1, "red", 1}, --health potion
[7620] = {900, 1, "purple", 1}, --mana potion
[7588] = {1800, 1, "red", 1}, --strong health potion
[7589] = {1500, 1, "purple", 1}, --strong mana potion
[7591] = {3500, 1, "red", 1}, --great health potion
[7590] = {2200, 1, "purple", 1}, --great mana potion
[8472] = {3500, 1, "yellow", 1}, --great spirit potion
[8473] = {5800, 1, "red", 1}, --ultimate health potion
--RUNES--
[2273] = {3300, 1, "blue", 1}, --UH
[2268] = {6600, 3, "grey", 1}, --SD
[2313] = {4700, 6, "purple", 1}, --explosion
[2287] = {600, 10, "green", 1}, --light magic missile
[2311] = {2200, 10, "purple", 1}, --heavy magic missile
[2304] = {3400, 4, "red", 1}, --great fireball
[2302] = {1800, 5, "red", 1}, --fireball
[2265] = {1800, 1, "grey", 1}, --IH
[2261] = {800, 3, "grey", 1}, --destroy field
[2316] = {7300, 1, "purple", 1}, --animate dead
[2262] = {6500, 2, "grey", 1}, --energy bomb
[2277] = {2200, 3, "blue", 1}, --energy field
[2315] = {2800, 4, "purple", 1}, --thunderstorm
[2274] = {3400, 4, "blue", 1}, --avalanche
[2271] = {2900, 5, "blue", 1}, --icile
[2308] = {4000, 3, "red", 1}, --soulfire
[2285] = {1200, 3, "green", 1}, --poison field
[2286] = {3200, 2, "green", 1}, --poison bomb
[2289] = {4000, 4, "green", 1}, --poison wall
[2290] = {1500, 1, "green", 1}, --convince creature
[2291] = {4000, 1, "green", 1}, --chameleon
[2292] = {2200, 10, "green", 1}, --stalagmite
[2288] = {2800, 4, "green", 1}, --stone shower
[2301] = {1600, 3, "red", 1}, --fire field
[2305] = {4400, 2, "red", 1}, --firebomb
[2303] = {4600, 4, "red", 1} --fire wall
}
-----
function onUse(cid, item, fromPosition, itemEx, toPosition)

local function backpackIdByName(name)
local backpacksId = {["green"]=1998, ["yellow"]=1999, ["red"]=2000, ["purple"]=2001, ["blue"]=2002, ["grey"]=2003, ["golden"]=2004}
	return backpacksId[name] or LUA_ERROR

end

local aid = item.actionid - 10000

	if aid == 2173 then
		if (doPlayerBuyItem(cid, 2173, 1, config.aolPrice, 1)) ~= LUA_ERROR then
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You've bought an amulet of loss.")
			doSendMagicEffect(getCreaturePosition(cid), config.effect)
		else
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You don't have enough money. The price is "..config.aolPrice.." gold pieces.")
		end

	else

				if (doPlayerBuyItemContainer(cid, backpackIdByName(prices[aid][3]), aid, 1, prices[aid][1], prices[aid][2])) == LUA_NO_ERROR then
					doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You've bought a backpack of "..getItemNameById(aid)..".")
					doSendMagicEffect(getCreaturePosition(cid), config.effect)
				else
					doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You don't have enough money. The price is "..prices[aid][1].." gold pieces.")
				end
	end
	return TRUE
end
pwnd? :d

##
hum?

you did not make it now d:
already see it some days ago...


i didnt take 30 sec to edit his script, don't cry ):
;(;(
 
Last edited:
hermes, i clicked the link and enter my name, and when i went out of my home morning, i didnt find any rectangles in the world

THIEFFFFFFF xD
 
@Keraxel&Jose
die plx :/ my one is simple and it's more evul than yours!!111oneone?

so newbies can better understand loop usage ;>
 
i need a script for when you pull a lever you get a lottery ticket and it costs 20k cuz im using rl tibia addon system
 
Lua:
local config = {cost = 20000, itemid = id of lottery ticket}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1945 and doPlayerRemoveMoney(cid, config.cost) == 1 then
			doPlayerAddItem(cid, config.itemid)
		else
			doPlayerSendCancel(cid,"Sorry, you don't have enough money.")
		end
	elseif item.itemid == 1946 then
		doTransformItem(item.uid, item.itemid-1)
	end
return TRUE
end
 
Last edited:
it wont work with tfs 0.3.4 maybe? :S
Anyone can tell me how to make it work with tfs 0.3.4v? :S
 
Sec. I will make it work with 0.3.4pl2 in a minute..

@edit
Okay, it's working now with TFS 0.3.4+
 
Khehehhe, i post my version tuu.
Code:
local items =
{
    [44401] = {6500, 5926, 2268, 3},
    --[actionid] = {cost, backpack_id, rune_or_potion_id, count}
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(item.itemid == 1946) then
        doTransformItem(item.uid, 1945)
        return true
    end
    if(item.itemid ~= 1945) then
        return false
    end
    local item = items[item.actionid]
    if(not item) then
        return false
    end
    if(getPlayerMoney(cid) < item[1]) then
        doPlayerSendCancel(cid, 'Sorry, you don\'t have enough money.')
        return true
    end
    local backpack = doCreateItemEx(item[2], 1)
    for i = 1, getContainerCapById(item[2]) do
        doAddContainerItem(backpack, item[3], item[4])
    end
    if(doPlayerAddItemEx(cid, backpack) ~= RETURNVALUE_NOERROR) then
        doPlayerSendCancel(cid, 'Sorry, you don\'t have enough cap.')
        return true
    else
        doPlayerRemoveMoney(cid, item[1])
        doPlayerSendTextMessage(cid, 'You succesfully bought a '.. getItemNameById(item[3]) ..' for '.. item[1] ..' gold coins.')
    end
    doTransformItem(item.uid, 1946)
    return true
end
 
Last edited:
What should I write in Actions.xml.?
I am using TFS 0.2.1 Mystic Spirit...
Thanks.
 
Back
Top