18.07.2012, 19:12
I'm trying to add some boxes to my speedometer. But I want to make it, that if that player isn't in a vehicle the box goes away.
This is what I have:
(The box used here, is for the textdraw: Damage)
So how can I make it that when he's out of the car, the box also disappears?
Kevin
This is what I have:
pawn Code:
if(vehicleid != 0)
{
TextDrawUseBox(Damage, 1);
TextDrawBoxColor(Damage, 0x00000033);
if(IsAFlyingVehiclee(vehicleid))
{
TextDrawUseBox(Damage, 0);
TextDrawHideForPlayer(playerid, APlayerData[playerid][SpeedometerText]);
TextDrawHideForPlayer(playerid, APlayerData[playerid][FuelGauge]);
TextDrawHideForPlayer(playerid, Damage);
}
else
{
TextDrawShowForPlayer(playerid, APlayerData[playerid][SpeedometerText]);
TextDrawShowForPlayer(playerid, APlayerData[playerid][FuelGauge]);
TextDrawShowForPlayer(playerid, Damage);
// Get the vehicles velocity
GetVehicleVelocity(vehicleid, speed_x, speed_y, speed_z);
// Calculate the speed (in kph)
final_speed = floatsqroot(((speed_x * speed_x) + (speed_y * speed_y)) + (speed_z * speed_z)) * 158.179;
// Convert the float value to an int value
final_speed_int = floatround(final_speed, floatround_round);
// Also save the speed for the player
APlayerData[playerid][PlayerSpeed] = final_speed_int;
// Setup the string to display for the player and display it
format(speed_string, 50, TXT_SpeedometerSpeed, final_speed_int);
TextDrawSetString(APlayerData[playerid][SpeedometerText], speed_string);
new Float:VehicleHealth;
GetVehicleHealth(vehicleid, VehicleHealth);
format(damage_string, 50, "Damage: %.0f%%", floatdiv(VehicleHealth, 10));
//%.0f will show float values with 0 decimal places. %% makes the per cent sign
TextDrawSetString(Damage, damage_string);
// Add the speed to the stats (this will be the meters driven in total)
APlayerData[playerid][StatsMetersDriven] = APlayerData[playerid][StatsMetersDriven] + (final_speed / 7.2);
// Check if the speed is above 10kph and the fuel of the vehicle isn't empty yet
if ((final_speed_int > 10) && (AVehicleData[vehicleid][Fuel] > 0))
AVehicleData[vehicleid][Fuel] = AVehicleData[vehicleid][Fuel] - 1; // Decrease the fuel for this vehicle every time the timer is run
// Construct the fuelgauge
if ((AVehicleData[vehicleid][Fuel] > 0) && (AVehicleData[vehicleid][Fuel] < 100000))
format(FuelStatus, 20, "~g~%s~r~%s", "|", "_________"); // Fuel is between 0% and 10% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 1)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 2)))
format(FuelStatus, 20, "~g~%s~r~%s", "||", "________"); // Fuel is between 10% and 20% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 2)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 3)))
format(FuelStatus, 20, "~g~%s~r~%s", "|||", "_______"); // Fuel is between 20% and 30% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 3)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 4)))
format(FuelStatus, 20, "~g~%s~r~%s", "||||", "______"); // Fuel is between 30% and 40% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 4)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 5)))
format(FuelStatus, 20, "~g~%s~r~%s", "|||||", "_____"); // Fuel is between 40% and 50% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 5)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 6)))
format(FuelStatus, 20, "~g~%s~r~%s", "||||||", "____"); // Fuel is between 50% and 60% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 6)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 7)))
format(FuelStatus, 20, "~g~%s~r~%s", "|||||||", "___"); // Fuel is between 60% and 70% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 7)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 8)))
format(FuelStatus, 20, "~g~%s~r~%s", "||||||||", "__"); // Fuel is between 70% and 80% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 8)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 9)))
format(FuelStatus, 20, "~g~%s~r~%s", "|||||||||", "_"); // Fuel is between 80% and 90% full
if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 9)) && (AVehicleData[vehicleid][Fuel] <= MaxFuel))
format(FuelStatus, 20, "~g~%s", "||||||||||"); // Fuel is between 90% and 100% full (all bars are green)
if (AVehicleData[vehicleid][Fuel] == 0)
format(FuelStatus, 20, "~r~%s", "||||||||||"); // Fuel is empty (all bars are red)
// Format the final fuel-gauge readout
format(FuelString, 50, TXT_SpeedometerFuel, FuelStatus);
// Display the fuel-gauge
TextDrawSetString(APlayerData[playerid][FuelGauge], FuelString);
// Check if the vehicle is out of fuel
if (AVehicleData[vehicleid][Fuel] == 0)
{
// Stop the engine and turn off the lights
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
}
// Check if the player is not in any plane or helicopter (those cannot be caught by speedcamera's)
if (IsVehicleAirVehicle(vehicleid) == 0)
if ((APlayerData[playerid][PlayerClass] == ClassBusDriver) || (APlayerData[playerid][PlayerClass] == ClassTruckDriver) || (APlayerData[playerid][PlayerClass] == ClassPilot) || (APlayerData[playerid][PlayerClass] == ClassMafia) || (APlayerData[playerid][PlayerClass] == ClassCourier) || (APlayerData[playerid][PlayerClass] == ClassAssistance) ||(APlayerData[playerid][PlayerClass] == ClassRoadWorker)) // Check if the player isn't speeding Cops and SRT shouldn't be able to get a speed ticket.
CheckPlayerSpeeding(playerid);
}
}
else
{
// If the player is not inside a vehicle, display an empty string (looks like the speedometer is gone)
TextDrawUseBox(Damage, 0);
TextDrawSetString(APlayerData[playerid][SpeedometerText], " ");
TextDrawSetString(APlayerData[playerid][FuelGauge], " ");
TextDrawSetString(Damage, " ");
// Set the speed of the player to 0
APlayerData[playerid][PlayerSpeed] = 0;
}
}
So how can I make it that when he's out of the car, the box also disappears?
Kevin