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

Master-m

Need help? Just ask!
Senator
Joined
May 28, 2007
Messages
4,338
Reaction score
16
Location
The Netherlands
Version 3.0 has been released! http://otland.net/f175/talkaction-advanced-buyitem-version-3-0-a-18479/

Updated to version 2.5!

This command let the player buy an item.


This script is based on my other script wich can be found here.
I made it much easier to edit.

Usage: !buyitem "Backpack
or !buyitem to get a list of the items :)

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:
-- Starting the function --
function onSay ( cid, words, param )
	
	--Start configuration --

	-- Items you can buy --
	items = 
	{
	
	 ['Backpack'] = { id = 3940, ammount = 1, stackable = 0, costmoney = 1, cost = 10, itemcost = 2472, itemammountcost = 1  } ,
	 ['Amulet of Loss'] = { id = 2173, ammount = 1, stackable = 0, costmoney = 1, cost = 10000, itemcost = 2472, itemammountcost = 1 },
	 ['Drunkness Rune'] = { id = 2267, ammount = 100, stackable = 1, costmoney = 1, cost = 1000, itemcost = 2472, itemammountcost = 1 },
	 ['Meat'] = { id = 2666, ammount = 100, stackable = 1, costmoney = 1, cost = 100, itemcost = 2472, itemammountcost = 1 },
	 ['Elven Legs'] = { id = 2507, ammount = 2, stackable = 0, costmoney = 0, cost = 10000, itemcost = 2471, itemammountcost = 3 }
	
	}
	
-- 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 the item is stackable --
					if item.stackable == 0 then

						-- Checks if the ammount is 1 --
						if item.ammount == 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.ammount..' '..param..' for '..item.cost..' golden pieces.' )
							
							-- Gives the player the item --
							doPlayerAddItem ( cid, item.id, 1 )
						
						-- What to do if the ammount is higher then 1 --
						else
							
							-- starting a function so it gives enough items and not just 1 --
							for i = 1,item.ammount 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.ammount..' '..param..' for '..item.cost..' golden pieces.' )		
						
						-- Ends the ammount 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.ammount..' '..param..' for '..item.cost..' golden pieces.' )
					
						-- Gives the player the item --
						doPlayerAddItem ( cid, item.id, item.ammount )
						
					-- Ends the stackable 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.itemammountcost ) == 1 then
		
					-- Checks if the item is stackable --
					if item.stackable == 0 then

						-- Checks if the ammount is 1 --
						if item.ammount == 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.ammount..' '..param..' for '..item.itemammountcost..'x a '..itemname..'.' )
							
							-- Gives the player the item --
							doPlayerAddItem ( cid, item.id, 1 )
						
						-- What to do if the ammount is higher then 1 --
						else
												
							-- starting a function so it gives enough items and not just 1 --
							for i = 1,item.ammount do
					
								-- Gives the player the item --
								doPlayerAddItem ( cid, item.id, 1 )
					
							-- ends the for function --
							end
					
							-- 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.ammount..' '..param..' for '..item.itemammountcost..'x a '..itemname..'.' )
						
						-- Ends the ammountcheck --
						end
					
					
					-- What to do when the player doesn't have the amount of the item --	
					else
		
						-- Gets the name of the item --
						itemname = getItemName(item.itemcost)
					
						-- Gives the player a message that he doesn't have the amount of the item --
						doPlayerSendCancel ( cid, 'You need at least '..item.itemammountcost..'x a '..itemname..' to get this item.' )
			
						-- Shows an effect on the player --
						doSendMagicEffect ( getPlayerPosition ( cid ), CONST_ME_POFF )
			
					-- Ends the item 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.ammount..' '..param..' for '..item.itemammountcost..'x a '..itemname..'.' )
					
					-- Gives the player the item --
					doPlayerAddItem ( cid, item.id, item.ammount )
						
				-- Ends the stackable check --	
				end
			
			-- Ends the check if it cost money or items --
			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

How to add an item to it:
past this above the other items
Code:
['Backpack'] = { id = 3940, ammount = 1, costmoney = 1, cost = 10, itemcost = 2472, itemammountcost = 1  },

Change the following things:

['Backpack'] Change this name to the name of the item you want to sell.
id = 3940 Change the 3940 to the id of the item.
ammount = 1, Change the 1 to the ammount of items you want to give.
stackable = 1 Change the 1 to 0 if it isn't stackable, if it is stackable keep it 1.
costmoney = 1, change the 1 to 0 if you want it to cost another item, keep it 1 if you want it to cost money.
cost = 10, Change the 10 the the ammount of gold you want it to cost.(costmoney = 1)
itemcost = 2472 Change the 2472 to the item id you want it to take.(costmoney = 0)
itemammountcost = 1 Change 1 to the ammount of items it cost.(costmoney = 0)

Post bugs/suggestions here and I hope you like it or even learn something from it!:p:D
 
Last edited:
Thanks, I know this is very simple but yet I think its very usefull also. It is also easy to edit now for hosters.
 
Code:
items = {
	["shovel"] = { id = 1111, price = 1000, count = 1 }
	},
	["rope"] = { id = 2222, price = 2000, count = 1 }
	},
	["pick"] = { id = 3333, price = 3000, count = 1 }
	}
}

function onSay(cid, words, param)
	local item = items[param]
		if item then
			if doPlayerRemoveMoney(cid, item.price) == TRUE then
				doPlayerAddItem(cid, item.id, item.count)
				doPlayerSendTextMessage(cid, 24, "You have bought a "..item.." for "..item.price.." gold.")
			else
				doPlayerSendTextMessage(cid, 24, "Not enough gold.")
			end
		else
			doPlayerSendTextMessage(cid, 24, "You can buy the following items: ")
			for itan in pairs(items) do
				doPlayerSendTextMessage(cid, 24, itan)
			end
		end
	return TRUE
