Action Buying Capacity

Guitar Freak

_LüA_n☺b_
Joined
Dec 27, 2008
Messages
831
Best answers
0
Reaction score
11
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.
 

chojrak

Banned User
Joined
Oct 25, 2008
Messages
5,832
Best answers
2
Reaction score
158
Nice :)

Can you play Tenacious D's Master Exploder on your guIt00r?
 

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,717
Best answers
8
Reaction score
285
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?
 

xyllaus

New Member
Joined
Apr 30, 2009
Messages
10
Best answers
0
Reaction score
0
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!
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
Your distro (TFS 0.2?) doesn't have function doPlayerSetMaxCapacity.
 

xyllaus

New Member
Joined
Apr 30, 2009
Messages
10
Best answers
0
Reaction score
0
[22/11/2009 13:33:35] The Forgotten Server, version 0.3.3 (Crying Damson)
 
OP
Guitar Freak

Guitar Freak

_LüA_n☺b_
Joined
Dec 27, 2008
Messages
831
Best answers
0
Reaction score
11
Location
Caracas, Venezuela
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:

xyllaus

New Member
Joined
Apr 30, 2009
Messages
10
Best answers
0
Reaction score
0
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^_^
 
OP
Guitar Freak

Guitar Freak

_LüA_n☺b_
Joined
Dec 27, 2008
Messages
831
Best answers
0
Reaction score
11
Location
Caracas, Venezuela
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 :)
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
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?
 
OP
Guitar Freak

Guitar Freak

_LüA_n☺b_
Joined
Dec 27, 2008
Messages
831
Best answers
0
Reaction score
11
Location
Caracas, Venezuela
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
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
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?
 
OP
Guitar Freak

Guitar Freak

_LüA_n☺b_
Joined
Dec 27, 2008
Messages
831
Best answers
0
Reaction score
11
Location
Caracas, Venezuela
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
 

froie

Expert Mapper
Joined
May 27, 2013
Messages
194
Best answers
0
Reaction score
5
Location
Canada
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.
 
Top