Onplayerstatechange help
#1

I have an onplayerstatechange command

Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
	{
 	new vehicleidd = GetPlayerVehicleID(playerid);
 	if(GetVehicleModel(vehicleidd) == 596 || GetVehicleModel(vehicleidd) == 523 || GetVehicleModel(vehicleidd) == 601 || GetVehicleModel(vehicleidd) == 432 || GetVehicleModel(vehicleidd) == 497)
  	if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_ARMY) {
  SendClientMessage(playerid,0xF08080AA,"This vehicle belongs to the city. You can use this vehicle to do your job");
  return 1;
	}
  new plwl;
	GetPlayerName(playerid,pname,24);
	if(StoleCopCarRecent[playerid] == 0) {
	plwl = GetPlayerWantedLevel(playerid);
	SetPlayerWantedLevel(playerid,plwl +4);
	}
	new pcol = GetPlayerColor(playerid);
  plwl = GetPlayerWantedLevel(playerid);
  SendClientMessage(playerid, 0xA9A9A9AA, "|_Crime Commited_|");
	format(string1, sizeof(string1), "(LAW ENFORCEMENT VEHICLE THEFT) Wanted Level %d",plwl);
	SendClientMessage(playerid,pcol,string1);
	commitedcrimerecently[playerid] +=200;
	if(StoleCopCarRecent[playerid] == 0) {
	for(new i=0;i<MAX_PLAYERS;i++)
	{
	new current_zone;
  current_zone = player_zone[playerid];
  if(LawEnforcementRadio[i] == 1) {
  format(string1, sizeof(string1), "DISPATCH:(LAW ENFORCEMENT VEHICLE THEFT) %s(%d) Has stolen a police vehicle.Location: %s",pname,playerid,zones[current_zone][zone_name]);
	SendClientMessage(i, COLOR_ROYALBLUE, string1);
  }
  }
	}
	StoleCopCarRecent[playerid] =1;
	}
This is suppose to make it so if a police officer goes into a police vehicle it says "This vehicle belongs to the city. You can use this vehicle to do your job"

but if anyone else gets into this vehicle, it sends cops a message saying "vehicle theft" but im having problems with this...

Everytime a cop gets into any other car (other then the ones given in the peice of code) it makes them wanted and sends police a message saying "vehicle theft" even though im a police officer...

I hope you understand what im trying to say lol...

so how do i fix this? thanks
Reply
#2

i did'nt look to fix the code but i need to tell you its a lot of stuff for that callback, this get called like 30 time a second per player! (http://forum.sa-mp.com/index.php?topic=115828.0) , you should use onplayerentervehicle ...
as for the code well good luck!

EDIT: my bad wrong callback ... but i think he should use onplayerentervehicle anyway.
Reply
#3

Quote:
Originally Posted by snoob
i did'nt look to fix the code but i need to tell you its a lot of stuff for that callback, this get called like 30 time a second per player! (http://forum.sa-mp.com/index.php?topic=115828.0) , you should use onplayerentervehicle ...
as for the code well good luck!
He's talking about OnPlayerStateChange, not about OnPlayerUpdate.
Reply
#4

You really should learn to indent your script.
It'll be more readable, and easier to find errors.
http://forum.sa-mp.com/index.php?topic=61893.0

pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
    new vehicleidd = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(vehicleidd) == 596 || GetVehicleModel(vehicleidd) == 523 || GetVehicleModel(vehicleidd) == 601 || GetVehicleModel(vehicleidd) == 432 || GetVehicleModel(vehicleidd) == 497)
    { //added a bracket here. After your *statement
        if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_ARMY)
        {
            SendClientMessage(playerid,0xF08080AA,"This vehicle belongs to the city. You can use this vehicle to do your job");
            return 1;
        }
        new plwl;
        GetPlayerName(playerid,pname,24);
        if(StoleCopCarRecent[playerid] == 0) //why not combine this with your other "StoleCopCarRecent" statement?
        {
            plwl = GetPlayerWantedLevel(playerid);
            SetPlayerWantedLevel(playerid,plwl +4);
        }
        new pcol = GetPlayerColor(playerid);
        plwl = GetPlayerWantedLevel(playerid);
        SendClientMessage(playerid, 0xA9A9A9AA, "|_Crime Commited_|");
        format(string1, sizeof(string1), "(LAW ENFORCEMENT VEHICLE THEFT) Wanted Level %d",plwl);
        SendClientMessage(playerid,pcol,string1);
        commitedcrimerecently[playerid] +=200;
        if(StoleCopCarRecent[playerid] == 0) //this one
        {
            for(new i=0;i<MAX_PLAYERS;i++)
            {
                new current_zone;
                current_zone = player_zone[playerid];
                if(LawEnforcementRadio[i] == 1)
                {
                    format(string1, sizeof(string1), "DISPATCH:(LAW ENFORCEMENT VEHICLE THEFT) %s(%d) Has stolen a police vehicle.Location: %s",pname,playerid,zones[current_zone][zone_name]);
                    SendClientMessage(i, COLOR_ROYALBLUE, string1);
                }
            }
        }
        StoleCopCarRecent[playerid] =1;//moved this into your *statement
    } //added a bracket to close your *statement
}
Reply
#5

Quote:
Originally Posted by |∞|-Рцппσĵσ-|∞|
You really should learn to indent your script.
It'll be more readable, and easier to find errors.
http://forum.sa-mp.com/index.php?topic=61893.0

pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
    new vehicleidd = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(vehicleidd) == 596 || GetVehicleModel(vehicleidd) == 523 || GetVehicleModel(vehicleidd) == 601 || GetVehicleModel(vehicleidd) == 432 || GetVehicleModel(vehicleidd) == 497)
    { //added a bracket here. After your *statement
        if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_ARMY)
        {
            SendClientMessage(playerid,0xF08080AA,"This vehicle belongs to the city. You can use this vehicle to do your job");
            return 1;
        }
        new plwl;
        GetPlayerName(playerid,pname,24);
        if(StoleCopCarRecent[playerid] == 0) //why not combine this with your other "StoleCopCarRecent" statement?
        {
            plwl = GetPlayerWantedLevel(playerid);
            SetPlayerWantedLevel(playerid,plwl +4);
        }
        new pcol = GetPlayerColor(playerid);
        plwl = GetPlayerWantedLevel(playerid);
        SendClientMessage(playerid, 0xA9A9A9AA, "|_Crime Commited_|");
        format(string1, sizeof(string1), "(LAW ENFORCEMENT VEHICLE THEFT) Wanted Level %d",plwl);
        SendClientMessage(playerid,pcol,string1);
        commitedcrimerecently[playerid] +=200;
        if(StoleCopCarRecent[playerid] == 0) //this one
        {
            for(new i=0;i<MAX_PLAYERS;i++)
            {
                new current_zone;
                current_zone = player_zone[playerid];
                if(LawEnforcementRadio[i] == 1)
                {
                    format(string1, sizeof(string1), "DISPATCH:(LAW ENFORCEMENT VEHICLE THEFT) %s(%d) Has stolen a police vehicle.Location: %s",pname,playerid,zones[current_zone][zone_name]);
                    SendClientMessage(i, COLOR_ROYALBLUE, string1);
                }
            }
        }
        StoleCopCarRecent[playerid] =1;//moved this into your *statement
    } //added a bracket to close your *statement
}
Thanks a lot, it works great. I will try to improve my indentation skills lol
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)