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

Ldrozd

Piszę skrypty w zeszycie.
Joined
Dec 13, 2008
Messages
430
Reaction score
2
Location
Guess where!
Hello guys,
I would like to present you my new script. It is my first release here. Before I didnt want to paste here basic script so I improved myself and wrote this one.

It lets you to buy backpack of potions. Just use the lever.

Lua:
  -- Written by Ldrozd with Tairen's advice; do not delete it, you arent the creator
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local potion = {
        [1000] = {id = 7620, bp = 2001, cost = 10000, anim = 30},
        [1001] = {id = 7589, bp = 2001, cost = 16000, anim = 30},
        [1002] = {id = 7590, bp = 2001, cost = 24000, anim = 30},
        [1003] = {id = 7618, bp = 1988, cost = 9200, anim = 29},
        [1004] = {id = 7588, bp = 1988, cost = 20000, anim = 29},
        [1005] = {id = 7591, bp = 1988, cost = 38000, anim = 29},
        [1006] = {id = 8473, bp = 1988, cost = 62000, anim = 29},
        [1007] = {id = 8472, bp = 1999, cost = 38000, anim = 28}
    }
       
                local actuallPotion = potion[item.actionid]
        local weight = getItemWeightById(actuallPotion.id, 20) + getItemWeightById(actuallPotion.bp, 1)                    
        if(getPlayerFreeCap(cid) >= weight) then
            if getPlayerMoney(cid) >= actuallPotion.cost then
                local bp = doCreateItemEx(cid, actuallPotion.bp, 1)
                doAddContainerItem(bp, actuallPotion.id, 20)
                    if(doPlayerAddItemEx(cid, bp) ~= RETURNVALUE_NOERROR) then
                        doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need more space in your container.")
                    else
                        doPlayerRemoveMoney(cid, actuallPotion.cost)
                        doSendMagicEffect(toPosition, actuallPotion.anim)
                        doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You have bought backpack of "..getItemNameById(actuallPotion.id).."s for "..actuallPotion.cost.." gold coins.")
                    end
            else
                doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need "..actuallPotion.cost.." gold coins to buy these potions.")
            end
        else
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need at least "..math.ceil(weight).." oz to buy this item.")
        end
           
            if item.itemid == 1945 then
                doTransformItem(item.uid, item.itemid+1)
            elseif item.itemid == 1946 then
                doTransformItem(item.uid, item.itemid-1)
            else
                return true
            end                    
return true
end

Maybe one picture to show you how it works. Not really needed but here is it:

2wevzw1.png
 
Last edited:
firstly, it is rather created for runes
secondly, when player hasnt got place in bp, backpack will be dropped(that doesnt happen in my script)
thirdly, mine has anim which make my script nice for eye :D

Dont you agree with me? :$
 
Yep, thanks for your release! :D
 
Ah, yeh, I didn't mean to offend you/your script.

I was just curious why you actually released it "again" in "another thread".

You could also contact the person (in the link mentioned above) and tell
him to update his script with your functions :eek:

This way everyone would get a fully advanced and nice script.

But that's just my oppinion, keep releasing though :thumbup:
 
I made this script from all over. So, it is not the same script. Telling my ideas to Sherlok wouldnt be just giving advices him.

Anyway thanks for comments guys. :) Also, any advices about my script are welcome.
 
1.
Code:
getItemNameById
instead of name in table.
2. What if I don't want to use bp, cost or anim? Script won't work.

Here's updated version of your script. Only potion id is necessary and script will work. In addition you can add effect or cost. Backpack can be also ignored in table so it will be default.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local potionTable = {
		[1000] = {id = 7620, bp = 2001, cost = 10000}, 
		[1001] = {id = 7589, bp = 2001, cost = 16000, anim = 30},
		[1002] = {id = 7590, bp = 2001, cost = 24000, anim = 30},
		[1003] = {id = 7618},
		[1004] = {id = 7588, cost = 20000, anim = 29},
		[1005] = {id = 7591, cost = 38000},
		[1006] = {id = 8473, cost = 62000, anim = 29},
		[1007] = {id = 8472, bp = 1999, cost = 38000, anim = 28}
	}
		
	local potion, backpack, cost, animation = potion[item.uid], 1988, 0, false
	if not potion or not potion.id then
		return true
	end
	
	if potion.bp then
		backpack = potion.bp
	elseif potion.cost then
		cost = potion.cost
	elseif potion.anim then
		animation = potion.anim
	end
	
	local weight = getItemWeightById(potion.id, 20) + getItemWeightById(backpack, 1)					
	if(getPlayerFreeCap(cid) < weight) then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need at least " .. math.ceil(weight) .. " oz to buy this item.")
		return true
	end
	
	if doPlayerRemoveMoney(cid, cost) or cost == 0 then
		local bp = doCreateItemEx(cid, backpack, 1)
		doAddContainerItem(bp, potion.id, 20)
		if(doPlayerAddItemEx(cid, bp) ~= RETURNVALUE_NOERROR) then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need more space in your container.")
		else
			if animation then
				doSendMagicEffect(toPosition, potion.anim)
			end
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought backpack of " .. getItemNameById(potion.id) .. "s for " .. cost .. " gold coins.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need " .. cost .. " gold coins to buy this item.")
	end

	if item.itemid == 1945 then
		doTransformItem(item.uid, 1946)
	elseif item.itemid == 1946 then
		doTransformItem(item.uid, 1945)
	end					 
	return true
end
 
K guys that's a rlly simple script...Anyways good release for noobs scripters...:p
@Cykotitan
just change/add bp Id, it's cost item u wanna add...simple! :wub:
 
I have updated script. Text was deleted and I used getItemById. Table is shorter now. Aswell I changed uniqueid into actionid to let you make more the same levers.

Also it is possible to add runes but you must remember that there will be always sold runes with 20 charges

Comments plx :p
 
Use logical operators
Code:
	if item.itemid == 1945 then
		doTransformItem(item.uid, item.itemid+1)
	elseif item.itemid == 1946 then
		doTransformItem(item.uid, item.itemid-1)
	else
		return true
	end
This should be enough:
Code:
	doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)

Also you should put static values like table potions outside (before) the function.

Other than that, nice script!
 
But when I use 'if' I'm sure that it will work. There is no need to make it shorter in this case. :)
 
Code:
<action actionid="1000-1007" event="script" value="script.lua"/>
 
Back
Top