Guitar Freak
_LüA_n☺b_
Hello, well I have been inactive on releasing scripts for a while so I decided to post this little script that I saw requested a couple of days ago.
♠ Description:
What it does is what the title says, you click an item (can be a lever, chest, etc) and it will purchase a certain amount of max capacity to the player.
I dont use it on my server/project and I know its nothing special, but maybe someone else wants it and I havent seen one released here.
♠ Compatibility:
Tested and working in 0.3.5pl1.
♠ Miscellaneous:
<- guIt00r!
♠ Script:
In /data/actions.xml:
In /data/actions/scripts/Buy Cap.lua:
As you can see, I used darkhaos's function for getting a players max cap, which is pretty much the whole base of the script, so feel free to +rep him if you found this useful.
If you find any bugs or can shorten/optimize it, feel free to.
Regards.
♠ Description:
What it does is what the title says, you click an item (can be a lever, chest, etc) and it will purchase a certain amount of max capacity to the player.
I dont use it on my server/project and I know its nothing special, but maybe someone else wants it and I havent seen one released here.
♠ Compatibility:
Tested and working in 0.3.5pl1.
♠ Miscellaneous:
<- guIt00r!
♠ Script:
In /data/actions.xml:
PHP:
<action actionid="3500" event="script" value="Buy Cap.lua"/>
In /data/actions/scripts/Buy Cap.lua:
Lua:
------------
-- Config --
------------
local config = {
amount = 15, -- Cap to add.
price = 1000 -- Price of it in gp.
}
------------
-- Script --
------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
local playerpos = getCreaturePosition(cid)
function getPlayerMaxCap(cid) -- Function by darkhaos
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_STATUS_CONSOLE_RED, "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 .. " capacity!")
doSendAnimatedText(playerpos, " +" .. config.amount .. "", TEXTCOLOR_ORANGE)
end
return TRUE
end
As you can see, I used darkhaos's function for getting a players max cap, which is pretty much the whole base of the script, so feel free to +rep him if you found this useful.
If you find any bugs or can shorten/optimize it, feel free to.
Regards.