cmd:car ! help !
#1

Hey I got this cmd on my script , I want to make you can instead /car engine just do /engine... To make another CMD to just turn on the engine , Here's the code , Somone can post the new code of the cmd : engine ?> Ty.




Код:
CMD:car(playerid, params[])
{
	if(isnull(params))
	{
		SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /car [name]");
		SendClientMessageEx(playerid, COLOR_GREY, "Available names: Status, Engine, Lights, Trunk, Hood, Fuel");
		return 1;
	}
	if(strcmp(params, "engine", true) == 0 && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		new engine,lights,alarm,doors,bonnet,boot,objective,vehicleid;
		new string[128];
		vehicleid = GetPlayerVehicleID(playerid);
		if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
		GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
		if(engine == VEHICLE_PARAMS_ON)
		{
			SetVehicleEngine(vehicleid, playerid);
		}
		else if((engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
		{
			   SendClientMessageEx(playerid, COLOR_WHITE, "Vehicle engine starting, please wait...");
			   new rand = random(4);
		       if(rand == 0)
			   {
				   SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
				   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine started");
		      	   format(string, sizeof(string), "* %s has started his vehicle's engine",  GetPlayerNameEx(playerid));
		 		   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
		       }
			   if(rand == 1)
			   {
				   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine failed to start");
				   format(string, sizeof(string), "* %s struggles to start the engine but fails",  GetPlayerNameEx(playerid));
		 		   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			   }
		       if(rand == 2)
			   {
				   SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
				   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine started");
				   format(string, sizeof(string), "* %s has started his vehicle's engine",  GetPlayerNameEx(playerid));
		   		   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			   }
			   if(rand == 3)
			   {
				   SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
				   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine started");
		           format(string, sizeof(string), "* %s has started his vehicle's engine",  GetPlayerNameEx(playerid));
		 		   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			   }
		}
	}
	else if(strcmp(params, "lights", true) == 0 && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		new vehicleid = GetPlayerVehicleID(playerid);
		if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
		SetVehicleLights(vehicleid, playerid);
	}
	else if(strcmp(params, "hood", true) == 0 && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			new vehicleid = GetPlayerVehicleID(playerid);
			if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510 || IsAPlane(vehicleid) || IsABike(vehicleid))
			{
				return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
			}
			SetVehicleHood(vehicleid, playerid);
		}
		else if(!IsPlayerInAnyVehicle(playerid))
		{
			new closestcar = GetClosestCar(playerid);
			if(IsPlayerInRangeOfVehicle(playerid, closestcar, 5.0))
			{
				if(GetVehicleModel(closestcar) == 481 || GetVehicleModel(closestcar) == 509 || GetVehicleModel(closestcar) == 510 || IsAPlane(closestcar) || IsABike(closestcar))
				{
					return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used on this vehicle.");
				}
				SetVehicleHood(closestcar, playerid);
			}
		}
	}
	else if(strcmp(params, "trunk", true) == 0)
	{
		if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			new vehicleid = GetPlayerVehicleID(playerid);
			if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510)
			{
				return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
			}
			SetVehicleTrunk(vehicleid, playerid);
		}
		else if(!IsPlayerInAnyVehicle(playerid))
		{
			new closestcar = GetClosestCar(playerid);
			if(IsPlayerInRangeOfVehicle(playerid, closestcar, 5.0))
			{
				if(GetVehicleModel(closestcar) == 481 || GetVehicleModel(closestcar) == 509 || GetVehicleModel(closestcar) == 510)
				{
					return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used on this vehicle.");
				}
				SetVehicleTrunk(closestcar, playerid);
			}
		}
	}
	else if(strcmp(params, "fuel", true) == 0 && IsPlayerInAnyVehicle(playerid))
	{
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 481 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
		if(GetPVarInt(playerid, "fuelonoff") == 0)
		{
			SendClientMessageEx(playerid, COLOR_WHITE, "You have turned on the fuel indicator (green bar).");
			SetPVarInt(playerid, "fuelonoff", 1);
			FuelBar[playerid] = CreateProgressBar(548.00, 26.00, 57.50, 3.20, 866792447, 100.0);
			textdrawscount++;
			SetProgressBarValue(FuelBar[playerid], VehicleFuel[GetPlayerVehicleID(playerid)]);
			ShowProgressBarForPlayer(playerid, FuelBar[playerid]);
		}
		else
		{
			SendClientMessageEx(playerid, COLOR_WHITE, "You have turned off the fuel indicator (green bar).");
			SetPVarInt(playerid, "fuelonoff", 0);
			DestroyProgressBar(FuelBar[playerid]);
			textdrawscount--;
			FuelBar[playerid] = INVALID_BAR_ID;
		}
	}
	else if(strcmp(params, "status", true) == 0)
	{
		if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			new vehicleid = GetPlayerVehicleID(playerid);
			new engine,lights,alarm,doors,bonnet,boot,objective,enginestatus[4],lightstatus[4], string[48];
			GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
			if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
			if(engine != VEHICLE_PARAMS_ON) format(enginestatus, sizeof(enginestatus), "OFF");
			else format(enginestatus, sizeof(enginestatus), "ON");
			if(lights != VEHICLE_PARAMS_ON) format(lightstatus, sizeof(lightstatus), "OFF");
			else format(lightstatus, sizeof(lightstatus), "ON");
			format(string, sizeof(string), "Engine: %s | Lights: %s | Fuel: %.2f.",enginestatus,lightstatus,VehicleFuel[vehicleid]);
			SendClientMessageEx(playerid, COLOR_WHITE, string);
		}
	}
	return 1;
}
Reply
#2

