TalkAction Advanced !Buyitem Version 2.5

Master-m

Need help? Just ask!
Joined
May 28, 2007
Messages
4,339
Best answers
0
Reaction score
15
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:
OP
M

Master-m

Need help? Just ask!
Joined
May 28, 2007
Messages
4,339
Best answers
0
Reaction score
15
Location
The Netherlands
Thanks, I know this is very simple but yet I think its very usefull also. It is also easy to edit now for hosters.
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
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:
OP
M

Master-m

Need help? Just ask!
Joined
May 28, 2007
Messages
4,339
Best answers
0
Reaction score
15
Location
The Netherlands
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:
OP
M

Master-m

Need help? Just ask!
Joined
May 28, 2007
Messages
4,339
Best answers
0
Reaction score
15
Location
The Netherlands
Updated to version 2.0! I explain the config in the first post! :D
 

Merchant

Expert Mapper
Joined
Mar 12, 2008
Messages
769
Best answers
0
Reaction score
20
Amazing, thanks sir.
Repp++ <3
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
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.
 
OP
M

Master-m

Need help? Just ask!
Joined
May 28, 2007
Messages
4,339
Best answers
0
Reaction score
15
Location
The Netherlands
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
 

wovaki

Programmer
Joined
Aug 11, 2007
Messages
154
Best answers
0
Reaction score
1
Nice script!!

Will be useful to a lot of servers. :D
 

soul4soul

Active Member
Joined
Aug 13, 2007
Messages
1,787
Best answers
0
Reaction score
43
Location
USA
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
 

Oehoehflexi

New Member
Joined
Jun 21, 2008
Messages
119
Best answers
0
Reaction score
0
Location
The Netherlands
thanks dude! im sure i will use this its easy for people like if they are in a cave without bps are something :)
 

[email protected]

Fudera Otserver
Joined
Jul 10, 2007
Messages
212
Best answers
0
Reaction score
0
Location
Brasil

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

[email protected]
 

Norix

Hosting Service !
Joined
Jan 18, 2008
Messages
544
Best answers
0
Reaction score
7
Location
Germany
@ 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
 
Top