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

Help! Scroll of Capacity TFS 1.X

snuckles

Banned User
Joined
Apr 4, 2009
Messages
74
Reaction score
3
Location
Hong Kong
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
 
To be honest, you don't need any of the below whatsoever....but it's still better than what it was xD
Lua:
local player = Player(cid)
   
if not player then
    return false
end
 
There's no need to do the below, onUse passes the player object directly, it shouldn't ever be nil...
Lua:
local player = player:getId()
local player = Player(player)
  
if not player then
    return false
end

Other than that it's good.

but one question for the OP...
Is there any need to do database queries, or is this a purchasable store item where you want to ensure data is updated in the event of a crash?

Otherwise...just update the cap and let server saves do its job, no need for the db queries.
fwiw, you can also player:save() to force it as well. xP
 
Back
Top