end

Hm?

--
Well, I've improved it a little but dunno if it wont pop-up any error since I didnt test it coz my server doesnt want to start :(

Code:
item = {
	["shovel"] = { id = 1111, price = 50, count = 1, stackable = 0 },
	["rope"] = { id = 2222, price = 50, count = 1, stackable = 0 },
	["sudden death rune"] = { id = 2267, price = 500, count = 25, stackable = 1 },
	["ham"] = { id = 2666, price = 200, count = 10, stackable = 1 }
	}
function onSay(cid, words, param)
	local item = items[param]
	if item then
		if doPlayerRemoveMoney(cid, item.price) == TRUE then
			if item.stackable == 0 then
				if item.count == 1 then
					doPlayerSendTextMessage(cid, 24, "You have bought 1 "..item.." for "..item.price.." gold coins.")
					doPlayerAddItem(cid, item.id, 1)
				else
					doPlayerSendTextMessage(cid, 24, "You have bought "..item.count.." "..item.."s for "..item.price.." gold coins.")
					for i = 1, item.count do
						doPlayerAddItem(cid, item.id, 1)
					end
				end
			elseif item.stackable == 1 then
				doPlayerSendTextMessage(cid, 24, "You have bought "..item.."(x"..item.count..") for "..item.price.." gold coins.")
				doPlayerAddItem(cid, item.id, item.count)
			end
		else
			doPlayerSendTextMessage(cid, 24, "Not enough gold mate!")
		end
	else
		doPlayerSendTextMessage(cid, 24, "Wrong item, you can buy the following ones: ")
		for itan in pairs(items) do
			doPlayerSendTextMessage(cid, 24, itan.."("..itan.price.."))
		end
	end
	return TRUE
end
 
Last edited:
Thanks but I don't need an improvement. I'm going to make the multi-items support later.

Edit: I improved my code a bit. I used your idea to use tables so they can buy multiple items.
 
Last edited:
Ok, but you still havent added stackable option.
If you want people to be able to buy runes with X charges, your script will give them X runes with 1 charge.
 
OMG yes you are right :O Thanks for telling:p I just forgot that lol. And thanks for the idea of useing a table ;D
 
Code:
items = {
	["shovel"] = { id = 1111, price = 1000, count = 1 }
	},
	["rope"] = { id = 2222, price = 2000, count = 1 }
	},
	["pick"] = { id = 3333, price = 3000, count = 1 }
	}
}

function onSay(cid, words, param)
	local item = items[param]
		if item then
			if doPlayerRemoveMoney(cid, item.price) == TRUE then
				doPlayerAddItem(cid, item.id, item.count)
				doPlayerSendTextMessage(cid, 24, "You have bought a "..item.." for "..item.price.." gold.")
			else
				doPlayerSendTextMessage(cid, 24, "Not enough gold.")
			end
		else
			doPlayerSendTextMessage(cid, 24, "You can buy the following items: ")
			for itan in pairs(items) do
				doPlayerSendTextMessage(cid, 24, itan)
			end
		end
	return TRUE
end

Hm?

--
Well, I've improved it a little but dunno if it wont pop-up any error since I didnt test it coz my server doesnt want to start :(

Code:
item = {
	["shovel"] = { id = 1111, price = 50, count = 1, stackable = 0 },
	["rope"] = { id = 2222, price = 50, count = 1, stackable = 0 },
	["sudden death rune"] = { id = 2267, price = 500, count = 25, stackable = 1 },
	["ham"] = { id = 2666, price = 200, count = 10, stackable = 1 }
	}
function onSay(cid, words, param)
	local item = items[param]
	if item then
		if doPlayerRemoveMoney(cid, item.price) == TRUE then
			if item.stackable == 0 then
				if item.count == 1 then
					doPlayerSendTextMessage(cid, 24, "You have bought 1 "..item.." for "..item.price.." gold coins.")
					doPlayerAddItem(cid, item.id, 1)
				else
					doPlayerSendTextMessage(cid, 24, "You have bought "..item.count.." "..item.."s for "..item.price.." gold coins.")
					for i = 1, item.count do
						doPlayerAddItem(cid, item.id, 1)
					end
				end
			elseif item.stackable == 1 then
				doPlayerSendTextMessage(cid, 24, "You have bought "..item.."(x"..item.count..") for "..item.price.." gold coins.")
				doPlayerAddItem(cid, item.id, item.count)
			end
		else
			doPlayerSendTextMessage(cid, 24, "Not enough gold mate!")
		end
	else
		doPlayerSendTextMessage(cid, 24, "Wrong item, you can buy the following ones: ")
		for itan in pairs(items) do
			doPlayerSendTextMessage(cid, 24, itan.."("..itan.price.."))
		end
	end
	return TRUE
end

yours has a bug change this
local item = items[param]

to

local item = item[param]

thanks master-m i used urs as a base/idea to make something else check it out here
 


-- Hey friend, how to me user your script to buy a set complete with one command???

Explain:

/buyitem "fire_set

you receive a fire set, have you to make this???

Many thx for you...

F@bio
 
-- Hey friend, how to me user your script to buy a set complete with one command???

Explain:

/buyitem "fire_set

you receive a fire set, have you to make this???

Many thx for you...

F@bio

give me a pm with the itemid's and I will create it for yah
 
@ master-m
Could u make the script sell items in Bp's for example a Bp of SD or Potions???
Thanks in advance.
Your's ballack13
 
Back
Top