use a variables much better.
Reply
#3

CMD:engine(playerid, params[])
{
return cmd_carengine(playerid, params);
}
But switch the cmd /car engine to /carengine.
Reply
#4

Quote:
Originally Posted by NoahF
Посмотреть сообщение
CMD:engine(playerid, params[])
{
return cmd_carengine(playerid, params);
}
But switch the cmd /car engine to /carengine.
Good but If I'll make it /carengine What should I do with the option's : /car lights , /car fuel ... ?
Reply
#5

Change them so that there is no space between the cmd and it's params, then just change the retun cmd_carengine(playerid, params); to the name of your command.
For example, if you want to add another thing to /car lights, it would be:

CMD:lights(playerid, params[])
{
return cmd_carlights(playerid, params);
}
Just copy and paste this example and change it for all your commands.
Reply
#6

Quote:
Originally Posted by NoahF
Посмотреть сообщение
Change them so that there is no space between the cmd and it's params, then just change the retun cmd_carengine(playerid, params); to the name of your command.
For example, if you want to add another thing to /car lights, it would be:

CMD:lights(playerid, params[])
{
return cmd_carlights(playerid, params);
}
Just copy and paste this example and change it for all your commands.

Man Can I just make an CMD of /engine and we've done ? Cause that's too much complecated...
Reply
#7

It's really not complicated.. But I guess you could just change the main command to /engine.
Reply
#8

Ok ty for you try help but I didnt succeed if you could just add all the cmd's in code here that's was help me more but ty . . .
Reply
#9

