SA-MP Forums Archive
Wanted level colors - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Wanted level colors (/showthread.php?tid=354229)



Wanted level colors - SnG.Scot_MisCuDI - 26.06.2012

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);
    }



Re: Wanted level colors - Dan_Barocu - 26.06.2012

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..


Respuesta: Wanted level colors - Chris1337 - 26.06.2012

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);
    }



Re: Wanted level colors - MP2 - 26.06.2012

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);
}



Re: Wanted level colors - SnG.Scot_MisCuDI - 26.06.2012

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


Re: Wanted level colors - Rokzlive - 26.06.2012

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.


Re: Wanted level colors - SnG.Scot_MisCuDI - 29.06.2012

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)


Re: Wanted level colors - Chris1337 - 29.06.2012

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
}



Re: Wanted level colors - SnG.Scot_MisCuDI - 30.06.2012

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)


Re: Wanted level colors - ReneG - 30.06.2012

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.