Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright 2014 Don Walt "Enforcer"
- // This work is distributed under the terms of the GNU General Public License
- //==============================================================================
- //
- // RealVehicle 1.0.1, Release Date 19-September-2014
- //
- //
- //
- //
- // RealVehicle Filterscript by Don_Walt "Enforcer"
- //
- //
- //
- //
- // This filterscript aims to give sa-mp vehicles
- // an enhanced feeling of realism, by implementing
- // an advanced fuel system and by providing
- // informational in game textdraws.
- //
- // Credits go to:
- // Don_Walt "Enforcer", for most of the code
- // Srdjan, for sections of code taken from "Realistic fuel system 1.0"
- // ev0lution, for the Quaternion Converter include
- // DANGER1979, for QuatToEuler function
- // JernejL, for the vector transformation function
- //
- //==============================================================================
- //------------------------------------------------------------------------------
- // basic includes
- //------------------------------------------------------------------------------
- #include <a_samp>
- #include "../include/gl_common.inc"
- //------------------------------------------------------------------------------
- // defines
- //------------------------------------------------------------------------------
- #define VEHTYPE_NONE 0
- #define VEHTYPE_SPORT 1
- #define VEHTYPE_COMMON 2
- #define VEHTYPE_OFFROAD 3
- #define VEHTYPE_TRUCK 4
- #define VEHTYPE_BIKE 5
- #define VEHTYPE_AIR 6
- #define VEHPROP_NONE 0
- #define VEHPROP_PUSH 1
- #define VEHPROP_ELECTRIC 2
- #define VEHPROP_PETROL 3
- #define VEHPROP_DIESEL 4
- #define VEHPROP_GASTURBINE 5
- #define VEHPROP_AVIATION 6
- #define FUELTYPE_NONE 0
- #define FUELTYPE_BATTERY 1
- #define FUELTYPE_REGULAR 2
- #define FUELTYPE_PREMIUM 3
- #define FUELTYPE_DIESEL 4
- #define FUELTYPE_AVIATION 5
- #define FUELPRICE_NONE 0.0
- #define FUELPRICE_BATTERY 0.5 // not yet implemented
- #define FUELPRICE_REGULAR 2.5 // price (in SA dollars) per litre of fuel
- #define FUELPRICE_PREMIUM 3.8
- #define FUELPRICE_DIESEL 4.2
- #define FUELPRICE_AVIATION 6.8
- #define REFUEL_RATE 0.5 // refuel at a rate of x Litres per 0.1 seconds
- #define REPAIR_RATE 0.5 // repair at a rate of x percent per 0.1 seconds
- #define REFUEL_COST 1.0 // fuel price multiplyer
- #define REPAIR_COST 2.0 // price (in SA dollars) per percent of repair
- #define COLOR_DEAD 0xAFAFAFAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_LIGHTGREEN 0x9ACD32AA
- #define COLOR_DEATH 0xAA3333AA
- #define COLOR_LIGHTBLUE 0x33CCFFAA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_ERROR 0xFF0000FF
- #define COLOR_PURPLE 0xC2A2DAAA
- #define COLOR_SERVER_MAIN_MSG 0xFFFFFFAA
- #define COLOR_SERVER_HELP_MSG 0x33CCFFAA
- #define COLOR_PRIVATE_MSG 0xFFFF00AA
- #define COLOR_GROUP 0xDAA520AA
- #define COLOR_ADMIN 0xFF40FFFF
- #define COLOR_PINK 0xFF40FFFF
- #define COLOR_DISPATCH 0x456EAF67
- #define COLOR_TEAM_LAW 0x000047B2AA
- #define COLOR_TEAM_DRIVER 0x00B800AA
- //------------------------------------------------------------------------------
- // custom includes
- //------------------------------------------------------------------------------
- /*
- *
- * Quaternion Converter
- * Allows simple conversion from quaternion angles (supplied by new SA-MP 0.3b functions) to yaw/pitch/roll
- *
- * NAME Quaternion Converter
- * AUTHOR ev0lution
- * FILE quaternion.inc
- * VERSION 1.0.0
- * LICENSE GNU General Public License (see below)
- * COPYRIGHT Copyright © 2010 ev0lution
- *
- * This file is part of Quaternion Converter.
- *
- * Quaternion Converter is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Quaternion Converter is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Quaternion Converter. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- stock QuaternionToYawPitchRoll(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:x,&Float:y,&Float:z) {
- x = atan2(2*((quat_x*quat_y)+(quat_w+quat_z)),(quat_w*quat_w)+(quat_x*quat_x)-(quat_y*quat_y)-(quat_z*quat_z));
- y = atan2(2*((quat_y*quat_z)+(quat_w*quat_x)),(quat_w*quat_w)-(quat_x*quat_x)-(quat_y*quat_y)+(quat_z*quat_z));
- z = asin(-2*((quat_x*quat_z)+(quat_w*quat_y)));
- return 1;
- }
- stock QuaternionGetRoll(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:roll) {
- roll = atan2(2*((quat_x*quat_y)+(quat_w+quat_z)),(quat_w*quat_w)+(quat_x*quat_x)-(quat_y*quat_y)-(quat_z*quat_z));
- return 1;
- }
- stock QuaternionGetPitch(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:pitch) {
- pitch = atan2(2*((quat_y*quat_z)+(quat_w*quat_x)),(quat_w*quat_w)-(quat_x*quat_x)-(quat_y*quat_y)+(quat_z*quat_z));
- return 1;
- }
- stock QuaternionGetYaw(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:yaw) {
- yaw = asin(-2*((quat_x*quat_z)+(quat_w*quat_y)));
- return 1;
- }
- // =============================================================================
- // =============================================================================
- // =============================================================================
- // code by DANGER1979, edited by Don Walt
- stock ConvertNonNormaQuatToEuler(Float: qw, Float: qx, Float:qy, Float:qz, &Float:heading, &Float:attitude, &Float:bank)
- {
- new Float: sqw = qw*qw;
- new Float: sqx = qx*qx;
- new Float: sqy = qy*qy;
- new Float: sqz = qz*qz;
- new Float: unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
- //åñëè normalised, - îäèí, â ïðîòèâíîì ñëó÷àå - ïîêàçàòåëü êîððåêöèè
- new Float: test = qx*qy + qz*qw;
- if (test > 0.499*unit)
- { // singularity at north pole - îñîáåííîñòü íà ñåâåðíîì ïîëþñå
- heading = 2*atan2(qx,qw);
- bank = 3.141592653/2;
- attitude = 0;
- return 1;
- }
- if (test < -0.499*unit)
- { // singularity at south pole - îñîáåííîñòü íà þæíîì ïîëþñå
- heading = -2*atan2(qx,qw);
- bank = -3.141592653/2;
- attitude = 0;
- return 1;
- }
- heading = atan2(2*qy*qw - 2*qx*qz, sqx - sqy - sqz + sqw);
- bank = asin(2*test/unit);
- attitude = atan2(2*qx*qw - 2*qy*qz, -sqx + sqy - sqz + sqw);
- return 1;
- }
- stock GetVehicleRotation(vehicleid, &Float:heading, &Float:attitude, &Float:bank)
- {
- new Float:quat_w, Float:quat_x, Float:quat_y, Float:quat_z;
- GetVehicleRotationQuat(vehicleid, quat_w, quat_x, quat_y, quat_z);
- ConvertNonNormaQuatToEuler(quat_w,quat_x, quat_z, quat_y, heading, attitude, bank);
- if(heading<0) heading += 360; // heading be from 0 to 360degrees clockwise
- attitude *= -1; // attitude be + for climb, - for descend, 0 for straight and level
- bank *= -1; // bank be + for roll to right, - for roll to left
- return 1;
- }
- // code by Don Walt
- // get the velocity and altitude for a vehicle
- stock getVehicleVelocity(vehicleid, &Float:actual, &Float:ground, &Float:heading, &Float:attitude, &Float:altitude, unitSpeed, unitAngle, unitAltitude)
- {
- // units; speed: kmh/mph, angle: mils/degrees, altitude: meters/feet (0/1 respectively)
- // get velocity in KM/H
- // ground/actual speed
- new Float:speed_x;
- new Float:speed_y;
- new Float:speed_z;
- GetVehicleVelocity(vehicleid, speed_x, speed_y, speed_z); // get the velocity for x y and z
- actual = floatsqroot( (speed_x*speed_x) + (speed_y*speed_y) + (speed_z*speed_z) ) * 180.00; // get the actual speed
- ground = floatsqroot( (speed_x*speed_x) + (speed_y*speed_y) ) * 180.00; // get the ground speed
- // 175 KM/H In LV Police Car at max speed
- // get the angles in degrees
- //new Float:heading;
- //new Float:attitude;
- new Float:bank;
- new Float:quat_w, Float:quat_x, Float:quat_y, Float:quat_z;
- GetVehicleRotationQuat(vehicleid, quat_w, quat_x, quat_y, quat_z);
- ConvertNonNormaQuatToEuler(quat_w,quat_x, quat_z, quat_y, heading, attitude, bank);
- if(heading<0) heading += 360; // heading be from 0 to 360degrees clockwise
- attitude *= -1; // attitude be + for climb, - for descend, 0 for straight and level
- bank *= -1; // bank be + for roll to right, - for roll to left
- // get the altitude in meters (samp uses meters as default unit)
- new Float:pos_x;
- new Float:pos_y;
- //new Float:pos_z;
- GetVehiclePos(vehicleid, pos_x, pos_y, altitude);
- // convert to the desired units as specified in "unitSpeed, unitAngle, unitAltitude"
- if(unitSpeed == 1){
- actual *= 0.621371; // km/h to mph scale factor
- ground *= 0.621371;
- }
- if(unitAngle == 0){
- heading *= 6400/360; // degrees to mils scale factor
- attitude *= 6400/360;
- }
- if(unitAltitude == 1){
- altitude *= 3.28084; // m to ft scale factor
- }
- }
- // =============================================================================
- // =============================================================================
- // =============================================================================
- // code by JernejL
- // transforms a vector using a 4x4 matrix (translation and scaling is ignored, only 3x3 part is used, we only need rotation!)
- stock MatrixTransformVector(Float:vector[3], Float:m[4][4], &Float:resx, &Float:resy, &Float:resz) {
- resz = vector[2] * m[0][0] + vector[1] * m[0][1] + vector[0] * m[0][2] + m[0][3];
- resy = vector[2] * m[1][0] + vector[1] * m[1][1] + vector[0] * m[1][2] + m[1][3];
- resx = -(vector[2] * m[2][0] + vector[1] * m[2][1] + vector[0] * m[2][2] + m[2][3]); // don't ask why -x was needed, i don't know either.
- }
- // something for 0.3b
- stock RotatePointVehicleRotation(vehid, Float:Invector[3], &Float:resx, &Float:resy, &Float:resz, worldspace=0) {
- new Float:Quaternion[4];
- new Float:transformationmatrix[4][4];
- GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
- // build a transformation matrix out of the quaternion
- new Float:xx = Quaternion[0] * Quaternion[0];
- new Float:xy = Quaternion[0] * Quaternion[1];
- new Float:xz = Quaternion[0] * Quaternion[2];
- new Float:xw = Quaternion[0] * Quaternion[3];
- new Float:yy = Quaternion[1] * Quaternion[1];
- new Float:yz = Quaternion[1] * Quaternion[2];
- new Float:yw = Quaternion[1] * Quaternion[3];
- new Float:zz = Quaternion[2] * Quaternion[2];
- new Float:zw = Quaternion[2] * Quaternion[3];
- transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
- transformationmatrix[0][1] = 2 * ( xy - zw );
- transformationmatrix[0][2] = 2 * ( xz + yw );
- transformationmatrix[0][3] = 0.0;
- transformationmatrix[1][0] = 2 * ( xy + zw );
- transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
- transformationmatrix[1][2] = 2 * ( yz - xw );
- transformationmatrix[1][3] = 0.0;
- transformationmatrix[2][0] = 2 * ( xz - yw );
- transformationmatrix[2][1] = 2 * ( yz + xw );
- transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
- transformationmatrix[2][3] = 0;
- transformationmatrix[3][0] = 0;
- transformationmatrix[3][1] = 0;
- transformationmatrix[3][2] = 0;
- transformationmatrix[3][3] = 1;
- // transform the point thru car's rotation
- MatrixTransformVector(Invector, transformationmatrix, resx, resy, resz);
- // if worldspace is set it'll return the coords in global space - useful to check tire coords against tire spike proximity directly, etc..
- if (worldspace == 1) {
- new Float:fX, Float:fY, Float:fZ;
- GetVehiclePos(vehid, fX, fY, fZ);
- resx += fX;
- resy += fY;
- resz += fZ;
- }
- }
- //------------------------------------------------------------------------------
- // global variables
- //------------------------------------------------------------------------------
- new vehicleNames[212][] = { // Vehicle Names Version 2 - enforcer
- "Landstalker",
- "Bravura",
- "Buffalo",
- "Linerunner",
- "Perrenial",
- "Sentinel",
- "Dumper",
- "Firetruck",
- "Trashmaster",
- "Stretch",
- "Manana",
- "Infernus",
- "Voodoo",
- "Pony",
- "Mule",
- "Cheetah",
- "Ambulance",
- "Leviathan",
- "Moonbeam",
- "Esperanto",
- "Taxi",
- "Washington",
- "Bobcat",
- "Mr Whoopee",
- "BF Injection",
- "Hunter",
- "Premier",
- "Enforcer",
- "Securicar",
- "Banshee",
- "Predator",
- "Bus",
- "Rhino",
- "Barracks",
- "Hotknife",
- "Trailer 1", //artict1
- "Previon",
- "Coach",
- "Cabbie",
- "Stallion",
- "Rumpo",
- "RC Bandit",
- "Romero",
- "Packer",
- "Monster",
- "Admiral",
- "Squalo",
- "Seasparrow",
- "Pizzaboy",
- "Tram",
- "Trailer 2", //artict2
- "Turismo",
- "Speeder",
- "Reefer",
- "Tropic",
- "Flatbed",
- "Yankee",
- "Caddy",
- "Solair",
- "Berkley's RC Van",
- "Skimmer",
- "PCJ-600",
- "Faggio",
- "Freeway",
- "RC Baron",
- "RC Raider",
- "Glendale",
- "Oceanic",
- "Sanchez",
- "Sparrow",
- "Patriot",
- "Quad",
- "Coastguard",
- "Dinghy",
- "Hermes",
- "Sabre",
- "Rustler",
- "ZR-350",
- "Walton",
- "Regina",
- "Comet",
- "BMX",
- "Burrito",
- "Camper",
- "Marquis",
- "Baggage",
- "Dozer",
- "Maverick",
- "News Chopper",
- "Rancher",
- "Ranger",
- "Virgo",
- "Greenwood",
- "Jetmax",
- "Hotring",
- "Sandking",
- "Blista Compact",
- "Police Maverick",
- "Boxville",
- "Benson",
- "Mesa",
- "RC Goblin",
- "Hotring Racer A", //hotrina
- "Hotring Racer B", //hotrinb
- "Bloodring Banger",
- "Rancher",
- "Super GT",
- "Elegant",
- "Journey",
- "Bike",
- "Mountain Bike",
- "Beagle",
- "Cropdust",
- "Stunt",
- "Tanker", //petro
- "Roadtrain",
- "Nebula",
- "Majestic",
- "Buccaneer",
- "Shamal",
- "Hydra",
- "FCR-900",
- "NRG-500",
- "HPV1000",
- "Cement Truck",
- "Tow Truck",
- "Fortune",
- "Cadrona",
- "Riot Truck",
- "Willard",
- "Forklift",
- "Tractor",
- "Combine",
- "Feltzer",
- "Remington",
- "Slamvan",
- "Blade",
- "Freight",
- "Streak",
- "Vortex",
- "Vincent",
- "Bullet",
- "Clover",
- "Sadler",
- "Firetruck LA", //firela
- "Hustler",
- "Intruder",
- "Primo",
- "Cargobob",
- "Tampa",
- "Sunrise",
- "Merit",
- "Utility",
- "Nevada",
- "Yosemite",
- "Windsor",
- "Monster A", //monstera
- "Monster B", //monsterb
- "Uranus",
- "Jester",
- "Sultan",
- "Stratum",
- "Elegy",
- "Nighthawk", // raindance
- "RC Tiger",
- "Flash",
- "Tahoma",
- "Savanna",
- "Bandito",
- "Freight Flat", //freiflat
- "Streak Carriage", //streakc
- "Kart",
- "Mower",
- "Duneride",
- "Sweeper",
- "Broadway",
- "Tornado",
- "AT-400",
- "DFT-30",
- "Huntley",
- "Stafford",
- "BF-400",
- "Newsvan",
- "Tug",
- "Trailer 3", //petrotr
- "Emperor",
- "Wayfarer",
- "Euros",
- "Hotdog",
- "Club",
- "Freight Carriage", //freibox
- "Trailer 3", //artict3
- "Andromada",
- "Dodo",
- "RC Cam",
- "Launch",
- "Police Cruiser LS",// (LSPD)
- "Police Cruiser SF",// (SFPD)
- "Police Cruiser LV",// (LVPD)
- "Police Ranger",
- "Picador",
- "S.W.A.T. Tank",
- "Alpha",
- "Phoenix",
- "Glendale",
- "Sadler",
- "Luggage Trailer A", //bagboxa
- "Luggage Trailer B", //bagboxb
- "Stair Trailer", //tugstair
- "Boxville",
- "Farm Plow", //farmtr1
- "Utility Trailer" //utiltr1
- };
- enum pInfo
- {
- pVehicleid,
- Float:pSpeedActual,
- Float:pSpeedGround,
- Float:pHeading,
- Float:pAttitude,
- Float:pAltitude,
- };
- enum vInfo
- {
- vModelid, // the vehicle model
- vNumberPlate,
- vLastPlayerid, // last player to drive this vehicle
- Float:vDamage,
- Float:vFuel, // in litres
- vFuelType, // the fuel type currently in the tank, eg aviation fuel
- Float:vTotalDistance,
- Float:vDistanceThisPlayer, // distance travelled by this playerid in this vehid
- Float:vDistanceRemaining, // distance left to travel on this tank of fuel
- };
- new PlayerInfo[MAX_PLAYERS][pInfo];
- new VehicleInfo[MAX_VEHICLES][vInfo];
- enum coordinate
- {
- Float: x,
- Float: y,
- Float: z,
- }
- new const fuelStations[][coordinate] =
- {
- { 1595.5406, 2198.0520, 10.3863 },
- { 2202.0649, 2472.6697, 10.5677 },
- { 2115.1929, 919.9908, 10.5266 },
- { 2640.7209, 1105.9565, 10.5274 },
- { 608.5971, 1699.6238, 6.9922 },
- { 618.4878, 1684.5792, 6.9922 },
- { 2146.3467, 2748.2893, 10.5245 },
- { -1679.4595, 412.5129, 6.9973 },
- { -1327.5607, 2677.4316, 49.8093 },
- { -1470.0050, 1863.2375, 32.3521 },
- { -2409.2200, 976.2798, 45.2969 },
- { -2244.1396, -2560.5833, 31.9219 },
- { -1606.0544, -2714.3083, 48.5335 },
- { 1937.4293, -1773.1865, 13.3828 },
- { -91.3854, -1169.9175, 2.4213 },
- { 1383.4221, 462.5385, 20.1506 },
- { 660.4590, -565.0394, 16.3359 },
- { 1381.7206, 459.1907, 20.3452 },
- { -1605.7156, -2714.4573, 48.5335 },
- { 1008.1107, -937.3372, 42.6493 },
- { -2029.4047, 157.2388, 28.5722 }
- };
- new Text:VehicleOperationDisplay[20][MAX_PLAYERS]; // 20 is the number of separate textdraws we need to do for this
- //------------------------------------------------------------------------------
- // samp fuctions
- //------------------------------------------------------------------------------
- public OnFilterScriptInit()
- {
- print("\n -----------------------------------------");
- print("-- Realistic Vehicle Performace Loaded --");
- print("-- by Don Walt \"Enforcer\" --");
- print(" -----------------------------------------\n");
- // init the vehicleinfo
- for(new vehicleid=0; vehicleid<MAX_VEHICLES; vehicleid++){
- VehicleInfo[vehicleid][vModelid] = -1;
- VehicleInfo[vehicleid][vNumberPlate] = -1;
- VehicleInfo[vehicleid][vLastPlayerid] = -1;
- VehicleInfo[vehicleid][vDamage] = -1;
- VehicleInfo[vehicleid][vFuel] = -1;
- VehicleInfo[vehicleid][vFuelType] = -1;
- VehicleInfo[vehicleid][vTotalDistance] = -1;
- VehicleInfo[vehicleid][vDistanceThisPlayer] = 0;
- VehicleInfo[vehicleid][vDistanceRemaining] = 0;
- }
- SetTimer("updateTextDraws", 500, 1);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- /* mapicon styles
- 0: MAPICON_LOCAL Display in the player's local area
- 1: MAPICON_GLOBAL Display always
- 2: MAPICON_LOCAL_CHECKPOINT Display in the player's local area and has a checkpoint marker
- 3: MAPICON_GLOBAL_CHECKPOINT Display always and has a checkpoint marker
- */
- // set petrol station map icons
- new iconid = 100;
- // for every fuel station
- for (new i=0; i<sizeof(fuelStations); i++)
- {
- iconid--;
- SetPlayerMapIcon(playerid, iconid, fuelStations[i][x], fuelStations[i][y], fuelStations[i][z], 19, 0, MAPICON_LOCAL);
- }
- // model name
- VehicleOperationDisplay[0][playerid] = TextDrawCreate(2.000000, 439.000000, "Cruiser"); // 2,470 Police Cruiser LVPD Velocity 500km/h 6400mils Damage 000% Fuel 000.0%
- TextDrawAlignment(VehicleOperationDisplay[0][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[0][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[0][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[0][playerid], 0.200000, 0.700000); // 0.220000,0.800000 0.280000,1.000000
- TextDrawColor(VehicleOperationDisplay[0][playerid], 0x88ED77FF);
- TextDrawSetOutline(VehicleOperationDisplay[0][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[0][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[0][playerid], 1);
- // display a box for the vehicle info
- TextDrawUseBox(VehicleOperationDisplay[0][playerid], 1);
- TextDrawBoxColor(VehicleOperationDisplay[0][playerid], 0x40404080);
- TextDrawTextSize(VehicleOperationDisplay[0][playerid], 638.00, 7.00);
- // velocity ground
- VehicleOperationDisplay[1][playerid] = TextDrawCreate(70.000000, 439.000000, "Velocity gnd"); // 2,470
- TextDrawAlignment(VehicleOperationDisplay[1][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[1][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[1][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[1][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[1][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[1][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[1][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[1][playerid], 1);
- VehicleOperationDisplay[2][playerid] = TextDrawCreate(142.000000, 439.000000, "500km/h");
- TextDrawAlignment(VehicleOperationDisplay[2][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[2][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[2][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[2][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[2][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[2][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[2][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[2][playerid], 1);
- // velocity actual
- VehicleOperationDisplay[3][playerid] = TextDrawCreate(146.000000, 439.000000, "act");
- TextDrawAlignment(VehicleOperationDisplay[3][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[3][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[3][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[3][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[3][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[3][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[3][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[3][playerid], 1);
- VehicleOperationDisplay[4][playerid] = TextDrawCreate(188.000000, 439.000000, "600km/h");
- TextDrawAlignment(VehicleOperationDisplay[4][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[4][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[4][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[4][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[4][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[4][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[4][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[4][playerid], 1);
- // heading
- VehicleOperationDisplay[5][playerid] = TextDrawCreate(192.000000, 439.000000, "head");
- TextDrawAlignment(VehicleOperationDisplay[5][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[5][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[5][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[5][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[5][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[5][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[5][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[5][playerid], 1);
- VehicleOperationDisplay[6][playerid] = TextDrawCreate(239.000000, 439.000000, "6400mils");
- TextDrawAlignment(VehicleOperationDisplay[6][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[6][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[6][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[6][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[6][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[6][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[6][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[6][playerid], 1);
- // elevation
- VehicleOperationDisplay[7][playerid] = TextDrawCreate(244.000000, 439.000000, "ptc");
- TextDrawAlignment(VehicleOperationDisplay[7][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[7][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[7][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[7][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[7][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[7][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[7][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[7][playerid], 1);
- VehicleOperationDisplay[8][playerid] = TextDrawCreate(285.000000, 439.000000, "6400mils");
- TextDrawAlignment(VehicleOperationDisplay[8][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[8][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[8][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[8][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[8][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[8][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[8][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[8][playerid], 1);
- // altitude
- VehicleOperationDisplay[9][playerid] = TextDrawCreate(289.000000, 439.000000, "Alt");
- TextDrawAlignment(VehicleOperationDisplay[9][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[9][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[9][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[9][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[9][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[9][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[9][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[9][playerid], 1);
- VehicleOperationDisplay[10][playerid] = TextDrawCreate(328.000000, 439.000000, "50000ft");
- TextDrawAlignment(VehicleOperationDisplay[10][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[10][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[10][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[10][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[10][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[10][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[10][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[10][playerid], 1);
- // damage
- VehicleOperationDisplay[11][playerid] = TextDrawCreate(338.000000, 439.000000, "Damage");
- TextDrawAlignment(VehicleOperationDisplay[11][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[11][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[11][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[11][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[11][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[11][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[11][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[11][playerid], 1);
- VehicleOperationDisplay[12][playerid] = TextDrawCreate(386.000000, 439.000000, "100%");
- TextDrawAlignment(VehicleOperationDisplay[12][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[12][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[12][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[12][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[12][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[12][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[12][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[12][playerid], 1);
- // fuel
- VehicleOperationDisplay[13][playerid] = TextDrawCreate(397.000000, 439.000000, "Fuel");
- TextDrawAlignment(VehicleOperationDisplay[13][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[13][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[13][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[13][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[13][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[13][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[13][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[13][playerid], 1);
- VehicleOperationDisplay[14][playerid] = TextDrawCreate(435.000000, 439.000000, "500.0L");
- TextDrawAlignment(VehicleOperationDisplay[14][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[14][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[14][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[14][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[14][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[14][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[14][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[14][playerid], 1);
- VehicleOperationDisplay[15][playerid] = TextDrawCreate(465.000000, 439.000000, "100.0%");
- TextDrawAlignment(VehicleOperationDisplay[15][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[15][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[15][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[15][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[15][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[15][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[15][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[15][playerid], 1);
- VehicleOperationDisplay[16][playerid] = TextDrawCreate(512.000000, 439.000000, "50.0L/100km");
- TextDrawAlignment(VehicleOperationDisplay[16][playerid], 3);
- TextDrawBackgroundColor(VehicleOperationDisplay[16][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[16][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[16][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[16][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[16][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[16][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[16][playerid], 1);
- // fuel type
- VehicleOperationDisplay[17][playerid] = TextDrawCreate(516.000000, 439.000000, "Petrol");
- TextDrawAlignment(VehicleOperationDisplay[17][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[17][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[17][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[17][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[17][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[17][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[17][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[17][playerid], 1);
- // total vehicle distance
- VehicleOperationDisplay[18][playerid] = TextDrawCreate(567.000000, 439.000000, "Distance");
- TextDrawAlignment(VehicleOperationDisplay[18][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[18][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[18][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[18][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[18][playerid], 0xFFFE80FF);
- TextDrawSetOutline(VehicleOperationDisplay[18][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[18][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[18][playerid], 1);
- VehicleOperationDisplay[19][playerid] = TextDrawCreate(597.000000, 439.000000, "5000000km");
- TextDrawAlignment(VehicleOperationDisplay[19][playerid], 1);
- TextDrawBackgroundColor(VehicleOperationDisplay[19][playerid], 0x00000077);
- TextDrawFont(VehicleOperationDisplay[19][playerid], 1);
- TextDrawLetterSize(VehicleOperationDisplay[19][playerid], 0.200000, 0.700000);
- TextDrawColor(VehicleOperationDisplay[19][playerid], -1);
- TextDrawSetOutline(VehicleOperationDisplay[19][playerid], 0);
- TextDrawSetProportional(VehicleOperationDisplay[19][playerid], 1);
- TextDrawSetShadow(VehicleOperationDisplay[19][playerid], 1);
- return 0;
- }
- public OnPlayerUpdate(playerid)
- {
- // if fuel is 0, turn the engine off
- if(IsPlayerConnected(playerid) && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
- new vehicleid = GetPlayerVehicleID(playerid);
- if(VehicleInfo[vehicleid][vFuel] < 0.2){ // less than 200ml in the fuel tank
- vehicleParamsSet(vehicleid, 0, -1, -1, -1, -1, -1, -1); // turn engine off
- }
- }
- return 1;
- }
- ShowVehicleOperationDisplay(playerid)
- {
- for(new i=0; i<20; i++){
- TextDrawShowForPlayer(playerid,VehicleOperationDisplay[i][playerid]);
- }
- }
- HideVehicleOperationDisplay(playerid)
- {
- for(new i=0; i<20; i++){
- TextDrawHideForPlayer(playerid,VehicleOperationDisplay[i][playerid]);
- }
- }
- public OnPlayerEnterVehicle(playerid, vehicleid)
- {
- // if this vehicle has not been initialized
- if(VehicleInfo[vehicleid][vTotalDistance] < 0){ // if distance travelled is -1
- vehicleInfoInit(vehicleid, playerid);
- }
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- HideVehicleOperationDisplay(playerid);
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(IsPlayerInAnyVehicle(playerid) && newstate==PLAYER_STATE_DRIVER){
- ShowVehicleOperationDisplay(playerid);
- }
- return 1;
- }
- public OnPlayerCommandText (playerid, cmdtext[])
- {
- new cmd[256+1];
- new idx;
- cmd = strtok(cmdtext, idx);
- // toggle the engine
- if (!strcmp (cmdtext, "/v", true))
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- vehicleParamsToggle(vehicleid, 1, 0, 0, 0, 0, 0, 0);
- return 1;
- }
- // set fuel to 20
- if (!strcmp (cmdtext, "/fuel20", true))
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- VehicleInfo[vehicleid][vFuel] = 20;
- return 1;
- }
- if (!strcmp (cmdtext, "/on", true))
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- vehicleParamsSet(vehicleid, 1, -1, -1, -1, -1, -1, -1);
- return 1;
- }
- if (!strcmp (cmdtext, "/off", true))
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- vehicleParamsSet(vehicleid, 0, -1, -1, -1, -1, -1, -1);
- return 1;
- }
- // refuel command
- if (!strcmp (cmd, "/refuel", true))
- {
- new params1[256];
- params1 = strtok(cmdtext, idx);
- new params2[256];
- params2 = strtok(cmdtext, idx);
- new string[256];
- format(string, sizeof(string), "%s %s", params1, params2);
- cmd_refuel(playerid, string);
- return 1;
- }
- // vehicle repair command
- if (!strcmp (cmd, "/fixcar", true))
- {
- new params[64];
- params = strtok(cmdtext, idx);
- cmd_repair(playerid, params);
- return 1;
- }
- return 0;
- }
- //------------------------------------------------------------------------------
- // stock fuctions
- //------------------------------------------------------------------------------
- // returns the price per litre of fuel
- stock Float: getFuelPrice(fuelType)
- {
- if(fuelType == FUELTYPE_NONE) return FUELPRICE_NONE;
- if(fuelType == FUELTYPE_BATTERY) return FUELPRICE_BATTERY;
- if(fuelType == FUELTYPE_REGULAR) return FUELPRICE_REGULAR;
- if(fuelType == FUELTYPE_PREMIUM) return FUELPRICE_PREMIUM;
- if(fuelType == FUELTYPE_DIESEL) return FUELPRICE_DIESEL;
- if(fuelType == FUELTYPE_AVIATION) return FUELPRICE_AVIATION;
- return FUELPRICE_NONE;
- }
- // are we at a gas station?
- stock IsPlayerAtFuelStation(playerid)
- {
- for (new i=0; i<sizeof(fuelStations); i++)
- {
- if (IsPlayerInRangeOfPoint (playerid, 10.0, fuelStations[i][x], fuelStations[i][y], fuelStations[i][z])) return 1;
- }
- return 0;
- }
- // return the type of vehicle for a modelid
- stock vehicleType(modelid)
- {
- switch(modelid){
- case 402, 411, 415, 602, 429, 541, 587, 565, 494, 502, 503,
- 559, 603, 506, 451, 558, 477, 560, 562: return VEHTYPE_SPORT;
- case 400, 424, 489, 495, 505, 568, 579, 599: return VEHTYPE_OFFROAD;
- case 403, 406, 407, 408, 413, 414, 416, 418, 423, 427, 428,
- 431, 432, 433, 437, 440, 443, 444, 455, 456, 459, 470,
- 482, 483, /*485,*/ 486, 498, 499, 508, 514, 515, 524,
- /*531, 532,*/543, 556, 557, /*572,*/573, 578, 582, 588,
- 601, 609: return VEHTYPE_TRUCK;
- case 401, 404, 405, 409, 410, 412, 419, 420, 421, 422, 426,
- 434, 436, 438, 439, 442, 445, 458, 466, 467, 474, 475,
- 478, 479, 490, 491, 492, 496, 500, 504, 507, 516, 517,
- 518, 525, 526, 527, 528, 529, 533, 534, 535, 536, 540,
- 542, 545, 546, 547, 549, 551, 552, 554, 555,
- 561, 566, 567, 575, 576, 580, 585, 589, 596, 597, 598,
- 600, 604, 605: return VEHTYPE_COMMON;
- case 448, 457, 461, 462, 468, 471, 521, 522, 523, 530, 571,
- 574, 581, 583, 586: return VEHTYPE_BIKE;
- case 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513,
- 548, 425, 417, 487, 488, 497, 563, 447, 469: return VEHTYPE_AIR;
- }
- return VEHTYPE_NONE;
- }
- // return the fuel tank capacity for a modelid
- // return -1 for an unknown modelid
- stock vehicleFuelTankCapacity(modelid)
- {
- switch (vehicleType(modelid))
- {
- case VEHTYPE_NONE: return 0;
- case VEHTYPE_SPORT: return 70;
- case VEHTYPE_COMMON: return 60;
- case VEHTYPE_OFFROAD: return 80;
- case VEHTYPE_TRUCK: return 130;
- case VEHTYPE_BIKE: return 25;
- case VEHTYPE_AIR: return 200;
- }
- return -1;
- }
- // init vehicle info
- stock vehicleInfoInit(vehicleid, playerid)
- {
- VehicleInfo[vehicleid][vModelid] = GetVehicleModel(vehicleid);
- VehicleInfo[vehicleid][vNumberPlate] = 0;
- VehicleInfo[vehicleid][vLastPlayerid] = playerid;
- VehicleInfo[vehicleid][vDamage] = 0;
- // fill the tank with a random ammount of fuel, from a min of 5L to max of full tank
- VehicleInfo[vehicleid][vFuel] = randnumb(5, vehicleFuelTankCapacity(VehicleInfo[vehicleid][vModelid]) );
- // put a suitable fuel in the tank
- switch(vehiclePropulsionType(VehicleInfo[vehicleid][vModelid])){
- case VEHPROP_NONE: VehicleInfo[vehicleid][vFuelType] = FUELTYPE_NONE;
- case VEHPROP_PUSH: VehicleInfo[vehicleid][vFuelType] = FUELTYPE_NONE;
- case VEHPROP_ELECTRIC: VehicleInfo[vehicleid][vFuelType] = FUELTYPE_BATTERY;
- case VEHPROP_PETROL: VehicleInfo[vehicleid][vFuelType] = FUELTYPE_REGULAR;
- case VEHPROP_DIESEL: VehicleInfo[vehicleid][vFuelType] = FUELTYPE_DIESEL;
- case VEHPROP_GASTURBINE: VehicleInfo[vehicleid][vFuelType] = FUELTYPE_DIESEL;
- case VEHPROP_AVIATION: VehicleInfo[vehicleid][vFuelType] = FUELTYPE_AVIATION;
- }
- VehicleInfo[vehicleid][vTotalDistance] = 0;
- VehicleInfo[vehicleid][vDistanceThisPlayer] = 0;
- VehicleInfo[vehicleid][vDistanceRemaining] = 0;
- }
- // return the type of propulsion for a modelid
- stock vehiclePropulsionType(modelid)
- {
- switch(modelid){
- case 435,450,584,591,606,607,608,610,611,590,594: return VEHPROP_NONE;
- case 481,509,510: return VEHPROP_PUSH;
- case 457,441,464,465,501,564: return VEHPROP_ELECTRIC;
- case 462,471,568,571,572,401,404,405,410,412,419,421,424,426,436,439,445,458,463,466,
- 467,468,474,475,480,483,491,492,550,516,517,518,521,526,527,529,533,534,536,540,
- 542,545,547,549,551,566,567,575,576,580,585,586,589,446,452,472,473,493,539,402,
- 411,415,429,434,451,461,477,494,496,500,502,503,504,506,507,522,541,546,555,558,
- 559,560,561,562,565,581,587,602,603,409,420,438,442,448,485,530,531,574,583,523,
- 596,597,598,416,604: return VEHPROP_PETROL;
- case 418,422,478,479,543,600,453,454,484,400,489,495,505,508,535,573,579,403,406,408,
- 413,414,423,431,437,440,443,444,455,456,459,482,486,498,499,514,515,524,525,532,
- 552,554,556,557,578,582,588,609,407,427,428,430,490,528,544,599,601,432,433,470,
- 595,605: return VEHPROP_DIESEL;
- case 417,460,469,487,488,511,512,513,519,553,577,593,497,563,425,447,476,520,548,592: return VEHPROP_AVIATION;
- }
- return VEHPROP_NONE;
- }
- // check if a fuel type is compatible with a vehicle
- // returns 1 for compatible and 0 for not compatible
- stock checkFuelVehicle(modelid, fuelType)
- {
- new propType = vehiclePropulsionType(modelid);
- // if the fueltype is safe for the engine type, return 1
- switch(propType){
- case VEHPROP_NONE: if(fuelType==FUELTYPE_NONE) return 1;
- case VEHPROP_PUSH: if(fuelType==FUELTYPE_NONE) return 1;
- case VEHPROP_ELECTRIC: if(fuelType==FUELTYPE_BATTERY) return 1;
- case VEHPROP_PETROL: if(fuelType==FUELTYPE_REGULAR || fuelType==FUELTYPE_PREMIUM) return 1;
- case VEHPROP_DIESEL: if(fuelType==FUELTYPE_DIESEL) return 1;
- case VEHPROP_GASTURBINE: if(fuelType==FUELTYPE_REGULAR || fuelType==FUELTYPE_PREMIUM || fuelType==FUELTYPE_DIESEL || fuelType==FUELTYPE_AVIATION) return 1;
- case VEHPROP_AVIATION: if(fuelType==FUELTYPE_AVIATION) return 1;
- }
- return 0; // return "not safe"
- }
- // return a string of the name of a fueltype_id
- stock fuelTypeString(fuelType)
- {
- new string[15];
- switch(fuelType){
- case FUELTYPE_NONE: string = "No Fuel Tank";
- case FUELTYPE_BATTERY: string = "Battery";
- case FUELTYPE_REGULAR: string = "Regular Petrol"; // 14 chars
- case FUELTYPE_PREMIUM: string = "Premium Petrol";
- case FUELTYPE_DIESEL: string = "Diesel Fuel";
- case FUELTYPE_AVIATION: string = "Aviation Fuel";
- }
- return string;
- }
- stock randnumb (min, max)
- {
- return random (max - min) + min;
- }
- // pass a value of 1 to turn a param on, 0 to turn it off, and -1 to leave it as it was
- stock vehicleParamsSet(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective)
- {
- new engine_state;
- new lights_state;
- new alarm_state;
- new doors_state;
- new bonnet_state;
- new boot_state;
- new objective_state;
- // get the old params state
- GetVehicleParamsEx(vehicleid, engine_state, lights_state, alarm_state, doors_state, bonnet_state, boot_state, objective_state);
- // set the vars to what the new state will be
- if(engine == 1) engine_state = 1; // if true turn on
- else if(engine == 0) engine_state = 0; // otherwise turn off
- if(lights == 1) lights_state = 1;
- else if(lights == 0)lights_state = 0;
- if(alarm == 1) alarm_state = 1;
- else if(alarm == 0) alarm_state = 0;
- if(doors == 1) doors_state = 1;
- else if(doors == 0) doors_state = 0;
- if(bonnet == 1) bonnet_state = 1;
- else if(bonnet == 0) bonnet_state = 0;
- if(boot == 1) boot_state = 1;
- else if(boot == 0) boot_state = 0;
- if(objective == 1) objective_state = 1;
- else if(objective == 0) objective_state = 0;
- // set the new params
- SetVehicleParamsEx(vehicleid, engine_state, lights_state, alarm_state, doors_state, bonnet_state, boot_state, objective_state);
- }
- // toggles a bool variable
- stock toggle(&boolInput)
- {
- if(boolInput) boolInput = false;
- else boolInput = true;
- return;
- }
- // pass a value of 1 to toggle a param, 0 to leave as was
- stock vehicleParamsToggle(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective)
- {
- new engine_state;
- new lights_state;
- new alarm_state;
- new doors_state;
- new bonnet_state;
- new boot_state;
- new objective_state;
- // get the old params state
- GetVehicleParamsEx(vehicleid, engine_state, lights_state, alarm_state, doors_state, bonnet_state, boot_state, objective_state);
- // set the vars to what the new state will be
- if (engine) toggle(engine_state);
- if (lights) toggle(lights_state);
- if (alarm) toggle(alarm_state);
- if (doors) toggle(doors_state);
- if (bonnet) toggle(bonnet_state);
- if (boot) toggle(boot_state);
- if (objective) toggle(objective_state);
- // set the new params
- SetVehicleParamsEx(vehicleid, engine_state, lights_state, alarm_state, doors_state, bonnet_state, boot_state, objective_state);
- }
- // return 1 if engine is on, 0 if it is off
- stock vehicleStateEngine(vehicleid)
- {
- new engine_state;
- new lights_state;
- new alarm_state;
- new doors_state;
- new bonnet_state;
- new boot_state;
- new objective_state;
- // get the old params state
- GetVehicleParamsEx(vehicleid, engine_state, lights_state, alarm_state, doors_state, bonnet_state, boot_state, objective_state);
- if(engine_state) return 1;
- return 0;
- }
- //------------------------------------------------------------------------------
- // other fuctions
- //------------------------------------------------------------------------------
- cmd_repair(playerid, params[])
- {
- new idx,ammount,tmp[256];
- tmp = strtok(params, idx);
- // if not in a vehicle
- if(!IsPlayerInAnyVehicle(playerid)){
- SendClientMessage(playerid, COLOR_ERROR, "You must be in a vehicle to repair it!");
- return 1;
- }
- // if not at a petrol station
- if(!IsPlayerAtFuelStation(playerid)){
- SendClientMessage(playerid, COLOR_ERROR, "You must at a fuel station to repair!");
- return 1;
- }
- new vehicleid = GetPlayerVehicleID(playerid);
- // if no params have been passed
- if(!strlen(tmp)){
- // make them for it
- new playerCash = GetPlayerMoney(playerid);
- new invoice = floatround((VehicleInfo[vehicleid][vDamage] * REPAIR_COST), floatround_round);
- if(playerCash-invoice < 0){ // if they can't afford
- SendClientMessage(playerid, COLOR_ERROR, "You can't afford to do this!");
- return 1;
- }
- GivePlayerMoney( playerid, (invoice * -1) );
- SendClientMessage(playerid, COLOR_SERVER_HELP_MSG, "Now Repairing"); // tell the player they are being repaired
- repairVehicle(vehicleid, -1, 0); // call the repair function
- return 1;
- }
- // if invalid params have been passed
- if(!isNumeric(tmp)){
- SendClientMessage(playerid, COLOR_ERROR, "Usage: /repair {percentage to repair}");
- return 1;
- }
- // if valid params have been passed
- ammount = strval(tmp);
- // if ammount is not a valid percentage
- if(ammount<0 || ammount>100){
- SendClientMessage(playerid, COLOR_ERROR, "{percentage to repair} must be an integer from 0 to 100!");
- return 1;
- }
- // make them for it
- new playerCash = GetPlayerMoney(playerid);
- new invoice = floatround( (ammount * REPAIR_COST), floatround_round );
- if(playerCash-invoice < 0){ // if they can't afford
- SendClientMessage(playerid, COLOR_ERROR, "You can't afford to do this!");
- return 1;
- }
- GivePlayerMoney( playerid, (invoice * -1) );
- // tell the player they are being repaired
- new string[256];
- format (string, sizeof (string), "Now repairing %d%%", ammount);
- SendClientMessage(playerid, COLOR_SERVER_HELP_MSG, string);
- repairVehicle(vehicleid, ammount, 0); // call the repair function
- return 1;
- }
- new repairTimer[MAX_VEHICLES];
- forward modifyVehicleDamage(vehicleid, Float: target, Float: rate);
- public modifyVehicleDamage(vehicleid, Float: target, Float: rate)
- {
- // if we have reached the target
- if(VehicleInfo[vehicleid][vDamage]-rate <= target){
- VehicleInfo[vehicleid][vDamage] = target; // correct for small errors
- // turn the engine back on
- vehicleParamsSet(vehicleid, 1, -1, -1, -1, -1, -1, -1);
- KillTimer(repairTimer[vehicleid]); // kill the repair timer
- }
- // but if we haven't...
- else{
- VehicleInfo[vehicleid][vDamage] -= rate;
- // make sure engine stays off
- vehicleParamsSet(vehicleid, 0, -1, -1, -1, -1, -1, -1);
- }
- // if we repaired enough, fix the vehicles paneling
- if(VehicleInfo[vehicleid][vDamage] < 10) RepairVehicle(vehicleid);
- // set the vehicle health from the vehicle damage
- new Float: vehicleHealth = (VehicleInfo[vehicleid][vDamage] * -1 +100) * 750/100 + 250;
- SetVehicleHealth(vehicleid, vehicleHealth);
- return;
- }
- // repair a vehicleid - pass a negative ammount to repair completely,
- // pass instant a value of false to repair using a timer (so it takes time to repair)
- stock repairVehicle(vehicleid, Float: ammount, instant)
- {
- // turn the engine off
- vehicleParamsSet(vehicleid, 0, -1, -1, -1, -1, -1, -1);
- // if the repair is to happen instantly
- if(instant){
- // if ammount is less than 0, repair fully
- if(ammount < 0) VehicleInfo[vehicleid][vDamage] = 0;
- // if an ammount is specified
- else{
- if(VehicleInfo[vehicleid][vDamage]-ammount < 0) VehicleInfo[vehicleid][vDamage] = 0; // if ammount would over-repair, repair to 0 damage
- else VehicleInfo[vehicleid][vDamage] -= ammount; // otherwise repair by ammount
- }
- // if we repaired enough, fix the vehicles paneling
- if(VehicleInfo[vehicleid][vDamage] < 10) RepairVehicle(vehicleid);
- // set the vehicle health from the vehicle damage
- new Float: vehicleHealth = (VehicleInfo[vehicleid][vDamage] * -1 +100) * 750/100 + 250;
- SetVehicleHealth(vehicleid, vehicleHealth);
- // turn the engine back on
- vehicleParamsSet(vehicleid, 1, -1, -1, -1, -1, -1, -1);
- }
- // if not using instant
- else{
- // if ammount is less than 0, repair fully
- if(ammount < 0){
- repairTimer[vehicleid] = SetTimerEx("modifyVehicleDamage", 100, 1, "dff", vehicleid, 0, REPAIR_RATE);
- }
- // if an ammount is specified
- else{
- // if ammount would over-repair, repair to 0 damage
- if(VehicleInfo[vehicleid][vDamage]-ammount <= 0){
- repairTimer[vehicleid] = SetTimerEx("modifyVehicleDamage", 100, 1, "dff", vehicleid, 0, REPAIR_RATE);
- }
- else{ // otherwise repair by ammount
- new Float: target = VehicleInfo[vehicleid][vDamage] - ammount; // target = current damage - ammount
- repairTimer[vehicleid] = SetTimerEx("modifyVehicleDamage", 100, 1, "dff", vehicleid, target, REPAIR_RATE); // repair to the target, instead of to 0 damage
- }
- }
- }
- return;
- }
- new refuelTimer[MAX_VEHICLES];
- // empty the tank before initiating the refuel function loop
- forward drainRefuelVehicle(vehicleid, Float: ammountToRefuel, Float: rate);
- public drainRefuelVehicle(vehicleid, Float: ammountToRefuel, Float: rate)
- {
- if(rate<0) rate *= -1; // rate must be positive;
- // check to see if we have reached the target (of 0)
- if(VehicleInfo[vehicleid][vFuel]-rate <= 0){
- // stop the timer that is calling this function
- KillTimer(refuelTimer[vehicleid]);
- // call the refuel function to refuel the "ammountToRefuel"
- refuelVehicle(vehicleid, ammountToRefuel, 0, 0);
- return 1;
- }
- // alter the vehicle fuel by the ammount of rate
- VehicleInfo[vehicleid][vFuel] -= rate;
- // make sure engine stays off
- vehicleParamsSet(vehicleid, 0, -1, -1, -1, -1, -1, -1);
- return 0;
- }
- // returns 1 when it reaches its target
- forward addFuelToVehicle(vehicleid, Float: target, Float: rate, &Float: fuelAdded);
- public addFuelToVehicle(vehicleid, Float: target, Float: rate, &Float: fuelAdded)
- {
- // if we get a negative rate, drain the tank instead of filling it
- if(rate<0){
- // check to see if we have reached the target
- if(VehicleInfo[vehicleid][vFuel]+rate <= target){
- // turn the engine back on
- vehicleParamsSet(vehicleid, 1, -1, -1, -1, -1, -1, -1);
- KillTimer(refuelTimer[vehicleid]); // stop the timer that is calling this function
- return 1;
- }
- }
- // if we get a positive rate
- else{
- // check to see if we have reached the target
- if(VehicleInfo[vehicleid][vFuel]+rate >= target){
- // turn the engine back on
- vehicleParamsSet(vehicleid, 1, -1, -1, -1, -1, -1, -1);
- KillTimer(refuelTimer[vehicleid]); // stop the timer that is calling this function
- return 1;
- }
- }
- // alter the vehicle fuel by the ammount of rate
- VehicleInfo[vehicleid][vFuel] += rate;
- fuelAdded += rate;
- // make sure engine stays off
- vehicleParamsSet(vehicleid, 0, -1, -1, -1, -1, -1, -1);
- return 0;
- }
- cmd_refuel(playerid, params[])
- {
- new idx;
- new tmp[256];
- new Float: ammount = -1.0;
- new fuelType = FUELTYPE_NONE;
- new reverse = false; // when set to true, removes fuel instead of adding it.
- new vehicleid = GetPlayerVehicleID(playerid);
- // if not in a vehicle
- if(!IsPlayerInAnyVehicle(playerid)){
- SendClientMessage(playerid, COLOR_ERROR, "You must be in a vehicle to refuel it!");
- return 1;
- }
- // if not at a petrol station
- if(!IsPlayerAtFuelStation(playerid)){
- SendClientMessage(playerid, COLOR_ERROR, "You must at a fuel station to refuel!");
- return 1;
- }
- // deal with the first param
- tmp = strtok(params, idx);
- // if no params has been passed
- if(!strlen(tmp)){
- ammount = -1; // -1 will fill the tank to the top
- }
- // if params have been passed
- else{
- if(!isNumeric(tmp)){ // if the passed params are invalid, (not a number)
- SendClientMessage(playerid, COLOR_ERROR, "Usage: /refuel {numerical ammount}");
- return 1;
- }
- ammount = strval(tmp); // convert the passed params to a value
- if(ammount<0){
- reverse = true; // if they entered a negative ammount, set reverse to true (to remove fuel from tank)
- ammount *= -1; // and invert ammount, because ammount must not be negative
- }
- }
- // deal with the second param
- tmp = strtok(params, idx);
- // if no params has been passed
- if(!strlen(tmp)){
- fuelType = VehicleInfo[vehicleid][vFuelType]; // set the new fuel type to what is already in the tank
- }
- // if params have been passed for fuel type
- else{
- if(!strcmp (tmp, "battery", true)) fuelType = FUELTYPE_BATTERY; // if the passed param matches a fuel type
- else if(!strcmp (tmp, "regular", true)) fuelType = FUELTYPE_REGULAR;
- else if(!strcmp (tmp, "premium", true)) fuelType = FUELTYPE_PREMIUM;
- else if(!strcmp (tmp, "diesel", true)) fuelType = FUELTYPE_DIESEL;
- else if(!strcmp (tmp, "aviation", true)) fuelType = FUELTYPE_AVIATION;
- // if we don't recognize the param they passed
- else{
- SendClientMessage(playerid, COLOR_ERROR, "Usage: /refuel {numerical ammount} {\"battery\" / \"regular\" / \"premium\" / \"diesel\" / \"aviation\"}");
- return 1;
- }
- }
- // check that the selected fuel type is compatible with their car
- if(!checkFuelVehicle(GetVehicleModel(vehicleid), fuelType)){
- new string[256];
- format (string, sizeof (string), "You cannot fill this vehicle with %s!", tmp);
- SendClientMessage(playerid, COLOR_ERROR, string);
- return 1;
- }
- // check if the player can pay for it
- new playerCash = GetPlayerMoney(playerid);
- new invoice = 0;
- new Float: fuelPrice = getFuelPrice(fuelType);
- new Float: tankCapacity = vehicleFuelTankCapacity(GetVehicleModel(vehicleid)); // find the tank capacity
- new Float: ammountToAdd;
- // if we are filling to a full tank
- if(ammount<0){
- // if we are to drain before filling
- if(fuelType != VehicleInfo[vehicleid][vFuelType]){
- ammountToAdd = tankCapacity; // add a full tank
- }
- else{
- ammountToAdd = tankCapacity - VehicleInfo[vehicleid][vFuel]; // don't add whats already in the tank
- }
- }
- // if we are filling a set ammount
- else{
- ammountToAdd = ammount;
- // check for overfill and correct it
- if(fuelType != VehicleInfo[vehicleid][vFuelType]){ // if we are to drain before filling
- // if we are going to overfill
- if(ammount>tankCapacity){
- ammountToAdd = tankCapacity; // add a full tank
- }
- }
- else{
- // if we are going to overfill
- if(ammount > tankCapacity-VehicleInfo[vehicleid][vFuelType]){
- ammountToAdd = tankCapacity-VehicleInfo[vehicleid][vFuelType]; // add a full tank
- }
- }
- }
- invoice = floatround( (ammountToAdd * fuelPrice * REFUEL_COST), floatround_round );
- // if removing fuel, skip the payment part
- if(!reverse){
- if(playerCash-invoice < 0){ // if they can't afford
- SendClientMessage(playerid, COLOR_ERROR, "You can't afford to do this!");
- return 1;
- }
- GivePlayerMoney( playerid, (invoice * -1) ); // pay
- }
- // if we have selected a different fuel than what is already in the tank
- if(fuelType != VehicleInfo[vehicleid][vFuelType]){
- new string[256];
- format (string, sizeof (string), "The fuel you selected (%s) is different to the fuel in the tank. The tank will be emptied before it is refilled!", tmp);
- SendClientMessage(playerid, COLOR_ERROR, string);
- // set a timer to call the drainRefuel function
- refuelTimer[vehicleid] = SetTimerEx("drainRefuelVehicle", 100, 1, "dff", vehicleid, ammount, REFUEL_RATE );
- }
- else{
- refuelVehicle(vehicleid, ammount, 0, reverse); // call the refuel function
- }
- // set the fuel type to what we just put in the tank
- VehicleInfo[vehicleid][vFuelType] = fuelType;
- // tell the player they are being refueled
- new string[128];
- if(ammount<0){
- format(string, sizeof (string), "Now Refueling.");
- }
- else{
- if(reverse) ammount *= -1;
- format(string, sizeof (string), "Now Refueling %.0f Litres.", ammount);
- }
- SendClientMessage(playerid, COLOR_SERVER_HELP_MSG, string);
- return 1;
- }
- // variables to pass to this function
- // "vehicleid" - the vehicles game id
- // "ammount" - the ammount of fuel that we wish to add/remove from the tank.
- // use a value of -1 to completely fill/empty the fuel tank.
- // "instant" - when true, the tank will be filled instantly, when false, the tank will be filled in real time
- // "reverse" - when true, ammount will be subtracted from the tank, rather than added
- stock refuelVehicle(vehicleid, Float: ammount, instant, reverse)
- {
- // turn the engine off
- vehicleParamsSet(vehicleid, 0, -1, -1, -1, -1, -1, -1);
- new Float: tankCapacity = vehicleFuelTankCapacity(GetVehicleModel(vehicleid)); // find the tank capacity
- new Float: target; // the target fuel level to have in the tank at the end of the refill
- // if we want to empty the tank
- if(reverse){
- // if ammount is < 0, just empty the tank completely
- if(ammount<0){
- target = 0.0;
- }
- else{
- // if subtracting ammount would exceed the tank limits
- if(VehicleInfo[vehicleid][vFuel]-ammount < 0.0) target = 0.0; // set the tank to empty
- // if it doesn't
- else target = VehicleInfo[vehicleid][vFuel] - ammount; // remove ammount from the tank
- }
- }
- // otherwise fill the tank
- else{
- // if ammount is < 0, just fill the tank completely
- if(ammount<0){
- target = tankCapacity; // fill the tank to near capacity
- }
- else{
- // if adding ammount would exceed the tank limits
- if(VehicleInfo[vehicleid][vFuel]+ammount >= tankCapacity) target = tankCapacity; // set the tank to near capacity
- // if it wouldn't
- else target = VehicleInfo[vehicleid][vFuel] + ammount; // add ammount to the tank
- }
- }
- // if the refill is to happen instantly
- if(instant){
- // set the fuel level to the target we calculated
- VehicleInfo[vehicleid][vFuel] = target;
- // turn the engine back on
- vehicleParamsSet(vehicleid, 1, -1, -1, -1, -1, -1, -1);
- }
- // if using realtime
- else{
- // if we want to empty the tank
- if(reverse){
- // set a timer to empty the tank to the "target" level
- refuelTimer[vehicleid] = SetTimerEx("addFuelToVehicle", 100, 1, "dff", vehicleid, target, (REFUEL_RATE * -1) );
- }
- // otherwise fill the tank
- else{
- // set a timer to fill the tank to the "target" level
- refuelTimer[vehicleid] = SetTimerEx("addFuelToVehicle", 100, 1, "dff", vehicleid, target, REFUEL_RATE );
- }
- }
- return;
- }
- //------------------------------------------------------------------------------
- // timed fuctions
- //------------------------------------------------------------------------------
- // calculate the fuel consumption for a vehicleid, return a value in Litres per 100km
- Float: vehicleConsumption (vehid)
- {
- if(vehicleType(GetVehicleModel(vehid) == 0 )) return -1.0; // if not a vehicle
- if(!vehicleStateEngine(vehid)) return 0.0; // if the engine is off
- new Float: speed [3], multiplier, final_speed, Float: health;
- GetVehicleVelocity (vehid, speed [0], speed [1], speed [2]);
- final_speed = floatround (floatsqroot (floatpower (speed [0], 2) + floatpower (speed [1], 2) + floatpower (speed [2], 2)) * 160.666667, floatround_round);
- GetVehicleHealth (vehid, health);
- switch (vehicleType(GetVehicleModel(vehid)))
- {
- case VEHTYPE_SPORT:
- {
- if (final_speed <= 80.0)
- {
- multiplier = floatround (final_speed / 10, floatround_round);
- }
- else
- {
- multiplier = - floatround (final_speed / 10, floatround_round);
- }
- return 9.5 + multiplier * 0.02 + (10.0 - health / 100) / 2;
- }
- case VEHTYPE_COMMON:
- {
- if (final_speed <= 65.0)
- {
- multiplier = floatround (final_speed / 10, floatround_round);
- }
- else
- {
- multiplier = - floatround (final_speed / 10, floatround_round);
- }
- return 7.5 + multiplier * 0.02 + (10.0 - health / 100) / 2;
- }
- case VEHTYPE_OFFROAD:
- {
- if (final_speed <= 85.0)
- {
- multiplier = floatround (final_speed / 10, floatround_round);
- }
- else
- {
- multiplier = - floatround (final_speed / 10, floatround_round);
- }
- return 10.5 + multiplier * 0.02 + (10.0 - health / 100) / 2;
- }
- case VEHTYPE_TRUCK:
- {
- if (final_speed <= 75.0)
- {
- multiplier = floatround (final_speed / 10, floatround_round);
- }
- else
- {
- multiplier = - floatround (final_speed / 10, floatround_round);
- }
- return 15.5 + multiplier * 0.02 + (10.0 - health / 100) / 2;
- }
- case VEHTYPE_BIKE:
- {
- if (final_speed <= 60.0)
- {
- multiplier = floatround (final_speed / 10, floatround_round);
- }
- else
- {
- multiplier = - floatround (final_speed / 10, floatround_round);
- }
- return 4.5 + multiplier * 0.02 + (10.0 - health / 100) / 2;
- }
- case VEHTYPE_AIR:
- {
- multiplier = floatround (final_speed / 10, floatround_round);
- return 20.0 + multiplier * 0.02 + (10.0 - health / 100) / 2;
- }
- }
- return 0.0; // if vehicletype is 0
- }
- new Float: vehpos [3];
- new Float: vehpos_old [MAX_VEHICLES][3];
- forward updateTextDraws();
- public updateTextDraws()
- {
- for(new playerid=0; playerid<MAX_PLAYERS; playerid++){
- if(IsPlayerConnected(playerid) && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- // calculate the textdraws
- new vehicleid = GetPlayerVehicleID(playerid);
- // vehid/modelid update
- PlayerInfo[playerid][pVehicleid] = GetPlayerVehicleID(playerid);
- VehicleInfo[PlayerInfo[playerid][pVehicleid]][vModelid] = GetVehicleModel(PlayerInfo[playerid][pVehicleid])-400;
- // velocity
- getVehicleVelocity(PlayerInfo[playerid][pVehicleid], PlayerInfo[playerid][pSpeedActual], PlayerInfo[playerid][pSpeedGround], PlayerInfo[playerid][pHeading],
- PlayerInfo[playerid][pAttitude], PlayerInfo[playerid][pAltitude], 0, 0, 1);
- // damage
- new Float:vehicleHealth;
- GetVehicleHealth(PlayerInfo[playerid][pVehicleid], vehicleHealth); // max health is 1000, vehicle will catch fire at 250 health
- if(vehicleHealth>250){
- VehicleInfo[PlayerInfo[playerid][pVehicleid]][vDamage] = ( (vehicleHealth-250) * 100/750 ) * -1 + 100; // calculate so damage may be measured from 0 to 100
- }
- else VehicleInfo[PlayerInfo[playerid][pVehicleid]][vDamage] = 100;
- // set the vehicle health from the vehicle damage
- //vehicleHealth = (VehicleInfo[PlayerInfo[playerid][pVehicleid]][vDamage] * -1 +100) * 750/100 + 250;
- //SetVehicleHealth(vehicleid, vehicleHealth);
- // fuel and distance
- GetVehiclePos(vehicleid, vehpos[0], vehpos[1], vehpos[2]); // get current position
- vehpos [0] = vehpos [0] - vehpos_old [vehicleid][0]; // calculate the displacement for each axis
- vehpos [1] = vehpos [1] - vehpos_old [vehicleid][1];
- vehpos [2] = vehpos [2] - vehpos_old [vehicleid][2];
- GetVehiclePos (vehicleid, vehpos_old[vehicleid][0], vehpos_old[vehicleid][1], vehpos_old[vehicleid][2]); // record the last position for next time
- new Float: displacement = floatsqroot(vehpos[0]*vehpos[0] + vehpos[1]*vehpos[1] + vehpos[2]*vehpos[2]); // calculate the displacement in 3d
- VehicleInfo[PlayerInfo[playerid][pVehicleid]][vTotalDistance] += (displacement * 4/5) / 1000; // add the displacement to the vehicles total distance travelled (convert from meters to km)
- VehicleInfo[PlayerInfo[playerid][pVehicleid]][vDistanceThisPlayer] += (displacement * 4/5) / 1000; // add the displacement to the vehicles distance travelled for this player
- // if the vehicle has moved
- if(displacement != 0){
- VehicleInfo[PlayerInfo[playerid][pVehicleid]][vFuel] -= vehicleConsumption(vehicleid) / 25000 * displacement;
- }
- else{ // if it has not
- VehicleInfo[PlayerInfo[playerid][pVehicleid]][vFuel] -= vehicleConsumption(vehicleid) / 25000 * 20; // engine idling
- }
- // update the textdraws
- // vehicle model actual ground heading pitch altitude damage fuel consumption type total distance (for vehid)
- //format(string,sizeof(string),"Police Cruiser LVPD Velocity gnd 500km/h act 600km/h head 6400mils ptc 6400mils Alt 50000ft Damage 000%% Fuel 500.0L 000.0%% 50.0L/100km Aviation Fuel Distance 5000000km",PlayerInfo[playerid][pSpeed]); // we measure heading in mils
- new string[32]; // [256] something small will sufice, but for testing use 256
- // model name
- format(string,sizeof(string),"%s",vehicleNames[GetVehicleModel(vehicleid) - 400]);
- TextDrawSetString(VehicleOperationDisplay[0][playerid], string);
- // ground
- format(string,sizeof(string),"%.0fkm/h",PlayerInfo[playerid][pSpeedGround]);
- TextDrawSetString(VehicleOperationDisplay[2][playerid], string);
- // actual speed
- format(string,sizeof(string),"%.0fkm/h",PlayerInfo[playerid][pSpeedActual]);
- TextDrawSetString(VehicleOperationDisplay[4][playerid], string);
- // heading
- format(string,sizeof(string),"%.0fmils",PlayerInfo[playerid][pHeading]);
- TextDrawSetString(VehicleOperationDisplay[6][playerid], string);
- // elevation
- format(string,sizeof(string),"%.0fmils",PlayerInfo[playerid][pAttitude]);
- TextDrawSetString(VehicleOperationDisplay[8][playerid], string);
- // altitude
- format(string,sizeof(string),"%.0fft",PlayerInfo[playerid][pAltitude]);
- TextDrawSetString(VehicleOperationDisplay[10][playerid], string);
- // damage
- format(string,sizeof(string),"%.0f%%",VehicleInfo[PlayerInfo[playerid][pVehicleid]][vDamage]);
- TextDrawSetString(VehicleOperationDisplay[12][playerid], string);
- // fuel litres
- format(string,sizeof(string),"%.1fL",VehicleInfo[PlayerInfo[playerid][pVehicleid]][vFuel]);
- TextDrawSetString(VehicleOperationDisplay[14][playerid], string);
- // fuel percent
- new Float: fuelPercent = VehicleInfo[PlayerInfo[playerid][pVehicleid]][vFuel] / vehicleFuelTankCapacity(GetVehicleModel(vehicleid)) * 100;
- format(string,sizeof(string),"%.1f%%",fuelPercent);
- TextDrawSetString(VehicleOperationDisplay[15][playerid], string);
- // fuel consumption
- format(string,sizeof(string),"%.1fL/100km",vehicleConsumption(PlayerInfo[playerid][pVehicleid]));
- TextDrawSetString(VehicleOperationDisplay[16][playerid], string);
- // fuel type
- format(string,sizeof(string),"%s",fuelTypeString(VehicleInfo[PlayerInfo[playerid][pVehicleid]][vFuelType]));
- TextDrawSetString(VehicleOperationDisplay[17][playerid], string);
- // distance
- format(string,sizeof(string),"%.0fkm",VehicleInfo[PlayerInfo[playerid][pVehicleid]][vTotalDistance]);
- TextDrawSetString(VehicleOperationDisplay[19][playerid], string);
- }
- }
- }
- //------------------------------------------------------------------------------
- // Don Walt "Enforcer"
- //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement