How can I add Player Levels forever?
#1

I have this code, but I aim to avoid making this code long. At the moment, it's checking every single level that I coded. I'd like for the levels to be unlimited. Is there a way to shorten down this code, so it doesn't have to check for specific levels, but instead increments these levels in an if statement, while incrementing value of rand_level by a defined amount on each new level?

Код:
if(Player[playerid][Level] == 1)
		{
			new rand_level = 100 + random(100);
			format(string, sizeof(string), "Level 1 pay: $%d", rand_level);
			SendClientMessage(playerid, WHITE, string);
			Player[playerid][Money] += rand_level;
		}
		
		if(Player[playerid][Level] == 2)
		{
			new rand_level = 200 + random(200);
			format(string, sizeof(string), "Level 2 pay: $%d", rand_level);
			SendClientMessage(playerid, WHITE, string);
			Player[playerid][Money] += rand_level;
		}
		
		if(Player[playerid][Level] == 3)
		{
			new rand_level = 300 + random(300);
			format(string, sizeof(string), "Level 3 pay: $%d", rand_level);
			SendClientMessage(playerid, WHITE, string);
			Player[playerid][Money] += rand_level;
		}
...and so on.

How can I make this shorter and more dynamic rather than static?
Reply
#2

Try these :
pawn Код:
new lvl = Player[playerid][Level]; //Just to shorten it abit...
new rand_level = (lvl * 100) + random(lvl * 100);
format(string, sizeof(string), "Level %d pay: $%d", lvl, rand_level);
SendClientMessage(playerid, WHITE, string);
Player[playerid][Money] += rand_level;
Reply
#3

Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)