[FilterScript] Vehicle Damage Enabler [Alpha v1.0]
#13

Looping through all players each time someone shoots an unoccupied vehicle is redudant and inefficent. Instead of looping through, you can use a variable and update it each time the driver enters/exits the vehicle(OnPlayerStateChange is great for this).

Example:
Code:
new
     vehicleDriver[MAX_VEHICLES] = INVALID_PLAYER_ID,
     playerCurVeh[MAX_PLAYERS] = INVALID_VEHICLE_ID;

public OnPlayerStateChange(playerid, newstate, oldstate)
{
        if(newstate == PLAYER_STATE_DRIVER) {
                 if(GetPlayerVehicleID(playerid) != INVALID_VEHICLE_ID) {
                          vehicleDriver[GetPlayerVehicleID(playerid)] = playerid;
                          playerCurVeh[playerid] = GetPlayerVehicleID(playerid);
                 }
        } else if(oldstate == PLAYER_STATE_DRIVER) {
                 if(playerCurVeh[playerid] != INVALID_VEHICLE_ID) {
                           if(vehicleDriver[playerCurVeh[playerid]] == playerid) vehicleDriver[playerCurVeh[playerid]] = INVALID_PLAYER_ID;
                 playerCurVeh[playerid] = INVALID_VEHICLE_ID;
        }

        return 1;
}

public OnPlayerDisconnect(playerid, reason) {
      if(playerCurVeh[playerid] != INVALID_PLAYER_ID)
              if(vehicleDriver[playerCurVeh[playerid]] == playerid) vehicleDriver[playerCurVeh[playerid]] = INVALID_PLAYER_ID;

      return 1;
}

DriverAvailable(vehicleid)
      return (vehicleDriver[vehicleid] == INVALID_PLAYER_ID) ? (false) : (true);
Also instead of subtracting a predefined value again and again you can just use an array. Example:
Code:
new AirDamage[] =
{
	{0.0},  // 0
	{0.0},  // 1
	{0.0},  // 2
	{0.0},  // 3
	{0.0},  // 4
	{0.0},  // 5
	{0.0},  // 6
	{0.0},  // 7
	{0.0},  // 8
	{0.0},  // 9
	{0.0},  // 10
	{0.0},  // 11
	{0.0},  // 12
	{0.0},  // 13
	{0.0},  // 14
	{0.0},  // 15
	{0.0},  // 16
	{0.0},  // 17
	{0.0},  // 18
	{0.0},  // 19
	{0.0},  // 20
	{0.0},  // 21
	{10.0}, // 22
	{16.0}, // 23
	{56.0}, // 24
	{60.0}, // 25
	{60.0}, // 26
	{48.0}, // 27
	{8.0},  // 28
	{10.0}, // 29
	{12.0}, // 30
	{12.0}, // 31
	{8.0}   // 32
	{30.0}, // 33
	{50.0}, // 34
	{0.0},  // 35
	{0.0},  // 36
	{0.0},  // 37
	{56.0}, // 38
};

...
SetVehicleHealth(hitid, vHealth-AirDamage[weaponid]);
Reply


Messages In This Thread
Vehicle Damage Enabler [Alpha v2.1] - by Salvator - 03.03.2016, 22:34
Re: Vehicle Damage Enabler [Alpha v1.0] - by AzaMx - 03.03.2016, 22:41
Re: Vehicle Damage Enabler [Alpha v1.0] - by Salvator - 03.03.2016, 23:25
Re: Vehicle Damage Enabler [Alpha v1.0] - by SeanGarnier - 04.03.2016, 00:47
Re: Vehicle Damage Enabler [Alpha v1.0] - by Crayder - 04.03.2016, 02:50
Re: Vehicle Damage Enabler [Alpha v1.0] - by illuminati2 - 04.03.2016, 07:13
Re: Vehicle Damage Enabler [Alpha v1.0] - by Salvator - 04.03.2016, 08:46
Re: Vehicle Damage Enabler [Alpha v1.0] - by illuminati2 - 04.03.2016, 08:57
Re: Vehicle Damage Enabler [Alpha v1.0] - by Kasis - 04.03.2016, 09:03
Re: Vehicle Damage Enabler [Alpha v1.0] - by Salvator - 04.03.2016, 11:05
New update Alpha v2.0 - by Salvator - 05.03.2016, 16:55
Re: Vehicle Damage Enabler [Alpha v1.0] - by wampiros6 - 05.03.2016, 17:08
Re: Vehicle Damage Enabler [Alpha v1.0] - by Abagail - 05.03.2016, 18:03
Re: Vehicle Damage Enabler [Alpha v1.0] - by Salvator - 05.03.2016, 18:58
Re: Vehicle Damage Enabler [Alpha v1.0] - by OmegaKiller72 - 05.03.2016, 21:54
Re: Vehicle Damage Enabler [Alpha v1.0] - by Crayder - 05.03.2016, 21:59
Re: Vehicle Damage Enabler [Alpha v1.0] - by Salvator - 05.03.2016, 23:27
Re: Vehicle Damage Enabler [Alpha v1.0] - by Crayder - 06.03.2016, 03:25
Re: Vehicle Damage Enabler [Alpha v1.0] - by Salvator - 06.03.2016, 14:01
New update Alpha 2.1 - by Salvator - 06.03.2016, 17:19

Forum Jump:


Users browsing this thread: 5 Guest(s)