05.03.2016, 18:03
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:
Also instead of subtracting a predefined value again and again you can just use an array. Example:
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);
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]);