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

CreatureEvent Level cap system with points!

Darad

New Member
Joined
Jun 23, 2009
Messages
119
Reaction score
1
Couldn't get it in a mod, so here's some scraps of code!

What does it do?
This script keeps players at a certain level. Creating a max level on your server. For every level they gain over the max they get a point. This points can be used in a shop or whatever you like.

Script includes a talkaction "!getpoints" that will give players a message of how many points they have.

Add this to player table.
Code:
ALTER TABLE players ADD cap_points int(11) DEFAULT 0

levelcap.lua
Lua:
local config = {
	levelcap = 100000
}

function onAdvance(cid, skill, oldlevel, newlevel)
	if skill == SKILL__LEVEL then

		if newlevel > config.levelcap then
			doPlayerAddExperience(cid, -(getExperienceForLevel(getPlayerLevel(cid)) - getExperienceForLevel(config.levelcap)))
			
			local points = newlevel - config.levelcap
			
			setPlayerPoints(cid, points)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'You gained ' .. points .. ' points.')
			return FALSE
		end
	end
	return TRUE
end

Add to creaturescripts.xml
Code:
<event type="advance" name="levelup" script="levelcap.lua"/>

Add to login.lua
Lua:
registerCreatureEvent(cid, "levelup")

Add to lib/function.lua
Lua:
function setPlayerPoints(cid, points)
	db.executeQuery("UPDATE `players` SET `cap_points` = `cap_points` +" .. points .. " WHERE `name` = '" .. getPlayerName(cid) .. "'")
end

function getPlayerPoints(cid)
	local result = db.getResult("SELECT `cap_points` FROM `players` WHERE `name` = '" .. getPlayerName(cid) .. "'")
	return result:getDataInt("cap_points")
	
end

Add to talkactions.xml
Code:
<talkaction words="!getpoints" event="script" hide="yes" value="getpoints.lua"/>

talkactions/scripts/getpoints.lua
Lua:
function onSay(cid, words, param, channel)
	local points = getPlayerPoints(cid)
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have " .. points .. " points available.")
	return true
end
 
Thanks, it works :p
rep +

Little bug:
If player get from 29 to 31 or 30 to 31 (instand) then player get more cap, hp, mp :p

I dont mean bug in server(client) or sth but player get more cap, mana or hp :p
 
Last edited:
Uhm so if you level over the maximum the player doesn't get downgraded on hp etc? But downgraded on level. I'll look into it :)

Edit: Can you specify the bug?
I tested what I thought you mean, but no bug there. After the downgrade my hp/mana/cap were back to normal.
 
Last edited:
This is actually very useful for me... but.. I'm wondering something.. Wouldn't this be futile if i desired to raise my level cap over time?
 
This is actually very useful for me... but.. I'm wondering something.. Wouldn't this be futile if i desired to raise my level cap over time?

In what way? Just make sure you've got the content for the new levels. Tons of mmo's do this for ages now :)
 
Lol, what I mean is, what would be the point of having lvl cap points if I decided to raise the level cap over time and new players joined? Wouldn't they feel they had some unfair disadvantage?>
 
Don't think so no, maybe they're behind in points, but that's all. Up to you to find a good balance in that ;)
 
Back
Top