Vehicle is turned off via script -
uTorrent - 06.05.2014
I created the command / engine to adjust the switching on and off of each individual vehicle. The problem is one. As soon as I get in the vehicle, the engine is off, but if I type the command / engine, it gives me the message "engine shutdown" - as if it was on, even if in reality it is not.
I think I need to set a variable that identifies each vehicle that spawns as off.. the problem is that I do not know where to put this variable.
code:
PHP код:
public OnGameModeInit()
{
ManualVehicleEngineAndLights();
public OnPlayerCommandText(playerid, cmdtext[])
{
COMMAND:engine(playerid, params[])
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new str[128];
new vehicle = GetPlayerVehicleID(playerid);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
{
SetVehicleParamsEx(vehicle,1,1,alarm,doors,bonnet,boot,objective);
format(str, sizeof(str), "* %s accende il motore del veicolo", GetICName(playerid));
SendNearByMessage(playerid, ACTION_COLOR, str, 10);
}
else
{
SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
format(str, sizeof(str), "* %s spegne il motore del veicolo", GetICName(playerid)); /// this is the message that appears the first time I type /engine, even if the vehicle is turned off
SendNearByMessage(playerid, ACTION_COLOR, str, 10);
}
}
return 1;
}
Re: Vehicle is turned off via script -
Konstantinos - 06.05.2014
Don't use OnPlayerCommandText at all if you use ZCMD. The callbacks should be out of any callback.
You get the vehicle's parameter but you never check whether the engine is off or not.
pawn Код:
COMMAND:engine(playerid, params[])
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new str[60], vehicle = GetPlayerVehicleID(playerid);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
if (!engine)
{
SetVehicleParamsEx(vehicle,1,1,alarm,doors,bonnet,boot,objective);
format(str, sizeof(str), "* %s accende il motore del veicolo", GetICName(playerid));
SendNearByMessage(playerid, ACTION_COLOR, str, 10);
}
else
{
SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
format(str, sizeof(str), "* %s spegne il motore del veicolo", GetICName(playerid)); /// this is the message that appears the first time I type /engine, even if the vehicle is turned off
SendNearByMessage(playerid, ACTION_COLOR, str, 10);
}
}
return 1;
}
Re: Vehicle is turned off via script -
uTorrent - 06.05.2014
Quote:
Originally Posted by Konstantinos
Don't use OnPlayerCommandText at all if you use ZCMD. The callbacks should be out of any callback.
You get the vehicle's parameter but you never check whether the engine is off or not.
pawn Код:
COMMAND:engine(playerid, params[]) { if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) { new str[60], vehicle = GetPlayerVehicleID(playerid); new engine,lights,alarm,doors,bonnet,boot,objective; GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective); if (!engine) { SetVehicleParamsEx(vehicle,1,1,alarm,doors,bonnet,boot,objective); format(str, sizeof(str), "* %s accende il motore del veicolo", GetICName(playerid)); SendNearByMessage(playerid, ACTION_COLOR, str, 10); } else { SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective); format(str, sizeof(str), "* %s spegne il motore del veicolo", GetICName(playerid)); /// this is the message that appears the first time I type /engine, even if the vehicle is turned off SendNearByMessage(playerid, ACTION_COLOR, str, 10); } } return 1; }
|
same problem.
As soon as I get on a vehicle and type /engine, it gives me the message to turn off the engine, and to turn on the engine, i have to retype the command /engine.
It does not recognize that each vehicle spawns just be turned off with the command /engine
Re: Vehicle is turned off via script -
Konstantinos - 06.05.2014
So GetVehicleParamsEx gives "engine" as on. When you create a vehicle, set the engine (SetVehicleParamsEx) to 0.
Re: Vehicle is turned off via script -
Vince - 06.05.2014
I'm pretty sure that the function simply returns -1 for a value if it's not been set before. However, in Pawn everything that isn't exactly 0 is evaluated as "true". Therefore, -1 is also "true". It should probably be evaluated as:
Re: Vehicle is turned off via script -
uTorrent - 06.05.2014
Quote:
Originally Posted by Vince
I'm pretty sure that the function simply returns -1 for a value if it's not been set before. However, in Pawn everything that isn't exactly 0 is evaluated as "true". Therefore, -1 is also "true". It should probably be evaluated as:
|
yeah! problem solved, thank you very much.