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

getPlayerMaxCap(cid)

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,255
Solutions
28
Reaction score
723
Location
Germany
The base might not be right, so feel free to edit it if it's not correct.

Lua:
function getPlayerMaxCap(cid)
local capacity =
{
[0] = {base = 100, gain = 5, level = 1, form = -1}, -- Calculated for level 1 // I'm unsure about this, base might not be right, so correct it, if it's wrong.
[1] = {base = 135, gain = 5, level = 8, form = -8}, -- Calculated for level 8
[2] = {base = 135, gain = 5, level = 8, form = -8}, -- Calculated for level 8
[3] = {base = 135, gain = 10, level = 8, form = -8}, -- Calculated for level 8
[4] = {base = 135, gain = 15, level = 8, form = -8}, -- Calculated for level 8
[5] = {base = 135, gain = 5, level = 8, form = -8}, -- Calculated for level 8
[6] = {base = 135, gain = 5, level = 8, form = -8}, -- Calculated for level 8
[7] = {base = 135, gain = 10, level = 8, form = -8}, -- Calculated for level 8
[8] = {base = 135, gain = 15, level = 8, form = -8} -- Calculated for level 8
}
local player = capacity[getPlayerVocation(cid)]
	if player then
		if getPlayerLevel(cid) > player.level then
			maxCap = (player.base + ((getPlayerLevel(cid) + (player.form)) * player.gain))
		else
			maxCap = player.base
		end
	end
	return maxCap
end


kind regards, Evil Hero
 
Last edited:
More easy and shorter haha!

Lua:
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
 
But it's calling many functions and stuff.
I think the query one is better..

Keep in mind, the more queries you use (or are executed in a moment) the more ressources will the server need.

I'm not saying mine is better or anything but I for myself avoid queries for the fact that it takes to much ressources with a high ammount of Players on a server :)


kind regards, Evil Hero
 
I agree with Evil on this,
I made some scripts for a server with 288 players online,
when we tested, they executed a query and lagged the server.

I needed to re-write the whole thing.
 
I agree with Evil on this,
I made some scripts for a server with 288 players online,
when we tested, they executed a query and lagged the server.

I needed to re-write the whole thing.

Glad I'm not the only one who encounters such problems :p


I've shortened the function again, takes a few less lines now.


kind regards, Evil Hero
 
Lua:
local baseCap = 100 -- edit this
function getPlayerMaxCap(cid)
    local vocInfo = getVocationInfo(getPlayerVocationId(cid))
    return baseCap + vocInfo.capacity * getPlayerLevel(cid)
end

This function would be best made in sources (to skip baseCap).
 
Lua:
local baseCap = 100 -- edit this
function getPlayerMaxCap(cid)
    local vocInfo = getVocationInfo(getPlayerVocationId(cid))
    return baseCap + vocInfo.capacity * getPlayerLevel(cid)
end

This function would be best made in sources (to skip baseCap).

Wont work this way.

Keep in mind that Knights and the other vocations, start at level 8
so the base capacity is not right set for them.

example:
Code:
Level 1 (None Vocation) = 100 base cap
Level 8 (any Vocation) = 135 base cap

Also keep in mind that your way, it wouldn't have been the right outcome

example:
Outcome from mine:
Code:
Level 1 = 100 (None Vocation)
Level 8 = 135 (None Vocation)

Outcome from yours:
Code:
Level 1 = 100
Level 8 = 140

You forgot that the first level has already it's cap and you gain just 7 levels uppon your level 8.

Same would have happened with the rest, calculations would have been wrong.

I've quickly updated your version (not best solution)
Lua:
function getPlayerMaxCap(cid)
local vocInfo = getVocationInfo(getPlayerVocationId(cid))
	if getPlayerVocation(cid) == 0 then
		if getPlayerLevel(cid) == 1 then
			maxCap = 100
		else
			maxCap = baseCap + vocInfo.capacity * (getPlayerLevel(cid) -1)
		end 
	elseif getPlayerVocation(cid) ~= 0 then
		if getPlayerLevel(cid) == 8 then
			maxCap = 135
		else
			maxCap = baseCap + vocInfo.capacity * (getPlayerLevel(cid) -8)
		end
	end
	return maxCap
end

this way it would work aswell.


kind regards, Evil Hero
 
Back
Top