SA-MP Forums Archive
OnPlayerStateChange[SOLVED] - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: OnPlayerStateChange[SOLVED] (/showthread.php?tid=154903)



OnPlayerStateChange[SOLVED] - jamesbond007 - 16.06.2010

i would like to set player wanted level by 1 if a civilian enters a civilian car. but if he enters a cop car his wanted level will go up by 4 stars...
how do i do that? pls help
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(gTeam[playerid] == TEAM_CIVILIAN)
	{
		if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
		{
 			new wanted = GetPlayerWantedLevel(playerid);
			new vehicleid = GetVehicleModel(playerid);
			switch(vehicleid)
  			{
		  			case 400: SetPlayerWantedLevel(playerid, wanted + 1);//landstalker
		  			case 401: SetPlayerWantedLevel(playerid, wanted + 1);//bravura
		            case 402: SetPlayerWantedLevel(playerid, wanted + 1);//buffalo
                    case 523: SetPlayerWantedLevel(playerid, wanted + 4);//Hpv-1000
                    case 598: SetPlayerWantedLevel(playerid, wanted + 4);//Cop Car LV
                               ...
             }
         }
     }
     return 1;

}



Re: OnPlayerStateChange - randomkid88 - 16.06.2010

When you compile this, does it give you errors? If so, post them here.


Re: OnPlayerStateChange - jamesbond007 - 16.06.2010

Quote:
Originally Posted by randomkid88
When you compile this, does it give you errors? If so, post them here.
no, only in game when i enter a car it doesnt do anything...


Re: OnPlayerStateChange - randomkid88 - 16.06.2010

Ok, try this. Where you have "wanted + 1" change to "wanted++" and "wanted + 4" to "wanted+4"

pawn Код:
case 400: SetPlayerWantedLevel(playerid, wanted++);//landstalker
case 401: SetPlayerWantedLevel(playerid, wanted++);//bravura
case 402: SetPlayerWantedLevel(playerid, wanted++ );//buffalo
case 523: SetPlayerWantedLevel(playerid, wanted+4);//Hpv-1000
case 598: SetPlayerWantedLevel(playerid, wanted+4);//Cop Car LV



Re: OnPlayerStateChange - (SF)Noobanatior - 16.06.2010

instead of a case do the last one at


default: { //docar stuff }

default will run when your case's dont apply


Re: OnPlayerStateChange - jamesbond007 - 16.06.2010

Quote:
Originally Posted by randomkid88
Ok, try this. Where you have "wanted + 1" change to "wanted++" and "wanted + 4" to "wanted+4"

pawn Код:
case 400: SetPlayerWantedLevel(playerid, wanted++);//landstalker
case 401: SetPlayerWantedLevel(playerid, wanted++);//bravura
case 402: SetPlayerWantedLevel(playerid, wanted++ );//buffalo
case 523: SetPlayerWantedLevel(playerid, wanted+4);//Hpv-1000
case 598: SetPlayerWantedLevel(playerid, wanted+4);//Cop Car LV
no, it doesnt work. i think the problem is in getvehiclemodel or something with the switch


Re: OnPlayerStateChange - randomkid88 - 16.06.2010

You could try switching it to OnPlayerEnterVehicle. Make sure you do
pawn Код:
if(!ispassenger)
{
   //switch stuff here
}
That way it only sets wanted level if they are entering as driver. You could take it out if you want.


Re: OnPlayerStateChange - jamesbond007 - 16.06.2010

Quote:
Originally Posted by (SF)Noobanatior
instead of a case do the last one at


default: { //docar stuff }

default will run when your case's dont apply
ok, i put default at the end and commented all the civilian cars now it gives me +1 wanted level for any stolen car but for police cars too.
what do i do now? i need to get 4 stars on entering a police car.


Re: OnPlayerStateChange - (SF)Noobanatior - 16.06.2010

or add if(!IsPlayerInAnyVehicle(playerid))print("player not in car yet);

to make sure they are in the car when this code runs


Re: OnPlayerStateChange - jamesbond007 - 16.06.2010

Quote:
Originally Posted by randomkid88
You could try switching it to OnPlayerEnterVehicle. Make sure you do
pawn Код:
if(!ispassenger)
{
   //switch stuff here
}
That way it only sets wanted level if they are entering as driver. You could take it out if you want.
i tried but it sets my level when im going to enter it, not when im already inside the car...