Wanted level colors
#1

So im making OnPlayerUpdate check if the player is wanted and if so change there color. Here is how i want it

0 stars = White
1-3 stars = Yellow
4-6 = Red

But the problem is, is that if they have 0 they dont get set white, but are yellow.

pawn Код:
if(GetPlayerWantedLevel(playerid) <= 0)
    {
        SetPlayerColor(playerid, COLOR_WHITE);
    }
    else if(GetPlayerWantedLevel(playerid) <= 3)
    {
        SetPlayerColor(playerid, COLOR_YELLOW);
    }
    else if(GetPlayerWantedLevel(playerid) >= 4)
    {
        SetPlayerColor(playerid, COLOR_RED);
    }
Reply
#2

like this?
PHP код:
if(GetPlayerWantedLevel(playerid) == 0)
    {
        
SetPlayerColor(playeridCOLOR_WHITE);
    }
    else if(
GetPlayerWantedLevel(playerid) <= 3
    {
        
SetPlayerColor(playeridCOLOR_YELLOW);
    }
    else if(
GetPlayerWantedLevel(playerid) >= 4)
    {
        
SetPlayerColor(playeridCOLOR_RED);
    } 
i got confused..sorry yeah how second post is..
Reply
#3

1st. make sure that if you have another team (cops ) and you have 0 wanted , your color will change

pawn Код:
if(GetPlayerWantedLevel(playerid) == 0)
    {
        SetPlayerColor(playerid, COLOR_WHITE);
    }
    else if(GetPlayerWantedLevel(playerid) >= 1 && GetPlayerWantedLevel(playerid) <= 3)
    {
        SetPlayerColor(playerid, COLOR_YELLOW);
    }
    else if(GetPlayerWantedLevel(playerid) >= 4)
    {
        SetPlayerColor(playerid, COLOR_RED);
    }
Reply
#4

Why are you setting it under OnPlayerUpdate? That's incredibly inefficient and un-necessary. Just set their color when you change their wanted level!

pawn Код:
switch(wantedlevel)
{
    case 0: SetPlayerColor(playerid, COLOR_WHITE);
    case 1..3: SetPlayerColor(playerid, COLOR_YELLOW);
    default: SetPlayerColor(playerid, COLOR_RED);
}
Reply
#5

Quote:
Originally Posted by MP2
Посмотреть сообщение
Why are you setting it under OnPlayerUpdate? That's incredibly inefficient and un-necessary. Just set their color when you change their wanted level!

pawn Код:
switch(wantedlevel)
{
    case 0: SetPlayerColor(playerid, COLOR_WHITE);
    case 1..3: SetPlayerColor(playerid, COLOR_YELLOW);
    default: SetPlayerColor(playerid, COLOR_RED);
}
I was thinking about doing that but i just thought it was be "easier" to make it do it itself. Ill just have to manual set i guess. Thanks +rep for all
Reply
#6

Quote:
Originally Posted by MP2
Посмотреть сообщение
Why are you setting it under OnPlayerUpdate? That's incredibly inefficient and un-necessary. Just set their color when you change their wanted level!

pawn Код:
switch(wantedlevel)
{
    case 0: SetPlayerColor(playerid, COLOR_WHITE);
    case 1..3: SetPlayerColor(playerid, COLOR_YELLOW);
    default: SetPlayerColor(playerid, COLOR_RED);
}
Very true, players update thousands of time a minute, it would cause lag like no other.
Reply
#7

Quote:
Originally Posted by MP2
Посмотреть сообщение
Why are you setting it under OnPlayerUpdate? That's incredibly inefficient and un-necessary. Just set their color when you change their wanted level!

pawn Код:
switch(wantedlevel)
{
    case 0: SetPlayerColor(playerid, COLOR_WHITE);
    case 1..3: SetPlayerColor(playerid, COLOR_YELLOW);
    default: SetPlayerColor(playerid, COLOR_RED);
}
Wouldnt default be white?
and how to make the player eventually lose all stars then the timer shuts off until gained stars again
(im trying to find the most efficient way of doing this)
Reply
#8

idk if you could do this :

pawn Код:
new hasatimer[MAX_PLAYERS];
new timer;
forward timer(playerid, wanted);

public OnPlayerUpdate
{
  new wanted;
  wanted = GetPlayerWantedLevel(playerid);
  if(wanted >= 3)
  {
      timer = SetTimerEx("timer", 10000, true, "ud", playerid, wantedlevel);
  }
  else if(wanted == 0 && hasatimer[playerid] == 1)
  {
     KillTimer(timer);
  }
}


public timer(playerid, wantedlevel)
{
   hasatimer[playerid] = 1;
   ///Your Loose Wanted
}
Reply
#9

Quote:
Originally Posted by axxelac
Посмотреть сообщение
idk if you could do this :

pawn Код:
new hasatimer[MAX_PLAYERS];
new timer;
forward timer(playerid, wanted);

public OnPlayerUpdate
{
  new wanted;
  wanted = GetPlayerWantedLevel(playerid);
  if(wanted >= 3)
  {
      timer = SetTimerEx("timer", 10000, true, "ud", playerid, wantedlevel);
  }
  else if(wanted == 0 && hasatimer[playerid] == 1)
  {
     KillTimer(timer);
  }
}


public timer(playerid, wantedlevel)
{
   hasatimer[playerid] = 1;
   ///Your Loose Wanted
}
isnt putting it under OnPlayerUpdate not necessary (MP2)
Reply
#10

I'm not going to tell you to change your code to a different callback or w/e, but here is what is going wrong.

For this example I have a 0 wanted level.

pawn Код:
if(GetPlayerWantedLevel(playerid) <= 0)
{
    // this code will be ran since I have
    // a zero wanted level
    SetPlayerColor(playerid, COLOR_WHITE);
}
else if(GetPlayerWantedLevel(playerid) <= 3)
{
    // this code will ALSO be ran because
    // the wanted level is still less than
    // or equal to 3
    SetPlayerColor(playerid, COLOR_YELLOW);
}
You need to return after each statement to stop the code from running to the next check.

You should still move it to a different callback because you wouldn't want the OnPlayerUpdate code to stop before important code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)