level system [question] -
Supermaxultraswag - 15.11.2014
Hey, im trying to create level system. But im kinda noob at pawno, su could you help me? I try to create my own, but im not sure if its good. Here :
Код HTML:
SetTimer("Check", 1000, true);
Код HTML:
forward Check(playerid);
public Check(playerid)
{
if(GetPlayerScore(playerid)>=0)
{
Lvl1[playerid]=true;
PlayerTextDrawShow(playerid, Level1[playerid]);
}
if(GetPlayerScore(playerid)>=150)
{
Lvl2[playerid]=true;
PlayerTextDrawDestroy(playerid, Level1[playerid]);
PlayerTextDrawShow(playerid, Level2[playerid]);
}
if(GetPlayerScore(playerid)>=400)
{
Lvl3[playerid]=true;
PlayerTextDrawDestroy(playerid, Level2[playerid]);
PlayerTextDrawShow(playerid, Level3[playerid]);
}
Is this a good system? What can be improved?
Re: level system [question] -
DavidSparks - 15.11.2014
To me it seems good.
Good job dude!
Re: level system [question] -
k0r - 15.11.2014
Hmmm, the method you used is good but it takes many memory waste.
Try like this. I use the same.
pawn Код:
new RankName[][] = {
"Newbie",
"Private",
"OMG DESTROYER!!!!"
};
new Rank[MAX_PLAYERS], PlayerText:tRank[MAX_PLAYERS];
forward Check();
public Check()
{
for(new i=0; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i)) { //If you use foreach instead of normal loop, it'd be better.
switch(GetPlayerScore(i)) {
case 0..9: Rank[i] = 0; //This is a bit confusing. case x..x means between x and x. like case 0..9 means between 0 and 9.
case 10..49: Rank[i] = 1;
default: Rank[i] = 2; //default means the rest.
}
PlayerTextDrawSetString(i, tRank[i], RankName[Rank[i]]);
}
return 1;
}
Re: level system [question] -
Supermaxultraswag - 15.11.2014
Quote:
Originally Posted by DavidSparks
To me it seems good.
Good job dude!
|
Thank you
Quote:
Originally Posted by k0r
Hmmm, the method you used is good but it takes many memory waste.
Try like this. I use the same.
pawn Код:
new RankName[][] = { "Newbie", "Private", "OMG DESTROYER!!!!" };
new Rank[MAX_PLAYERS], PlayerText:tRank[MAX_PLAYERS];
forward Check(); public Check() { for(new i=0; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i)) { //If you use foreach instead of normal loop, it'd be better. switch(GetPlayerScore(i)) { case 0..9: Rank[i] = 0; //This is a bit confusing. case x..x means between x and x. like case 0..9 means between 0 and 9. case 10..49: Rank[i] = 1; default: Rank[i] = 2; //default means the rest. } PlayerTextDrawSetString(i, tRank[i], RankName[Rank[i]]); } return 1; }
|
Thank you, but i had a question. Why i need that :
Код:
for(new i=0; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))
as i understand, this line checks if the player is online, right? But player couldn't get score, when he's offline, so why i need that?
Re: level system [question] -
Supermaxultraswag - 15.11.2014
Also, one more question. Why i get this warning :
warning 211: possibly unintended assignment
when i use this :
if(Rank[i] = 0)
Re: level system [question] -
CutX - 15.11.2014
Quote:
Originally Posted by Supermaxultraswag
Also, one more question. Why i get this warning :
warning 211: possibly unintended assignment
when i use this :
if(Rank[i] = 0)
|
pawn lang explanation
Where a conditional expression was expected,
the assignment operator (=) was found instead of
the equality operator (==).
As this is a frequent mistake, the compiler issues a warning.
To avoid this message, put parentheses around the expression,
e.g. if ((a=2))
do "==" instead of "="
"=" means to assign something
and "==" to compare something.
you want to compare something, so "==" is correct here
Quote:
Originally Posted by Supermaxultraswag
Thank you, but i had a question. Why i need that :
Код:
for(new i=0; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))
as i understand, this line checks if the player is online, right? But player couldn't get score, when he's offline, so why i need that?
|
because GetMaxPlayers returns the maximum number of players
that can join the server, as set by the server var 'maxplayers' in server.cfg
for example, we set the max to 200 but there are only 12 ppls online,
it'll still loop through until "i<200"
if you'd use foreach, it'll only loop through the number of connected players,
so we don't need 2 check if we're looping through a "real" player.