[HELP] custom police car
#1

i want to make a undercover police car

for example : i want to create infernus and attach police light in it... an turn the light on when i press "H"

i have this car
PDinfernus = AddStaticVehicleEx(411,1526.4309,-1646.1412,6.0788,178.1691,0,1,6000);
Reply
#2

You'll need to use those functions: CreateObject, AttachObjectToVehicle, OnPlayerKeyStateChange. Have fun!
Reply
#3

can you give me the object id for police light?? pls
Reply
#4

I'm not sure, but you can try with 18646.

Find them all here.
Reply
#5

thx for help
Reply
#6

i make like this

Код:
	pdlight = CreateObject(18646,0,0,0,0,0,0);
	buffpd1 = AddStaticVehicleEx(402,1545.5215,-1680.1603,5.7222,89.7425,0,0,30000); // buffalo pd
	buffpd2 = AddStaticVehicleEx(402,1544.9746,-1676.1263,5.7223,91.2767,0,0,30000); // buffalo pd
	buffpd3 = AddStaticVehicleEx(402,1600.9907,-1695.9442,5.7223,89.9302,0,0,30000); // buffalo pd
	buffpd4 = AddStaticVehicleEx(402,1601.1803,-1700.0834,5.7223,90.7667,0,0,30000); // buffalo pd
	AttachObjectToVehicle(pdlight, buffpd1, 0, -0.0, 0, 2.0, 2.0, 3.0);
	AttachObjectToVehicle(pdlight, buffpd2, 0, -0.0, 0, 2.0, 2.0, 3.0);
	AttachObjectToVehicle(pdlight, buffpd3, 0, -0.0, 0, 2.0, 2.0, 3.0);
	AttachObjectToVehicle(pdlight, buffpd4, 0, -0.0, 0, 2.0, 2.0, 3.0);
but the object isn't there and no light

what i do wrong?

all is in "public OnGameModeInit()"
Reply
#7

You have to create one police light per vehicle:
Код:
pdlight1 = CreateObject(18646,0,0,0,0,0,0);
pdlight2 = CreateObject(18646,0,0,0,0,0,0);
pdlight3 = CreateObject(18646,0,0,0,0,0,0);
pdlight4 = CreateObject(18646,0,0,0,0,0,0);
buffpd1 = AddStaticVehicleEx(402,1545.5215,-1680.1603,5.7222,89.7425,0,0,30000); // buffalo pd
buffpd2 = AddStaticVehicleEx(402,1544.9746,-1676.1263,5.7223,91.2767,0,0,30000); // buffalo pd
buffpd3 = AddStaticVehicleEx(402,1600.9907,-1695.9442,5.7223,89.9302,0,0,30000); // buffalo pd
buffpd4 = AddStaticVehicleEx(402,1601.1803,-1700.0834,5.7223,90.7667,0,0,30000); // buffalo pd
AttachObjectToVehicle(pdlight1, buffpd1, 0, -0.0, 0, 2.0, 2.0, 3.0);
AttachObjectToVehicle(pdlight2, buffpd2, 0, -0.0, 0, 2.0, 2.0, 3.0);
AttachObjectToVehicle(pdlight3, buffpd3, 0, -0.0, 0, 2.0, 2.0, 3.0);
AttachObjectToVehicle(pdlight4, buffpd4, 0, -0.0, 0, 2.0, 2.0, 3.0);
And i would use arrays instead of all these variables.
Reply
#8

thx for help
Reply
#9

i make something like this

