• 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!

Action Buying Capacity

Guitar Freak

_LüA_n☺b_
Joined
Dec 27, 2008
Messages
831
Reaction score
13
Location
Caracas, Venezuela
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! :D

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.
 
Nice :)

Can you play Tenacious D's Master Exploder on your guIt00r?
 
Code:
db.executeQuery("UPDATE `players` SET `cap` = " .. (getPlayerMaxCap(cid) + config.amount) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")

Code:
local query = db.getResult("SELECT `cap` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";")

these functions already have in mysql?
 
thx, but I have some error.
I need this script with: the player buy and remove 1 gold ingot(9971) and give 1000 capacity, I dont know how put for remove gold ingots. And i have this error:
Code:
[22/11/2009 11:45:24] Lua Script Error: [Action Interface] 
[22/11/2009 11:45:24] data/actions/scripts/other/buycap.lua:onUse

[22/11/2009 11:45:24] data/actions/scripts/other/buycap.lua:30: attempt to call global 'doPlayerSetMaxCapacity' (a nil value)
[22/11/2009 11:45:24] stack traceback:
[22/11/2009 11:45:24] 	data/actions/scripts/other/buycap.lua:30: in function 'AddCap'
[22/11/2009 11:45:24] 	data/actions/scripts/other/buycap.lua:39: in function <data/actions/scripts/other/buycap.lua:16>

I want to give 1000 cap and remove 1 gold ingot(9971)This is my script:
Code:
------------
        -- Config --
        ------------

        local config    =       {
       
                amount  =       1000,     -- Cap to add.
                price   =       1    -- 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, "No tienes suficientes histerya gold ingot, necesitas " .. config.price .. " histerya gold ingot.")
                doSendMagicEffect(playerpos, CONST_ME_POFF)
        else
                doPlayerRemoveMoney(cid, config.price)
                AddCap()
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Acabas de recibir " .. config.amount .. " de capacidad maxima!")
                doSendAnimatedText(playerpos, " +" .. config.amount .. "", TEXTCOLOR_ORANGE)
        end
        return TRUE
end

Thx!
 
Your distro (TFS 0.2?) doesn't have function doPlayerSetMaxCapacity.
 
[22/11/2009 13:33:35] The Forgotten Server, version 0.3.3 (Crying Damson)
 
thx, but I have some error.
I need this script with: the player buy and remove 1 gold ingot(9971) and give 1000 capacity, I dont know how put for remove gold ingots. And i have this error:
Code:
[22/11/2009 11:45:24] Lua Script Error: [Action Interface] 
[22/11/2009 11:45:24] data/actions/scripts/other/buycap.lua:onUse

[22/11/2009 11:45:24] data/actions/scripts/other/buycap.lua:30: attempt to call global 'doPlayerSetMaxCapacity' (a nil value)
[22/11/2009 11:45:24] stack traceback:
[22/11/2009 11:45:24] 	data/actions/scripts/other/buycap.lua:30: in function 'AddCap'
[22/11/2009 11:45:24] 	data/actions/scripts/other/buycap.lua:39: in function <data/actions/scripts/other/buycap.lua:16>

I want to give 1000 cap and remove 1 gold ingot(9971)

Are gold ingots on your server part of the currencies or just a random item?

(Si no entiendes eso, me refiero a que si en tu server los gold ingots son parte del sistema "monetario", es decir igual que las crystal coins etc, o si son un item item?)

If they are part of the currency system like being worth 1 million each or something like that, then just change the "amount" in the config to 1000 and the "price" to 1000000 and the universe will do the rest :p

Use this one and test it in your server before doing any modifications to it, just to see if it works:

Lua:
	------------
        -- Config --
        ------------

        local config    =       {
        
                amount  =       1000,     -- Cap to add.
                price   =       1000000    -- 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

It worked in mine and I use custom currencies too so it should work for yours!

And thanks a lot to everyone! I wasnt expecting this good feedback :)

@Chojrak:

I could do about a year ago, I should be able to now too.. hopefully :p
PS: Tenacious D owns lol
 
Last edited:
I hace the same error,
[23/11/2009 20:54:06] Lua Script Error: [Action Interface]
[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:eek:nUse

[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:30: attempt to call global 'doPlayerSetMaxCapacity' (a nil value)
[23/11/2009 20:54:06] stack traceback:
[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:30: in function 'AddCap'
[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:39: in function <data/actions/scripts/other/buycap.lua:16>



Gold ingot is a item item. Thx for the spanish^_^
 
I hace the same error,
[23/11/2009 20:54:06] Lua Script Error: [Action Interface]
[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:eek:nUse

[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:30: attempt to call global 'doPlayerSetMaxCapacity' (a nil value)
[23/11/2009 20:54:06] stack traceback:
[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:30: in function 'AddCap'
[23/11/2009 20:54:06] data/actions/scripts/other/buycap.lua:39: in function <data/actions/scripts/other/buycap.lua:16>

I thought so.. well, I think your problem is your distro (using 0.3.3 right?)!

Before doing anything further, you should check your /doc/functions document and see if the distro you're using has the "doPlayerSetMaxCapacity" function, because usually I get that error when Im calling a function that doesnt exist.

Id also strongly suggest you to update to 0.3.5pl1, since it is more likely for you to get better support with that distro, and you can find better scripts.

PS: I answered your PM :)
 
Code:
        function AddCap()
                doPlayerSetMaxCapacity(cid, (getPlayerMaxCap(cid) + config.amount))
                db.executeQuery("UPDATE `players` SET `cap` = " .. (getPlayerMaxCap(cid) + config.amount) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")             
        end
Maybe you should check if player is online to avoid having to execute Sql query every time?
 
Code:
        function AddCap()
                doPlayerSetMaxCapacity(cid, (getPlayerMaxCap(cid) + config.amount))
                db.executeQuery("UPDATE `players` SET `cap` = " .. (getPlayerMaxCap(cid) + config.amount) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")             
        end
Maybe you should check if player is online to avoid having to execute Sql query every time?

Well considering it is a script that only works when the player uses an item, I guess that means he has to be online for it to run in the first place xD
 
Well considering it is a script that only works when the player uses an item, I guess that means he has to be online for it to run in the first place xD
uhm, i fail sorry
but why do you execute the sql query too?
 
uhm, i fail sorry
but why do you execute the sql query too?

Because when I tried it without the sql query, it was only buying correctly once for some reason :huh: after that it would buy the cap but it wouldnt update on screen until player relogged, or something similar I dont really recall correctly, I just know the query must be done for it to work correctly :p

:peace:

PS: Your new avatar kinda creeps me out :D
 
how do i get this to work :/ I am using TFS v0.2.14 and i want it to be the Dragon Eye ItemID: [18526]. im doing everything right but im not sure why it will not work.
 
Back
Top