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

A simple function :).. but very useful

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
Open you data/lib/function.lua and add:
Code:
[COLOR="Navy"][COLOR="DarkGreen"]function[/COLOR] doPlayerAddLevel[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"],[/COLOR] lv[COLOR="DarkGreen"])[/COLOR]

	local cidlv [COLOR="DarkGreen"]=[/COLOR] getPlayerLevel[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"])[/COLOR]
	local newLevel [COLOR="DarkGreen"]=[/COLOR] cidlv[COLOR="DarkGreen"]+[/COLOR]lv
	local newExp [COLOR="DarkGreen"]=[/COLOR] getExperienceForLevel[COLOR="DarkGreen"]([/COLOR]newLevel[COLOR="DarkGreen"])[/COLOR]
	local formula [COLOR="DarkGreen"]=[/COLOR] newExp[COLOR="DarkGreen"]-[/COLOR]getExperienceForLevel[COLOR="DarkGreen"]([/COLOR]cidlv[COLOR="DarkGreen"])[/COLOR]

	[COLOR="DarkGreen"]return[/COLOR] doPlayerAddExp[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"],[/COLOR] formula[COLOR="DarkGreen"])[/COLOR]
end[/COLOR]

And how use?.. very easy, this is an example:

Code:
[COLOR="Navy"][COLOR="DarkGreen"]function[/COLOR] onUse[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"],[/COLOR] item[COLOR="DarkGreen"],[/COLOR] fromPosition[COLOR="DarkGreen"],[/COLOR] itemEx[COLOR="DarkGreen"],[/COLOR] toPosition[COLOR="DarkGreen"])[/COLOR]
[COLOR="DarkGreen"]if[/COLOR] getPlayerStorageValue[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"],[/COLOR] 1000[COLOR="DarkGreen"])[/COLOR] [COLOR="DarkGreen"]==[/COLOR] 1 [COLOR="DarkGreen"]then[/COLOR]
doPlayerAddLevel[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"],[/COLOR] 2[COLOR="DarkGreen"])[/COLOR]
else
doPlayerSendTextMessage[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"],[/COLOR] MESSAGE_STATUS_CONSOLE_ORANGE[COLOR="DarkGreen"],[/COLOR] [COLOR="Red"]"You can't obtain the present."[/COLOR][COLOR="DarkGreen"])[/COLOR]
end
end[/COLOR]

This function will give levels to the players.
 
Last edited:
Ok will explain it to you, normally the persons if they want to add a level to a player should use three functions, an example is this:

Code:
[COLOR="Blue"]doPlayerAddExp[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"],[/COLOR] getExperienceForLevel[COLOR="DarkGreen"]([/COLOR]getPlayerLevel[COLOR="DarkGreen"]([/COLOR]cid)[COLOR="DarkGreen"]+[/COLOR]1[COLOR="DarkGreen"])[/COLOR][COLOR="DarkGreen"]-[/COLOR]getExperienceForLevel[COLOR="DarkGreen"]([/COLOR]getPlayerLevel[COLOR="DarkGreen"]([/COLOR]cid[COLOR="DarkGreen"]))[/COLOR][/COLOR]

But .. with my function you only to need to place all the levels you want to add the player and ready!!, without need to calculate the experience for the next level.
 
Same function accepting negative values - doPlayerAddLevel(cid, -100) (Works only in TFS 0.3)

Code:
function doPlayerAddLevel(cid, amount)
	local newExp = 0
	local currentLevel = getPlayerLevel(cid)
	if(amount > 0) then
		newExp = getExperienceForLevel(currentLevel + amount) - getExperienceForLevel(currentLevel)
	else
		newExp = getExperienceForLevel(currentLevel) - getExperienceForLevel(currentLevel + amount)
	end

	return doPlayerAddExp(cid, newExp)
end
 
PHP:
--[[function by Keraxel]] function setLevel(cid, level)
	return doPlayerAddExp(cid, (getExperienceForLevel(level) - getPlayerExperience(cid))) and TRUE or FALSE
end
level can be (getPlayerLevel(cid) +/- level) ;)
 
Last edited:
PHP:
--[[function by Keraxel]] function setLevel(cid, level)
	return doPlayerAddExp(cid, (getExperienceForLevel(level) - getPlayerExperience(cid))) and TRUE or FALSE
end
level can be (getPlayerLevel(cid) +/- level) ;)

The functions "set" are to place such a thing, on the other hand the function "addLevel" is to add levels to the current level
 
As I said you can do for instance setLevel(cid, (getPlayerLevel(cid) + 2))

#edit: Ok, there is much shorter doPlayerAddLevel:
PHP:
--[[by keraxel]] function doPlayerAddLevel(cid, level)
	return doPlayerAddExp(cid, getExperienceForLevel(getPlayerLevel(cid) + level) - getPlayerExperience(cid)) or FALSE
end

#slawkens: doPlayerAddExp is bugged, it does not remove experience :/
 
Last edited:
Back
Top