Speed cam disable for vehicles of police
#1

I need to disable speed cam for police vehicles.

Код HTML:
//===================================================================================================
//                                              Timers
//===================================================================================================
forward UpdateCameras();
public UpdateCameras()
{
        for(new a = 0;a<MAX_PLAYERS;a++)
        {
            if(!IsPlayerConnected(a)) continue;
            if(!IsPlayerInAnyVehicle(a)) continue;
            if(GetPVarInt(a,"PlayerHasBeenFlashed") == 1)
                {
                        continue;
                } else if (GetPVarInt(a,"PlayerHasBeenFlashed") == 2)
                {
                        DeletePVar(a,"PlayerHasBeenFlashed");
                        continue;
                }
            for(new b = 0;b<loaded_cameras +1;b++)
            {
                if(SpeedCameras[b][_active] == false) continue;
                if(IsPlayerInRangeOfPoint(a,SpeedCameras[b][_range],SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z]))
                {
                    new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(a),SpeedCameras[b][_usemph]));
                    new limit = SpeedCameras[b][_limit];
                    if(speed > limit)
                    {
                        TextDrawShowForPlayer(a,flash);
                        #if CAMERA_PERSPECTIVE == true
                        SetPlayerCameraPos(a,SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z] + 5);
                        new Float:x,Float:y,Float:z;GetPlayerPos(a,x,y,z);
                        SetPlayerCameraLookAt(a,x,y,z);
                        #endif
                        SetPVarInt(a,"PlayerHasBeenFlashed",1);
                        SetTimerEx("RemoveFlash",CAMERA_FLASH_TIME,false,"i",a);
                                        if(GetPlayerState(a) == PLAYER_STATE_DRIVER)
                                        {
                                                        if(SpeedCameras[b][_usemph] == 0)
                                                        {
                                                                SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"kmh where you were allowed to drive ",limit, "kmh.");
                                                                SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
                                                        } else {
                                                                SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"mph where you were allowed to drive ",limit, "mph.");
                                                                SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
                                                        }
                                                        GivePlayerMoney(a, - SpeedCameras[b][_fine]);
                                        }
                    }
                }
            }
        }
}
forward RemoveFlash(playerid);
public RemoveFlash(playerid)
{
        TextDrawHideForPlayer(playerid,flash);
        SetPVarInt(playerid,"PlayerHasBeenFlashed",2);
        #if CAMERA_PERSPECTIVE == true
        SetCameraBehindPlayer(playerid);
        #endif
}
Reply
#2

Код:
stock IsPoliceVehicle(vehicleid)
{
	new veh_id = GetVehicleModel(vehicleid);
	switch(veh_id)
	{
	    case 427, 523, 528, 596, 597, 598, 599: return true;
	}
	return false;
}

forward UpdateCameras();
public UpdateCameras()
{
    for(new a = 0; a < MAX_PLAYERS; a++)
    {
	    if(!IsPlayerConnected(a)) continue;
	    if(!IsPlayerInAnyVehicle(a)) continue;
	    if(!IsPoliceVehicle(GetPlayerVehicleID(a)) continue;

        if(GetPVarInt(a,"PlayerHasBeenFlashed") == 1)
        {
        	continue;
        }
		else if (GetPVarInt(a,"PlayerHasBeenFlashed") == 2)
        {
            DeletePVar(a,"PlayerHasBeenFlashed");
            continue;
        }
        
        for(new b = 0;b<loaded_cameras +1;b++)
        {
            if(SpeedCameras[b][_active] == false) continue;
            if(IsPlayerInRangeOfPoint(a,SpeedCameras[b][_range],SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z]))
            {
                new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(a),SpeedCameras[b][_usemph]));
                new limit = SpeedCameras[b][_limit];
                if(speed > limit)
                {
                    TextDrawShowForPlayer(a,flash);
                    #if CAMERA_PERSPECTIVE == true
                    SetPlayerCameraPos(a,SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z] + 5);
                    new Float:x,Float:y,Float:z;GetPlayerPos(a,x,y,z);
                    SetPlayerCameraLookAt(a,x,y,z);
                    #endif
                    SetPVarInt(a,"PlayerHasBeenFlashed",1);
                    SetTimerEx("RemoveFlash",CAMERA_FLASH_TIME,false,"i",a);
                    if(GetPlayerState(a) == PLAYER_STATE_DRIVER)
                    {
                        if(SpeedCameras[b][_usemph] == 0)
                        {
                            SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"kmh where you were allowed to drive ",limit, "kmh.");
                            SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
                        } else {
                            SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"mph where you were allowed to drive ",limit, "mph.");
                            SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
                        }
                        GivePlayerMoney(a, - SpeedCameras[b][_fine]);
                    }
                }
            }
        }
    }
}

