Lua:
------------
-- Config --
------------
local config = {
amount = 500, -- Cap to add.
price = 500000 -- Price of it in gp.
}
------------
-- Script --
------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
local playerpos = getCreaturePosition(cid)
function getPlayerMaxCap(cid)
local query = db.getResult("SELECT `cap` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";")
if query:getID() ~= -1 then
return query:getDataInt("cap")
end
query:free()
return LUA_ERROR
end
function AddCap()
doPlayerSetMaxCapacity(cid, (getPlayerMaxCap(cid) + config.amount))
db.executeQuery("UPDATE `players` SET `cap` = " .. (getPlayerMaxCap(cid) + config.amount) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")
end
if getPlayerMoney(cid) < config.price then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You don't have enough money to buy this. You need " .. config.price .. " gp.")
doSendMagicEffect(playerpos, CONST_ME_POFF)
else
doPlayerRemoveMoney(cid, config.price)
AddCap()
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have received " .. config.amount .. " of capacity!")
doRemoveItem(item.uid, 1)
end
return TRUE
end
Post automatically merged:
Need help to fix this! transform to version TFS 1.X more