help with vehicle params
#1

hello guys. im trying to make vehicle commands with zcmd. i want them to work like when you enter engine it turns it on and when you do it again it turns off. but somethings wrong with my code. there are no errors or warnings. please tell me whats wrong.

Код:
COMMAND:engine(playerid,params[])
	{
	    if(IsPlayerConnected(playerid))
     {
           new vid = GetPlayerVehicleID(playerid);
		   if (engine == 1) // check if engine ON
	       {
			  if(vid != INVALID_VEHICLE_ID)
	          {
                  GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                  SetVehicleParamsEx(vid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
				  
			  }
	       }
	       else if (engine == 0) // check if engine off
	       {
			  if(vid != INVALID_VEHICLE_ID)
			  {
                 GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                 SetVehicleParamsEx(vid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
                 
			  }
	       }
		}
		return 1;
	}

COMMAND:lights(playerid,params[])
	{
	    if(IsPlayerConnected(playerid))
     {
           new vid = GetPlayerVehicleID(playerid);
		   if (lights == 1)
	       {
			  if(vid != INVALID_VEHICLE_ID)
	          {
                  GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                  SetVehicleParamsEx(vid,engine,0,alarm,doors,bonnet,boot,objective);
				  
			  }
	       }
	       else if (lights == 0)
	       {
			  if(vid != INVALID_VEHICLE_ID)
			  {
                 GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                 SetVehicleParamsEx(vid,engine,1,alarm,doors,bonnet,boot,objective);

			  }
	       }
		}
		return 1;
	}


COMMAND:alarm(playerid,params[])
	{
	    if(IsPlayerConnected(playerid))
     {
           new vid = GetPlayerVehicleID(playerid);
		   if (alarm == 1) // check if engine ON
	       {
			  if(vid != INVALID_VEHICLE_ID)
	          {
                  GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                  SetVehicleParamsEx(vid,engine,lights,VEHICLE_PARAMS_OFF,doors,bonnet,boot,objective);
				  alarm = 0;
			  }
	       }
	       else if (alarm == 0) // check if engine off
	       {
			  if(vid != INVALID_VEHICLE_ID)
			  {
                 GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                 SetVehicleParamsEx(vid,engine,lights,VEHICLE_PARAMS_ON,doors,bonnet,boot,objective);
                 alarm = 1;
			  }
	       }
		}
		return 1;
	}


COMMAND:hood(playerid,params[])
	{
	    if(IsPlayerConnected(playerid))
     {
           new vid = GetPlayerVehicleID(playerid);
		   if (bonnet == 1) // check if engine ON
	       {
			  if(vid != INVALID_VEHICLE_ID)
	          {
                  GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                  SetVehicleParamsEx(vid,engine,lights,alarm,doors,VEHICLE_PARAMS_OFF,boot,objective);
				  bonnet = 0;
			  }
	       }
	       else if (bonnet == 0) // check if engine off
	       {
			  if(vid != INVALID_VEHICLE_ID)
			  {
                 GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                 SetVehicleParamsEx(vid,engine,lights,alarm,doors,VEHICLE_PARAMS_ON,boot,objective);
                 bonnet = 1;
			  }
	       }
		}
		return 1;
	}

COMMAND:boot(playerid,params[])
	{
	    if(IsPlayerConnected(playerid))
     {
           new vid = GetPlayerVehicleID(playerid);
		   if (boot == 1) // check if engine ON
	       {
			  if(vid != INVALID_VEHICLE_ID)
	          {
                  GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                  SetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,VEHICLE_PARAMS_OFF,objective);
				  boot = 0;
			  }
	       }
	       else if (boot == 0) // check if engine off
	       {
			  if(vid != INVALID_VEHICLE_ID)
			  {
                 GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                 SetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,VEHICLE_PARAMS_ON,objective);
                 boot = 1;
			  }
	       }
		}
		return 1;
	}

COMMAND:highlight(playerid,params[])
	{
	    if(IsPlayerConnected(playerid))
     {
           new vid = GetPlayerVehicleID(playerid);
		   if (objective == 1) // check if engine ON
	       {
			  if(vid != INVALID_VEHICLE_ID)
	          {
                  GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                  SetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,VEHICLE_PARAMS_OFF);
				  objective = 0;
			  }
	       }
	       else if (objective == 0) // check if engine off
	       {
			  if(vid != INVALID_VEHICLE_ID)
			  {
                 GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                 SetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,VEHICLE_PARAMS_ON);
                 objective = 1;
			  }
	       }
		}
		return 1;
	}
Reply
#2

What i'm wondering is why you are checking to see if it's an invalid vehicle id... It can't be invalid if the player is in it, if it was invalid the getplayervehicleid wouldn't work because there is no vehicle.

As for your question I would suggest only using GetVehicleParamsEx only once outside of ur engine checks. When you set the engine to on it will change the params outside your engine check to 1 then you can use ur engine check to turn it off.

If u don't understand tell me and I'll post the code for you.
Reply
#3

if (engine != 1) and else. 1 is on, 0 and -1 is off. Remember to define ManualVehicleEngineLights();
Reply
#4

ok thanks gonna check now
Reply
#5

Well what I mean.
pawn Код:
COMMAND:engine(playerid, params[])
{
    if(!IsPlayerConnected(playerid)) return false;
    new vid, engine, lights, alarm, doors, bonnet, objective);
    vid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine != 1)
    {    
        // Turning on the engine
        SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet,boot,objective);
    }
    else
    {
        // Shutting down the engine
        SetVehicleParamsEx(vid,0,lights,alarm,doors,bonnet,boot,objective);
    }
    return true;
}
Reply
#6

ok all te cmds work now but one problem. i have to enter a command twice before it does its job. for eg:
when i enter /lights the lights turn on but when type it once again it doesnt do anything but when i do it once again it turns the lights off. (its not only with lights.)
Reply
#7

Regarding the lights they behave differently depending on the world time. As I stated earlier (Params: 1 = On, 0 = Off, -1 = Default).
Reply
#8

but its not only with lights =(
Reply
#9

But the engine works like it should?
Reply
#10

everything works but only thing is i have to enter the cmd twice to get them work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)