local SHOP = {
[ACTION_ID] = {
reward = ITEM_ID,
cost = 100,
count = 1,
}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local t = SHOP[item.actionid]
if t then
if(doPlayerRemoveMoney(cid, t.cost)) then
local id = doCreateItemEx(t.reward, t.count or 1)
if(doPlayerAddItemEx(cid, id) ~= RETURNVALUE_NOERROR) then
return doPlayerSendCancel(cid, "You cannot carry this item."), false
end
doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have purchased " .. getItemName(t.reward) .. ".")
else
doPlayerSendCancel(cid, "You do not have enough money.")
end
end
return true
end
Bad idea - to many connection to database.Can anyone make this work with premium points. You need premium points to buy item and not money
Nope if he use the exhaustion for talkaction![]()
local item = 2157
local price = 10
local count = 10
local exh = 10
local exhstorage = 35252
function onSay(cid, words, param, channel)
if (exhaustion.get (cid, exhstorage)) then
doPlayerSendCancel (cid, "You are exhausted!")
return true
else
exhaustion.set(cid, exhstorage, exh)
end
local query = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
local pkt = query:getDataInt("premium_points")
if pkt >= price then
local update = db.executeQuery("UPDATE `accounts` SET `premium_points`= "..(pkt - price).." WHERE `id`= " .. getPlayerAccountId(cid) .. "; ")
doPlayerSendTextMessage(cid, 22, "You have bought item for 10 premium points!")
doPlayerAddItem(cid,item, count)
else
doPlayerSendCancel(cid, "You need 10 premium points to buy this item!")
end
return true
end