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

TalkAction Advanced !Buyitem Version 3.0

Master-m

Need help? Just ask!
Senator
Joined
May 28, 2007
Messages
4,338
Reaction score
16
Location
The Netherlands
This is version 3.0.

It supports buying backpacks with items now.

Usage:
!buyitem to view a list of items that you can buy.
!buyitem itemnamehere to buy the item.

First open up Talkactions.xml.
(It is located in ../Data/talkactions/)

Put the following line under your other lines but before </talkactions>
Code:
<talkaction words="!buyitem" script="CreateItem.lua" />

Now go to the folder called scripts and create a new .lua file.
Call the new .lua file CreateItem.lua and paste this in it:

CreateItem.lua
Code:
--[[
						Some info
					---------------------------------

		This script is created by Master-M, this script is only posted on otland.net .
		More scripts, programs or other tools can be found on http://otland.net/f173/.
		I commented most of the lines to help you a bit of understanding lua.


				A little explanation of the configuration	
		--------------------------------------------------------------------------------
		
		I take the first line of the configuration
		['Backpack'] = { id = 3940, amount = 1, stackable = 0, costmoney = 1,  bpwithitems = 0, countinbp = 20, bpid = 3940, cost = 10, itemcost = 2472, itemamountcost = 1  } 
		['Backpack']  - The name of the item that will be show in the list when saying the correct word(s). Here is that 'Backpack'.
		amount = 1 - This is the amount of the items you want to get.
		id = 3940 - This is the id of the item that will be given. Here we use '3940' thats a backpack.
		stackable = 0, - Set this to 1 for stackable and 0 if it isn't stackable. An example is 'Meat' that is stackable so its 1.
		costmoney = 1 - Set this to 1 if you want it to cost money, else set it to 0 to trade it for another item or multiple items.
		bpwithitems = 0 - Set this to 1 if you want an item or multiple items being sold in a backpack. When you use this function you should put 'id' to the itemid that you want inside the backpack. Also amount is the charges by runes then.
		countinbp = 20 - How much items you want to get in the backpack.
		bpid = 3940 - The id of the backpack that you want to use.
		cost = 10 - How much money it costs(This is only when 'costmoney = 1').
		itemcost = 2472 - The id of the item that you need to pay for it(This is only when 'costmoney = 0').
		itemamountcost = 1 - How much of the items you need to pay(This is also only needed when you use trade for item so 'costmoney = 0').


--]]

-- Starting the function --
function onSay ( cid, words, param )
	
	--Start configuration --

	-- Items you can buy --
	items = 
	{
	
	 ['Backpack'] = { id = 3940, amount = 1, stackable = 0, costmoney = 1,  bpwithitems = 0, countinbp = 20, bpid = 3940, cost = 10, itemcost = 2472, itemamountcost = 1  } ,
	 ['Amulet of Loss'] = { id = 2173, amount = 1, stackable = 0,  bpwithitems = 0, countinbp = 20, bpid = 3940,costmoney = 1, cost = 10000, itemcost = 2472, itemamountcost = 1 },
	 ['Drunkness Rune'] = { id = 2267, amount = 100, stackable = 1, bpwithitems = 0, countinbp = 20, bpid = 3940, costmoney = 1, cost = 1000, itemcost = 2472, itemamountcost = 1 },
	 ['Meat'] = { id = 2666, amount = 100, stackable = 1, costmoney = 1, bpwithitems = 0, countinbp = 20, bpid = 3940, cost = 100, itemcost = 2472, itemamountcost = 1 },
	 ['Elven Legs'] = { id = 2507, amount = 2, stackable = 0, costmoney = 0, bpwithitems = 0, countinbp = 20, bpid = 3940, cost = 10000, itemcost = 2471, itemamountcost = 3 },
	 ['Bp Drunkness'] = { id = 2267, amount = 13, stackable = 0, costmoney = 1, bpwithitems = 1, countinbp = 20, bpid = 3940, cost = 30000, itemcost = 0, itemamountcost = 0 }

	}
	
