• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Simply Shop System

KylerXX

Active Member
Joined
Jun 24, 2010
Messages
439
Reaction score
30
Well, I created a base as example, the scripts works:
I want a banana, ok, then I say:

/shop banana, quantity

Depends on the price you've put the banana, and the amount you asked for, will cost you what you need to cost.

Lua:
local items = {
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500},
["item"] = {itemid = 2882, price = 500}
}
function onSay(cid, words, param, channel) -- script by xaft
local s = string.explode(param, ",")
local shop = items[s[1]]
--
if s[1] == nil and s[2] == nil then
	return doPlayerSendCancel(cid, "Please, you must expecificate the item and the quantity.")
elseif s[1] ~= nil and s[2] == nil then
	return doPlayerSendCancel(cid, "Please, you must expecificate the quantity.")
end
if s[2] == "0" then
	return doPlayerSendCancel(cid, "Please, the quantity will be 1 or higher.")
end
--
	if shop then
		if getItemWeightById(shop.itemid)*s[2] < getPlayerFreeCap(cid) then
			if doPlayerRemoveMoney(cid, shop.price*s[2]) then
				for i = 1,s[2] do
					doPlayerAddItem(cid, shop.itemid, 1)
				end
				doPlayerSendTextMessage(cid, 22, "You have received ".. s[2] .." ".. getItemNameById(shop.itemid) .."!")
			else
				doPlayerSendCancel(cid, "You do not have enough money.")
			end
		else
			doPlayerSendCancel(cid, "You do not have enough capacity.")
		end
	else
		doPlayerSendCancel(cid, "Invalid shop item.")
	end	
return 0
end

Will modify:
["item"] = {itemid = 2882, price = 500},

Green -> name of the item (!shop name, x)
Red -> itemid of the item.
Blue -> price of the item (only one).


talkactions.xml
XML:
<talkaction words="!shop;/shop" event="script" value="shop.lua"/>
 
how can i put when you buy something from the list, you lose premiumdays and not cash :p
i put:
if doPlayerRemovePremiumDays(cid, shop.price*s[2]) then
but when you use it it gives me 24157861251 prem days O.O
 
now i dont recive the item :<
[27/12/2010 11:14:15] [Error - TalkAction Interface]
[27/12/2010 11:14:15] data/talkactions/scripts/shop.lua:eek:nSay
[27/12/2010 11:14:15] Description:
[27/12/2010 11:14:15] data/talkactions/scripts/shop.lua:29: attempt to index field '?' (a nil value)
[27/12/2010 11:14:15] stack traceback:
[27/12/2010 11:14:15] data/talkactions/scripts/shop.lua:29: in function <data/talkactions/scripts/shop.lua:14>
[27/12/2010 11:14:25] > Saving server...
[27/12/2010 11:14:26] > SAVE: Complete in 0.37 seconds using relational house storage.
 
yup, i got the item, but... u.u when i loose my prem days it give me more days WTF:

11:23 You have 2147483647 Premium days left. idk why u.u


or how can i change it to just prem players can use it ;P
 
Last edited:
Lua:
local il = {
	['item'] = {id=1523,c=5},
	['item2'] = {id=1524,c=5}
	}
	
function onSay(cid,words,param)
local m,t = string.explode(param,','),il[m[1]]
	if m[1] ~= nil and m[2] ~= nil and tonumber(m[2]) > 0 then
		if t then
			if getPlayerFreeCap(cid) >= getItemWeightById(t.id)*tonumber(m[2]) then
				if doPlayerRemovePremiumDays(cid,t.c*tonumber(m[2])) then
					for i = 1,tonumber(m[2]) do
						doPlayerAddItem(cid,t.id,t.c*tonumber(m[2]))
					end
					doPlayerSendTextMessage(cid,MESSAGE_FIRST, "You have recieved ".. s[2] .." ".. getItemNameById(shop.itemid) .."!")
				else
					doPlayerSendCancel(cid,'You have insufficient money.')
				end
			else
				doPlayerSendCancel(cid,'You have too less cap.')
			end
		else
			doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You entered a wrong item name.')
		end
	else
		doPlayerSendTextMessage(cid,MESSAGE_FIRST,'Please use this format: \'!shop itemname,quantity\'.')
	end
	return true
end

I think this will work
 
Last edited:
send this error
[27/12/2010 11:47:33] [Error - LuaScriptInterface::loadFile] data/talkactions/scripts/shop.lua:14: ')' expected (to close '(' at line 13) near 'end'
[27/12/2010 11:47:33] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/shop.lua)
[27/12/2010 11:47:33] data/talkactions/scripts/shop.lua:14: ')' expected (to close '(' at line 13) near 'end'
[27/12/2010 11:47:33] Reloaded talk actions.

and how i add more items :p
 
updated the script, to add more items just make a new line in the table 'il'.
Code:
local il = {
	['item'] = {id=1523,c=5},
	['item2'] = {id=1524,c=5}[COLOR="red"][B],[/B]
	[B]['item3'] = {id=1525,c=5}[/B][/COLOR]
	}
 
Back
Top