Vehicle Damage
#1

Hey guys!

Well i'm making a thing for the Vehicle damage so when it gets under 20% you get a message saying that you can't drive this car anymore.
But i can't get that to work , so anyone know how i can do that , i'm using
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
}
So it get all players.

Would apreciate help!

Cheers / Jax
Reply
#2

pawn Код:
forward VehicleHealthTimer();
public OnGameModeInit()
{
  SetTimer("VehicleHealthTimer",5000,1);
  return 1;
}

new Float:vhealth[MAX_VEHICLES];

public VehicleHealthTimer()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerInAnyVehicle(i))
    {
      GetVehicleHealth(GetPlayerVehicleID(i),vhealth[i]);
      if(vhealth[i] <= 200)
      {
        RemovePlayerFromVehicle(i);
        SendClientMessage(i,0xC60000FF,"You can't drive this car anymore!");
      }
    }
  }
}
Should work...
Reply
#3

Quote:
Originally Posted by CracKman
pawn Код:
forward VehicleHealthTimer();
public OnGameModeInit()
{
  SetTimer("VehicleHealthTimer",5000,1);
  return 1;
}

new Float:vhealth[MAX_VEHICLES];

public VehicleHealthTimer()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerInAnyVehicle(i))
    {
      GetVehicleHealth(GetPlayerVehicleID(i),vhealth[i]);
      if(vhealth[i] <= 200)
      {
        RemovePlayerFromVehicle(i);
        SendClientMessage(i,0xC60000FF,"You can't drive this car anymore!");
      }
    }
  }
}
Should work...
Doesn't work... it compiler but it doesn't work
Reply
#4

Why can't i get this working my code looks like:
pawn Код:
forward Damage();

new DamageTimer;
new Float: VHealth[MAX_VEHICLES];

public OnGameModeInit()
{
    DamageTimer = SetTimer("Damage", 1000, 1);
    return 1;
}

public OnGameModeExit()
{
    KillTimer("DamageTimer");
    return 1;
}

public Damage()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
      if(IsPlayerConnected(i))
      {
        if(IsPlayerInAnyVehicle(i))
        {
          if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
          {
                    new Text[255];
                    GetVehicleHealth(GetPlayerVehicleID(i), VHealth[i]);
                    format(Text, sizeof(Text), "%d", VHealth[i]);
                    SCM(i, COLOR_WHITE, Text);
                    if(VHealth[i] < 200)
                    {
                      SCM(i, COLOR_RED, "MAIN ERROR(Your car is too broken to drive!)");
                      RemovePlayerFromVehicle(i);
                    }
                }
            }
        }
    }
    return 1;
}
I think this should work but when i enter a vehicle i get that the health is a huge number :/
Reply
#5

Haha, I found the error.
pawn Код:
public VehicleHealthTimer()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerInAnyVehicle(i))
    {
      new vehid=GetPlayerVehicleID(i);
      GetVehicleHealth(vehid,vhealth[vehid]);
      if(vhealth[vehid] <= 200)
      {
        RemovePlayerFromVehicle(i);
        SendClientMessage(i,0xC60000FF,"You can't drive this car anymore!");
      }
    }
  }
}
Reply
#6

This works in filterscript

Код:
#include <a_samp>
new Float:vhealth[MAX_VEHICLES];
forward VehicleHealthTimer();

public OnFilterScriptInit()
{
  SetTimer("VehicleHealthTimer",1000,1);
  return 1;
}

public VehicleHealthTimer()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerInAnyVehicle(i))
    {
      GetVehicleHealth(GetPlayerVehicleID(i),vhealth[i]);
      if(vhealth[i] < 250)
      {
        RemovePlayerFromVehicle(i);
        SendClientMessage(i,0xC60000FF,"You can't drive this car anymore!");
      }
    }
  }
}
Reply
#7

The last one works fine, just changed some stuff in it! , Thanks for the help
Reply
#8

Use this one instead of having a constant timer running, With this it will start the timer when they get in a car and kill it when they get out

pawn Код:
// At the top of your script
new CarDamageTimer[MAX_PLAYERS];
forward CarDamage(playerid);

// At the end of your script
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {  
        CarDamageTimer[playerid] = SetTimerEx("CarDamage", 1000, 1, "i", playerid);
           return 1;
     }
     if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
     {
           KillTimer(CarDamageTimer[playerid]);
           return 1;
     }
     return 1;
}

public CarDamage(playerid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new vehicleid;
        new Float:vehhealth;
        vehicleid = GetPlayerVehicleID(playerid);
        GetVehicleHealth(vehicleid, vehhealth);
        if(vehhealth <= 299)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_LIGHTGREEN, "Status: You car has stalled and wont start back up");
            return 1;
        }
    }
    return 1;
}
Reply
#9

First off all the Helth ~200 is when car is burning bether use if vehicel helth is 450
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)