Using timers
#1

I am using timers in an auto repair script and am wondering if it is best to have a timer running constantly presuming there will be at least 1 player in a car at all times?
Reply
#2

loop players
IsPlayerInVehicle
GetVehicleHealth

if less than the lowest health you want,

SetVehicleHealth



Put them in a timer and that should do it
Reply
#3

Or map it to a key:
pawn Код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
      new vehicleid = GetPlayerVehicleID(playerid);
      if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
      {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
          RepairVehicle(vehicleid);
          SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
          return 1;
            }
            if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
            {
                SendClientMessage(playerid,COLOR_RED,"You're not the driver of this vehicle!");
                return 1;
            }
            if(IsPlayerInAnyVehicle(playerid) != PLAYER_STATE_DRIVER )
            {
                SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!");
                return 1;
            }
        }
    }
}
Although the "You're not in a vehicle" bit is broken, no idea why :S

Easiest way to do it IMO
Reply
#4

He wants a script that autorepairs without the need for a key press for stunt servers etc

Also biltong, try this

pawn Код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
  if(IsPlayerInAnyVehicle(playerid))
  {
    new vehicleid = GetPlayerVehicleID(playerid);
    if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
    {
      if( !IsPlayerInAnyVehicle ( playerid ) )
      {
        SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!");
        return 1;
      }

      if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
      {
        RepairVehicle(vehicleid);
        SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
        return 1;
      }
     
      if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
      {
        SendClientMessage(playerid,COLOR_RED,"You're not the driver of this vehicle!");
        return 1;
      }
    }
  }

  return 1;
}
Reply
#5

Thank you for your help.
Reply
#6

Quote:
Originally Posted by WrathOfGenesis
He wants a script that autorepairs without the need for a key press for stunt servers etc

Also biltong, try this

pawn Код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
  if(IsPlayerInAnyVehicle(playerid))
  {
    new vehicleid = GetPlayerVehicleID(playerid);
    if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
    {
      if( !IsPlayerInAnyVehicle ( playerid ) )
      {
        SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!");
        return 1;
      }

      if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
      {
        RepairVehicle(vehicleid);
        SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
        return 1;
      }
     
      if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
      {
        SendClientMessage(playerid,COLOR_RED,"You're not the driver of this vehicle!");
        return 1;
      }
    }
  }

  return 1;
}
Yeah thanks, I deserve a facepalm, I used IsPlayerInAnyVehicle to chek the player state -.-
Changed to yours, about to test
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)