SHOW:
|
|
- or go back to the newest paste.
| 1 | /* Speed checking FS | |
| 2 | All credits go to Spenzo */ | |
| 3 | ||
| 4 | ||
| 5 | #include <a_samp> | |
| 6 | ||
| 7 | #define COLOR_YELLOW 0xFFFF00AA | |
| 8 | ||
| 9 | new VehRadarID [MAX_VEHICLES]; | |
| 10 | new Text: RadarHud; | |
| 11 | new Text: SpeedAndModel [MAX_VEHICLES]; | |
| 12 | new CheckingSpeed [MAX_VEHICLES]; | |
| 13 | new OldVehID [MAX_PLAYERS]; | |
| 14 | ||
| 15 | forward UpdateSpeed (vehid); | |
| 16 | forward CheckValidTextDraws(); | |
| 17 | ||
| 18 | ||
| 19 | new VehicleModel[212][] ={
| |
| 20 | "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial","Sentinel", "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", | |
| 21 | "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance","Leviathan", "Moonbeam", "Esperanto", "Taxi", | |
| 22 | "Washington", "Bobcat","Whoopee", "BF Injection", "Hunter", "Premier","Enforcer", "Securicar", "Banshee", | |
| 23 | "Predator", "Bus", "Rhino", "Barracks", "Hotknife","Trailer 1", "Previon", "Coach", "Cabbie", "Stallion", | |
| 24 | "Rumpo", "RC Bandit", "Romero", "Packer","Monster", "Admiral", "Squalo","Seasparrow", "Pizzaboy", "Tram", "Trailer 2", | |
| 25 | "Turismo", "Speeder", "Reefer", "Tropic","Flatbed", "Yankee", "Caddy", "Solair","Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", | |
| 26 | "Freeway", "RC Baron", "RC Raider","Glendale", "Oceanic", "Sanchez", "Sparrow","Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", | |
| 27 | "Sabre", "Rustler", "ZR-350","Walton", "Regina", "Comet", "BMX", "Burrito","Camper", "Marquis", "Baggage", "Dozer", "Maverick", | |
| 28 | "News Chopper", "Rancher","FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring","Sandking", "Blista Compact", "Police Maverick", | |
| 29 | "Boxvillde", "Benson","Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B","Bloodring Banger", "Rancher", "Super GT", "Elegant", | |
| 30 | "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster","Stunt", "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", | |
| 31 | "Shamal", "Hydra","FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune","Cadrona", "FBI Truck", "Willard", | |
| 32 | "Forklift", "Tractor", "Combine","Feltzer", "Remington", "Slamvan", "Blade", "Freight","Streak","Vortex", "Vincent", "Bullet", | |
| 33 | "Clover", "Sadler", "Firetruck LA","Hustler", "Intruder", "Primo", "Cargobob", "Tampa","Sunrise", "Merit","Utility", "Nevada", | |
| 34 | "Yosemite", "Windsor", "Monster A", "Monster B", "Uranus", "Jester", "Sultan","Stratum", "Elegy", "Raindance","RC Tiger", | |
| 35 | "Flash", "Tahoma", "Savanna", "Bandito","Freight Flat", "Streak Carriage", "Kart","Mower", "Dune", "Sweeper", "Broadway", | |
| 36 | "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford","BF-400", "News Van", "Tug", "Trailer 3", "Emperor","Wayfarer", "Euros", | |
| 37 | "Hotdog","Club", "Freight Carriage", "Trailer 4","Andromada", "Dodo", "RC Cam", "Launch", "Police Car (LSPD)","Police Car (SFPD)", | |
| 38 | "Police Car (LVPD)", "Police Ranger", "Picador", "S.W.A.T", "Alpha","Phoenix", "Glendale", "Sadler", "Luggage Trailer A", | |
| 39 | "Luggage Trailer B", "Stairs", "Boxville", "Tiller", "Utility Trailer" }; | |
| 40 | ||
| 41 | ||
| 42 | public OnFilterScriptInit () | |
| 43 | {
| |
| 44 | printf (" \nCruiser speed radar made by Srdjan loaded.\n");
| |
| 45 | ||
| 46 | SetTimer ("CheckValidTextDraws", 1000, 1);
| |
| 47 | ||
| 48 | RadarHud = TextDrawCreate (495.0, 200.0, "~b~Model: ~n~~r~Speed: kmph"); | |
| 49 | TextDrawFont (RadarHud, 2); | |
| 50 | TextDrawLetterSize (RadarHud, 0.3, 1.0); | |
| 51 | ||
| 52 | for (new i = 1; i <= MAX_VEHICLES; i++) | |
| 53 | {
| |
| 54 | VehRadarID [i] = -1; | |
| 55 | SpeedAndModel [i] = TextDrawCreate (545.0, 200.0, "~b~ ~n~~r~"); | |
| 56 | TextDrawFont (SpeedAndModel [i], 2); | |
| 57 | TextDrawLetterSize (SpeedAndModel [i], 0.3, 1.0); | |
| 58 | CheckingSpeed [i] = 0; | |
| 59 | } | |
| 60 | ||
| 61 | return 1; | |
| 62 | } | |
| 63 | ||
| 64 | public OnPlayerCommandText (playerid, cmdtext[]) | |
| 65 | {
| |
| 66 | if (!strcmp (cmdtext, "/placeradar")) | |
| 67 | {
| |
| 68 | if (IsPlayerInAnyVehicle (playerid)) | |
| 69 | {
| |
| 70 | new vehid = GetPlayerVehicleID (playerid); | |
| 71 | if (VehRadarID [vehid] > -1) return 1; | |
| 72 | ||
| 73 | new Float: x, Float: y, Float: z, Float: a; | |
| 74 | GetVehiclePos (vehid, x, y, z); | |
| 75 | GetVehicleZAngle (vehid, a); | |
| 76 | SendClientMessage (playerid, COLOR_YELLOW, "Radar has been added successfully."); | |
| 77 | VehRadarID [vehid] = CreateObject (367, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 300.0); | |
| 78 | AttachObjectToVehicle (VehRadarID [vehid], vehid, 0.2, 0.50, 0.3, 0.0, 0.0, 90.0); | |
| 79 | ||
| 80 | for (new i = 0; i < MAX_PLAYERS; i++) | |
| 81 | {
| |
| 82 | if (IsPlayerInVehicle (i, vehid)) | |
| 83 | {
| |
| 84 | TextDrawShowForPlayer (i, RadarHud); | |
| 85 | } | |
| 86 | } | |
| 87 | } | |
| 88 | return 1; | |
| 89 | } | |
| 90 | ||
| 91 | if (!strcmp (cmdtext, "/removeradar")) | |
| 92 | {
| |
| 93 | if (IsPlayerInAnyVehicle (playerid)) | |
| 94 | {
| |
| 95 | new vehid = GetPlayerVehicleID (playerid); | |
| 96 | if (VehRadarID [vehid] == -1) return 1; | |
| 97 | ||
| 98 | DestroyObject (VehRadarID [vehid]); | |
| 99 | SendClientMessage (playerid, COLOR_YELLOW, "Radar has been removed successfully."); | |
| 100 | VehRadarID [vehid] = -1; | |
| 101 | KillTimer (CheckingSpeed [vehid]); | |
| 102 | CheckingSpeed [vehid] = -1; | |
| 103 | ||
| 104 | for (new i = 0; i < MAX_PLAYERS; i++) | |
| 105 | {
| |
| 106 | if (IsPlayerInVehicle (i, vehid)) | |
| 107 | {
| |
| 108 | TextDrawHideForPlayer (i, RadarHud); | |
| 109 | TextDrawHideForPlayer (playerid, SpeedAndModel [vehid]); | |
| 110 | } | |
| 111 | } | |
| 112 | } | |
| 113 | return 1; | |
| 114 | } | |
| 115 | ||
| 116 | if (!strcmp (cmdtext, "/checkspeed")) | |
| 117 | {
| |
| 118 | if (IsPlayerInAnyVehicle (playerid)) | |
| 119 | {
| |
| 120 | new vehid = GetPlayerVehicleID (playerid); | |
| 121 | if (VehRadarID [vehid] == -1) return 1; | |
| 122 | CheckingSpeed [vehid] = SetTimerEx ("UpdateSpeed", 100, 1, "d", vehid);
| |
| 123 | } | |
| 124 | return 1; | |
| 125 | } | |
| 126 | ||
| 127 | if (!strcmp (cmdtext, "/stopchecking")) | |
| 128 | {
| |
| 129 | if (IsPlayerInAnyVehicle (playerid)) | |
| 130 | {
| |
| 131 | new vehid = GetPlayerVehicleID (playerid); | |
| 132 | if (CheckingSpeed [vehid] > 0) | |
| 133 | {
| |
| 134 | KillTimer (CheckingSpeed [vehid]); | |
| 135 | CheckingSpeed [vehid] = -1; | |
| 136 | } | |
| 137 | for (new i = 0; i < MAX_PLAYERS; i++) | |
| 138 | {
| |
| 139 | if (IsPlayerInVehicle (i, vehid)) | |
| 140 | {
| |
| 141 | TextDrawHideForPlayer (i, SpeedAndModel [vehid]); | |
| 142 | } | |
| 143 | } | |
| 144 | } | |
| 145 | return 1; | |
| 146 | } | |
| 147 | ||
| 148 | - | if (!strcmp (cmdtext, "/issueticket")) |
| 148 | + | |
| 149 | } | |
| 150 | ||
| 151 | GetVehicleInfrontID (vehid) | |
| 152 | {
| |
| 153 | - | if (CheckingSpeed [vehid] > -1) |
| 153 | + | |
| 154 | new j = 0; | |
| 155 | - | for (new i = 0; i < MAX_PLAYERS; i++) |
| 155 | + | |
| 156 | - | {
|
| 156 | + | |
| 157 | - | if (IsPlayerConnected (i) && i != playerid) |
| 157 | + | |
| 158 | - | {
|
| 158 | + | |
| 159 | - | if (IsPlayerInVehicle (i, GetVehicleInfrontID (vehid))) |
| 159 | + | |
| 160 | - | {
|
| 160 | + | |
| 161 | - | if (GetPlayerVehicleSeat (i) == 0) |
| 161 | + | |
| 162 | - | {
|
| 162 | + | |
| 163 | - | GivePlayerMoney (i, -1500); |
| 163 | + | |
| 164 | - | } |
| 164 | + | |
| 165 | - | } |
| 165 | + | |
| 166 | - | } |
| 166 | + | |
| 167 | - | } |
| 167 | + | |
| 168 | {
| |
| 169 | x1 = x1 + (distance * floatsin(-a, degrees)); | |
| 170 | y1 = y1 + (distance * floatcos(-a, degrees)); | |
| 171 | ||
| 172 | distance = floatsqroot ((floatpower ((x1 - x2), 2)) + (floatpower ((y1 - y2), 2))); | |
| 173 | ||
| 174 | if (temp > distance) | |
| 175 | {
| |
| 176 | temp = distance; | |
| 177 | j = i; | |
| 178 | } | |
| 179 | } | |
| 180 | } | |
| 181 | } | |
| 182 | } | |
| 183 | if (temp < 7.0) return j; | |
| 184 | return -1; | |
| 185 | } | |
| 186 | ||
| 187 | public UpdateSpeed (vehid) | |
| 188 | {
| |
| 189 | new id = GetVehicleInfrontID (vehid); | |
| 190 | if (id < 0) | |
| 191 | {
| |
| 192 | TextDrawSetString (SpeedAndModel [vehid], "~b~N/A ~n~~r~N/A"); | |
| 193 | } | |
| 194 | else | |
| 195 | {
| |
| 196 | new str[32], Float: velocityX, Float: velocityY, Float: velocityZ; | |
| 197 | GetVehicleVelocity (id, velocityX, velocityY, velocityZ); | |
| 198 | new speed = floatround (floatsqroot (floatpower (velocityX, 2) + floatpower (velocityY, 2) + floatpower (velocityZ, 2)) * 136.666667, floatround_round); | |
| 199 | format (str, sizeof (str), "~b~%s ~n~~r~%d", VehicleModel [GetVehicleModel (id) - 400], speed); | |
| 200 | TextDrawSetString (SpeedAndModel [vehid], str); | |
| 201 | } | |
| 202 | ||
| 203 | for (new i = 0; i < MAX_PLAYERS; i++) | |
| 204 | {
| |
| 205 | if (IsPlayerInVehicle (i, vehid)) | |
| 206 | {
| |
| 207 | TextDrawShowForPlayer (i, SpeedAndModel [vehid]); | |
| 208 | } | |
| 209 | } | |
| 210 | return 1; | |
| 211 | } | |
| 212 | ||
| 213 | public CheckValidTextDraws() | |
| 214 | {
| |
| 215 | for (new i = 0; i < MAX_PLAYERS; i++) | |
| 216 | {
| |
| 217 | if (IsPlayerConnected (i)) | |
| 218 | {
| |
| 219 | if (IsPlayerInAnyVehicle (i)) | |
| 220 | {
| |
| 221 | new vehid = GetPlayerVehicleID (i); | |
| 222 | if (VehRadarID [vehid] > -1) | |
| 223 | {
| |
| 224 | TextDrawShowForPlayer (i, RadarHud); | |
| 225 | if (CheckingSpeed [vehid] > 0) | |
| 226 | {
| |
| 227 | TextDrawShowForPlayer (i, SpeedAndModel [vehid]); | |
| 228 | } | |
| 229 | else | |
| 230 | {
| |
| 231 | TextDrawHideForPlayer (i, SpeedAndModel [vehid]); | |
| 232 | } | |
| 233 | } | |
| 234 | else | |
| 235 | {
| |
| 236 | TextDrawHideForPlayer (i, RadarHud); | |
| 237 | } | |
| 238 | } | |
| 239 | ||
| 240 | else | |
| 241 | {
| |
| 242 | TextDrawHideForPlayer (i, RadarHud); | |
| 243 | TextDrawHideForPlayer (i, SpeedAndModel [OldVehID[i]]); | |
| 244 | OldVehID [i] = 0; | |
| 245 | } | |
| 246 | } | |
| 247 | } | |
| 248 | return 1; | |
| 249 | } | |
| 250 | ||
| 251 | public OnPlayerStateChange (playerid, newstate, oldstate) | |
| 252 | {
| |
| 253 | if ((oldstate == PLAYER_STATE_ONFOOT) && (newstate == PLAYER_STATE_PASSENGER || newstate == PLAYER_STATE_DRIVER)) | |
| 254 | {
| |
| 255 | OldVehID [playerid] = GetPlayerVehicleID (playerid); | |
| 256 | } | |
| 257 | return 1; | |
| 258 | } | |
| 259 | ||
| 260 | public OnVehicleDeath (vehicleid) | |
| 261 | {
| |
| 262 | DestroyObject (VehRadarID [vehicleid]); | |
| 263 | VehRadarID [vehicleid] = -1; | |
| 264 | KillTimer (CheckingSpeed [vehicleid]); | |
| 265 | CheckingSpeed [vehicleid] = -1; | |
| 266 | for (new i = 0; i < MAX_PLAYERS; i++) | |
| 267 | {
| |
| 268 | if (IsPlayerInVehicle (i, vehicleid)) | |
| 269 | {
| |
| 270 | TextDrawHideForPlayer (i, RadarHud); | |
| 271 | TextDrawHideForPlayer (i, SpeedAndModel [vehicleid]); | |
| 272 | } | |
| 273 | } | |
| 274 | } |