Код:
if (newkeys == KEY_CROUCH)
    {
        new pdlight1;
		new pdlight2;
		new pdlight3;
		new pdlight4;
		new pdlighton;
  		if(pdlighton == 0)
		{
    	                new checkcar = GetPlayerVehicleID(playerid);
		    if(checkcar == buffpd1)
		        {
		            pdlight1 = CreateObject(18646,0,0,0,0,0,0);
  		            AttachObjectToVehicle(pdlight1, buffpd1, 0, -0.0, 0, 2.0, 2.0, 3.0);
		            pdlighton = 1;
		        }
		    else if(checkcar == buffpd2)
 		        {
		            ipdlight2 = CreateObject(18646,0,0,0,0,0,0);
		            iAttachObjectToVehicle(pdlight2, buffpd2, 0, -0.0, 0, 2.0, 2.0, 3.0);
 		            ipdlighton = 1;
		        }
		    else if(checkcar == buffpd3)
			{
			    pdlight3 = CreateObject(18646,0,0,0,0,0,0);
			    AttachObjectToVehicle(pdlight3, buffpd3, 0, -0.0, 0, 2.0, 2.0, 3.0);
			    pdlighton = 1;
			}
			else if(checkcar == buffpd4)
			{
			    pdlight4 = CreateObject(18646,0,0,0,0,0,0);
			    AttachObjectToVehicle(pdlight4, buffpd4, 0, -0.0, 0, 2.0, 2.0, 3.0);
			    pdlighton = 1;
			}
		    return 1;
	    }
	    else
	    {
	        new checkcar = GetPlayerVehicleID(playerid);
    	        if(checkcar == buffpd1)
    	        {
    	            DestroyObject(pdlight1);
    	        }
                    else if(checkcar == buffpd2)
    	        {
    	            DestroyObject(pdlight2);
    	        }
                    else if(checkcar == buffpd3)
	        {
	            DestroyObject(pdlight3);
	        }
                    else if(checkcar == buffpd4)
	        {
	            DestroyObject(pdlight4);
	        }
                    return 1;
	    }
		    
    }
but when i use again KEY_CROUCH that police light is still there..

how can i make a variable which depend by carid?

or how i can solve this problem?
Reply
#10

i solved some problem

until now always attach new police light...now i solved

bot now i don't know why didn't destroy the police light

here is the code

pawn Код:
if (newkeys == KEY_CROUCH)
    {
      if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
      {
        new pdlight1;
        new pdlight2;
        new pdlight3;
        new pdlight4;
        new checkcar = GetPlayerVehicleID(playerid);
        if(pdlighton1 == 0 && checkcar == buffpd1 || pdlighton2 == 0 && checkcar == buffpd2 || pdlighton3 == 0 && checkcar == buffpd3 || pdlighton4 == 0 && checkcar == buffpd4)
        {
            if(checkcar == buffpd1)
            {
                pdlight1 = CreateObject(18646,0,0,0,0,0,0);
                AttachObjectToVehicle(pdlight1, buffpd1, 0, -0.0, 0, 2.0, 2.0, 3.0);
                pdlighton1 = 1;
            }
            if(checkcar == buffpd2)
            {
                pdlight2 = CreateObject(18646,0,0,0,0,0,0);
                AttachObjectToVehicle(pdlight2, buffpd2, 0, -0.0, 0, 2.0, 2.0, 3.0);
                pdlighton2 = 1;
            }
            if(checkcar == buffpd3)
            {
                pdlight3 = CreateObject(18646,0,0,0,0,0,0);
                AttachObjectToVehicle(pdlight3, buffpd3, 0, -0.0, 0, 2.0, 2.0, 3.0);
                pdlighton3 = 1;
            }
            if(checkcar == buffpd4)
            {
                pdlight4 = CreateObject(18646,0,0,0,0,0,0);
                AttachObjectToVehicle(pdlight4, buffpd4, 0, -0.0, 0, 2.0, 2.0, 3.0);
                pdlighton4 = 1;
            }
        }
        else
        {
            if(checkcar == buffpd1)
            {
                DestroyObject(pdlight1);
            }
            if(checkcar == buffpd2)
            {
                DestroyObject(pdlight2);
            }
            if(checkcar == buffpd3)
            {
                DestroyObject(pdlight3);
            }
            if(checkcar == buffpd4)
            {
                DestroyObject(pdlight4);
            }
        }
      }
    }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)