-- End configuration --	

	-- Gets the itemname --
	local item = items[param]
		
		-- Checks if we can use that itemname --
		if item then
		
			-- Checks if it should cost money --
			if item.costmoney == 1 then
	
				-- Checks if the player has enough money --
				if doPlayerRemoveMoney ( cid, item.cost ) == 1 then
		
					-- Checks if its going to use a bp with items--
					if item.bpwithitems == 1 then
											
						-- Sends the player a message wich includes what he has bought and how much it cost --
						doPlayerSendTextMessage ( cid, 24, 'You have bought a backpack with '..getItemNameById(item.id)..' for '..item.cost..' golden pieces.' )
							
						-- Gives the player the items --
						local bp = doPlayerAddItem ( cid, item.bpid, 1 )
								
						-- starting a function so it gives enough items and not just 1 --
						for i = 1,item.countinbp do								
							doAddContainerItem( bp, item.id, item.amount )
								
						-- ends the for function --
						end
						
					-- what to do if it isn't going to use a bp with items--
					else
						
						-- Checks if the item is stackable --
						if item.stackable == 0 then
							
							-- Checks if the amount is 1 --
							if item.amount == 1 then
						
								-- Sends the player a message wich includes what he has bought and how much it cost --
								doPlayerSendTextMessage ( cid, 24, 'You have bought '..item.amount..' '..param..' for '..item.cost..' golden pieces.' )
							
								-- Gives the player the item --
								doPlayerAddItem ( cid, item.id, 1 )
						
							-- What to do if the amount is higher then 1 --
							else
							
								-- starting a function so it gives enough items and not just 1 --
								for i = 1,item.amount do
					
								-- Gives the player the item --
								doPlayerAddItem ( cid, item.id, 1 )
					
								-- ends the for function --
								end
					
								-- Sends the player a message wich includes what he has bought and how much it cost --
								doPlayerSendTextMessage ( cid, 24, 'You have bought '..item.amount..' '..param..' for '..item.cost..' golden pieces.' )		
						
							-- Ends the amount check -
							end
					
						elseif item.stackable == 1 then

							-- Sends the player a message wich includes what he has bought and how much it cost --
							doPlayerSendTextMessage ( cid, 24, 'You have bought '..item.amount..' '..param..' for '..item.cost..' golden pieces.' )
					
							-- Gives the player the item --
							doPlayerAddItem ( cid, item.id, item.amount )
						
						-- Ends the stackable check --	
						end
						
					-- ends the bp with items check --
					end
					
				-- What to do when the player doesn't have enough money --	
				else
		
					-- Gives the player a message that he doesn't have enough money --
					doPlayerSendCancel ( cid, 'You need at least '..item.cost..' golden coins to buy this item.' )
			
					-- Shows an effect on the player --
					doSendMagicEffect ( getPlayerPosition ( cid ), CONST_ME_POFF )
			
				-- Ends the money check --	
				end
		
			-- Checks if it should cost money --
			elseif item.costmoney == 0 then
			
				-- Checks if the player has enough amount of the correct item --
				if doPlayerRemoveItem ( cid, item.itemcost, item.itemamountcost ) == 1 then
		
					-- Checks if its going to use a bp with items--
					if item.bpwithitems == 1 then
											
						-- Sends the player a message wich includes what he has bought and how much it cost --
						doPlayerSendTextMessage ( cid, 24, 'You have bought a backpack with '..getItemNameById(item.id)..' for '..item.itemamountcost..'x a '..itemname..'.' )
							
						-- Gives the player the items --
						local bp = doPlayerAddItem ( cid, item.bpid, 1 )
								
						-- starting a function so it gives enough items and not just 1 --
						for i = 1,item.countinbp do								
							doAddContainerItem( bp, item.id, item.amount )
								
						-- ends the for function --
						end
						
					-- what to do if it isn't going to use a bp with items--
					else
						
						-- Checks if the item is stackable --
						if item.stackable == 0 then
							
							-- Checks if the amount is 1 --
							if item.amount == 1 then
						
								-- Sends the player a message wich includes what he has bought and how much it cost --
								doPlayerSendTextMessage ( cid, 24, 'You have bought '..item.amount..' '..param..' for '..item.itemamountcost..'x a '..itemname..'.' )
							
								-- Gives the player the item --
								doPlayerAddItem ( cid, item.id, 1 )
						
							-- What to do if the amount is higher then 1 --
							else
							
								-- starting a function so it gives enough items and not just 1 --
								for i = 1,item.amount do
					
								-- Gives the player the item --
								doPlayerAddItem ( cid, item.id, 1 )
					
								-- ends the for function --
								end
					
								-- Sends the player a message wich includes what he has bought and how much it cost --
								doPlayerSendTextMessage ( cid, 24, 'You have bought '..item.amount..' '..param..' for '..item.itemamountcost..'x a '..itemname..'.' )		
						
							-- Ends the amount check -
							end
							
						elseif item.stackable == 1 then

							-- Gets the name of the item --
							itemname = getItemName(item.itemcost)
				
							-- Sends the player a message wich includes what he has bought and how much it cost --
							doPlayerSendTextMessage ( cid, 24, 'You have bought '..item.amount..' '..param..' for '..item.itemamountcost..'x a '..itemname..'.' )
					
							-- Gives the player the item --
							doPlayerAddItem ( cid, item.id, item.amount )
						
						-- Ends the stackable check --	
						end
			
					--ends the bp with items check --
					end
				
				-- What to do when the player doesn't have the amount of the item --	
				else
		
					-- Gets the name of the item --
					itemname = getItemNameById ( item.itemcost )
					
					-- Gives the player a message that he doesn't have the amount of the item --
					doPlayerSendCancel ( cid, 'You need at least '..item.itemamountcost..'x a '..itemname..' to get this item.' )
			
					-- Shows an effect on the player --
					doSendMagicEffect ( getPlayerPosition ( cid ), CONST_ME_POFF )
			
				-- Ends the item check --	
				end	
				
			-- Ends the moneycheck --
			end
			
		else	
			
			-- Sends the player a message wich includes items he can buy --
			doPlayerSendTextMessage ( cid, 24, 'You can buy the following items:' )
			
			-- Getting the all itemnames --
			for item1 in pairs (items) do
								
				-- Sends a message with each itemname and price --
				doPlayerSendTextMessage ( cid, 24, item1 )
				
			-- Ends the for function--
			end
			
		-- ends the itemname check --
		end
		