Here are the commands.
/engine
pawn Код:
CMD:engine(playerid, params[])
{
new engine,lights,alarm,doors,bonnet,boot,objective,vehicleid;
        new string[128];
        vehicleid = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
        GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
        if(engine == VEHICLE_PARAMS_ON)
        {
            SetVehicleEngine(vehicleid, playerid);
        }
        else if((engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
        {
               SendClientMessageEx(playerid, COLOR_WHITE, "Vehicle engine starting, please wait...");
               new rand = random(4);
               if(rand == 0)
               {
                   SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
                   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine started");
                   format(string, sizeof(string), "* %s has started his vehicle's engine",  GetPlayerNameEx(playerid));
                   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
               }
               if(rand == 1)
               {
                   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine failed to start");
                   format(string, sizeof(string), "* %s struggles to start the engine but fails",  GetPlayerNameEx(playerid));
                   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
               }
               if(rand == 2)
               {
                   SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
                   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine started");
                   format(string, sizeof(string), "* %s has started his vehicle's engine",  GetPlayerNameEx(playerid));
                   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
               }
               if(rand == 3)
               {
                   SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
                   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine started");
                   format(string, sizeof(string), "* %s has started his vehicle's engine",  GetPlayerNameEx(playerid));
                   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
               }
        }
return 1;
}
/lights
pawn Код:
CMD:lights(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
        SetVehicleLights(vehicleid, playerid);
return 1;
}
/hood
pawn Код:
CMD:hood(playerid, params[])
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510 || IsAPlane(vehicleid) || IsABike(vehicleid))
            {
                return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
            }
            SetVehicleHood(vehicleid, playerid);
        }
        else if(!IsPlayerInAnyVehicle(playerid))
        {
            new closestcar = GetClosestCar(playerid);
            if(IsPlayerInRangeOfVehicle(playerid, closestcar, 5.0))
            {
                if(GetVehicleModel(closestcar) == 481 || GetVehicleModel(closestcar) == 509 || GetVehicleModel(closestcar) == 510 || IsAPlane(closestcar) || IsABike(closestcar))
                {
                    return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used on this vehicle.");
                }
                SetVehicleHood(closestcar, playerid);
            }
        }
return 1;
}
/trunk
pawn Код:
CMD:trunk(playerid, params[])
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510)
            {
                return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
            }
            SetVehicleTrunk(vehicleid, playerid);
        }
        else if(!IsPlayerInAnyVehicle(playerid))
        {
            new closestcar = GetClosestCar(playerid);
            if(IsPlayerInRangeOfVehicle(playerid, closestcar, 5.0))
            {
                if(GetVehicleModel(closestcar) == 481 || GetVehicleModel(closestcar) == 509 || GetVehicleModel(closestcar) == 510)
                {
                    return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used on this vehicle.");
                }
                SetVehicleTrunk(closestcar, playerid);
            }
        }
return 1;
}
/fuel
pawn Код:
CMD:fuel(playerid, paramsp[])
{
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 481 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
        if(GetPVarInt(playerid, "fuelonoff") == 0)
        {
            SendClientMessageEx(playerid, COLOR_WHITE, "You have turned on the fuel indicator (green bar).");
            SetPVarInt(playerid, "fuelonoff", 1);
            FuelBar[playerid] = CreateProgressBar(548.00, 26.00, 57.50, 3.20, 866792447, 100.0);
            textdrawscount++;
            SetProgressBarValue(FuelBar[playerid], VehicleFuel[GetPlayerVehicleID(playerid)]);
            ShowProgressBarForPlayer(playerid, FuelBar[playerid]);
        }
        else
        {
            SendClientMessageEx(playerid, COLOR_WHITE, "You have turned off the fuel indicator (green bar).");
            SetPVarInt(playerid, "fuelonoff", 0);
            DestroyProgressBar(FuelBar[playerid]);
            textdrawscount--;
            FuelBar[playerid] = INVALID_BAR_ID;
        }
return 1;
}
/status
pawn Код:
CMD:status(playerid, params[])
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            new engine,lights,alarm,doors,bonnet,boot,objective,enginestatus[4],lightstatus[4], string[48];
            GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
            if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
            if(engine != VEHICLE_PARAMS_ON) format(enginestatus, sizeof(enginestatus), "OFF");
            else format(enginestatus, sizeof(enginestatus), "ON");
            if(lights != VEHICLE_PARAMS_ON) format(lightstatus, sizeof(lightstatus), "OFF");
            else format(lightstatus, sizeof(lightstatus), "ON");
            format(string, sizeof(string), "Engine: %s | Lights: %s | Fuel: %.2f.",enginestatus,lightstatus,VehicleFuel[vehicleid]);
            SendClientMessageEx(playerid, COLOR_WHITE, string);
        }
return 1;
}
Please fix the loose indentations yourself..I didn't script this in an editor so i couldn't indent it properly..
Reply
#10

TYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)