forward RemoveFlash(playerid);
public RemoveFlash(playerid)
{
    TextDrawHideForPlayer(playerid,flash);
    SetPVarInt(playerid,"PlayerHasBeenFlashed",2);
    #if CAMERA_PERSPECTIVE == true
    SetCameraBehindPlayer(playerid);
    #endif
}
Reply
#3

Use this >>
PHP код:
if(GetVehicleModel(vehicleid) == the police car id here
after "IsPlayerInAnyVehicle" and then return a 0;

I mean like that..

PHP код:
/*forward UpdateCameras();
public UpdateCameras()
{
    for(new a = 0; a < MAX_PLAYERS; a++)
    {
        if(!IsPlayerConnected(a)) continue;
        if(!IsPlayerInAnyVehicle(a)) continue;
            if(GetVehicleModel(vehicleid) == the police car id here) return 0;
        if(GetPVarInt(a,"PlayerHasBeenFlashed") == 1)
        {
            continue;
        }
        else if (GetPVarInt(a,"PlayerHasBeenFlashed") == 2)
        {
            DeletePVar(a,"PlayerHasBeenFlashed");
            continue;
        }
        
        for(new b = 0;b<loaded_cameras +1;b++)
        {
            if(SpeedCameras[b][_active] == false) continue;
            if(IsPlayerInRangeOfPoint(a,SpeedCameras[b][_range],SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z]))
            {
                new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(a),SpeedCameras[b][_usemph]));
                new limit = SpeedCameras[b][_limit];
                if(speed > limit)
                {
                    TextDrawShowForPlayer(a,flash);
                    #if CAMERA_PERSPECTIVE == true
                    SetPlayerCameraPos(a,SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z] + 5);
                    new Float:x,Float:y,Float:z;GetPlayerPos(a,x,y,z);
                    SetPlayerCameraLookAt(a,x,y,z);
                    #endif
                    SetPVarInt(a,"PlayerHasBeenFlashed",1);
                    SetTimerEx("RemoveFlash",CAMERA_FLASH_TIME,false,"i",a);
                    if(GetPlayerState(a) == PLAYER_STATE_DRIVER)
                    {
                        if(SpeedCameras[b][_usemph] == 0)
                        {
                            SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"kmh where you were allowed to drive ",limit, "kmh.");
                            SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
                        } else {
                            SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"mph where you were allowed to drive ",limit, "mph.");
                            SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
                        }
                        GivePlayerMoney(a, - SpeedCameras[b][_fine]);
                    }
                }
            }
        }
    }
}
forward RemoveFlash(playerid);
public RemoveFlash(playerid)
{
    TextDrawHideForPlayer(playerid,flash);
    SetPVarInt(playerid,"PlayerHasBeenFlashed",2);
    #if CAMERA_PERSPECTIVE == true
    SetCameraBehindPlayer(playerid);
    #endif
}*/ 
Reply
#4

Quote:
Originally Posted by Freedom.
Посмотреть сообщение
Just add to beginning and end of your code /* */
FOR POLICE CARS, he means an exception, to make the speedcam work EXCEPT for police cars..
Reply
#5

Quote:
Originally Posted by JasonRiggs
Посмотреть сообщение
FOR POLICE CARS, he means an exception, to make the speedcam work EXCEPT for police cars..
Why you double posting? I see my mistake and I changed it. You could text in one message.
Reply
#6

This method is extremely inefficient, you're not only looping through 499 player slots every time this is called. You're also looping through 2000 possibly empty slots at the same time. Consider using something such as dynamic areas from the streamer plugin.

This allows distance checking to be handled in C, which is already faster. Just add vehicle, speed and other checks when they enter the area.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)