-- Ends the functions --	
end

Post bugs/suggestions here and I hope you like it or even learn something from it:D:p

Todo:
Make a dialog show a list of items and what it costs.

old version can be found here:
http://otland.net/f81/advanced-buyitem-version-2-5-a-8547/
 
Last edited:
You dont need costmoney and bpwithitems variables.
Just -> if cost ~= 0 then remove da monays, same with bpwithitems, if countinbp ~= 0 then add iteasnz.
 
Advanced buycontainer system though an talkaction, that looks rather awesome! :eek:

:p
 
You dont need costmoney and bpwithitems variables.
Just -> if cost ~= 0 then remove da monays, same with bpwithitems, if countinbp ~= 0 then add iteasnz.


ooh. You are right xD But I just updated my old one didn't looked for other things:p Thanks for putting it out. When I've some time again I will maybe rewrite it all from scratch, its a bit messy now:p
 
kk my brain started thinking and as always i came up with a good idea for ur script.. make a dialog with all offers/prices ;)
 
kk my brain started thinking and as always i came up with a good idea for ur script.. make a dialog with all offers/prices ;)

Try adding it above second end counting from the bottom of the file:
Code:
	elseif param == "list" or param == "offer" then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can buy the following items:")
		for item, variable in pairs(items) do
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, item.." ["..variable[8].." gp].")
		end
 
Try adding it above second end counting from the bottom of the file:
Code:
	elseif param == "list" or param == "offer" then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can buy the following items:")
		for item, variable in pairs(items) do
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, item.." ["..variable[8].." gp].")
		end

need to use doPlayerSendTextDialog and use \n etc else its gonna suck bigtime shit
 
Your attempt to be funny has failed.
Code:
	elseif param == "list" or param == "offer" then
		local text = "You can buy the following items:\n")
		for item, variable in pairs(items) do
			text = text..""..item.." ["..variable[8].." gp]\n")
		end
		doShowTextDialog(cid, text, 1967)
 
Oh by the way, is this only supported in 0.3? Or can 0.2 enjoy this script as well? :D
 
It doesn't work?

It just makes effect and nothing appears.. it take smoney but I don't get the item?
 
Back
Top