• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Feature Level ranks

Gelio

Lua PHP C++ programmer
Joined
Jun 13, 2008
Messages
61
Reaction score
4
Location
Poland, Lublin
Hello. I've made this code. It's 100 & by me (Gelio). If you look on other player you will see near his nick and level:
He/She is a |RANK|.
Rank will be one of ranks you set. Ranks change if you got level up. Ok:

In: player.cpp:
Above:
Code:
std::string Player::getDescription(int32_t lookDistance) const
Add:
Code:
std::string Player::getPVPRank(uint32_t level) const
{
        std::string ranga = "newbie";
        if(level >= 40 && level <= 45)
        {
            ranga = "normal PK";
        }
        else if(level > 45 && level <= 60)
        {
            ranga = "soldier";
        }
        else if(level > 60 && level <= 75)
        {
            ranga = "experienced soldier";
        }
        else if(level > 75 && level <= 90)
        {
            ranga = "guard";
        }
        else if(level > 90 && level <= 105)
        {
            ranga = "experienced guard";
        }
        else if(level > 105 && level <= 120)
        {
            ranga = "general";
        }
        else if(level > 120 && level <= 135)
        {
            ranga = "PK mastah";
        }
        else if(level > 135)
        {
            ranga = "master of life and death";
        } 
        return ranga;
}
In this code (up) you will change ranks etc.

In funcion (in player.cpp):
Code:
std::string Player::getDescription(int32_t lookDistance) const
Under:
Code:
			s << " (Level " << level << ")";
        }

		s << ".";
Add:
Code:
            if(sex == PLAYERSEX_FEMALE)
            {
                s << " She";
            }
            else
            {
                s << " He";
            }
            s << " is ";
            std::string rank = Player::getPVPRank(level);
            s << rank << ".";

In player.h:
Above:
Code:
		virtual std::string getDescription(int32_t lookDistance) const;
Add:
Code:
		virtual std::string getPVPRank(uint32_t level) const;

Ok. Now compile and run. Now I will show you how to make your own ranks:
1. Open code where are ranks (player.cpp).
2. Prepare your rank:
else if(level < xxx && level >= yyy)
{
rank = "your rank, xxx is minimum level, yyy is maximum level";
}
3. Add above any else if in this function your prepared rank.



Yours,
Gelio
 
Last edited:
It may look in LUA like this:
Code:
local ranks =
{
	--fromLevel, rank
	--from hightest rank, to lowest
	{135, "master of life and death"},
	{120, "PK mastah"},
	{105, "general"},
	{90, "experienced guard"},
	{75, "guard"},
	{60, "experienced soldier"},
	{45, "soldier"},
	{40, "newbie"}
}

function onLook(cid, lookThing)
	if(isPlayer(lookThing) == TRUE) then
		local level = getPlayerLevel(lookThing)
		local tmp = "He"
		if(getPlayerSex(lookThing) == PLAYERSEX_FEMALE) then
			tmp = "She"
		end

		for _, t in pairs(ranks) do
			if(level >= t[1]) then
				return "\n" .. tmp .. " is a " .. t[2] .. "."
			end
		end
	end

	return TRUE
end

or dunno how Elf have done it, maybe he added new lua function setPlayerSpecialDescription(cid, desc).

We need to wait for next release : ()
 
Last edited:
Sorry for refreshing thread
This feature is very kool but i wanted to use additional field in players table instead of level and i just dont know how to do it, because im just newbie in programing:/
Can anybody help me with it?
 
for 0.3.5: (untested)

creaturescripts/scripts/rank.lua
Code:
local ranks =
{
	--from hightest rank, to lowest
	{level = 135, rank = "master of life and death"},
	{level = 120, rank = "PK mastah"},
	{level = 105, rank = "general"},
	{level = 90, rank = "experienced guard"},
	{level = 75, rank = "guard"},
	{level = 60, rank = "experienced soldier"},
	{level = 45, rank = "soldier"},
	{level = 40, rank = "newbie"}
}

function onLogin(cid)
	local level = getPlayerLevel(cid)
	local tmp = "He"
	if(getPlayerSex(cid) == PLAYERSEX_FEMALE) then
		tmp = "She"
	end

	for _, t in pairs(ranks) do
			if(level >= t[1]) then
				doPlayerSetSpecialDescription(cid, "\n" .. tmp .. " is a " .. t[2] .. ".")
				break
			end
		end
	end

	return TRUE
end

creaturescripts.xml:
Code:
	<event type="login" name="RankLogin" event="script" value="login.lua"/>
 
@up
great :). Gonna test it now and post here results ;p.

#
ahah ;d
[07/08/2009 20:18:30] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/ranks.lua)
[07/08/2009 20:18:30] data/creaturescripts/scripts/ranks.lua:30: '<eof>' expected near 'end'

Ok fixed it(deleted one end near 'break' and tabbed good) but now I have this error:
Code:
[07/08/2009 20:21:05] Renusek has logged in.

[07/08/2009 20:21:05] Lua Script Error: [CreatureScript Interface] 
[07/08/2009 20:21:05] data/creaturescripts/scripts/ranks.lua:onLogin

[07/08/2009 20:21:05] data/creaturescripts/scripts/ranks.lua:22: attempt to compare nil with number
[07/08/2009 20:21:05] stack traceback:
[07/08/2009 20:21:05] 	data/creaturescripts/scripts/ranks.lua:22: in function <data/creaturescripts/scripts/ranks.lua:14>
[07/08/2009 20:21:05] Renusek has logged out.

Slawkens help ;p.
 
Last edited:
oh try this one [;
also fixed wrong description (thanks ChojRaK!)
Code:
local ranks =
{
	--from hightest rank, to lowest
	{level = 135, rank = "a master of life and death"},
	{level = 120, rank = "a PK mastah"},
	{level = 105, rank = "a general"},
	{level = 90, rank = "an experienced guard"},
	{level = 75, rank = "a guard"},
	{level = 60, rank = "an experienced soldier"},
	{level = 45, rank = "a soldier"},
	{level = 40, rank = "a newbie"}
}

function onLogin(cid)
	local level = getPlayerLevel(cid)
	for _, t in pairs(ranks) do
		if(level >= t.level) then
			doPlayerSetSpecialDescription(cid, "\n" .. (getPlayerSex(cid) == PLAYERSEX_FEMALE and "She" or "He") .. " is " .. t.rank .. ".")
			break
		end
	end

	return TRUE
end
 
Hm. Is it possible to do that, if you look on yourself it will show:
You see yourself. You are vocation. You are a '..rank..' ? This function is not showing your rank when you look on yourself ;<.
 
Back
Top