it's my simple !buyitem function, you can add many items, it's so easy.
buyitem.lua
talkactions.xml
you adding items to show by table items("{{'name', itemid, cost}}")
if player say with param item name and have money, he's buy it, if param is 'selling list' to script send to player list of items that shop offering.
buyitem.lua
Code:
-- simple !buyitem system fully working made by ersiu(Azi). --
function onSay(cid, param, words)
local items = {{'backpack', 1980, 10}, {'amulet of loss', 2173, 50000}} -- items for sell.
for x = 1, #items do
if(param == items[x][1])then
pos = x
end
end
if(doPlayerRemoveMoney(cid, items[pos][3]) == TRUE)then
doPlayerAddItem(cid, items[pos][2])
doPlayerSendTextMessage(cid, 19, 'You bought '..items[pos][1]..' for '..items[pos][3]..', thank you!')
else
doPlayerSendTextMessage(cid, 19, 'Sorry, that\'s too expensive for you.')
end
if(param == 'selling list')then
local items_count = table.getn(items)
local list_nr = 1
while(1 <= items_count)do
doPlayerSendTextMessage(cid, 19, '-'..list_nr..'. '..items[list_nr][1]..' costs: '..list_nr..'. '..items[list_nr][3]..'\n.')
list_nr = list_nr+1
end
end
end
Code:
<talkaction words="!buyitem" script="buyitem.lua"/>
if player say with param item name and have money, he's buy it, if param is 'selling list' to script send to player list of items that shop offering.
Last edited: