/engine command -
LiamM - 19.02.2011
Hey guys, well I know a lot of people code the /engineoff and /engineon to turn the engine on and off but I dont think its a very efficient way in doing it, as people can spam engineoff even when it is off..
I have attempted to code all of it in one command (/engine) So that if the engine is on, and you type /engine it turns it off. Problem is.. If you turn the /engine on and then leave the vehicle and go to a different vehicle and type /engine to turn the engine off, it says "You have turned your engine off", instead of on.
Reason why (I think) is because the bool im using (new bool:engineonoff = false) that changes from on to off on use of the command, But is there a way to detect if the vehicles engine is turned off when they use the command or if its turned on so that it turns the engine off or on according to what state the engine is in.
Thanks in advance.
Re: /engine command -
PowerPC603 - 19.02.2011
pawn Код:
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1 - engine, lights, alarm, doors, bonnet, boot, objective);
This code reads the status of the vehicle and toggles the engine on or off, based on the current status.
If the engine is on (engine = 1), the engine will be turned off.
If it's off (engine = 0), it will be turned on.
Re: /engine command -
LiamM - 19.02.2011
Thank you for your reply, I gave your suggestion a go but ended up the engine could be started but on typing the command again to turn it off returned nothing, not even the message saying "You have turned off your engine" Here is my code.
Код:
COMMAND:engine(playerid, params[])
{
new vid = GetPlayerVehicleID(playerid);
if(engine == 1)
{
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vid, 0,lights,alarm,doors,bonnet,boot,objective);
SCM(playerid, COLOR_GREEN, "You have turned off your vehicles engine.");
}
else if(engine == 0)
{
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, COLOR_GREEN, "You have turned on your vehicles engine.");
}
return 1;
}
Re: /engine command -
PowerPC603 - 19.02.2011
pawn Код:
COMMAND:engine(playerid, params[])
{
new engine, lights, alarm, doors, bonnet, boot, objective;
new vid = GetPlayerVehicleID(playerid);
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
if(engine == 1)
{
SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, COLOR_GREEN, "You have turned off your vehicles engine.");
}
else if(engine == 0)
{
SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, COLOR_GREEN, "You have turned on your vehicles engine.");
}
return 1;
}
Your variable "engine" was always 0 when you entered the command, as you didn't get the engine-status first by using GetVehicleParamsEx.
Re: /engine command -
LiamM - 20.02.2011
Quote:
Originally Posted by PowerPC603
pawn Код:
COMMAND:engine(playerid, params[]) { new engine, lights, alarm, doors, bonnet, boot, objective; new vid = GetPlayerVehicleID(playerid); GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
if(engine == 1) { SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, objective); SCM(playerid, COLOR_GREEN, "You have turned off your vehicles engine."); } else if(engine == 0) { SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective); SCM(playerid, COLOR_GREEN, "You have turned on your vehicles engine."); } return 1; }
Your variable "engine" was always 0 when you entered the command, as you didn't get the engine-status first by using GetVehicleParamsEx.
|
I have allready tried this and when I re tried it, it returned nothing for the vehicles. I could not turn on any vehicles engine, therefore all vehicles were un-moveable. I have these definitions to, I will show you my entire cmd + defines
pawn Код:
#define VEHICLE_PARAMS_UNSET -1
#define VEHICLE_PARAMS_OFF 0
#define VEHICLE_PARAMS_ON 1
COMMAND:engine(playerid, params[])
{
new engine, lights, alarm, doors, bonnet, boot, objective;
new vid = GetPlayerVehicleID(playerid);
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
if(engine == 1)
{
SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, COLOR_GREEN, "You have turned off your vehicles engine.");
}
else if(engine == 0)
{
SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, COLOR_GREEN, "You have turned on your vehicles engine.");
}
return 1;
}
Re: /engine command -
LiamM - 20.02.2011
Any ideas? Anyone?
Re: /engine command -
Gertin - 21.02.2011
Try that :
Quote:
public OnGameModeInit()
{
ManualVehicleEngineAndLights();
|
Re: /engine command -
LiamM - 22.02.2011
I have allready done this man
Thanks for your help though
Re: /engine command -
Hashski - 22.02.2011
Try this..
Код:
COMMAND:engine(playerid, params[])
{
new engine, lights, alarm, doors, bonnet, boot, objective;
new vid = GetPlayerVehicleID(playerid);
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
if(GetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective))
{
SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, COLOR_GREEN, "INFO: You have turned off your vehicles engine");
}
else if(GetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
{
SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, COLOR_GREEN, "INFO: You have turned on your vehicles engine");
engine == 0;
}
return 1;
}
Re: /engine command -
LiamM - 26.02.2011
Nothing, it gave a number of errors like argument mismatches and errors with Vid and vehicleid params. :/ thanks though