[HELP]Engine Breaking System
#1

Using this system https://sampforum.blast.hk/showthread.php?tid=152774

I want to do when the car has 300 hp car engine to stop, do not want him out of the car or give him freeze.

What I've tried so far:

pawn Код:
forward EngineBreak();
public EngineBreak()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
        if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            new Float:TempCarHealth;
            GetVehicleHealth(GetPlayerVehicleID(i), TempCarHealth);
            if(TempCarHealth <= 300.0)
            {
            new engine,lights,alarm,doors,bonnet,boot,objective;
            GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
             if(engine == 1)
             {
             if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                {
                //SetVehicleHealth(GetPlayerVehicleID(i), 350.0);
                SendClientMessage(i, COLOR_RED, "The vehicle`s engine was broken. Call a mechanic");
                //RemovePlayerFromVehicle(i);
                TogglePlayerControllable(i, 0);
                    }
                 }
             }
         }
    }
}
Sorry for my english
Reply
#2

Maybe you should use a timer or OnPlayerUpdate Function to check..

pawn Код:
// Under OnGameModeInit
public OnGameModeInit()
{
      SetTimer("EngineBreak", 100, true); // Set a timer for "EngineBreak" function, 100 is fast more than 1 second, true to keep it restarting , not only one time.
      return 1;
}
EDIT: and you're doing it incorrectly, you looped inside players, and using i in SetVehicleParamsEx, so that you are using player instead of vehicle. to solve do:
pawn Код:
new veh = GetPlayerVehicleID(i);
If didn't work,
SetVehicleParamEx(veh ,0,lights,alarm,doors,bonnet,boot,objective);  // 0 turned off the engine
Reply
#3

Not working
Reply
#4

pawn Код:
forward EngineBreak();
public EngineBreak()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
        if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            new Float:TempCarHealth;
            GetVehicleHealth(GetPlayerVehicleID(i), TempCarHealth);
            if(TempCarHealth <= 300.0)
            {
                new engine,lights,alarm,doors,bonnet,boot,objective;
                GetVehicleParamsEx(GetVehicleID(i),engine,lights,alarm,doors,bonnet,boot,objective);
                SetVehicleParamEx(GetVehicleID(i) ,0,lights,alarm,doors,bonnet,boot,objective);  // 0 turned off the engine
                SendClientMessage(i, COLOR_RED, "The vehicle`s engine was broken. Call a mechanic");
                TogglePlayerControllable(i, 0); // player wont be able to move ,but you shout down the engine anyway
             }
         }
    }
}

//And add this  next line under ongamemodeinit somwhere
SetTimer("EngineBreak", 4000, false);
Just sayng tho
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
Is useless to veryfy if is connected AND is in any vehicle ,just to check if he is the driver , he cant be the driver unless he is connected and is in a vehicle .
Reply
#5

pawn Код:
C:\Documents and Settings\Administrator\Desktop\New Begin\gamemodes\rpg.pwn(20757) : error 017: undefined symbol "GetVehicleID"
C:\Documents and Settings\Administrator\Desktop\New Begin\gamemodes\rpg.pwn(20758) : error 017: undefined symbol "SetVehicleParamEx"


2 Errors.
Reply
#6

HELP ?
Reply
#7

SetVehicleParamsEx not SetVehicleParamEx, you missed the s, and it's GetPlayerVehicleID, not getvehicleid
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)