PDA

View Full Version : /engine command


LiamM
19/02/2011, 09:05 PM
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.

PowerPC603
19/02/2011, 09:50 PM
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.

LiamM
19/02/2011, 11:04 PM
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;
}

PowerPC603
19/02/2011, 11:52 PM
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.

LiamM
20/02/2011, 12:47 AM
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


#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;
}

LiamM
20/02/2011, 09:49 PM
Any ideas? Anyone?

Gertin
21/02/2011, 04:36 PM
Try that :
public OnGameModeInit()
{
ManualVehicleEngineAndLights();

LiamM
22/02/2011, 09:50 PM
I have allready done this man :( Thanks for your help though

Hashski
22/02/2011, 11:40 PM
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;
}

LiamM
26/02/2011, 11:44 AM
Nothing, it gave a number of errors like argument mismatches and errors with Vid and vehicleid params. :/ thanks though

LiamM
28/02/2011, 05:04 PM
Anyone else? Much appreciated, I cant find a way around it

EDIT: Never mind after working on it for 2 hours straight I have managed to fix it :) If anyone would like the code if anyone else is stuck, just leave a comment and I will post it.

Riskyshot
10/09/2011, 12:29 AM
you know what i spent just about as much time trying to get it going for myself then i noticed the second page lmao the funniest part was that script was almost right


else if (PRESSED(KEY_SUBMISSION))
{
new engine,lights,alarm,doors,bonnet,boot,objective;
new vid = GetPlayerVehicleID(playerid);
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vid, 1, 1, alarm, doors, bonnet, boot, objective);
if (engine == 1)
{
SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
}
else if (engine == 0)
{
SetVehicleParamsEx(vid, 1, 1, alarm, doors, bonnet, boot, objective);
}
}

well im just happy i figured it out on my own & so far works 100%

BoyDenker
31/01/2012, 09:43 AM
LiamM can you post the code please? :D

Duck4coder
25/03/2014, 08:02 PM
I don't know if this is relevant, but I have a working one :D

//place at the top of gamemode
enum vData
{
bool:Engine
}
new Vehicle_Data[MAX_VEHICLES][vData];

//Place in OnGameModeInit
for(new i=0; i < MAX_VEHICLES; i++) Vehicle_Data[i][Engine] = true;

//actual command used zcmd to make this :D
CMD:engine(playerid, params[])
{
SendClientMessageToAll(WHITE, "Command called!");
new VehID = GetPlayerVehicleID(playerid),
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective;

GetVehicleParamsEx(VehID, engine, lights, alarm, doors, bonnet, boot, objective);
if(!Vehicle_Data[VehID][Engine])
{
SendClientMessageToAll(WHITE, "Command called! -- Engine is 1");
SetVehicleParamsEx(VehID, 1, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, GREEN, "Your engine has been turned on.");
Vehicle_Data[VehID][Engine] = true;
}
else
{
SendClientMessageToAll(WHITE, "Command called! -- Engine is 0");
SetVehicleParamsEx(VehID, 0, lights, alarm, doors, bonnet, boot, objective);
SCM(playerid, GREEN, "Your engine has been turned of.");
Vehicle_Data[VehID][Engine] = false;
}
return 1;
}