Vehicle is turned off via script
#1

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(playeridcmdtext[])
{
COMMAND:engine(playeridparams[])
{
   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(strsizeof(str), "* %s accende il motore del veicolo"GetICName(playerid));
  
SendNearByMessage(playeridACTION_COLORstr10);
}
else
{
  
SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
  
format(strsizeof(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(playeridACTION_COLORstr10);
}
}
return 
1;

Reply
#2

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

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
Reply
#4

So GetVehicleParamsEx gives "engine" as on. When you create a vehicle, set the engine (SetVehicleParamsEx) to 0.
Reply
#5

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:
pawn Код:
if(engine != 1)
Reply
#6

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:
pawn Код:
if(engine != 1)
yeah! problem solved, thank you very much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)