├── .editorconfig ├── .gitattributes ├── .gitignore ├── LICENSE.md ├── README.md ├── tdw_vdamage.inc ├── tdw_vdata.inc ├── tdw_vdetail.inc ├── tdw_vdwos.inc ├── tdw_vehicle.inc ├── tdw_viterator.inc ├── tdw_vmath.inc ├── tdw_vnplate.inc ├── tdw_vsa_data.inc ├── tdw_vsa_handling.inc ├── tdw_vtdata.inc ├── tdw_vutils.inc ├── tdw_vxneon.inc ├── tdw_vxplight.inc ├── tdw_vxsignals.inc ├── tdw_vyboost.inc ├── tdw_vydrift.inc ├── tdw_vyengine.inc ├── tdw_vyfuel.inc ├── tdw_vylabel.inc ├── tdw_vylimit.inc ├── tdw_vylock.inc ├── tdw_vymileage.inc └── tdw_vyradar.inc /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | 7 | [*.{inc,pwn}] 8 | indent_style = tab 9 | indent_size = 4 10 | charset = cp1251 11 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.inc linguist-language=PAWN -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | /tdw_vehicle/test/*.amx 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2017 Double V 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgement in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![TDW Vehicle libraries](https://raw.githubusercontent.com/TDW-org/samp-include-vehicle/develop/tdw_vehicle/docs/img/logo.png) 2 | 3 | # TDW Vehicle Libraries 4 | A collection of libraries for vehicles in SA:MP. The collection contains systems that have many features. 5 | 6 | ## Getting started 7 | 1. Download the library. 8 | 2. All files move into the folder 'pawno/include'. Also, you can use the flag '-i' to specify an alternative path. 9 | 3. Include it in your script: 10 | ```pawn 11 | #include 12 | #include 13 | ``` 14 | 15 | ## Developing 16 | ```shell 17 | git clone git@github.com:TDW-org/samp-include-vehicle.git 18 | cd 19 | ``` 20 | 21 | ## Contributing 22 | If you'd like to contribute, please fork the repository and use a feature branch. 23 | 24 | ## Licensing 25 | The code in this project is licensed under ZLIB license. 26 | -------------------------------------------------------------------------------- /tdw_vdamage.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Damage status 3 | 4 | | Description: 5 | Change the visual appearance of the vehicle. It interacts with all parts of 6 | the vehicles. 7 | 8 | | License: 9 | Copyright (c) 2016-2017 Double V 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgement in the product documentation would be 22 | appreciated but is not required. 23 | 2. Altered source versions must be plainly marked as such, and must not be 24 | misrepresented as being the original software. 25 | 3. This notice may not be removed or altered from any source distribution. 26 | 27 | | Metadata: 28 | [Functions]: 29 | Stock: 30 | - GetVehicleDoorsStatus 31 | - GetVehicleLightsStatus 32 | - GetVehiclePanelsStatus 33 | - GetVehicleTiresStatus 34 | - SetVehicleDoorsStatus 35 | - SetVehicleLightsStatus 36 | - SetVehiclePanelsStatus 37 | - SetVehicleTiresStatus 38 | Static: 39 | - 40 | Public: 41 | - 42 | Hooks: 43 | - 44 | [Callbacks]: 45 | - 46 | [Definitions]: 47 | - 48 | [Enumerations]: 49 | - 50 | [Macros]: 51 | - 52 | [Tags]: 53 | - 54 | [Variables]: 55 | Global scope: 56 | - 57 | Static scope: 58 | - TDW_g_sNullStorage 59 | [Natives]: 60 | - 61 | [Operators]: 62 | - 63 | | Dependencies: 64 | - 65 | \* ========================================================================== */ 66 | 67 | #if defined _inc_tdw_vdamage 68 | // I remove this constant because the compiler automatically generates it. 69 | // github.com/Zeex/pawn/issues/107 70 | #undef _inc_tdw_vdamage 71 | #endif 72 | 73 | #if defined _TDW_VH_DAMAGE_STATUS 74 | #endinput 75 | #endif 76 | 77 | #define _TDW_VH_DAMAGE_STATUS 78 | 79 | #include "tdw_vehicle" 80 | 81 | // ----------------------------------------------------------------------------- 82 | // Static scope: 83 | 84 | static stock 85 | TDW_g_sNullStorage = 0; // We use this to reduce the size of the stack. 86 | 87 | // ----------------------------------------------------------------------------- 88 | // Functions: 89 | 90 | /** ------------------------------------------------------------------------ **\ 91 | GetVehicleLightsStatus 92 | The ID of the vehicle 93 | The state of the front left light 94 | The state of the front right light 95 | The state of the back lights 96 | 97 | - 98 | 99 | 100 | 101 | \** ------------------------------------------------------------------------ **/ 102 | 103 | stock GetVehicleLightsStatus(vehicleid, &front_left_light, &front_right_light, 104 | &back_lights) 105 | { 106 | new 107 | lights; 108 | 109 | // Check availability of the vehicle in the game and get the flag of 110 | // the headlights. 111 | if (0 == GetVehicleDamageStatus(vehicleid, TDW_g_sNullStorage, 112 | TDW_g_sNullStorage, lights, TDW_g_sNullStorage)) 113 | return 0; 114 | 115 | front_left_light = lights & 1; 116 | front_right_light = (lights >>> 2) & 1; 117 | back_lights = (lights >>> 6) & 1; 118 | 119 | return 1; 120 | } 121 | 122 | /** ------------------------------------------------------------------------ **\ 123 | SetVehicleLightsStatus 124 | The ID of the vehicle 125 | The state of the front left light 126 | The state of the front right light 127 | The state of the back lights 128 | 129 | - 130 | 131 | 132 | 133 | \** ------------------------------------------------------------------------ **/ 134 | 135 | stock SetVehicleLightsStatus(vehicleid, front_left_light, front_right_light, 136 | back_lights) 137 | { 138 | new 139 | panels, 140 | doors, 141 | tires; 142 | 143 | // Check availability of the vehicle in the game and get the flags of 144 | // other statuses. 145 | if (0 == GetVehicleDamageStatus(vehicleid, panels, doors, 146 | TDW_g_sNullStorage, tires)) 147 | return 0; 148 | 149 | UpdateVehicleDamageStatus(vehicleid, panels, doors, 150 | ((back_lights & 1) << 6) | ((front_right_light & 1) << 2) | 151 | (front_left_light & 1), tires); 152 | 153 | return 1; 154 | } 155 | 156 | /** ------------------------------------------------------------------------ **\ 157 | GetVehicleTiresStatus 158 | The ID of the vehicle 159 | The state of the rear right tire 160 | The state of the front right tire 161 | The state of the rear left tire 162 | The state of the front left tire 163 | 164 | - 165 | 166 | 167 | 168 | \** ------------------------------------------------------------------------ **/ 169 | 170 | stock GetVehicleTiresStatus(vehicleid, &rear_right_tire, &front_right_tire, 171 | &rear_left_tire, &front_left_tire) 172 | { 173 | new 174 | tires; 175 | 176 | if (0 == GetVehicleDamageStatus(vehicleid, TDW_g_sNullStorage, 177 | TDW_g_sNullStorage, TDW_g_sNullStorage, tires)) 178 | return 0; 179 | 180 | rear_right_tire = tires & 1; 181 | front_right_tire = (tires >>> 1) & 1; 182 | rear_left_tire = (tires >>> 2) & 1; 183 | front_left_tire = (tires >>> 3) & 1; 184 | 185 | return 1; 186 | } 187 | 188 | /** ------------------------------------------------------------------------ **\ 189 | SetVehicleTiresStatus 190 | The ID of the vehicle 191 | The state of the rear right tire 192 | The state of the front right tire 193 | The state of the rear left tire 194 | The state of the front left tire 195 | 196 | - 197 | 198 | 199 | 200 | \** ------------------------------------------------------------------------ **/ 201 | 202 | stock SetVehicleTiresStatus(vehicleid, rear_right_tire, front_right_tire, 203 | rear_left_tire, front_left_tire) 204 | { 205 | new 206 | panels, 207 | doors, 208 | lights; 209 | 210 | if (0 == GetVehicleDamageStatus(vehicleid, panels, doors, lights, 211 | TDW_g_sNullStorage)) 212 | return 0; 213 | 214 | UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, 215 | rear_right_tire | (front_right_tire << 1) | (rear_left_tire << 2) | 216 | (front_left_tire << 3) 217 | ); 218 | 219 | return 1; 220 | } 221 | 222 | /** ------------------------------------------------------------------------ **\ 223 | GetVehiclePanelsStatus 224 | The ID of the vehicle 225 | The state of the front left panel 226 | The state of the front right panel 227 | The state of the rear left panel 228 | The state of the rear right panel 229 | The state of the windshield 230 | The state of the front bumper 231 | The state of the rear bumper 232 | 233 | - 234 | 235 | 236 | 237 | \** ------------------------------------------------------------------------ **/ 238 | 239 | stock GetVehiclePanelsStatus(vehicleid, &front_left_panel, &front_right_panel, 240 | &rear_left_panel, &rear_right_panel, &windshield, &front_bumper, 241 | &rear_bumper) 242 | { 243 | new 244 | panels; 245 | 246 | if (0 == GetVehicleDamageStatus(vehicleid, panels, TDW_g_sNullStorage, 247 | TDW_g_sNullStorage, TDW_g_sNullStorage)) 248 | return 0; 249 | 250 | front_left_panel = panels & 0xF; 251 | front_right_panel = (panels >> 4) & 0xF; 252 | rear_left_panel = (panels >> 8) & 0xF; 253 | rear_right_panel = (panels >> 12) & 0xF; 254 | windshield = (panels >> 16) & 0xF; 255 | front_bumper = (panels >> 20) & 0xF; 256 | rear_bumper = (panels >> 24) & 0xF; 257 | 258 | return 1; 259 | } 260 | 261 | /** ------------------------------------------------------------------------ **\ 262 | SetVehiclePanelsStatus 263 | The ID of the vehicle 264 | The state of the front left panel 265 | The state of the front right panel 266 | The state of the rear left panel 267 | The state of the rear right panel 268 | The state of the windshield 269 | The state of the front bumper 270 | The state of the rear bumper 271 | 272 | - 273 | 274 | 275 | 276 | \** ------------------------------------------------------------------------ **/ 277 | 278 | stock SetVehiclePanelsStatus(vehicleid, front_left_panel, front_right_panel, 279 | rear_left_panel, rear_right_panel, windshield, front_bumper, 280 | rear_bumper) 281 | { 282 | new 283 | doors, 284 | lights, 285 | tires; 286 | 287 | if (0 == GetVehicleDamageStatus(vehicleid, TDW_g_sNullStorage, doors, 288 | lights, tires)) 289 | return 0; 290 | 291 | UpdateVehicleDamageStatus(vehicleid, (front_left_panel | 292 | (front_right_panel << 4) | (rear_left_panel << 8) | 293 | (rear_right_panel << 12) | (windshield << 16) | (front_bumper << 20) | 294 | (rear_bumper << 24)), doors, lights, tires 295 | ); 296 | 297 | return 1; 298 | } 299 | 300 | /** ------------------------------------------------------------------------ **\ 301 | GetVehicleDoorsStatus 302 | The ID of the vehicle 303 | The state of the bonnet 304 | The state of the rear boot 305 | The state of the driver door 306 | The state of the passenger door 307 | 308 | - 309 | 310 | 311 | 312 | \** ------------------------------------------------------------------------ **/ 313 | 314 | stock GetVehicleDoorsStatus(vehicleid, &bonnet, &boot, &driver_door, 315 | &passenger_door) 316 | { 317 | new 318 | doors; 319 | 320 | if (0 == GetVehicleDamageStatus(vehicleid, TDW_g_sNullStorage, doors, 321 | TDW_g_sNullStorage, TDW_g_sNullStorage)) 322 | return 0; 323 | 324 | bonnet = doors & 7; 325 | boot = (doors >>> 8) & 7; 326 | driver_door = (doors >>> 16) & 7; 327 | passenger_door = (doors >>> 24) & 7; 328 | 329 | return 1; 330 | } 331 | 332 | /** ------------------------------------------------------------------------ **\ 333 | SetVehicleDoorsStatus 334 | The state of the bonnet 335 | The state of the rear boot 336 | The state of the driver door 337 | The state of the passenger door 338 | 339 | - 340 | 341 | 342 | 343 | \** ------------------------------------------------------------------------ **/ 344 | 345 | stock SetVehicleDoorsStatus(vehicleid, bonnet, boot, driver_door, 346 | passenger_door) 347 | { 348 | new 349 | panels, 350 | lights, 351 | tires; 352 | 353 | if (0 == GetVehicleDamageStatus(vehicleid, panels, TDW_g_sNullStorage, 354 | lights, tires)) 355 | return 0; 356 | 357 | UpdateVehicleDamageStatus(vehicleid, panels, bonnet | (boot << 8) | 358 | (driver_door << 16) | (passenger_door << 24), lights, tires 359 | ); 360 | 361 | return 1; 362 | } 363 | -------------------------------------------------------------------------------- /tdw_vdata.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Data 3 | 4 | | Description: 5 | All repeatedly updated information, e.g., colors, interior, spawn 6 | information, etc.. 7 | 8 | | License: 9 | Copyright (c) 2016-2017 Double V 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgement in the product documentation would be 22 | appreciated but is not required. 23 | 2. Altered source versions must be plainly marked as such, and must not be 24 | misrepresented as being the original software. 25 | 3. This notice may not be removed or altered from any source distribution. 26 | 27 | | Metadata: 28 | [Functions]: 29 | Stock: 30 | - CreateVehicleEx 31 | - GetVehicleColor 32 | - SetVehicleColor 33 | Static: 34 | - 35 | Public: 36 | - OnVehicleRespray 37 | Hooks: 38 | - AddStaticVehicle 39 | - AddStaticVehicleEx 40 | - ChangeVehicleColor 41 | - CreateVehicle 42 | - DestroyVehicle 43 | [Callbacks]: 44 | - TDWVH_DATA@OnVehicleRespray 45 | [Definitions]: 46 | - 47 | [Enumerations]: 48 | - E_TDW_VEHICLE_DATA 49 | [Macros]: 50 | - 51 | [Tags]: 52 | - 53 | [Variables]: 54 | Global scope: 55 | - 56 | Static scope: 57 | - TDW_g_sVehicle@Color1 58 | - TDW_g_sVehicle@Color2 59 | - TDW_g_sVehicle@Data 60 | - TDW_g_sVehicle@Interior 61 | - TDW_g_sVehicle@Siren 62 | - TDW_g_sVehicleId 63 | [Natives]: 64 | - BAD_AddStaticVehicle 65 | - BAD_AddStaticVehicleEx 66 | - BAD_ChangeVehicleColor 67 | - BAD_CreateVehicle 68 | - BAD_DestroyVehicle 69 | [Operators]: 70 | - 71 | | Dependencies: 72 | - 73 | \* ========================================================================== */ 74 | 75 | #if defined _inc_tdw_vdata 76 | // I remove this constant because the compiler automatically generates it. 77 | // github.com/Zeex/pawn/issues/107 78 | #undef _inc_tdw_vdata 79 | #endif 80 | 81 | #if defined _TDW_VH_VEHICLE_DATA 82 | #endinput 83 | #endif 84 | 85 | #define _TDW_VH_VEHICLE_DATA 86 | 87 | #include "tdw_vehicle" 88 | 89 | // ----------------------------------------------------------------------------- 90 | // Enumerations: 91 | 92 | _TDW_STATIC_ENUM enum E_TDW_VEHICLE_DATA 93 | { 94 | Float:EI_VEHICLE_SPAWN_POS_X, 95 | Float:EI_VEHICLE_SPAWN_POS_Y, 96 | Float:EI_VEHICLE_SPAWN_POS_Z, 97 | Float:EI_VEHICLE_SPAWN_ANGLE, 98 | EI_VEHICLE_RESPAWN_TIME, 99 | EI_VEHICLE_MODEL_ID 100 | }; 101 | 102 | // ----------------------------------------------------------------------------- 103 | // Static scope: 104 | 105 | static stock 106 | TDW_g_sVehicle@Data[MAX_VEHICLES][E_TDW_VEHICLE_DATA], 107 | // To reduce the data segment, we will create a few arrays with char 108 | // operator. It reduces the size of the arrays. 109 | TDW_g_sVehicle@Color1[MAX_VEHICLES char], // 0 - 255 110 | TDW_g_sVehicle@Color2[MAX_VEHICLES char], // 0 - 255 111 | bool:TDW_g_sVehicle@Siren[MAX_VEHICLES char], // 0-1 112 | TDW_g_sVehicle@Interior[MAX_VEHICLES char], // 0 - 18 113 | // We use a global variable to not use the stack. 114 | TDW_g_sVehicleId; 115 | 116 | // ----------------------------------------------------------------------------- 117 | // Hooks: 118 | 119 | // AddStaticVehicle hook 120 | #if !defined BAD_AddStaticVehicle 121 | native BAD_AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, 122 | Float:spawn_z, Float:z_angle, color1, color2) = AddStaticVehicle; 123 | #endif 124 | 125 | stock TDWVH_DATA@AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, 126 | Float:spawn_z, Float:z_angle, color1, color2) 127 | { 128 | if (INVALID_VEHICLE_ID != (TDW_g_sVehicleId = AddStaticVehicle(modelid, 129 | spawn_x, spawn_y, spawn_z, z_angle, color1, color2))) { 130 | // Store all values 131 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_MODEL_ID] = modelid; 132 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_X] = spawn_x; 133 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_Y] = spawn_y; 134 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_Z] = spawn_z; 135 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_ANGLE] = z_angle; 136 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_RESPAWN_TIME] = -1; 137 | TDW_g_sVehicle@Color1{TDW_g_sVehicleId} = color1; 138 | TDW_g_sVehicle@Color2{TDW_g_sVehicleId} = color2; 139 | TDW_g_sVehicle@Siren{TDW_g_sVehicleId} = false; 140 | } 141 | return TDW_g_sVehicleId; 142 | } 143 | 144 | #if defined _ALS_AddStaticVehicle 145 | #undef AddStaticVehicle 146 | #else 147 | #define _ALS_AddStaticVehicle 148 | #endif 149 | 150 | #define AddStaticVehicle TDWVH_DATA@AddStaticVehicle 151 | 152 | 153 | // AddStaticVehicleEx hook 154 | #if !defined BAD_AddStaticVehicleEx 155 | native BAD_AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, 156 | Float:spawn_z, Float:z_angle, color1, color2, respawn_delay, 157 | addsiren = 0) = AddStaticVehicleEx; 158 | #endif 159 | 160 | stock TDWVH_DATA@AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, 161 | Float:spawn_z, Float:z_angle, color1, color2, respawn_delay, addsiren = 0) 162 | { 163 | if (INVALID_VEHICLE_ID != (TDW_g_sVehicleId = AddStaticVehicleEx(modelid, 164 | spawn_x, spawn_y, spawn_z, z_angle, color1, color2, respawn_delay, 165 | addsiren))) { 166 | // Store all values 167 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_MODEL_ID] = modelid; 168 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_X] = spawn_x; 169 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_Y] = spawn_y; 170 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_Z] = spawn_z; 171 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_ANGLE] = z_angle; 172 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_RESPAWN_TIME] = 173 | respawn_delay; 174 | TDW_g_sVehicle@Color1{TDW_g_sVehicleId} = color1; 175 | TDW_g_sVehicle@Color2{TDW_g_sVehicleId} = color2; 176 | TDW_g_sVehicle@Siren{TDW_g_sVehicleId} = bool:addsiren; 177 | } 178 | return TDW_g_sVehicleId; 179 | } 180 | 181 | #if defined _ALS_AddStaticVehicleEx 182 | #undef AddStaticVehicleEx 183 | #else 184 | #define _ALS_AddStaticVehicleEx 185 | #endif 186 | 187 | #define AddStaticVehicleEx TDWVH_DATA@AddStaticVehicleEx 188 | 189 | 190 | // CreateVehicle hook 191 | #if !defined BAD_CreateVehicle 192 | native BAD_CreateVehicle(vehicletype, Float:x, Float:y, Float:z, 193 | Float:rotation, color1, color2, respawn_delay, 194 | addsiren = 0) = CreateVehicle; 195 | #endif 196 | 197 | stock TDWVH_DATA@CreateVehicle(vehicletype, Float:x, Float:y, Float:z, 198 | Float:rotation, color1, color2, respawn_delay, addsiren = 0) 199 | { 200 | if (INVALID_VEHICLE_ID != (TDW_g_sVehicleId = CreateVehicle(vehicletype, 201 | x, y, z, rotation, color1, color2, respawn_delay, 202 | addsiren))) { 203 | // Store all values 204 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_MODEL_ID] = 205 | vehicletype; 206 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_X] = x; 207 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_Y] = y; 208 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_POS_Z] = z; 209 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_SPAWN_ANGLE] = 210 | rotation; 211 | TDW_g_sVehicle@Data[TDW_g_sVehicleId][EI_VEHICLE_RESPAWN_TIME] = 212 | respawn_delay; 213 | TDW_g_sVehicle@Color1{TDW_g_sVehicleId} = color1; 214 | TDW_g_sVehicle@Color2{TDW_g_sVehicleId} = color2; 215 | TDW_g_sVehicle@Siren{TDW_g_sVehicleId} = bool:addsiren; 216 | } 217 | return TDW_g_sVehicleId; 218 | } 219 | 220 | #if defined _ALS_CreateVehicle 221 | #undef CreateVehicle 222 | #else 223 | #define _ALS_CreateVehicle 224 | #endif 225 | 226 | #define CreateVehicle TDWVH_DATA@CreateVehicle 227 | 228 | 229 | // DestroyVehicle hook 230 | #if !defined BAD_DestroyVehicle 231 | native BAD_DestroyVehicle(vehicleid) = DestroyVehicle; 232 | #endif 233 | 234 | stock TDWVH_DATA@DestroyVehicle(vehicleid) 235 | { 236 | if (0 == DestroyVehicle(vehicleid)) 237 | return 0; 238 | 239 | // Reset all values 240 | TDW_g_sVehicle@Data[vehicleid][EI_VEHICLE_MODEL_ID] = 241 | TDW_g_sVehicle@Data[vehicleid][EI_VEHICLE_RESPAWN_TIME] = 242 | TDW_g_sVehicle@Color1{vehicleid} = 243 | TDW_g_sVehicle@Color2{vehicleid} = 244 | TDW_g_sVehicle@Interior{vehicleid} = 0; 245 | TDW_g_sVehicle@Siren{vehicleid} = false; // bool 246 | TDW_g_sVehicle@Data[vehicleid][EI_VEHICLE_SPAWN_POS_X] = 247 | TDW_g_sVehicle@Data[vehicleid][EI_VEHICLE_SPAWN_POS_Y] = 248 | TDW_g_sVehicle@Data[vehicleid][EI_VEHICLE_SPAWN_POS_Z] = 249 | TDW_g_sVehicle@Data[vehicleid][EI_VEHICLE_SPAWN_ANGLE] = 0.0; // float 250 | 251 | return 1; 252 | } 253 | 254 | #if defined _ALS_DestroyVehicle 255 | #undef DestroyVehicle 256 | #else 257 | #define _ALS_DestroyVehicle 258 | #endif 259 | 260 | #define DestroyVehicle TDWVH_DATA@DestroyVehicle 261 | 262 | 263 | // OnVehicleRespray hook 264 | #if defined TDWVH_DATA@OnVehicleRespray 265 | forward TDWVH_DATA@OnVehicleRespray(playerid, vehicleid, color1, color2); 266 | #endif 267 | 268 | public OnVehicleRespray(playerid, vehicleid, color1, color2) 269 | { 270 | TDW_g_sVehicle@Color1{vehicleid} = color1; 271 | TDW_g_sVehicle@Color2{vehicleid} = color2; 272 | 273 | #if defined TDWVH_DATA@OnVehicleRespray 274 | // The server checks the return value: 275 | // Returning 0 in this callback will deny the colour change. 276 | // Returning 1 will allow it. This can be used to prevent hackers from 277 | // changing vehicle colours using cheats. 278 | return TDWVH_DATA@OnVehicleRespray(playerid, vehicleid, color1, color2); 279 | #else 280 | return 1; 281 | #endif 282 | } 283 | 284 | #if defined _ALS_OnVehicleRespray 285 | #undef OnVehicleRespray 286 | #else 287 | #define _ALS_OnVehicleRespray 288 | #endif 289 | 290 | #define OnVehicleRespray TDWVH_DATA@OnVehicleRespray 291 | 292 | 293 | // ChangeVehicleColor hook 294 | #if !defined ChangeVehicleColor 295 | native BAD_ChangeVehicleColor(vehicleid, color1, 296 | color2) = ChangeVehicleColor; 297 | #endif 298 | 299 | // 300 | // -- See SetVehicleColor 301 | // 302 | 303 | #if defined _ALS_ChangeVehicleColor 304 | #undef ChangeVehicleColor 305 | #else 306 | #define _ALS_ChangeVehicleColor 307 | #endif 308 | 309 | #define ChangeVehicleColor SetVehicleColor 310 | 311 | // ----------------------------------------------------------------------------- 312 | // Functions: 313 | 314 | /** ------------------------------------------------------------------------ **\ 315 | GetVehicleColor 316 | The ID of the vehicle 317 | The vehicle's primary color 318 | The vehicle's secondary color 319 | 320 | - 321 | 322 | 323 | Get the colors of a vehicle. 324 | 325 | \** ------------------------------------------------------------------------ **/ 326 | 327 | stock GetVehicleColor(vehicleid, &color1, &color2) 328 | { 329 | if (0 == IsValidVehicle(vehicleid)) 330 | return _:(color1 = color2 = 0); // return 0 331 | 332 | color1 = TDW_g_sVehicle@Color1{vehicleid}; 333 | color2 = TDW_g_sVehicle@Color2{vehicleid}; 334 | 335 | return 1; 336 | } 337 | 338 | /** ------------------------------------------------------------------------ **\ 339 | SetVehicleColor 340 | The ID of the vehicle 341 | The vehicle's primary color 342 | The vehicle's secondary color 343 | 344 | - 345 | 346 | 347 | Change the colors of the vehicle, and store it in the array. 348 | 349 | \** ------------------------------------------------------------------------ **/ 350 | 351 | stock SetVehicleColor(vehicleid, color1, color2) 352 | { 353 | if (0 == IsValidVehicle(vehicleid)) 354 | return 0; 355 | 356 | TDW_g_sVehicle@Color1{vehicleid} = color1; 357 | TDW_g_sVehicle@Color2{vehicleid} = color2; 358 | 359 | return 1; 360 | } 361 | 362 | /** ------------------------------------------------------------------------ **\ 363 | CreateVehicleEx 364 | The model for the vehicle 365 | The X coordinate for the vehicle 366 | The Y coordinate for the vehicle 367 | The Z coordinate for the vehicle 368 | The facing angle for the vehicle 369 | The primary color ID 370 | The secondary color ID 371 | 372 | The delay until the car is respawned without a driver in seconds. 373 | Using -1 will prevent the vehicle from respawning. 374 | 375 | 376 | Has a default value 0. Enables the vehicle to have a siren, providing 377 | the vehicle has a horn. 378 | 379 | 380 | - 381 | 382 | 383 | Creates a vehicle in the world. It can create any vehicle, such as: train, 384 | etc.. 385 | 386 | We can't create the trains using CreateVehicle. Instead, we use 387 | AddStaticVehicleEx because it contains all the arguments that contains in 388 | CreateVehicle. 389 | 390 | ID - Vehicle Name 391 | 537 - Freight (Train) 392 | 538 - Brownstreak (Train) 393 | 570 - Streak Trailer (Train) 394 | 449 - Tram 395 | 396 | Notice: AddStaticVehicleEx, CreateVehicle functions are hooked. 397 | 398 | \** ------------------------------------------------------------------------ **/ 399 | 400 | stock CreateVehicleEx(vehicletype, Float:x, Float:y, Float:z, Float:rotation, 401 | color1, color2, respawn_delay, addsiren = 0) 402 | { 403 | switch (vehicletype) { 404 | case 449, 537, 538, 570: 405 | return AddStaticVehicleEx(vehicletype, x, y, z, rotation, color1, 406 | color2, respawn_delay, addsiren); 407 | default: 408 | return CreateVehicle(vehicletype, x, y, z, rotation, color1, color2, 409 | respawn_delay, addsiren); 410 | } 411 | 412 | return 0; 413 | } 414 | -------------------------------------------------------------------------------- /tdw_vdetail.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Detailed Data 3 | 4 | | Description: 5 | Detailed information about the vehicle, such as: paintjob id, virtual world, 6 | last driver of the vehicle. 7 | 8 | | License: 9 | Copyright (c) 2016-2017 Double V 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgement in the product documentation would be 22 | appreciated but is not required. 23 | 2. Altered source versions must be plainly marked as such, and must not be 24 | misrepresented as being the original software. 25 | 3. This notice may not be removed or altered from any source distribution. 26 | 27 | | Metadata: 28 | [Functions]: 29 | Stock: 30 | - GetVehicleLastDriverId 31 | - GetVehiclePaintjobId 32 | - SetVehiclePaintjobId 33 | Static: 34 | - 35 | Public: 36 | - OnPlayerStateChange 37 | - OnVehiclePaintjob 38 | Hooks: 39 | - ChangeVehiclePaintjob 40 | - SetVehicleVirtualWorld 41 | [Callbacks]: 42 | - TDW_DETAIL@OnPlayerStateChange 43 | - TDW_DETAIL@OnVehiclePaintjob 44 | [Definitions]: 45 | - 46 | [Enumerations]: 47 | - 48 | [Macros]: 49 | - 50 | [Tags]: 51 | - 52 | [Variables]: 53 | Global scope: 54 | - 55 | Static scope: 56 | - TDW_g_sVehicle@LastDriverId 57 | - TDW_g_sVehicle@PaintjobId 58 | - TDW_g_sVehicle@VirtualWorld 59 | [Natives]: 60 | - BAD_ChangeVehiclePaintjob 61 | - BAD_SetVehicleVirtualWorld 62 | [Operators]: 63 | - 64 | | Dependencies: 65 | - 66 | \* ========================================================================== */ 67 | 68 | #if defined _inc_tdw_vdetail 69 | // I remove this constant because the compiler automatically generates it. 70 | // github.com/Zeex/pawn/issues/107 71 | #undef _inc_tdw_vdetail 72 | #endif 73 | 74 | #if defined _TDW_VH_VEHICLE_DETAIL 75 | #endinput 76 | #endif 77 | 78 | #define _TDW_VH_VEHICLE_DETAIL 79 | 80 | #include "tdw_vehicle" 81 | 82 | // ----------------------------------------------------------------------------- 83 | // Static scope: 84 | 85 | static stock 86 | // To reduce the data segment, we will create a few arrays with char 87 | // operator. It reduces the size of the arrays. 88 | TDW_g_sVehicle@PaintjobId[MAX_VEHICLES char], // 0-3 89 | TDW_g_sVehicle@VirtualWorld[MAX_VEHICLES], 90 | TDW_g_sVehicle@LastDriverId[MAX_VEHICLES] = {INVALID_PLAYER_ID, ...}; 91 | 92 | // ----------------------------------------------------------------------------- 93 | // Hooks: 94 | 95 | // SetVehicleVirtualWorld hook 96 | #if !defined BAD_SetVehicleVirtualWorld 97 | native BAD_SetVehicleVirtualWorld(vehicleid, 98 | worldid) = SetVehicleVirtualWorld; 99 | #endif 100 | 101 | // We have to reduce the name of the function, because the full name does not 102 | // fit in size (VM - VirtualWorld). 103 | stock TDWVH_DETAIL@SetVehicleVW(vehicleid, worldid) 104 | { 105 | if (0 == IsValidVehicle(vehicleid)) 106 | return 0; 107 | 108 | SetVehicleVirtualWorld(vehicleid, 109 | (TDW_g_sVehicle@VirtualWorld[vehicleid] = worldid)); 110 | 111 | return 1; 112 | } 113 | 114 | #if defined _ALS_SetVehicleVirtualWorld 115 | #undef SetVehicleVirtualWorld 116 | #else 117 | #define _ALS_SetVehicleVirtualWorld 118 | #endif 119 | 120 | #define SetVehicleVirtualWorld TDWVH_DETAIL@SetVehicleVW 121 | 122 | 123 | // OnVehiclePaintjob hook 124 | #if defined TDW_DETAIL@OnVehiclePaintjob 125 | forward TDW_DETAIL@OnVehiclePaintjob(playerid, vehicleid, paintjobid); 126 | #endif 127 | 128 | public OnVehiclePaintjob(playerid, vehicleid, paintjobid) 129 | { 130 | TDW_g_sVehicle@PaintjobId{vehicleid} = paintjobid; 131 | 132 | #if defined TDW_DETAIL@OnVehiclePaintjob 133 | TDW_DETAIL@OnVehiclePaintjob(playerid, vehicleid, paintjobid); 134 | #endif 135 | 136 | return 1; 137 | } 138 | 139 | #if defined _ALS_OnVehiclePaintjob 140 | #undef OnVehiclePaintjob 141 | #else 142 | #define _ALS_OnVehiclePaintjob 143 | #endif 144 | 145 | #define OnVehiclePaintjob TDW_DETAIL@OnVehiclePaintjob 146 | 147 | 148 | // OnPlayerStateChange hook 149 | #if defined TDW_DETAIL@OnPlayerStateChange 150 | forward TDW_DETAIL@OnPlayerStateChange(playerid, newstate, oldstate); 151 | #endif 152 | 153 | public OnPlayerStateChange(playerid, newstate, oldstate) 154 | { 155 | if (newstate == PLAYER_STATE_DRIVER) { 156 | new vehicleid = GetPlayerVehicleID(playerid); 157 | 158 | TDW_g_sVehicle@LastDriverId[vehicleid] = playerid; 159 | } 160 | 161 | #if defined TDW_DETAIL@OnPlayerStateChange 162 | TDW_DETAIL@OnPlayerStateChange(playerid, newstate, oldstate); 163 | #endif 164 | 165 | return 1; 166 | } 167 | 168 | #if defined _ALS_OnPlayerStateChange 169 | #undef OnPlayerStateChange 170 | #else 171 | #define _ALS_OnPlayerStateChange 172 | #endif 173 | 174 | #define OnPlayerStateChange TDW_DETAIL@OnPlayerStateChange 175 | 176 | // ----------------------------------------------------------------------------- 177 | // Functions: 178 | 179 | /** ------------------------------------------------------------------------ **\ 180 | SetVehiclePaintjobId 181 | The ID of the vehicle 182 | The ID of the Paintjob 183 | 184 | - 185 | 186 | 187 | Change a vehicle's paintjob. 188 | 189 | \** ------------------------------------------------------------------------ **/ 190 | 191 | stock SetVehiclePaintjobId(vehicleid, paintjobid) 192 | { 193 | if (0 == IsValidVehicle(vehicleid)) 194 | return 0; 195 | if (0 == IS_VALID_PAINTJOB(paintjobid)) 196 | return 0; 197 | 198 | ChangeVehiclePaintjob(vehicleid, paintjobid); 199 | TDW_g_sVehicle@PaintjobId{vehicleid} = paintjobid; 200 | 201 | return 1; 202 | } 203 | 204 | /** ------------------------------------------------------------------------ **\ 205 | GetVehicleLastDriverId 206 | The ID of the vehicle 207 | 208 | - 209 | 210 | 211 | Returns the ID of the player 212 | 213 | \** ------------------------------------------------------------------------ **/ 214 | 215 | stock GetVehicleLastDriverId(vehicleid) 216 | { 217 | if (0 == IsValidVehicle(vehicleid)) 218 | return 0; 219 | return TDW_g_sVehicle@LastDriverId[vehicleid]; 220 | } 221 | 222 | /** ------------------------------------------------------------------------ **\ 223 | GetVehiclePaintjobId 224 | The ID of the vehicle 225 | 226 | - 227 | 228 | 229 | Returns the ID of the paint job. 230 | 231 | \** ------------------------------------------------------------------------ **/ 232 | 233 | stock GetVehiclePaintjobId(vehicleid) 234 | { 235 | if (0 == IsValidVehicle(vehicleid)) 236 | return 0; 237 | return TDW_g_sVehicle@PaintjobId{vehicleid}; 238 | } 239 | 240 | // ----------------------------------------------------------------------------- 241 | // Hooks: 242 | 243 | // ChangeVehiclePaintjob hook 244 | #if !defined BAD_ChangeVehiclePaintjob 245 | native BAD_ChangeVehiclePaintjob(vehicleid, 246 | paintjobid) = ChangeVehiclePaintjob; 247 | #endif 248 | 249 | // 250 | // -- See SetVehiclePaintjobId 251 | // 252 | 253 | #if defined _ALS_ChangeVehiclePaintjob 254 | #undef ChangeVehiclePaintjob 255 | #else 256 | #define _ALS_ChangeVehiclePaintjob 257 | #endif 258 | 259 | #define ChangeVehiclePaintjob SetVehiclePaintjobId 260 | -------------------------------------------------------------------------------- /tdw_vdwos.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Doors and Windows Manager 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - GetVehicleDoorState 30 | - SetVehicleDoorState 31 | - GetVehicleDoorPos 32 | - GetVehicleWindowState 33 | - SetVehicleWindowState 34 | Static: 35 | - 36 | Public: 37 | - 38 | Hooks: 39 | - 40 | [Callbacks]: 41 | - 42 | [Definitions]: 43 | - 44 | [Enumerations]: 45 | - E_TDW_VH_DOOR_STATE 46 | - E_TDW_VH_WINDOW_STATE 47 | [Macros]: 48 | - OpenVehicleDoor 49 | - CloseVehicleDoor 50 | - IsVehicleDoorInState 51 | - OpenVehicleWindow 52 | - CloseVehicleWindow 53 | - IsVehicleWindowInState 54 | [Tags]: 55 | - 56 | [Variables]: 57 | Global scope: 58 | - 59 | Static scope: 60 | - 61 | [Natives]: 62 | - 63 | [Operators]: 64 | - 65 | | Dependencies: 66 | - 67 | \* ========================================================================== */ 68 | 69 | #if defined _inc_tdw_vdwos 70 | // I remove this constant because the compiler automatically generates it. 71 | // github.com/Zeex/pawn/issues/107 72 | #undef _inc_tdw_vdwos 73 | #endif 74 | 75 | #if defined _TDW_VH_DWOS_MANAGER 76 | #endinput 77 | #endif 78 | 79 | #define _TDW_VH_DWOS_MANAGER 80 | 81 | #include "tdw_vehicle" 82 | 83 | // ----------------------------------------------------------------------------- 84 | // Macros: 85 | 86 | // Doors 87 | 88 | #if !defined OpenVehicleDoor 89 | // Arguments: 90 | // %1 - vehicleid 91 | // %2 - E_TDW_VEHICLE_DOOR:door 92 | #define OpenVehicleDoor%0(%1,%2) SetVehicleDoorState(%1,%2,DOOR_OPENED) 93 | #endif 94 | 95 | #if !defined CloseVehicleDoor 96 | // Arguments: 97 | // %1 - vehicleid 98 | // %2 - E_TDW_VEHICLE_DOOR:door 99 | #define CloseVehicleDoor%0(%1,%2) SetVehicleDoorState(%1,%2,DOOR_CLOSED) 100 | #endif 101 | 102 | #if !defined IsVehicleDoorInState 103 | // Arguments: 104 | // %1 - vehicleid 105 | // %2 - E_TDW_VEHICLE_DOOR:door 106 | // %3 - E_TDW_VH_DOOR_STATE:state 107 | #define IsVehicleDoorInState%0(%1,%2,%3) \ 108 | (_:(GetVehicleDoorState(%1,%2)) == _:(E_TDW_VH_DOOR_STATE:(%3))) 109 | #endif 110 | 111 | // Windows 112 | 113 | #if !defined OpenVehicleWindow 114 | // Arguments: 115 | // %1 - vehicleid 116 | // %2 - E_TDW_VEHICLE_DOOR:door 117 | #define OpenVehicleWindow%0(%1,%2)\ 118 | SetVehicleWindowState(%1,%2,WINDOW_OPENED) 119 | #endif 120 | 121 | #if !defined CloseVehicleWindow 122 | // Arguments: 123 | // %1 - vehicleid 124 | // %2 - E_TDW_VEHICLE_DOOR:door 125 | #define CloseVehicleWindow%0(%1,%2)\ 126 | SetVehicleWindowState(%1,%2,WINDOW_CLOSED) 127 | #endif 128 | 129 | #if !defined IsVehicleWindowInState 130 | // Arguments: 131 | // %1 - vehicleid 132 | // %2 - E_TDW_VEHICLE_DOOR:door 133 | // %3 - E_TDW_VH_WINDOW_STATE:state 134 | #define IsVehicleWindowInState%0(%1,%2,%3)\ 135 | (_:(GetVehicleWindowState(%1,%2) == _:(E_TDW_VH_WINDOW_STATE:(%3)))) 136 | #endif 137 | 138 | // ----------------------------------------------------------------------------- 139 | // Enumerations: 140 | 141 | // Doors 142 | 143 | enum E_TDW_VH_DOOR_STATE 144 | { 145 | DOOR_NOT_SET = -1, 146 | DOOR_OPENED = 1, 147 | DOOR_CLOSED = 2 148 | }; 149 | 150 | // Windows 151 | 152 | enum E_TDW_VH_WINDOW_STATE 153 | { 154 | WINDOW_NOT_SET = -1, 155 | WINDOW_OPENED = 0, 156 | WINDOW_CLOSED 157 | }; 158 | 159 | // ----------------------------------------------------------------------------- 160 | // Functions: 161 | 162 | // Doors 163 | 164 | /** ------------------------------------------------------------------------ **\ 165 | GetVehicleDoorState 166 | 167 | 168 | - 169 | 170 | 171 | 172 | \** ------------------------------------------------------------------------ **/ 173 | 174 | stock GetVehicleDoorState(vehicleid, E_TDW_VEHICLE_DOOR:door) 175 | { 176 | if (0 == IsValidVehicle(vehicleid)) 177 | return 0; 178 | if (0 == _:(0 <= _:door < MAX_VEHICLE_DOORS)) 179 | return -1; 180 | 181 | new 182 | driver, 183 | passenger, 184 | backleft, 185 | backright; 186 | 187 | GetVehicleParamsCarDoors(vehicleid, driver, passenger, backleft, backright); 188 | 189 | // Return state of the door, which was specified when calling the function. 190 | switch (door) { 191 | case FRONT_LEFT_DOOR: 192 | return driver; 193 | case FRONT_RIGHT_DOOR: 194 | return passenger; 195 | case REAR_LEFT_DOOR: 196 | return backleft; 197 | case REAR_RIGHT_DOOR: 198 | return backright; 199 | } 200 | return -1; 201 | } 202 | 203 | /** ------------------------------------------------------------------------ **\ 204 | SetVehicleDoorState 205 | 206 | 207 | - 208 | 209 | 210 | 211 | \** ------------------------------------------------------------------------ **/ 212 | 213 | stock SetVehicleDoorState(vehicleid, E_TDW_VEHICLE_DOOR:door, 214 | E_TDW_VH_DOOR_STATE:newstate) 215 | { 216 | if (0 == IsValidVehicle(vehicleid)) 217 | return 0; 218 | if (0 == _:(0 <= _:door < MAX_VEHICLE_DOORS)) 219 | return 0; 220 | 221 | new 222 | driver, 223 | passenger, 224 | backleft, 225 | backright; 226 | 227 | GetVehicleParamsCarDoors(vehicleid, driver, passenger, backleft, backright); 228 | 229 | switch (door) { 230 | case FRONT_LEFT_DOOR: 231 | return SetVehicleParamsCarDoors(vehicleid, _:newstate, passenger, 232 | backleft, backright); 233 | case FRONT_RIGHT_DOOR: 234 | return SetVehicleParamsCarDoors(vehicleid, driver, _:newstate, 235 | backleft, backright); 236 | case REAR_LEFT_DOOR: 237 | return SetVehicleParamsCarDoors(vehicleid, driver, passenger, 238 | _:newstate, backright); 239 | case REAR_RIGHT_DOOR: 240 | return SetVehicleParamsCarDoors(vehicleid, driver, passenger, 241 | backleft, _:newstate); 242 | } 243 | return 0; 244 | } 245 | 246 | /** ------------------------------------------------------------------------ **\ 247 | GetVehicleDoorPos 248 | 249 | 250 | - 251 | 252 | 253 | 254 | \** ------------------------------------------------------------------------ **/ 255 | 256 | stock GetVehicleDoorPos(vehicletype, E_TDW_VEHICLE_DOOR:door, &Float:x, 257 | &Float:y, &Float:z) 258 | { 259 | if (0 == GetVehiclePos(vehicletype, x, y, z)) 260 | return _:(x = y = z = 0.0); // return 0 261 | 262 | new 263 | Float:z_angle, 264 | Float:vehicle_x, 265 | Float:vehicle_y, 266 | Float:vehicle_z, 267 | Float:div; 268 | 269 | GetVehicleZAngle(vehicletype, z_angle); 270 | vehicletype = GetVehicleModel(vehicletype); 271 | 272 | switch (door) { 273 | case FRONT_LEFT_DOOR, FRONT_RIGHT_DOOR: 274 | GetVehicleModelInfo(vehicletype, 275 | VEHICLE_MODEL_INFO_FRONTSEAT, 276 | vehicle_x, vehicle_y, vehicle_z); 277 | case REAR_LEFT_DOOR, REAR_RIGHT_DOOR: 278 | GetVehicleModelInfo(vehicletype, 279 | VEHICLE_MODEL_INFO_REARSEAT, 280 | vehicle_x, vehicle_y, vehicle_z); 281 | } 282 | 283 | div = (_:door % 2) ? (vehicle_x) : (-vehicle_x); 284 | 285 | x = (floatsin((z_angle = 360 - z_angle), degrees) * vehicle_y) + 286 | (floatcos(z_angle, degrees) * div) + x; 287 | y = (floatcos(z_angle, degrees) * vehicle_y) - 288 | (floatsin(z_angle, degrees) * div) + y; 289 | z += vehicle_z; 290 | 291 | return 1; 292 | } 293 | 294 | // Windows 295 | 296 | /** ------------------------------------------------------------------------ **\ 297 | GetVehicleWindowState 298 | 299 | 300 | - 301 | 302 | 303 | 304 | \** ------------------------------------------------------------------------ **/ 305 | 306 | stock GetVehicleWindowState(vehicleid, E_TDW_VEHICLE_DOOR:door) 307 | { 308 | if (0 == IsValidVehicle(vehicleid)) 309 | return 0; 310 | if (0 == _:(0 <= _:door < MAX_VEHICLE_DOORS)) 311 | return -1; 312 | 313 | new 314 | driver, 315 | passenger, 316 | backleft, 317 | backright; 318 | 319 | GetVehicleParamsCarWindows(vehicleid, driver, passenger, backleft, 320 | backright); 321 | 322 | // Return state of the door, which was specified when calling the function. 323 | switch (door) { 324 | case FRONT_LEFT_DOOR: 325 | return driver; 326 | case FRONT_RIGHT_DOOR: 327 | return passenger; 328 | case REAR_LEFT_DOOR: 329 | return backleft; 330 | case REAR_RIGHT_DOOR: 331 | return backright; 332 | } 333 | 334 | return -1; 335 | } 336 | 337 | /** ------------------------------------------------------------------------ **\ 338 | SetVehicleWindowState 339 | 340 | 341 | - 342 | 343 | 344 | 345 | \** ------------------------------------------------------------------------ **/ 346 | 347 | stock SetVehicleWindowState(vehicleid, E_TDW_VEHICLE_DOOR:door, 348 | E_TDW_VH_WINDOW_STATE:newstate) 349 | { 350 | if (0 == IsValidVehicle(vehicleid)) 351 | return 0; 352 | if (0 == _:(0 <= _:door < MAX_VEHICLE_DOORS)) 353 | return 0; 354 | 355 | new 356 | driver, 357 | passenger, 358 | backleft, 359 | backright; 360 | 361 | GetVehicleParamsCarWindows(vehicleid, driver, passenger, backleft, 362 | backright); 363 | 364 | switch (door) { 365 | case FRONT_LEFT_DOOR: 366 | return SetVehicleParamsCarWindows(vehicleid, _:newstate, passenger, 367 | backleft, backright); 368 | case FRONT_RIGHT_DOOR: 369 | return SetVehicleParamsCarWindows(vehicleid, driver, _:newstate, 370 | backleft, backright); 371 | case REAR_LEFT_DOOR: 372 | return SetVehicleParamsCarWindows(vehicleid, driver, passenger, 373 | _:newstate, backright); 374 | case REAR_RIGHT_DOOR: 375 | return SetVehicleParamsCarWindows(vehicleid, driver, passenger, 376 | backleft, _:newstate); 377 | } 378 | return 0; 379 | } -------------------------------------------------------------------------------- /tdw_vehicle.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | TDW Vehicle 3 | 4 | | License: 5 | Copyright (c) 2016-2017 Double V 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgement in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | | Metadata: 24 | [Functions]: 25 | Stock: 26 | - 27 | Static: 28 | - 29 | Public: 30 | - 31 | Hooks: 32 | - 33 | [Callbacks]: 34 | - 35 | [Definitions]: 36 | - MAX_VEHICLE_COMPONENT_ID 37 | - MAX_VEHICLE_COMPONENTS 38 | - MAX_VEHICLE_MODEL 39 | - MAX_VEHICLE_MODELS 40 | - MAX_VEHICLE_PAINTJOB 41 | - MIN_VEHICLE_COMPONENT_ID 42 | - MIN_VEHICLE_MODEL 43 | - MIN_VEHICLE_PAINTJOB 44 | [Enumerations]: 45 | - 46 | [Macros]: 47 | - IS_VALID_COMPONENT_ID 48 | - IS_VALID_MODEL 49 | - IS_VALID_PAINTJOB 50 | - IS_VALID_VEHICLEID 51 | [Tags]: 52 | - 53 | [Variables]: 54 | Global scope: 55 | - 56 | Static scope: 57 | - 58 | [Natives]: 59 | - 60 | [Operators]: 61 | - 62 | | Dependencies: 63 | - 64 | \* ========================================================================== */ 65 | 66 | #if defined _inc_tdw_vehicle 67 | // I remove this constant because the compiler automatically generates it. 68 | // github.com/Zeex/pawn/issues/107 69 | #undef _inc_tdw_vehicle 70 | #endif 71 | 72 | #if defined _TDW_VH_CORE 73 | #endinput 74 | #endif 75 | 76 | #define _TDW_VH_CORE 77 | 78 | // ----------------------------------------------------------------------------- 79 | // Definitions: 80 | 81 | // Paintjob 82 | #if !defined MIN_VEHICLE_PAINTJOB 83 | #define MIN_VEHICLE_PAINTJOB (0) 84 | #endif 85 | #if !defined MAX_VEHICLE_PAINTJOB 86 | #define MAX_VEHICLE_PAINTJOB (3) 87 | #endif 88 | 89 | // Models 90 | #if !defined MIN_VEHICLE_MODEL 91 | #define MIN_VEHICLE_MODEL (400) 92 | #endif 93 | #if !defined MAX_VEHICLE_MODEL 94 | #define MAX_VEHICLE_MODEL (611) 95 | #endif 96 | #if !defined MAX_VEHICLE_MODELS 97 | #define MAX_VEHICLE_MODELS (MAX_VEHICLE_MODEL - MIN_VEHICLE_MODEL) 98 | #endif 99 | 100 | // Components 101 | #if !defined MIN_VEHICLE_COMPONENT_ID 102 | #define MIN_VEHICLE_COMPONENT_ID (1000) 103 | #endif 104 | #if !defined MAX_VEHICLE_COMPONENT_ID 105 | #define MAX_VEHICLE_COMPONENT_ID (1193) 106 | #endif 107 | #if !defined MAX_VEHICLE_COMPONENTS 108 | #define MAX_VEHICLE_COMPONENTS (MAX_VEHICLE_COMPONENT_ID - \ 109 | MIN_VEHICLE_COMPONENT_ID) 110 | #endif 111 | 112 | // Number plate 113 | #if !defined MAX_NUMBER_PLATE_SIZE 114 | #define MAX_NUMBER_PLATE_SIZE (32) 115 | #endif 116 | #if !defined MAX_NUMBER_PLATE 117 | #define MAX_NUMBER_PLATE (8) 118 | #endif 119 | 120 | // Passengers 121 | #if !defined MAX_VEHICLE_PASSENGERS 122 | #define MAX_VEHICLE_PASSENGERS (8) 123 | #endif 124 | 125 | // Doors 126 | #if !defined MAX_VEHICLE_DOORS 127 | #define MAX_VEHICLE_DOORS (4) 128 | #endif 129 | 130 | // 131 | #if !defined _TDW_FOREACH_MAX_VEHICLES_ 132 | #if defined GetVehiclePoolSize 133 | #define _TDW_FOREACH_MAX_VEHICLES_ (GetVehiclePoolSize() + 1) 134 | #else 135 | #define _TDW_FOREACH_MAX_VEHICLES_ (MAX_VEHICLES) 136 | #endif 137 | #endif 138 | 139 | #if !defined _TDW_FOREACH_MAX_PLAYERS_ 140 | #if defined GetPlayerPoolSize 141 | #define _TDW_FOREACH_MAX_PLAYERS_ (GetPlayerPoolSize() + 1) 142 | #else 143 | #define _TDW_FOREACH_MAX_PLAYERS_ (GetMaxPlayers()) 144 | #endif 145 | #endif 146 | 147 | // ----------------------------------------------------------------------------- 148 | // Macros: 149 | 150 | // Paintjob 151 | #if !defined IS_VALID_PAINTJOB 152 | #define IS_VALID_PAINTJOB%0(%1) _:(MIN_VEHICLE_PAINTJOB <= \ 153 | (%1) <= MAX_VEHICLE_PAINTJOB) 154 | #endif 155 | 156 | // Models 157 | #if !defined IS_VALID_MODEL 158 | #define IS_VALID_MODEL%0(%1) _:(MIN_VEHICLE_MODEL <= \ 159 | (%1) <= MAX_VEHICLE_MODEL) 160 | #endif 161 | 162 | // Components 163 | #if !defined IS_VALID_COMPONENT_ID 164 | #define IS_VALID_COMPONENT_ID%0(%1) _:(MIN_VEHICLE_COMPONENT_ID <= \ 165 | (%1) <= MAX_VEHICLE_COMPONENT_ID) 166 | #endif 167 | 168 | // Vehicleid 169 | #if !defined IS_VALID_VEHICLEID 170 | #define IS_VALID_VEHICLEID%0(%1) _:(0 < (%1) < MAX_VEHICLES) 171 | #endif 172 | 173 | // ----------------------------------------------------------------------------- 174 | // Natives: 175 | 176 | #if !defined IsValidVehicle 177 | // This function is not defined in SA:MP library. 178 | native IsValidVehicle(vehicleid); 179 | #endif 180 | 181 | // ----------------------------------------------------------------------------- 182 | // Support 3.2: 183 | 184 | #if !defined _TDW_STATIC_ENUM 185 | #if defined __PawnBuild 186 | #define _TDW_STATIC_ENUM static 187 | #else 188 | #define _TDW_STATIC_ENUM 189 | #endif 190 | #endif 191 | 192 | // ----------------------------------------------------------------------------- 193 | // 194 | 195 | @__TDW_VEHICLE_CALL_EMIT_FIX__@(); 196 | @__TDW_VEHICLE_CALL_EMIT_FIX__@() 197 | { 198 | #emit RETN 199 | static null_string[] = !" "; 200 | // The stock compiler crashes because of using sysreq.c on a native 201 | // function. 202 | DestroyVehicle(0); 203 | SetVehicleNumberPlate(0, null_string); 204 | Create3DTextLabel(null_string, 0, 0.0, 0.0, 0.0, 0.0, 0, 0); 205 | Attach3DTextLabelToVehicle(Text3D:0, 0, 0.0, 0.0, 0.0); 206 | #if defined _TDW_VH_DETECT_STREAMER 207 | UpdateDynamic3DTextLabelText(Text3D:0, 0, null_string); 208 | #else 209 | Update3DTextLabelText(Text3D:0, 0, null_string); 210 | #endif 211 | } 212 | -------------------------------------------------------------------------------- /tdw_viterator.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Iterator Array 3 | 4 | | Description: 5 | Create the iterator. Add new functions. 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - DestroyVehicleSafe 30 | Static: 31 | - 32 | Public: 33 | - 34 | Hooks: 35 | - 36 | [Callbacks]: 37 | - 38 | [Definitions]: 39 | - 40 | [Enumerations]: 41 | - 42 | [Macros]: 43 | - 44 | [Tags]: 45 | - 46 | [Variables]: 47 | Global scope: 48 | - Vehicle 49 | Static scope: 50 | - 51 | [Natives]: 52 | - 53 | [Operators]: 54 | - 55 | | Dependencies: 56 | - foreach, or YSI with y_iterator (optional) 57 | \* ========================================================================== */ 58 | 59 | #if defined _inc_tdw_viterator 60 | // I remove this constant because the compiler automatically generates it. 61 | // github.com/Zeex/pawn/issues/107 62 | #undef _inc_tdw_viterator 63 | #endif 64 | 65 | #if defined _TDW_VH_ITERATOR_ARRAY 66 | #endinput 67 | #endif 68 | 69 | #define _TDW_VH_ITERATOR_ARRAY 70 | 71 | // ----------------------------------------------------------------------------- 72 | // Definitions: 73 | 74 | #if !defined foreach || !defined Iter_Add 75 | #endinput 76 | #endif 77 | 78 | #if !defined _TDW_VH_DETECT_FOREACH 79 | #define _TDW_VH_DETECT_FOREACH 80 | #endif 81 | 82 | #if !defined Vehicle@YSII_Ag 83 | // Create the iterator. 84 | new Iterator:Vehicle; 85 | // Remove the warning messages. 86 | // 87 | // foreach generate names with tags. 88 | #pragma unused Vehicle@YSII_Ag, Vehicle@YSII_Cg 89 | #endif 90 | 91 | // ----------------------------------------------------------------------------- 92 | // Static scope: 93 | 94 | static stock 95 | TDW_g_sVehicleId; 96 | 97 | // ----------------------------------------------------------------------------- 98 | // Hooks: 99 | 100 | // AddStaticVehicle hook 101 | #if !defined BAD_AddStaticVehicle 102 | native BAD_AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, 103 | Float:spawn_z, Float:z_angle, color1, color2) = AddStaticVehicle; 104 | #endif 105 | 106 | stock TDWVH_ITER@AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, 107 | Float:spawn_z, Float:z_angle, color1, color2) 108 | { 109 | if (INVALID_VEHICLE_ID != (TDW_g_sVehicleId = AddStaticVehicle(modelid, 110 | spawn_x, spawn_y, spawn_z, z_angle, color1, color2))) { 111 | Iter_Add(Vehicle, TDW_g_sVehicleId); 112 | } 113 | return TDW_g_sVehicleId; 114 | } 115 | 116 | #if defined _ALS_AddStaticVehicle 117 | #undef AddStaticVehicle 118 | #else 119 | #define _ALS_AddStaticVehicle 120 | #endif 121 | 122 | #define AddStaticVehicle TDWVH_ITER@AddStaticVehicle 123 | 124 | 125 | // AddStaticVehicleEx hook 126 | #if !defined BAD_AddStaticVehicleEx 127 | native BAD_AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, 128 | Float:spawn_z, Float:z_angle, color1, color2, respawn_delay, 129 | addsiren = 0) = AddStaticVehicleEx; 130 | #endif 131 | 132 | stock TDWVH_ITER@AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, 133 | Float:spawn_z, Float:z_angle, color1, color2, respawn_delay, addsiren = 0) 134 | { 135 | if (INVALID_VEHICLE_ID != (TDW_g_sVehicleId = AddStaticVehicleEx(modelid, 136 | spawn_x, spawn_y, spawn_z, z_angle, color1, color2, respawn_delay, 137 | addsiren))) { 138 | Iter_Add(Vehicle, TDW_g_sVehicleId); 139 | } 140 | return TDW_g_sVehicleId; 141 | } 142 | 143 | #if defined _ALS_AddStaticVehicleEx 144 | #undef AddStaticVehicleEx 145 | #else 146 | #define _ALS_AddStaticVehicleEx 147 | #endif 148 | 149 | #define AddStaticVehicleEx TDWVH_ITER@AddStaticVehicleEx 150 | 151 | 152 | // CreateVehicle hook 153 | #if !defined BAD_CreateVehicle 154 | native BAD_CreateVehicle(vehicletype, Float:x, Float:y, Float:z, 155 | Float:rotation, color1, color2, respawn_delay, 156 | addsiren = 0) = CreateVehicle; 157 | #endif 158 | 159 | stock TDWVH_ITER@CreateVehicle(vehicletype, Float:x, Float:y, Float:z, 160 | Float:rotation, color1, color2, respawn_delay, addsiren = 0) 161 | { 162 | if (INVALID_VEHICLE_ID != (TDW_g_sVehicleId = CreateVehicle(vehicletype, 163 | x, y, z, rotation, color1, color2, respawn_delay, 164 | addsiren))) { 165 | Iter_Add(Vehicle, TDW_g_sVehicleId); 166 | } 167 | return TDW_g_sVehicleId; 168 | } 169 | 170 | #if defined _ALS_CreateVehicle 171 | #undef CreateVehicle 172 | #else 173 | #define _ALS_CreateVehicle 174 | #endif 175 | 176 | #define CreateVehicle TDWVH_ITER@CreateVehicle 177 | 178 | 179 | // ----------------------------------------------------------------------------- 180 | // Functions: 181 | 182 | /** ------------------------------------------------------------------------ **\ 183 | DestroyVehicleSafe 184 | The ID of the vehicle (ref) 185 | 186 | - 187 | 188 | 189 | Delete the ID of the vehicle from the iterator. 190 | 191 | \** ------------------------------------------------------------------------ **/ 192 | 193 | stock DestroyVehicleSafe(&vehicleid) 194 | { 195 | Iter_SafeRemove(Vehicle, vehicleid, vehicleid); 196 | return DestroyVehicle(vehicleid); 197 | } 198 | 199 | 200 | // ----------------------------------------------------------------------------- 201 | // Hooks: 202 | 203 | // DestroyVehicle hook 204 | #if !defined BAD_DestroyVehicle 205 | native BAD_DestroyVehicle(vehicleid) = DestroyVehicle; 206 | #endif 207 | 208 | stock TDWVH_ITER@DestroyVehicle(vehicleid) 209 | { 210 | return DestroyVehicleSafe(vehicleid); 211 | } 212 | 213 | #if defined _ALS_DestroyVehicle 214 | #undef DestroyVehicle 215 | #else 216 | #define _ALS_DestroyVehicle 217 | #endif 218 | 219 | #define DestroyVehicle TDWVH_ITER@DestroyVehicle 220 | -------------------------------------------------------------------------------- /tdw_vmath.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Math 3 | 4 | | Description: 5 | Mathematical functions for finding the positions. 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - GetNearestVehicleFromPoint 30 | - GetVehicleOffsetFromPos 31 | - GetVehicleBootPos 32 | - GetVehicleBonnetPos 33 | - GetVehicleRoofPos 34 | - IsVehicleInRangeOfPoint 35 | - GetVehicleSpeedFromVelocity 36 | - GetVehicleSpeed 37 | - SetVehicleSpeed 38 | - IsVehicleUpsideDown 39 | - GetVehicleVelocityDirection 40 | Static: 41 | - 42 | Public: 43 | - 44 | Hooks: 45 | - 46 | [Callbacks]: 47 | - 48 | [Definitions]: 49 | - FLOAT_INFINITY 50 | [Enumerations]: 51 | - E_TDW_MATH_VEHICLE_SPEED_TYPE 52 | [Macros]: 53 | - 54 | [Tags]: 55 | - 56 | [Variables]: 57 | Global scope: 58 | - 59 | Static scope: 60 | - 61 | [Natives]: 62 | - 63 | [Operators]: 64 | - 65 | | Dependencies: 66 | - 67 | \* ========================================================================== */ 68 | 69 | #if defined _inc_tdw_vmath 70 | // I remove this constant because the compiler automatically generates it. 71 | // github.com/Zeex/pawn/issues/107 72 | #undef _inc_tdw_vmath 73 | #endif 74 | 75 | #if defined _TDW_VH_MATH 76 | #endinput 77 | #endif 78 | 79 | #define _TDW_VH_MATH 80 | 81 | #include "tdw_vehicle" 82 | 83 | // ----------------------------------------------------------------------------- 84 | // Definitions: 85 | 86 | #if !defined FLOAT_INFINITY 87 | #define FLOAT_INFINITY (Float:0x7F800000) 88 | #endif 89 | 90 | // ----------------------------------------------------------------------------- 91 | // Enumerations: 92 | 93 | enum E_TDW_MATH_VEHICLE_SPEED_TYPE 94 | { 95 | EI_MATH_SPEED_KMPH, // kilometers per hour 96 | EI_MATH_SPEED_MPH // miles per hour 97 | }; 98 | 99 | // ----------------------------------------------------------------------------- 100 | // Functions: 101 | 102 | /** ------------------------------------------------------------------------ **\ 103 | GetNearestVehicleFromPoint 104 | The X map coordinate. 105 | The Y map coordinate. 106 | The Z map coordinate. 107 | The distance 108 | 109 | - 110 | 111 | 112 | 113 | \** ------------------------------------------------------------------------ **/ 114 | 115 | stock GetNearestVehicleFromPoint(Float:x, Float:y, Float:z, 116 | Float:distance = 30.0) 117 | { 118 | new 119 | Float:min_dist, 120 | vehicleid = INVALID_VEHICLE_ID; 121 | #pragma tabsize 0 122 | #if defined _TDW_VH_DETECT_FOREACH 123 | foreach (new i: Vehicle) 124 | #else 125 | for (new i = _TDW_FOREACH_MAX_VEHICLES_; --i != 0;) 126 | #endif 127 | { 128 | if ((min_dist = GetVehicleDistanceFromPoint(i, x, y, z)) <= distance) { 129 | vehicleid = i; 130 | distance = min_dist; 131 | } 132 | } 133 | #pragma tabsize 4 134 | return vehicleid; 135 | } 136 | 137 | /** ------------------------------------------------------------------------ **\ 138 | GetVehicleOffsetFromPos 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | - 148 | 149 | 150 | 151 | \** ------------------------------------------------------------------------ **/ 152 | 153 | stock GetVehicleOffsetFromPos(vehicleid, Float:point_x, Float:point_y, 154 | Float:point_z, &Float:offset_x, &Float:offset_y, &Float:offset_z) 155 | { 156 | new 157 | Float:x, 158 | Float:y, 159 | Float:z; 160 | 161 | if (0 == GetVehiclePos(vehicleid, x, y, z)) 162 | return _:(point_x = point_y = point_z = 0.0); // return 0 163 | 164 | offset_x = floatsub(point_x, x); 165 | offset_y = floatsub(point_y, y); 166 | offset_z = floatsub(point_z, z); 167 | 168 | return 1; 169 | } 170 | 171 | /** ------------------------------------------------------------------------ **\ 172 | GetVehicleBootPos 173 | 174 | 175 | - 176 | 177 | 178 | 179 | \** ------------------------------------------------------------------------ **/ 180 | 181 | stock GetVehicleBootPos(vehicleid, &Float:x, &Float:y, &Float:z) 182 | { 183 | new 184 | Float:angle, 185 | Float:distance; 186 | 187 | if (0 == GetVehicleZAngle(vehicleid, angle)) 188 | return _:(x = y = z = 0.0); // return 0 189 | 190 | GetVehicleModelInfo( 191 | GetVehicleModel(vehicleid), 192 | VEHICLE_MODEL_INFO_SIZE, 193 | x, distance, z 194 | ); 195 | 196 | distance = floatadd(floatdiv(distance, 2.0), 0.1); 197 | 198 | GetVehiclePos(vehicleid, x, y, z); 199 | 200 | x = floatadd(x, floatmul(distance, floatsin(floatadd(-angle, 180.0), 201 | degrees))); 202 | y = floatadd(y, floatmul(distance, floatcos(floatadd(-angle, 180.0), 203 | degrees))); 204 | 205 | return 1; 206 | } 207 | 208 | /** ------------------------------------------------------------------------ **\ 209 | GetVehicleBonnetPos 210 | 211 | 212 | - 213 | 214 | 215 | 216 | \** ------------------------------------------------------------------------ **/ 217 | 218 | stock GetVehicleBonnetPos(vehicleid, &Float:x, &Float:y, &Float:z) 219 | { 220 | new 221 | Float:angle, 222 | Float:distance; 223 | 224 | if (0 == GetVehicleZAngle(vehicleid, angle)) 225 | return _:(x = y = z = 0.0); // return 0 226 | 227 | GetVehicleModelInfo( 228 | GetVehicleModel(vehicleid), 229 | VEHICLE_MODEL_INFO_SIZE, 230 | x, distance, z 231 | ); 232 | 233 | distance = floatadd(floatdiv(distance, 2.0), 0.1); 234 | 235 | GetVehiclePos(vehicleid, x, y, z); 236 | 237 | x = floatsub(x, floatmul(distance, floatsin(floatadd(-angle, 180.0), 238 | degrees))); 239 | y = floatsub(y, floatmul(distance, floatsin(floatadd(-angle, 180.0), 240 | degrees))); 241 | 242 | return 1; 243 | } 244 | 245 | /** ------------------------------------------------------------------------ **\ 246 | GetVehicleRoofPos 247 | 248 | 249 | - 250 | 251 | 252 | 253 | \** ------------------------------------------------------------------------ **/ 254 | 255 | stock GetVehicleRoofPos(vehicleid, &Float:x, &Float:y, &Float:z) 256 | { 257 | new 258 | modelid, 259 | Float:vehicle_z; 260 | 261 | if (0 == (modelid = GetVehicleModel(vehicleid))) 262 | return _:(x = y = z = 0.0); // return 0 263 | 264 | GetVehicleModelInfo(modelid, VEHICLE_MODEL_INFO_SIZE, x, y, vehicle_z); 265 | GetVehiclePos(vehicleid, x, y, z); 266 | 267 | z = floatadd(z, floatsqroot(vehicle_z)); 268 | 269 | return 1; 270 | } 271 | 272 | /** ------------------------------------------------------------------------ **\ 273 | IsVehicleInRangeOfPoint 274 | 275 | 276 | - 277 | 278 | 279 | 280 | \** ------------------------------------------------------------------------ **/ 281 | 282 | stock IsVehicleInRangeOfPoint(vehicleid, Float:range, Float:x, Float:y, Float:z) 283 | { 284 | new 285 | Float:vehicle_x, 286 | Float:vehicle_y, 287 | Float:vehicle_z; 288 | 289 | if (0 == GetVehiclePos(vehicleid, vehicle_x, vehicle_y, vehicle_z)) 290 | return 0; 291 | 292 | x = floatsub(x, vehicle_x); 293 | y = floatsub(y, vehicle_y); 294 | z = floatsub(z, vehicle_z); 295 | 296 | return VectorSize(x, y, z) < floatpower(range, 2); 297 | } 298 | 299 | /** ------------------------------------------------------------------------ **\ 300 | GetVehicleSpeedFromVelocity 301 | 302 | 303 | - 304 | 305 | 306 | 307 | \** ------------------------------------------------------------------------ **/ 308 | 309 | stock Float:GetVehicleSpeedFromVelocity(Float:x, Float:y, Float:z, 310 | E_TDW_MATH_VEHICLE_SPEED_TYPE:type = EI_MATH_SPEED_KMPH) 311 | { 312 | return floatmul(VectorSize(x, y, z), (type == EI_MATH_SPEED_KMPH 313 | ? 180.0 314 | : 111.846814)); 315 | } 316 | 317 | /** ------------------------------------------------------------------------ **\ 318 | GetVehicleSpeed 319 | 320 | 321 | - 322 | 323 | 324 | 325 | \** ------------------------------------------------------------------------ **/ 326 | 327 | stock Float:GetVehicleSpeed(vehicleid, 328 | E_TDW_MATH_VEHICLE_SPEED_TYPE:type = EI_MATH_SPEED_KMPH) 329 | { 330 | static 331 | Float:x, 332 | Float:y, 333 | Float:z; 334 | 335 | return GetVehicleVelocity(vehicleid, x, y, z) 336 | ? GetVehicleSpeedFromVelocity(x, y, z, type) 337 | : FLOAT_INFINITY; 338 | } 339 | 340 | /** ------------------------------------------------------------------------ **\ 341 | SetVehicleSpeed 342 | 343 | 344 | - 345 | 346 | 347 | 348 | \** ------------------------------------------------------------------------ **/ 349 | 350 | stock SetVehicleSpeed(vehicleid, Float:speed, 351 | E_TDW_MATH_VEHICLE_SPEED_TYPE:type = EI_MATH_SPEED_KMPH) 352 | { 353 | new 354 | Float:x, 355 | Float:y, 356 | Float:z; 357 | 358 | if (GetVehicleVelocity(vehicleid, x, y, z)) 359 | { 360 | new 361 | Float:angle; 362 | 363 | GetVehicleVelocity(vehicleid, x, y, z); 364 | GetVehicleZAngle(vehicleid, angle); 365 | 366 | switch (type) 367 | { 368 | case EI_MATH_SPEED_KMPH: 369 | speed = floatdiv(speed, 180.0); 370 | case EI_MATH_SPEED_MPH: 371 | speed = floatdiv(speed, 111.846814); 372 | } 373 | 374 | x = floatmul(speed, floatsin(-angle, degrees)); 375 | y = floatmul(speed, floatcos(-angle, degrees)); 376 | 377 | SetVehicleVelocity(vehicleid, x, y, z); 378 | } 379 | return 0; 380 | } 381 | 382 | /** ------------------------------------------------------------------------ **\ 383 | IsVehicleUpsideDown 384 | 385 | 386 | - 387 | 388 | 389 | 390 | \** ------------------------------------------------------------------------ **/ 391 | 392 | stock IsVehicleUpsideDown(vehicleid) 393 | { 394 | new 395 | Float:x, 396 | Float:y, 397 | Float:z, 398 | Float:w; 399 | 400 | if (0 == GetVehicleRotationQuat(vehicleid, w, x, y, z)) 401 | return 0; 402 | 403 | new 404 | Float:angle = atan2(((y * z) + (w * x)) * 2.0, 405 | (w * w) - (x * x) - (y * y) + (z * z)); 406 | 407 | return ((angle > 90.0) || (angle < -90.0)); 408 | } 409 | 410 | /** ------------------------------------------------------------------------ **\ 411 | GetVehicleVelocityDirection 412 | 413 | 414 | - 415 | 416 | 417 | 418 | \** ------------------------------------------------------------------------ **/ 419 | 420 | stock GetVehicleVelocityDirection(vehicleid, &Float:direction) 421 | { 422 | new 423 | Float:x, 424 | Float:y, 425 | Float:z; 426 | 427 | if (0 == GetVehicleVelocity(vehicleid, x, y, z)) 428 | return 0; 429 | 430 | if (x < 0.0) { 431 | if (y > 0.0) 432 | direction = atan(floatabs(floatdiv(x, y))); 433 | else if (y <= 0.0) 434 | direction = floatadd(atan(floatdiv(y, x)), 90.0); 435 | } else if (x > 0) { 436 | if (y < 0.0) 437 | direction = floatadd(atan(floatabs(floatdiv(x, y))), 180.0); 438 | else if (y >= 0.0) 439 | direction = floatadd(atan(floatdiv(y, x)), 270.0); 440 | } else if (x == 0) { 441 | if (y > 0.0) 442 | direction = 0.0; 443 | else if (y < 0.0) 444 | direction = 180.0; 445 | } 446 | 447 | return 1; 448 | } 449 | -------------------------------------------------------------------------------- /tdw_vnplate.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Number plate 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - GetVehicleNumberPlate 30 | Static: 31 | - 32 | Public: 33 | - 34 | Hooks: 35 | - SetVehicleNumberPlate 36 | [Callbacks]: 37 | - 38 | [Definitions]: 39 | - 40 | [Enumerations]: 41 | - 42 | [Macros]: 43 | - 44 | [Tags]: 45 | - 46 | [Variables]: 47 | Global scope: 48 | - 49 | Static scope: 50 | - TDW_g_sVehicle@NumberPlate 51 | [Natives]: 52 | - BAD_SetVehicleNumberPlate 53 | [Operators]: 54 | - 55 | | Dependencies: 56 | - 57 | \* ========================================================================== */ 58 | 59 | #if defined _inc_tdw_vnplate 60 | // I remove this constant because the compiler automatically generates it. 61 | // github.com/Zeex/pawn/issues/107 62 | #undef _inc_tdw_vnplate 63 | #endif 64 | 65 | #if defined _TDW_VH_NUMBER_PLATE 66 | #endinput 67 | #endif 68 | 69 | #define _TDW_VH_NUMBER_PLATE 70 | 71 | #include "tdw_vehicle" 72 | 73 | // ----------------------------------------------------------------------------- 74 | // Static scope: 75 | 76 | static stock 77 | TDW_g_sVehicle@NumberPlate[MAX_VEHICLES][MAX_NUMBER_PLATE_SIZE char]; 78 | 79 | // ----------------------------------------------------------------------------- 80 | // Hooks: 81 | 82 | // SetVehicleNumberPlate hook 83 | #if !defined BAD_SetVehicleNumberPlate 84 | native BAD_SetVehicleNumberPlate(vehicleid, 85 | numberplate[]) = SetVehicleNumberPlate; 86 | #endif 87 | 88 | stock TDW_NUMPL@SetVehicleNumberPlate(vehicleid, const number_plate[]) 89 | { 90 | new 91 | Float:current_x, 92 | Float:current_y, 93 | Float:current_z; 94 | 95 | if (0 == GetVehiclePos(vehicleid, current_x, current_y, current_z)) 96 | return 0; 97 | 98 | new 99 | Float:current_z_angle, 100 | Float:current_health, 101 | current_panels, 102 | current_doors, 103 | current_lights, 104 | current_tires, 105 | passenegers[MAX_VEHICLE_PASSENGERS]; 106 | 107 | GetVehicleZAngle(vehicleid, current_z_angle); 108 | 109 | #if !defined TDW_NUMPLATE_NOT_SAFE_DAMAGE 110 | GetVehicleHealth(vehicleid, current_health); 111 | GetVehicleDamageStatus(vehicleid, current_panels, current_doors, 112 | current_lights, current_tires); 113 | #endif 114 | 115 | GetVehicleOccupantPlayers(vehicleid, passengers); 116 | 117 | const 118 | PUSH_ARGS_COUNT = 2 * 4, 119 | PUSHED_ARGS = PUSH_ARGS_COUNT + 4; 120 | 121 | #emit PUSH.s number_plate 122 | #emit PUSH.s vehicleid 123 | #emit PUSH.c PUSH_ARGS_COUNT 124 | #emit SYSREQ.c SetVehicleNumberPlate 125 | #emit STACK PUSHED_ARGS 126 | 127 | SetVehicleToRespawn(vehicleid); 128 | 129 | #if !defined TDW_NUMPLATE_NOT_SAFE_NUMBER 130 | strcpy(TDW_g_sVehicle@NumberPlate[vehicleid], number_plate); 131 | #endif 132 | 133 | SetVehiclePos(vehicleid, current_x, current_y, current_z); 134 | 135 | new i; 136 | do { 137 | PutPlayerInVehicle(passengers[i], vehicleid, i); 138 | } while (++i < sizeof passengers); 139 | 140 | #if !defined TDW_NUMPLATE_NOT_SAFE_DAMAGE 141 | SetVehicleHealth(vehicleid, current_health); 142 | UpdateVehicleDamageStatus(vehicleid, current_panels, current_doors, 143 | current_lights, current_tires); 144 | #endif 145 | 146 | return 1; 147 | } 148 | 149 | #if defined _ALS_SetVehicleNumberPlate 150 | #undef SetVehicleNumberPlate 151 | #else 152 | #define _ALS_SetVehicleNumberPlate 153 | #endif 154 | 155 | #define SetVehicleNumberPlate TDW_NUMPL@SetVehicleNumberPlate 156 | 157 | // ----------------------------------------------------------------------------- 158 | // Internal: 159 | 160 | // Checks if a string is packed. 161 | // Other information: //www.compuphase.com/pawn/String_Manipulation.pdf 162 | // Author: Untonyst. 163 | #if !defined IsPackedString 164 | #define IsPackedString(%0) ((%0){0} != 0) 165 | #endif 166 | 167 | #if !defined strcpy 168 | static stock strcpy(dest[], const string[], dest_size = sizeof dest) 169 | { 170 | return 171 | (IsPackedString(dest) ? (dest{0} = '\0') : (dest[0] = '\0')), 172 | strcat(dest, string, dest_size); 173 | } 174 | #endif 175 | 176 | // ----------------------------------------------------------------------------- 177 | // Functions: 178 | 179 | /** ------------------------------------------------------------------------ **\ 180 | GetVehicleNumberPlate 181 | 182 | 183 | - 184 | 185 | 186 | 187 | \** ------------------------------------------------------------------------ **/ 188 | 189 | stock GetVehicleNumberPlate(vehicleid, dest[], bool:packed = false, 190 | dest_size = sizeof dest) 191 | { 192 | #if !defined TDW_NPLATE_NOT_SAFE_NUMBER 193 | return packed 194 | ? strcpy(dest, TDW_g_sNumberPlate[vehicleid], dest_size) 195 | : strunpack(dest, TDW_g_sNumberPlate[vehicleid], dest_size); 196 | #else 197 | return 0; 198 | #endif 199 | } -------------------------------------------------------------------------------- /tdw_vsa_data.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | GTA San Andreas Vehicle Data 3 | 4 | | Description: 5 | The data about the vehicles, such as: name, type, max velocity, category. 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - GetModelStaticSpeed 30 | - GetModelStaticIdFromName 31 | - GetModelStaticNameFromId 32 | - GetModelStaticCategory 33 | - GetModelStaticType 34 | Static: 35 | - 36 | Public: 37 | - 38 | Hooks: 39 | - 40 | [Callbacks]: 41 | - 42 | [Definitions]: 43 | - 44 | [Enumerations]: 45 | - E_TDW_VEHICLE_SA_CATEGORY 46 | - E_TDW_VEHICLE_SA_TYPE 47 | [Macros]: 48 | - 49 | [Tags]: 50 | - 51 | [Variables]: 52 | Global scope: 53 | - 54 | Static scope: 55 | - TDW_g_sVehicleSpeed 56 | - TDW_g_sVehicleNames 57 | - TDW_g_sVehicleCategory 58 | [Natives]: 59 | - 60 | [Operators]: 61 | - 62 | | Dependencies: 63 | - 64 | \* ========================================================================== */ 65 | 66 | #if defined _inc_tdw_vsa_data 67 | // I remove this constant because the compiler automatically generates it. 68 | // github.com/Zeex/pawn/issues/107 69 | #undef _inc_tdw_vsa_data 70 | #endif 71 | 72 | #if defined _TDW_VH_GTASA_DATA 73 | #endinput 74 | #endif 75 | 76 | #define _TDW_VH_GTASA_DATA 77 | 78 | #include "tdw_vehicle" 79 | 80 | // ----------------------------------------------------------------------------- 81 | // Enumerations: 82 | 83 | enum E_TDW_VEHICLE_SA_CATEGORY 84 | { 85 | OFF_ROAD, 86 | SALOONS, 87 | SPORT, 88 | INDUSTRIAL, 89 | STATION_WAGONS, 90 | UNIQUE, 91 | PUBLIC_SERVICE, 92 | LOWRIDERS, 93 | RADIOC, 94 | HELICOPTERS, 95 | BOATS, 96 | TRAILERS, 97 | AIRPLANE, 98 | CONVERTIBLES, 99 | BIKES 100 | }; 101 | 102 | enum E_TDW_VEHICLE_SA_TYPE 103 | { 104 | CAR, 105 | HELICOPTE, 106 | BOAT, 107 | TRAILER, 108 | MOTORBIKE, 109 | TRAIN, 110 | PLANE, 111 | BIKE, 112 | RC 113 | }; 114 | 115 | // ----------------------------------------------------------------------------- 116 | // Static scope: 117 | 118 | static stock const 119 | TDW_g_sVehicleSpeed[MAX_VEHICLE_MODELS + 1] = 120 | { 121 | 160, 160, 200, 120, 150, 165, 110, 170, 110, 180, 160, 240, 160, 160, 140, 122 | 230, 155, 200, 150, 160, 180, 180, 165, 145, 170, 200, 200, 170, 170, 200, 123 | 190, 130, 80, 180, 200, 120, 160, 160, 160, 160, 160, 75, 150, 150, 110, 124 | 165, 280, 200, 190, 150, 120, 240, 190, 190, 190, 140, 160, 160, 165, 160, 125 | 200, 190, 190, 190, 75, 75, 160, 160, 190, 200, 170, 160, 190, 190, 160, 126 | 160, 200, 200, 150, 165, 200, 120, 150, 120, 190, 160, 100, 200, 200, 170, 127 | 170, 160, 160, 190, 220, 170, 200, 200, 140, 140, 160, 75, 220, 220, 160, 128 | 170, 230, 165, 140, 120, 140, 200, 200, 200, 120, 120, 165, 165, 160, 330, 129 | 330, 190, 190, 190, 110, 160, 160, 160, 170, 160, 60, 70, 140, 200, 160, 130 | 160, 160, 110, 110, 150, 160, 230, 160, 165, 170, 160, 160, 160, 200, 160, 131 | 160, 165, 160, 200, 170, 180, 110, 110, 200, 200, 200, 200, 200, 200, 75, 132 | 200, 160, 160, 170, 110, 110, 90, 60, 110, 60, 160, 160, 200, 110, 160, 133 | 165, 190, 160, 170, 120, 165, 190, 200, 140, 200, 110, 120, 200, 200, 60, 134 | 190, 200, 200, 200, 160, 165, 110, 200, 200, 160, 165, 160, 160, 160, 140, 135 | 160, 160 136 | }, 137 | TDW_g_sVehicleNames[MAX_VEHICLE_MODELS + 1][] = 138 | { 139 | !"Landstalker", !"Bravura", !"Buffalo", !"Linerunner", !"Perenniel", 140 | !"Sentinel", !"Dumper", !"Firetruck", !"Trashmaster", !"Stretch", 141 | !"Manana", !"Infernus", !"Voodoo", !"Pony", !"Mule", !"Cheetah", 142 | !"Ambulance", !"Leviathan", !"Moonbeam", !"Esperanto", !"Taxi", 143 | !"Washington", !"Bobcat", !"Mr Whoopee", !"BF Injection", !"Hunter", 144 | !"Premier", !"Enforcer", !"Securicar", !"Banshee", !"Predator", !"Bus", 145 | !"Rhino", !"Barracks", !"Hotknife", !"Article Trailer", !"Previon", 146 | !"Coach", !"Cabbie", !"Stallion", !"Rumpo", !"RC Bandit", !"Romero", 147 | !"Packer", !"Monster", !"Admiral", !"Squallo", !"Seasparrow", !"Pizzaboy", 148 | !"Tram", !"Article Trailer 2", !"Turismo", !"Speeder", !"Reefer", 149 | !"Tropic", !"Flatbed", !"Yankee", !"Caddy", !"Solair", 150 | !"Topfun Van (Berkley's RC)", !"Skimmer", !"PCJ-600", !"Faggio", 151 | !"Freeway", !"RC Baron", !"RC Raider", !"Glendale", !"Oceanic", !"Sanchez", 152 | !"Sparrow", !"Patriot", !"Quad", !"Coastguard", !"Dinghy", !"Hermes", 153 | !"Sabre", !"Rustler", !"ZR-350", !"Walton", !"Regina", !"Comet", !"BMX", 154 | !"Burrito", !"Camper", !"Marquis", !"Baggage", !"Dozer", !"Maverick", 155 | !"SAN News Maverick", !"Rancher", !"FBI Rancher", !"Virgo", !"Greenwood", 156 | !"Jetmax", !"Hotring Racer", !"Sandking", !"Blista Compact", 157 | !"Police Maverick", !"Boxville", !"Benson", !"Mesa", !"RC Goblin", 158 | !"Hotring Racer", !"Hotring Racer", !"Bloodring Banger", !"Rancher", 159 | !"Super GT", !"Elegant", !"Journey", !"Bike", !"Mountain Bike", !"Beagle", 160 | !"Cropduster", !"Stuntplane", !"Tanker", !"Roadtrain", !"Nebula", 161 | !"Majestic", !"Buccaneer", !"Shamal", !"Hydra", !"FCR-900", !"NRG-500", 162 | !"HPV1000", !"Cement Truck", !"Towtruck", !"Fortune", !"Cadrona", 163 | !"FBI Truck", !"Willard", !"Forklift", !"Tractor", !"Combine Harvester", 164 | !"Feltzer", !"Remington", !"Slamvan", !"Blade", !"Freight (Train)", 165 | !"Brownstreak (Train)", !"Vortex", !"Vincent", !"Bullet", !"Clover", 166 | !"Sadler", !"Firetruck LA", !"Hustler", !"Intruder", !"Primo", !"Cargobob", 167 | !"Tampa", !"Sunrise", !"Merit", !"Utility Van", !"Nevada", !"Yosemite", 168 | !"Windsor", !"Monster \"A\"", !"Monster \"B\"", !"Uranus", !"Jester", 169 | !"Sultan", !"Stratum", !"Elegy", !"Raindance", !"RC Tiger", !"Flash", 170 | !"Tahoma", !"Savanna", !"Bandito", !"Freight Flat Trailer (Train)", 171 | !"Streak Trailer (Train)", !"Kart", !"Mower", !"Dune", !"Sweeper", 172 | !"Broadway", !"Tornado", !"AT400", !"DFT-30", !"Huntley", !"Stafford", 173 | !"BF-400", !"Newsvan", !"Tug", !"Petrol Trailer", !"Emperor", !"Wayfarer", 174 | !"Euros", !"Hotdog", !"Club", !"Freight Box Trailer (Train)", 175 | !"Article Trailer 3", !"Andromada", !"Dodo", !"RC Cam", !"Launch", 176 | !"Police Car (LSPD)", !"Police Car (SFPD)", !"Police Car (LVPD)", 177 | !"Police Ranger", !"Picador", !"S.W.A.T.", !"Alpha", !"Phoenix", 178 | !"Glendale Shit", !"Sadler Shit", !"Baggage Trailer \"A\"", 179 | !"Baggage Trailer \"B\"", !"Tug Stairs Trailer", !"Boxville", 180 | !"Farm Trailer", !"Utility Trailer" 181 | }, 182 | E_TDW_VEHICLE_SA_CATEGORY:TDW_g_sVehicleCategory[MAX_VEHICLE_MODELS + 1] = 183 | { 184 | OFF_ROAD, SALOONS, SPORT, INDUSTRIAL, 185 | STATION_WAGONS, SALOONS, UNIQUE, PUBLIC_SERVICE, 186 | INDUSTRIAL, UNIQUE, SALOONS, SPORT, 187 | LOWRIDERS, INDUSTRIAL, INDUSTRIAL, SPORT, 188 | PUBLIC_SERVICE, HELICOPTERS, STATION_WAGONS, SALOONS, 189 | PUBLIC_SERVICE, SALOONS, INDUSTRIAL, UNIQUE, 190 | OFF_ROAD, HELICOPTERS, SALOONS, PUBLIC_SERVICE, 191 | UNIQUE, SPORT, BOATS, PUBLIC_SERVICE, 192 | PUBLIC_SERVICE, PUBLIC_SERVICE, UNIQUE, TRAILERS, 193 | SALOONS, PUBLIC_SERVICE, PUBLIC_SERVICE, CONVERTIBLES, 194 | INDUSTRIAL, RADIOC, UNIQUE, INDUSTRIAL, 195 | OFF_ROAD, SALOONS, BOATS, HELICOPTERS, 196 | BIKES, UNIQUE, TRAILERS, SPORT, 197 | BOATS, BOATS, BOATS, INDUSTRIAL, 198 | INDUSTRIAL, UNIQUE, STATION_WAGONS, INDUSTRIAL, 199 | AIRPLANE, BIKES, BIKES, BIKES, 200 | RADIOC, RADIOC, SALOONS, SALOONS, 201 | BIKES, HELICOPTERS, OFF_ROAD, BIKES, 202 | BOATS, BOATS, SALOONS, SPORT, 203 | AIRPLANE, SPORT, INDUSTRIAL, STATION_WAGONS, 204 | CONVERTIBLES, BIKES, INDUSTRIAL, UNIQUE, 205 | BOATS, UNIQUE, UNIQUE, HELICOPTERS, 206 | HELICOPTERS, OFF_ROAD, PUBLIC_SERVICE, SALOONS, 207 | SALOONS, BOATS, SPORT, OFF_ROAD, 208 | SPORT, HELICOPTERS, INDUSTRIAL, INDUSTRIAL, 209 | OFF_ROAD, RADIOC, SPORT, SPORT, 210 | SALOONS, OFF_ROAD, SPORT, SALOONS, 211 | UNIQUE, BIKES, BIKES, AIRPLANE, 212 | AIRPLANE, AIRPLANE, INDUSTRIAL, INDUSTRIAL, 213 | SALOONS, SALOONS, SALOONS, AIRPLANE, 214 | AIRPLANE, BIKES, BIKES, PUBLIC_SERVICE, 215 | INDUSTRIAL, UNIQUE, SALOONS, SALOONS, 216 | PUBLIC_SERVICE, SALOONS, UNIQUE, INDUSTRIAL, 217 | UNIQUE, CONVERTIBLES, LOWRIDERS, LOWRIDERS, 218 | LOWRIDERS, UNIQUE, UNIQUE, UNIQUE, 219 | SALOONS, SPORT, SALOONS, INDUSTRIAL, 220 | PUBLIC_SERVICE, UNIQUE, SALOONS, SALOONS, 221 | HELICOPTERS, SALOONS, SALOONS, SALOONS, 222 | INDUSTRIAL, AIRPLANE, INDUSTRIAL, CONVERTIBLES, 223 | OFF_ROAD, OFF_ROAD, SPORT, SPORT, 224 | SALOONS, STATION_WAGONS, SALOONS, HELICOPTERS, 225 | RADIOC, SPORT, LOWRIDERS, LOWRIDERS, 226 | OFF_ROAD, TRAILERS, TRAILERS, UNIQUE, 227 | UNIQUE, OFF_ROAD, UNIQUE, LOWRIDERS, 228 | LOWRIDERS, AIRPLANE, INDUSTRIAL, OFF_ROAD, 229 | SALOONS, BIKES, INDUSTRIAL, UNIQUE, 230 | TRAILERS, SALOONS, BIKES, SPORT, 231 | UNIQUE, SPORT, TRAILERS, TRAILERS, 232 | AIRPLANE, AIRPLANE, RADIOC, BOATS, 233 | PUBLIC_SERVICE, PUBLIC_SERVICE, PUBLIC_SERVICE, PUBLIC_SERVICE, 234 | INDUSTRIAL, PUBLIC_SERVICE, SPORT, SPORT, 235 | SALOONS, INDUSTRIAL, TRAILERS, TRAILERS, 236 | TRAILERS, INDUSTRIAL, TRAILERS, TRAILERS 237 | }, 238 | E_TDW_VEHICLE_SA_TYPE:TDW_g_sVehicleType[MAX_VEHICLE_MODELS + 1] = 239 | { 240 | CAR, CAR, CAR, CAR, CAR, CAR, CAR, 241 | CAR, CAR, CAR, CAR, CAR, CAR, CAR, 242 | CAR, CAR, CAR, HELICOPTE, CAR, CAR, CAR, 243 | CAR, CAR, CAR, CAR, HELICOPTE, CAR, CAR, 244 | CAR, CAR, BOAT, CAR, CAR, CAR, CAR, 245 | TRAILER, CAR, CAR, CAR, CAR, CAR, RC, 246 | CAR, CAR, CAR, CAR, BOAT, HELICOPTE, MOTORBIKE, 247 | TRAIN, TRAILER, CAR, BOAT, BOAT, BOAT, CAR, 248 | CAR, CAR, CAR, CAR, PLANE, MOTORBIKE, MOTORBIKE, 249 | MOTORBIKE, RC, RC, CAR, CAR, MOTORBIKE, CAR, 250 | CAR, CAR, BOAT, BOAT, CAR, CAR, PLANE, 251 | CAR, CAR, CAR, CAR, BIKE, CAR, CAR, 252 | BOAT, CAR, CAR, HELICOPTE, HELICOPTE, CAR, CAR, 253 | CAR, CAR, BOAT, CAR, CAR, CAR, HELICOPTE, 254 | CAR, CAR, CAR, RC, CAR, CAR, CAR, 255 | CAR, CAR, CAR, CAR, BIKE, BIKE, PLANE, 256 | PLANE, PLANE, CAR, CAR, CAR, CAR, CAR, 257 | PLANE, PLANE, MOTORBIKE, MOTORBIKE, MOTORBIKE, CAR, CAR, 258 | CAR, CAR, CAR, CAR, CAR, CAR, CAR, 259 | CAR, CAR, CAR, CAR, TRAIN, TRAIN, CAR, 260 | CAR, CAR, CAR, CAR, CAR, CAR, CAR, 261 | CAR, HELICOPTE, CAR, CAR, CAR, CAR, PLANE, 262 | CAR, CAR, CAR, CAR, CAR, CAR, CAR, 263 | CAR, CAR, HELICOPTE, RC, CAR, CAR, CAR, 264 | CAR, TRAIN, TRAIN, RC, CAR, CAR, CAR, 265 | CAR, CAR, PLANE, CAR, CAR, CAR, MOTORBIKE, 266 | CAR, CAR, TRAILER, CAR, MOTORBIKE, CAR, CAR, 267 | CAR, TRAIN, TRAILER, PLANE, PLANE, RC, BOAT, 268 | CAR, CAR, CAR, CAR, CAR, CAR, CAR, 269 | CAR, CAR, CAR, TRAILER, TRAILER, TRAILER, CAR, 270 | TRAILER, TRAILER 271 | }; 272 | 273 | // ----------------------------------------------------------------------------- 274 | // Functions: 275 | 276 | /** ------------------------------------------------------------------------ **\ 277 | GetModelStaticSpeed 278 | The model id 279 | 280 | - 281 | 282 | 283 | 284 | \** ------------------------------------------------------------------------ **/ 285 | 286 | stock GetModelStaticSpeed(modelid) 287 | { 288 | if (0 == IS_VALID_MODEL(modelid)) 289 | return -1; 290 | return TDW_g_sVehicleSpeed[modelid - MIN_VEHICLE_MODEL]; 291 | } 292 | 293 | /** ------------------------------------------------------------------------ **\ 294 | GetModelStaticIdFromName 295 | The model name 296 | 297 | - 298 | 299 | 300 | 301 | \** ------------------------------------------------------------------------ **/ 302 | 303 | stock 304 | GetModelStaticIdFromName(const name[]) 305 | { 306 | for (new i = sizeof TDW_g_sVehicleNames; --i != -1;) { 307 | if (strcmp(name, TDW_g_sVehicleNames[i], true) != 0) 308 | continue; 309 | return i + MIN_VEHICLE_MODEL; 310 | } 311 | return 0; 312 | } 313 | 314 | /** ------------------------------------------------------------------------ **\ 315 | GetModelStaticNameFromId 316 | The model id 317 | An array into which to store the name 318 | The length of the string that should be stored 319 | 320 | - 321 | 322 | 323 | 324 | \** ------------------------------------------------------------------------ **/ 325 | 326 | stock GetModelStaticNameFromId(modelid, name[], name_size = sizeof name) 327 | { 328 | if (0 == IS_VALID_MODEL(modelid)) 329 | return _:(name[0] = '\0'); // return 0 330 | name[0] = '\0'; 331 | return strunpack(name, TDW_g_sVehicleNames[modelid - MIN_VEHICLE_MODEL], 332 | name_size); 333 | } 334 | 335 | /** ------------------------------------------------------------------------ **\ 336 | GetModelStaticCategory 337 | The model id 338 | 339 | - 340 | 341 | 342 | 343 | \** ------------------------------------------------------------------------ **/ 344 | 345 | stock E_TDW_VEHICLE_SA_CATEGORY:GetModelStaticCategory(modelid) 346 | { 347 | if (0 == IS_VALID_MODEL(modelid)) 348 | return E_TDW_VEHICLE_SA_CATEGORY:-1; 349 | return TDW_g_sVehicleCategory[modelid - MIN_VEHICLE_MODEL]; 350 | } 351 | 352 | /** ------------------------------------------------------------------------ **\ 353 | GetModelStaticType 354 | The model id 355 | 356 | - 357 | 358 | 359 | 360 | \** ------------------------------------------------------------------------ **/ 361 | 362 | stock E_TDW_VEHICLE_SA_TYPE:GetModelStaticType(modelid) 363 | { 364 | if (0 == IS_VALID_MODEL(modelid)) 365 | return E_TDW_VEHICLE_SA_TYPE:-1; 366 | return TDW_g_sVehicleType[modelid - MIN_VEHICLE_MODEL]; 367 | } 368 | -------------------------------------------------------------------------------- /tdw_vutils.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Useful functions 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - DestroyVehicles 30 | - GetNumberOfValidVehicles 31 | - IsVehicleOccupied 32 | - IsVehicleSeatOccupied 33 | - GetVehicleMaxPassengers 34 | - GetVehicleDoorsCount 35 | - IsValidModelForPaintjob 36 | - GetVehicleWheelPos 37 | - GetVehicleOccupant 38 | - GetVehicleOccupantPlayers 39 | - IsVehicleMoving 40 | - IsVehicleBackwordsDirection 41 | Static: 42 | - 43 | Public: 44 | - 45 | Hooks: 46 | - 47 | [Callbacks]: 48 | - 49 | [Definitions]: 50 | - 51 | [Enumerations]: 52 | - E_TDW_VEHICLE_WHEEL 53 | [Macros]: 54 | - 55 | [Tags]: 56 | - 57 | [Variables]: 58 | Global scope: 59 | - 60 | Static scope: 61 | - 62 | [Natives]: 63 | - 64 | [Operators]: 65 | - 66 | | Dependencies: 67 | - 68 | \* ========================================================================== */ 69 | 70 | #if defined _inc_tdw_vutils 71 | // I remove this constant because the compiler automatically generates it. 72 | // github.com/Zeex/pawn/issues/107 73 | #undef _inc_tdw_vutils 74 | #endif 75 | 76 | #if defined _TDW_VH_USEFUL_FUNCTIONS 77 | #endinput 78 | #endif 79 | 80 | #define _TDW_VH_USEFUL_FUNCTIONS 81 | 82 | #include "tdw_vehicle" 83 | 84 | // ----------------------------------------------------------------------------- 85 | // Enumerations: 86 | 87 | enum E_TDW_VEHICLE_WHEEL 88 | { 89 | FRONT_LEFT, FRONT_RIGHT, 90 | MIDDLE_LEFT, MIDDLE_RIGHT, // applies to vehicles with 3 axes 91 | REAR_LEFT, REAR_RIGTH 92 | }; 93 | 94 | // ----------------------------------------------------------------------------- 95 | // Functions: 96 | 97 | /** ------------------------------------------------------------------------ **\ 98 | DestroyVehicles 99 | 100 | 101 | - 102 | 103 | 104 | 105 | \** ------------------------------------------------------------------------ **/ 106 | 107 | stock DestroyVehicles(const ...) 108 | { 109 | const BYTES_PER_CELL = cellbits / charbits; 110 | 111 | new 112 | count, 113 | bytes_args; 114 | 115 | // Get number (in bytes) of the variadic arguments 116 | #emit LOAD.s.pri 8 117 | #emit STOR.s.pri bytes_args 118 | 119 | if (0 != bytes_args) { 120 | new 121 | darg_start, 122 | darg_end, 123 | ret; 124 | 125 | // Get the pointer of start dynamic arguments 126 | #emit LCTRL 5 127 | #emit ADD.c 12 128 | #emit STOR.s.pri darg_start 129 | 130 | // Get the pointer of end dynamic arguments 131 | #emit LOAD.s.alt bytes_args 132 | #emit ADD 133 | #emit STOR.s.pri darg_end 134 | 135 | // Use it! 136 | do { 137 | // Get the value from te pointer 138 | #emit LOAD.i 139 | // Push the value 140 | #emit PUSH.pri 141 | #emit PUSH.c 4 142 | #emit SYSREQ.c DestroyVehicle 143 | // Get the return value from the called function 144 | #emit STOR.s.pri ret 145 | 146 | if (ret) 147 | count++; 148 | 149 | darg_end -= BYTES_PER_CELL; 150 | 151 | #emit LOAD.s.pri darg_end 152 | } while (darg_end > darg_start); 153 | 154 | bytes_args += bytes_args + BYTES_PER_CELL; 155 | // Restore the stack 156 | #emit LCTRL 4 157 | #emit LOAD.s.alt bytes_args 158 | #emit ADD 159 | #emit SCTRL 4 160 | } else { 161 | #if defined _TDW_VH_DETECT_FOREACH 162 | foreach (new i: Vehicle) 163 | #else 164 | for (new i = _TDW_FOREACH_MAX_VEHICLES_; --i != 0;) 165 | #endif 166 | { 167 | if (0 == DestroyVehicle(i)) 168 | ++count; 169 | } 170 | } 171 | return count; 172 | } 173 | 174 | /** ------------------------------------------------------------------------ **\ 175 | GetNumberOfValidVehicles 176 | 177 | 178 | - 179 | 180 | 181 | 182 | \** ------------------------------------------------------------------------ **/ 183 | 184 | stock GetNumberOfValidVehicles() 185 | { 186 | #if defined _TDW_VH_DETECT_FOREACH 187 | return Iter_Count(Vehicle); 188 | #else 189 | new 190 | count; 191 | for (new i = _TDW_FOREACH_MAX_VEHICLES_; --i != 0;) 192 | if (IsValidVehicle(i)) 193 | ++count; 194 | return count; 195 | #endif 196 | } 197 | 198 | /** ------------------------------------------------------------------------ **\ 199 | IsVehicleOccupied 200 | 201 | 202 | - 203 | 204 | 205 | 206 | \** ------------------------------------------------------------------------ **/ 207 | 208 | stock IsVehicleOccupied(vehicleid) 209 | { 210 | if (IsValidVehicle(vehicleid)) { 211 | #if defined foreach 212 | foreach (new i: Player) 213 | #else 214 | for (new i = _TDW_FOREACH_MAX_PLAYERS_; --i != -1;) 215 | #endif 216 | { 217 | if (0 != IsPlayerInVehicle(i, vehicleid)) 218 | return 1; 219 | } 220 | } 221 | return 0; 222 | } 223 | 224 | /** ------------------------------------------------------------------------ **\ 225 | IsVehicleSeatOccupied 226 | 227 | 228 | - 229 | 230 | 231 | 232 | \** ------------------------------------------------------------------------ **/ 233 | 234 | stock IsVehicleSeatOccupied(vehicleid, seatid) 235 | { 236 | if (IsValidVehicle(vehicleid)) { 237 | #if defined foreach 238 | foreach (new i: Player) 239 | #else 240 | for (new i = _TDW_FOREACH_MAX_PLAYERS_; --i != -1;) 241 | #endif 242 | { 243 | if (0 == IsPlayerInVehicle(i, vehicleid)) 244 | continue; 245 | if (GetPlayerVehicleSeat(i) != seatid) 246 | continue; 247 | return 1; 248 | } 249 | } 250 | return 0; 251 | } 252 | 253 | /** ------------------------------------------------------------------------ **\ 254 | GetVehicleMaxPassengers 255 | 256 | 257 | - 258 | 259 | 260 | 261 | \** ------------------------------------------------------------------------ **/ 262 | 263 | stock GetVehicleMaxPassengers(modelid) 264 | { 265 | static const 266 | vehicle_seat_data[MAX_VEHICLE_MODELS + 1 char] = 267 | { 268 | 4, 2, 2, 2, 4, 4, 1, 2, 2, 4, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 4, 4, 2, 2, 269 | 2, 1, 4, 4, 4, 2, 1, 7, 1, 2, 2, 0, 2, 7, 4, 2, 4, 1, 2, 2, 2, 4, 1, 2, 270 | 1, 0, 0, 2, 1, 1, 1, 2, 2, 2, 4, 4, 2, 2, 2, 2, 1, 1, 4, 4, 2, 2, 4, 2, 271 | 1, 1, 2, 2, 1, 2, 2, 4, 2, 1, 4, 3, 1, 1, 1, 4, 2, 2, 4, 2, 4, 1, 2, 2, 272 | 2, 4, 4, 2, 2, 1, 2, 2, 2, 2, 2, 4, 2, 1, 1, 2, 1, 1, 2, 2, 4, 2, 2, 1, 273 | 1, 2, 2, 2, 2, 2, 2, 2, 2, 4, 1, 1, 1, 2, 2, 2, 2, 7, 7, 1, 4, 2, 2, 2, 274 | 2, 2, 4, 4, 2, 2, 4, 4, 2, 1, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 1, 2, 4, 4, 275 | 1, 0, 0, 1, 1, 2, 1, 2, 2, 1, 2, 4, 4, 2, 4, 1, 0, 4, 2, 2, 2, 2, 0, 0, 276 | 7, 2, 2, 1, 4, 4, 4, 2, 2, 2, 2, 2, 4, 2, 0, 0, 0, 4, 0, 0 277 | }; 278 | return ( 279 | IS_VALID_MODEL(modelid) 280 | ? (vehicle_seat_data{modelid - MIN_VEHICLE_MODEL}) 281 | : 0 282 | ); 283 | } 284 | 285 | /** ------------------------------------------------------------------------ **\ 286 | GetVehicleDoorsCount 287 | 288 | 289 | - 290 | 291 | 292 | 293 | \** ------------------------------------------------------------------------ **/ 294 | 295 | stock GetVehicleDoorsCount(modelid) 296 | { 297 | static const 298 | vehicle_door_data[MAX_VEHICLE_MODELS + 1 char] = 299 | { 300 | 4, 2, 2, 2, 4, 4, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 4, 4, 2, 2, 301 | 0, 1, 4, 2, 2, 0, 0, 0, 0, 2, 2, 0, 2, 0, 4, 0, 2, 0, 2, 2, 2, 4, 0, 2, 302 | 0, 0, 0, 2, 0, 0, 0, 2, 2, 0, 4, 2, 0, 0, 0, 0, 0, 0, 4, 4, 0, 2, 4, 0, 303 | 0, 0, 2, 2, 1, 2, 2, 4, 0, 0, 2, 2, 0, 0, 0, 4, 4, 2, 4, 2, 4, 0, 0, 2, 304 | 2, 4, 2, 2, 2, 0, 0, 0, 0, 2, 2, 4, 2, 0, 0, 2, 0, 0, 2, 2, 4, 2, 2, 0, 305 | 1, 0, 0, 0, 2, 2, 2, 2, 2, 4, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 4, 2, 2, 2, 306 | 2, 2, 4, 4, 0, 2, 4, 4, 2, 0, 2, 0, 2, 2, 2, 2, 4, 4, 2, 2, 0, 2, 4, 0, 307 | 0, 0, 0, 0, 0, 2, 2, 0, 2, 0, 2, 4, 4, 0, 2, 2, 0, 4, 0, 2, 2, 2, 0, 0, 308 | 0, 2, 0, 0, 4, 4, 4, 2, 2, 0, 2, 2, 4, 2, 0, 0, 0, 2, 0, 0 309 | }; 310 | return ( 311 | IS_VALID_MODEL(modelid) 312 | ? (vehicle_door_data{modelid - MIN_VEHICLE_MODEL}) 313 | : 0 314 | ); 315 | } 316 | 317 | /** ------------------------------------------------------------------------ **\ 318 | IsValidModelForPaintjob 319 | 320 | 321 | - 322 | 323 | 324 | 325 | \** ------------------------------------------------------------------------ **/ 326 | 327 | stock IsValidModelForPaintjob(modelid) 328 | { 329 | switch (modelid) { 330 | case 483: // 0 331 | return 1; 332 | case 575: // 1 333 | return 2; 334 | case 534, 535, 536, 558, 559, 560, 561, 562, 567, 576: // 012 335 | return 3; 336 | } 337 | return 0; 338 | } 339 | 340 | /** ------------------------------------------------------------------------ **\ 341 | GetVehicleWheelPos 342 | 343 | 344 | - 345 | 346 | 347 | 348 | \** ------------------------------------------------------------------------ **/ 349 | 350 | stock GetVehicleWheelPos(vehicletype, E_TDW_VEHICLE_WHEEL:wheel, &Float:x, 351 | &Float:y, &Float:z) 352 | { 353 | if (0 == GetVehiclePos(vehicletype, x, y, z)) 354 | return _:(x = y = z = 0.0); // return 0 355 | 356 | new 357 | Float:z_angle, 358 | Float:vehicle_x, 359 | Float:vehicle_y, 360 | Float:vehicle_z, 361 | Float:div; 362 | 363 | GetVehicleZAngle(vehicletype, z_angle); 364 | vehicletype = GetVehicleModel(vehicletype); 365 | 366 | switch (wheel) 367 | { 368 | case FRONT_LEFT, FRONT_RIGHT: 369 | GetVehicleModelInfo(vehicletype, 370 | VEHICLE_MODEL_INFO_WHEELSFRONT, 371 | vehicle_x, vehicle_y, vehicle_z 372 | ); 373 | case MIDDLE_LEFT, MIDDLE_RIGHT: 374 | GetVehicleModelInfo(vehicletype, 375 | VEHICLE_MODEL_INFO_WHEELSMID, 376 | vehicle_x, vehicle_y, vehicle_z 377 | ); 378 | case REAR_LEFT, REAR_RIGTH: 379 | GetVehicleModelInfo(vehicletype, 380 | VEHICLE_MODEL_INFO_WHEELSREAR, 381 | vehicle_x, vehicle_y, vehicle_z 382 | ); 383 | } 384 | 385 | div = (_:wheel % 2) ? (vehicle_x) : (-vehicle_x); 386 | 387 | x = (floatsin((z_angle = 360 - z_angle), degrees) * vehicle_y) + 388 | (floatcos(z_angle, degrees) * div) + x; 389 | y = (floatcos(z_angle, degrees) * vehicle_y) - 390 | (floatsin(z_angle, degrees) * div) + y; 391 | z = z + vehicle_z; 392 | 393 | return 1; 394 | } 395 | 396 | /** ------------------------------------------------------------------------ **\ 397 | GetVehicleOccupant 398 | 399 | 400 | - 401 | 402 | 403 | 404 | \** ------------------------------------------------------------------------ **/ 405 | 406 | stock GetVehicleOccupant(vehicleid, seatid = 0) 407 | { 408 | if (IsValidVehicle(vehicleid)) { 409 | #if defined foreach 410 | foreach (new i: Player) 411 | #else 412 | for (new i = _TDW_FOREACH_MAX_PLAYERS_; --i != -1;) 413 | #endif 414 | { 415 | if (GetPlayerVehicleID(i) != vehicleid) 416 | continue; 417 | if (GetPlayerVehicleSeat(i) != seatid) 418 | continue; 419 | 420 | return i; 421 | } 422 | } 423 | return INVALID_PLAYER_ID; 424 | } 425 | 426 | /** ------------------------------------------------------------------------ **\ 427 | GetVehicleOccupantPlayers 428 | 429 | 430 | - 431 | 432 | 433 | 434 | \** ------------------------------------------------------------------------ **/ 435 | 436 | stock GetVehicleOccupantPlayers(vehicleid, playerlist[], 437 | size = sizeof playerlist) 438 | { 439 | if (IsValidVehicle(vehicleid)) 440 | { 441 | new 442 | array_index, 443 | i; 444 | 445 | #if defined foreach 446 | foreach (new i: Player) 447 | #else 448 | for (new i = _TDW_FOREACH_MAX_PLAYERS_; --i != -1;) 449 | #endif 450 | { 451 | if (GetPlayerVehicleID(i) != vehicleid) 452 | continue; 453 | if (array_index >= size) 454 | break; 455 | else playerlist[array_index++] = i; 456 | } 457 | if (0 != array_index) { 458 | playerlist[array_index] = INVALID_VEHICLE_ID; 459 | return 1; 460 | } 461 | } 462 | return 0; 463 | } 464 | 465 | /** ------------------------------------------------------------------------ **\ 466 | IsVehicleMoving 467 | 468 | 469 | - 470 | 471 | 472 | 473 | \** ------------------------------------------------------------------------ **/ 474 | 475 | stock IsVehicleMoving(vehicleid) 476 | { 477 | new 478 | Float:x, 479 | Float:y, 480 | Float:z; 481 | 482 | if (0 != GetVehicleVelocity(vehicleid, x, y, z)) { 483 | if (0 == _:floatcmp(x, 0.0) && 0 == _:floatcmp(y, 0.0) && 484 | 0 == _:floatcmp(z, 0.0)) 485 | return 1; 486 | } 487 | return 0; 488 | } 489 | 490 | /** ------------------------------------------------------------------------ **\ 491 | IsVehicleBackwordsDirection 492 | 493 | 494 | - 495 | 496 | 497 | 498 | \** ------------------------------------------------------------------------ **/ 499 | 500 | stock IsVehicleBackwordsDirection(vehicleid) 501 | { 502 | new 503 | Float:x, 504 | Float:y, 505 | Float:z; 506 | 507 | if (GetVehicleVelocity(vehicleid, x, y, z)) 508 | { 509 | new 510 | Float:z_angle; 511 | 512 | GetVehicleZAngle(vehicleid, z_angle); 513 | 514 | if (z_angle < 90.0) { 515 | if (x > 0.0 && y < 0.0) 516 | return 1; 517 | } else if (z_angle < 180.0) { 518 | if (x > 0.0 && y > 0.0) 519 | return 1; 520 | } else if (z_angle < 270.0) { 521 | if (x < 0.0 && y > 0.0) 522 | return 1; 523 | } else { 524 | if (x < 0.0 && y < 0.0) 525 | return 1; 526 | } 527 | } 528 | return 0; 529 | } 530 | -------------------------------------------------------------------------------- /tdw_vxneon.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Neon 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - AddNeonToVehicle 30 | - RemoveNeonFromVehicle 31 | Static: 32 | - 33 | Public: 34 | - OnVehicleDeath 35 | Hooks: 36 | - 37 | [Callbacks]: 38 | - TDWHNE@OnVehicleDeath 39 | [Definitions]: 40 | - 41 | [Enumerations]: 42 | - E_TDW_NEON_COLOR 43 | - E_TDW_NEON_OBJECTS 44 | [Macros]: 45 | - 46 | [Tags]: 47 | - 48 | [Variables]: 49 | Global scope: 50 | - 51 | Static scope: 52 | - TDW_g_sNeon 53 | - TDW_g_sIsNeonAttached 54 | [Natives]: 55 | - 56 | [Operators]: 57 | - 58 | | Dependencies: 59 | - 60 | \* ========================================================================== */ 61 | 62 | #if defined _inc_tdw_vxneon 63 | // I remove this constant because the compiler automatically generates it. 64 | // github.com/Zeex/pawn/issues/107 65 | #undef _inc_tdw_vxneon 66 | #endif 67 | 68 | #if defined _TDW_VH_SYS_VEHICLE_NEON 69 | #endinput 70 | #endif 71 | 72 | #define _TDW_VH_SYS_VEHICLE_NEON 73 | 74 | #include "tdw_vehicle" 75 | 76 | // Modules 77 | #include "tdw_vsa_data" 78 | 79 | // ----------------------------------------------------------------------------- 80 | // Enumerations: 81 | 82 | enum E_TDW_NEON_COLOR 83 | { 84 | // objects 85 | NEON_COLOR_RED = 18647, 86 | NEON_COLOR_BLUE, 87 | NEON_COLOR_GREEN, 88 | NEON_COLOR_YELLOW, 89 | NEON_COLOR_PINK, 90 | NEON_COLOR_WHITE 91 | }; 92 | 93 | _TDW_STATIC_ENUM enum E_TDW_NEON_OBJECTS 94 | { 95 | EI_NEON_LEFT_ID, 96 | EI_NEON_RIGHT_ID 97 | }; 98 | 99 | // ----------------------------------------------------------------------------- 100 | // Static scope: 101 | 102 | static stock 103 | TDW_g_sNeon[MAX_VEHICLES][E_TDW_NEON_OBJECTS], 104 | bool:TDW_g_sIsNeonAttached[MAX_VEHICLES char]; 105 | 106 | // ----------------------------------------------------------------------------- 107 | // Hooks: 108 | 109 | // OnVehicleDeath hook 110 | #if defined TDWHNE@OnVehicleDeath 111 | forward OnVehicleDeath(vehicleid, killerid); 112 | #endif 113 | 114 | public 115 | OnVehicleDeath(vehicleid, killerid) 116 | { 117 | RemoveNeonFromVehicle(vehicleid); 118 | 119 | #if defined TDWHNE@OnVehicleDeath 120 | return TDWHNE@OnVehicleDeath(vehicleid, killerid); 121 | #else 122 | return 1; 123 | #endif 124 | } 125 | #if defined _ALS_OnVehicleDeath 126 | #undef OnVehicleDeath 127 | #else 128 | #define _ALS_OnVehicleDeath 129 | #endif 130 | 131 | #define OnVehicleDeath TDWHNE@OnVehicleDeath 132 | 133 | // ----------------------------------------------------------------------------- 134 | // Functions: 135 | 136 | stock AddNeonToVehicle(vehicleid, E_TDW_NEON_COLOR:color) 137 | { 138 | new 139 | vehicle_model; 140 | 141 | if ((vehicle_model = GetVehicleModel(vehicleid)) == 0) 142 | return 0; 143 | if (GetModelStaticType(vehicle_model) != CAR) 144 | return 0; 145 | 146 | new 147 | Float:size_x, 148 | Float:size_y, 149 | Float:size_z; 150 | 151 | GetVehicleModelInfo(vehicle_model, VEHICLE_MODEL_INFO_SIZE, size_x, size_y, 152 | size_z); 153 | 154 | new 155 | objectid; 156 | const Float:OFFSET_Z = -0.6; 157 | 158 | objectid = TDW_g_sNeon[vehicleid][EI_NEON_LEFT_ID] = CreateObject(_:color, 159 | 0.0, 0.0, 0.0, // Positions 160 | 0.0, 0.0, 0.0, // Rotations 161 | 0.0 // Draw distance 162 | ); 163 | AttachObjectToVehicle(objectid, vehicleid, 164 | -size_x / 2.8, 0.0, OFFSET_Z, // Positions 165 | 0.0, 0.0, 0.0 // Rotations 166 | ); 167 | objectid = TDW_g_sNeon[vehicleid][EI_NEON_RIGHT_ID] = CreateObject(_:color, 168 | 0.0, 0.0, 0.0, // Positions 169 | 0.0, 0.0, 0.0, // Rotations 170 | 0.0 // Draw distance 171 | ); 172 | AttachObjectToVehicle(objectid, vehicleid, 173 | size_x / 2.8, 0.0, OFFSET_Z, // Positions 174 | 0.0, 0.0, 0.0 // Rotations 175 | ); 176 | 177 | TDW_g_sIsNeonAttached{vehicleid} = true; 178 | 179 | return 1; 180 | } 181 | 182 | stock RemoveNeonFromVehicle(vehicleid) 183 | { 184 | if (IsValidVehicle(vehicleid) == 0) 185 | return 0; 186 | if (_:TDW_g_sIsNeonAttached{vehicleid} == 0) { 187 | DestroyObject(TDW_g_sNeon[vehicleid][EI_NEON_LEFT_ID]); 188 | DestroyObject(TDW_g_sNeon[vehicleid][EI_NEON_RIGHT_ID]); 189 | TDW_g_sIsNeonAttached{vehicleid} = false; 190 | } 191 | return 1; 192 | } 193 | -------------------------------------------------------------------------------- /tdw_vxplight.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Police Lights 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - UpdatePoliceLights 30 | - RemovePoliceLights 31 | Static: 32 | - 33 | Public: 34 | - 35 | Hooks: 36 | - 37 | [Callbacks]: 38 | - 39 | [Definitions]: 40 | - 41 | [Enumerations]: 42 | - E_TDW_SIREN_TYPE 43 | [Macros]: 44 | - 45 | [Tags]: 46 | - 47 | [Variables]: 48 | Global scope: 49 | - 50 | Static scope: 51 | - TDW_g_sPLVehicle 52 | [Natives]: 53 | - 54 | [Operators]: 55 | - 56 | | Dependencies: 57 | - 58 | \* ========================================================================== */ 59 | 60 | #if defined _inc_tdw_vxplights 61 | // I remove this constant because the compiler automatically generates it. 62 | // github.com/Zeex/pawn/issues/107 63 | #undef _inc_tdw_vxplights 64 | #endif 65 | 66 | #if defined _TDW_VH_SYS_VEHICLE_PLIGHTS 67 | #endinput 68 | #endif 69 | 70 | #define _TDW_VH_SYS_VEHICLE_PLIGHTS 71 | 72 | #include "tdw_vehicle" 73 | 74 | // Modules 75 | #include "tdw_vsa_data" 76 | 77 | // ----------------------------------------------------------------------------- 78 | // Enumerations: 79 | 80 | enum E_TDW_SIREN_TYPE 81 | { 82 | SIREN_TYPE_POLICE, 83 | SIREN_TYPE_AMBULANCE 84 | }; 85 | 86 | // ----------------------------------------------------------------------------- 87 | // Static scope: 88 | 89 | static stock 90 | TDW_g_sPLVehicle[MAX_VEHICLES]; 91 | 92 | // ----------------------------------------------------------------------------- 93 | // Functions: 94 | 95 | stock UpdatePoliceLights(vehicleid, E_TDW_SIREN_TYPE:type = SIREN_TYPE_POLICE) 96 | { 97 | new 98 | modelid; 99 | 100 | if ((modelid = GetVehicleModel(vehicleid)) == 0) 101 | return 0; 102 | if (GetModelStaticType(modelid) != CAR) 103 | return 0; 104 | 105 | new 106 | siren_state; 107 | 108 | if ((siren_state = GetVehicleParamsSirenState(vehicleid)) == -1) 109 | return 0; 110 | 111 | new 112 | objectid, 113 | Float:size_x, 114 | Float:size_y, 115 | Float:size_z, 116 | object_model; 117 | 118 | if (type == SIREN_TYPE_POLICE) { 119 | // 19420 - police_lights02 120 | // 19419 - police_lights01 121 | object_model = siren_state ? 19420 : 19419; 122 | } else { 123 | // 11702 - AmbulanceLights2 124 | // 11701 - AmbulanceLights1 125 | object_model = siren_state ? 11702 : 11701; 126 | } 127 | 128 | GetVehicleModelInfo(modelid, VEHICLE_MODEL_INFO_SIZE, size_x, size_y, 129 | size_z 130 | ); 131 | 132 | if ((objectid = TDW_g_sPLVehicle[vehicleid])) 133 | DestroyObject(objectid); 134 | 135 | objectid = TDW_g_sPLVehicle[vehicleid] = CreateObject(object_model, 136 | 0.0, 0.0, 0.0, // Positions 137 | 0.0, 0.0, 0.0, // Rotations 138 | 0.0 139 | ); 140 | AttachObjectToVehicle(objectid, vehicleid, 141 | 0.0, 0.0, size_z / 2.0, // Positions 142 | 0.0, 0.0, 0.0 // Rotations 143 | ); 144 | 145 | return 1; 146 | } 147 | 148 | 149 | stock RemovePoliceLights(vehicleid) 150 | { 151 | if (IsValidVehicle(vehicleid)) 152 | return 0; 153 | 154 | new 155 | objectid; 156 | 157 | if ((objectid = TDW_g_sPLVehicle[vehicleid])) 158 | DestroyObject(objectid); 159 | 160 | return 1; 161 | } 162 | -------------------------------------------------------------------------------- /tdw_vxsignals.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Signals 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - AddVehicleTurnSignals 30 | - RemoveVehicleTurnSignals 31 | Static: 32 | - 33 | Public: 34 | - 35 | Hooks: 36 | - 37 | [Callbacks]: 38 | - 39 | [Definitions]: 40 | - TDW_SIGNAL_OBJECT_ID 41 | [Enumerations]: 42 | - E_TDW_TURN_SIGNAL_STATE 43 | - E_TDW_TURN_SIGNAL_OBJECT_IDS 44 | [Macros]: 45 | - 46 | [Tags]: 47 | - 48 | [Variables]: 49 | Global scope: 50 | - 51 | Static scope: 52 | - TDW_g_sVehicleObjects 53 | [Natives]: 54 | - 55 | [Operators]: 56 | - 57 | | Dependencies: 58 | - 59 | \* ========================================================================== */ 60 | 61 | #if defined _inc_tdw_vxsignals 62 | // I remove this constant because the compiler automatically generates it. 63 | // github.com/Zeex/pawn/issues/107 64 | #undef _inc_tdw_vxsignals 65 | #endif 66 | 67 | #if defined _TDW_VH_SYS_VEHICLE_SIGNALS 68 | #endinput 69 | #endif 70 | 71 | #define _TDW_VH_SYS_VEHICLE_SIGNALS 72 | 73 | #include "tdw_vehicle" 74 | 75 | // Modules 76 | #include "tdw_vsa_data" 77 | 78 | // ----------------------------------------------------------------------------- 79 | // Definitions: 80 | 81 | #if !defined TDW_SIGNAL_OBJECT_ID 82 | #define TDW_SIGNAL_OBJECT_ID (19294) 83 | #endif 84 | 85 | // ----------------------------------------------------------------------------- 86 | // Enumerations: 87 | 88 | enum E_TDW_TURN_SIGNAL_STATE(<<= 1) 89 | { 90 | EI_TURN_SIGNAL_LEFT = 1, 91 | EI_TURN_SIGNAL_RIGHT, 92 | EI_TURN_SIGNAL_BOTH = EI_TURN_SIGNAL_LEFT | EI_TURN_SIGNAL_RIGHT 93 | }; 94 | 95 | _TDW_STATIC_ENUM enum E_TDW_TURN_SIGNAL_OBJECT_IDS 96 | { 97 | EI_TURN_SIGNAL_FRONT_LEFT, 98 | EI_TURN_SIGNAL_FRONT_RIGHT, 99 | EI_TURN_SIGNAL_BACK_LEFT, 100 | EI_TURN_SIGNAL_BACK_RIGHT 101 | }; 102 | 103 | // ----------------------------------------------------------------------------- 104 | // Static scope: 105 | 106 | static stock 107 | TDW_g_sVehicleObjects[MAX_VEHICLES][E_TDW_TURN_SIGNAL_OBJECT_IDS]; 108 | 109 | 110 | // ----------------------------------------------------------------------------- 111 | // Functions: 112 | 113 | stock AddVehicleTurnSignals(vehicleid, E_TDW_TURN_SIGNAL_STATE:turn_signal) 114 | { 115 | new 116 | vehicle_model; 117 | 118 | if ((vehicle_model = GetVehicleModel(vehicleid)) == 0) 119 | return 0; 120 | if (GetModelStaticType(vehicle_model) != CAR) 121 | return 0; 122 | 123 | new 124 | Float:x, 125 | Float:y, 126 | Float:z; 127 | 128 | GetVehicleModelInfo(vehicle_model, VEHICLE_MODEL_INFO_SIZE, x, y, z); 129 | 130 | if (turn_signal & EI_TURN_SIGNAL_LEFT) { 131 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_FRONT_LEFT] = 132 | CreateObject( 133 | TDW_SIGNAL_OBJECT_ID, 134 | 0.0, 0.0, 0.0, 135 | 0.0, 0.0, 0.0, // Rotations 136 | 0.0 // DrawDistance 137 | ); 138 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_BACK_LEFT] = 139 | CreateObject( 140 | TDW_SIGNAL_OBJECT_ID, 141 | 0.0, 0.0, 0.0, 142 | 0.0, 0.0, 0.0, // Rotations 143 | 0.0 // DrawDistance 144 | ); 145 | AttachObjectToVehicle( 146 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_FRONT_LEFT], 147 | vehicleid, 148 | -x / 2.23, y / 2.23, 0.1, // Offsets 149 | 0.0, 0.0, 0.0 // Rotations 150 | ); 151 | AttachObjectToVehicle( 152 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_BACK_LEFT], 153 | vehicleid, 154 | -x / 2.23, -y / 2.23, 0.1, // Offsets 155 | 0.0, 0.0, 0.0 // Rotations 156 | ); 157 | } 158 | if (turn_signal & EI_TURN_SIGNAL_RIGHT) { 159 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_FRONT_RIGHT] = 160 | CreateObject( 161 | TDW_SIGNAL_OBJECT_ID, 162 | 0.0, 0.0, 0.0, 163 | 0.0, 0.0, 0.0, // Rotations 164 | 0.0 // DrawDistance 165 | ); 166 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_BACK_RIGHT] = 167 | CreateObject( 168 | TDW_SIGNAL_OBJECT_ID, 169 | 0.0, 0.0, 0.0, 170 | 0.0, 0.0, 0.0, // Rotations 171 | 0.0 // DrawDistance 172 | ); 173 | AttachObjectToVehicle( 174 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_FRONT_RIGHT], 175 | vehicleid, 176 | x / 2.23, y / 2.23, 0.1, // Offsets 177 | 0.0, 0.0, 0.0 // Rotations 178 | ); 179 | AttachObjectToVehicle( 180 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_BACK_RIGHT], 181 | vehicleid, 182 | x / 2.23, -y / 2.23, 0.1, // Offsets 183 | 0.0, 0.0, 0.0 // Rotations 184 | ); 185 | } 186 | return 1; 187 | } 188 | 189 | stock RemoveVehicleTurnSignals(vehicleid, E_TDW_TURN_SIGNAL_STATE:turn_signal) 190 | { 191 | new 192 | vehicle_model; 193 | 194 | if ((vehicle_model = GetVehicleModel(vehicleid)) == 0) 195 | return 0; 196 | if (GetModelStaticType(vehicle_model) != CAR) 197 | return 0; 198 | 199 | if (turn_signal & EI_TURN_SIGNAL_LEFT) { 200 | DestroyObject( 201 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_FRONT_LEFT]); 202 | DestroyObject( 203 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_BACK_LEFT]); 204 | } 205 | if (turn_signal & EI_TURN_SIGNAL_RIGHT) { 206 | DestroyObject( 207 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_FRONT_RIGHT]); 208 | DestroyObject( 209 | TDW_g_sVehicleObjects[vehicleid][EI_TURN_SIGNAL_BACK_RIGHT]); 210 | } 211 | return 1; 212 | } 213 | -------------------------------------------------------------------------------- /tdw_vyboost.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Speed Booster 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - 30 | Static: 31 | - 32 | Public: 33 | - @_TDW_BOOSTER_SPEED_UPDATE 34 | - OnPlayerStateChange 35 | Hooks: 36 | - 37 | [Callbacks]: 38 | - TDWVH_BOOST@OnPlayerStateChange 39 | [Definitions]: 40 | - _TDW_BOOSTER_SPEED_UPDATE 41 | - _TDW_BOOSTER_MIN_SPEED 42 | - _TDW_BOOSTER_BOOST_SPEED 43 | - _TDW_BOOSTER_INACCURACY 44 | [Enumerations]: 45 | - 46 | [Macros]: 47 | - 48 | [Tags]: 49 | - 50 | [Variables]: 51 | Global scope: 52 | - 53 | Static scope: 54 | - TDW_g_sTimerName 55 | [Natives]: 56 | - 57 | [Operators]: 58 | - 59 | | Dependencies: 60 | - 61 | \* ========================================================================== */ 62 | 63 | #if defined _inc_tdw_vyboost 64 | // I remove this constant because the compiler automatically generates it. 65 | // github.com/Zeex/pawn/issues/107 66 | #undef _inc_tdw_vyboost 67 | #endif 68 | 69 | #if defined _TDW_VH_SYS_VEHICLE_SPEED_BOOST 70 | #endinput 71 | #endif 72 | 73 | #define _TDW_VH_SYS_VEHICLE_SPEED_BOOST 74 | 75 | #include "tdw_vehicle" 76 | 77 | // Modules 78 | #include "tdw_vsa_data" 79 | #include "tdw_vmath" 80 | #include "tdw_vutils" 81 | 82 | // ----------------------------------------------------------------------------- 83 | // Definitions: 84 | 85 | #if !defined _TDW_BOOSTER_SPEED_UPDATE 86 | #define _TDW_BOOSTER_SPEED_UPDATE (450) 87 | #else 88 | #assert (0 <= _TDW_BOOSTER_SPEED_UPDATE) 89 | #endif 90 | 91 | #if !defined _TDW_BOOSTER_MIN_SPEED 92 | #define _TDW_BOOSTER_MIN_SPEED (5.0) 93 | #else 94 | #assert (0 <= _TDW_BOOSTER_MIN_SPEED) 95 | #endif 96 | 97 | #if !defined _TDW_BOOSTER_BOOST_SPEED 98 | #define _TDW_BOOSTER_BOOST_SPEED (10.0) 99 | #endif 100 | 101 | #if !defined _TDW_BOOSTER_INACCURACY 102 | #define _TDW_BOOSTER_INACCURACY (0.15) 103 | #endif 104 | 105 | // ----------------------------------------------------------------------------- 106 | // Static scope: 107 | 108 | static stock 109 | TDW_g_sTimerName[] = !"@_TDW_BOOSTER_SPEED_UPDATE"; 110 | 111 | // ----------------------------------------------------------------------------- 112 | // Hooks: 113 | 114 | // OnPlayerStateChange hook 115 | #if defined TDWVH_BOOST@OnPlayerStateChange 116 | forward TDWVH_BOOST@OnPlayerStateChange(playerid, newstate, oldstate); 117 | #endif 118 | 119 | public OnPlayerStateChange(playerid, newstate, oldstate) 120 | { 121 | if (newstate == PLAYER_STATE_DRIVER) { 122 | new vehicleid = GetPlayerVehicleID(playerid); 123 | 124 | if (GetModelStaticType(GetVehicleModel(vehicleid)) == CAR) 125 | @_TDW_BOOSTER_SPEED_UPDATE(playerid, vehicleid); 126 | } 127 | 128 | #if defined TDWVH_BOOST@OnPlayerStateChange 129 | TDWVH_BOOST@OnPlayerStateChange(playerid, newstate, oldstate); 130 | #endif 131 | 132 | return 1; 133 | } 134 | 135 | #if defined _ALS_OnPlayerStateChange 136 | #undef OnPlayerStateChange 137 | #else 138 | #define _ALS_OnPlayerStateChange 139 | #endif 140 | 141 | #define OnPlayerStateChange TDWVH_BOOST@OnPlayerStateChange 142 | 143 | // ----------------------------------------------------------------------------- 144 | // Internal: 145 | 146 | @_TDW_BOOSTER_SPEED_UPDATE(playerid, vehicleid); 147 | @_TDW_BOOSTER_SPEED_UPDATE(playerid, vehicleid) 148 | { 149 | static 150 | Float:z_angle, 151 | keys, __keys, 152 | Float:z_angle_old[MAX_VEHICLES], 153 | Float:angle_tmp, 154 | Float:tmp, 155 | Float:speed; 156 | 157 | if (0 == GetVehicleZAngle(vehicleid, z_angle)) 158 | return 0; 159 | 160 | GetPlayerKeys(playerid, keys, __keys, __keys); 161 | 162 | if (keys & KEY_SPRINT) { 163 | tmp = z_angle_old[vehicleid] = floatround(floatabs(floatadd( 164 | z_angle_old[vehicleid], _TDW_BOOSTER_INACCURACY))); 165 | angle_tmp = floatround(floatabs(z_angle)); 166 | 167 | if (_:(tmp > angle_tmp || tmp < angle_tmp) == 0) { 168 | speed = GetVehicleSpeed(vehicleid); 169 | 170 | if (_:(speed < _TDW_BOOSTER_MIN_SPEED || 171 | IsVehicleBackwordsDirection(vehicleid)) == 0) 172 | SetVehicleSpeed(vehicleid, speed + _TDW_BOOSTER_BOOST_SPEED); 173 | } 174 | } 175 | 176 | z_angle_old[vehicleid] = z_angle; 177 | 178 | return SetTimerEx(TDW_g_sTimerName, _TDW_BOOSTER_SPEED_UPDATE, false, !"ii", 179 | playerid, vehicleid 180 | ); 181 | } 182 | -------------------------------------------------------------------------------- /tdw_vydrift.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Drift System 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - 30 | Static: 31 | - 32 | Public: 33 | - @_TDW_VEHICLE_DRIFT 34 | - OnPlayerStateChange 35 | - OnFilterScriptInit 36 | - OnGameModeInit 37 | Hooks: 38 | - 39 | [Callbacks]: 40 | - TDWVH_DRIFT@OnPlayerStateChange 41 | - TDWVH_DRIFT@OnFilterScriptInit 42 | - TDWVH_DRIFT@OnGameModeInit 43 | - OnPlayerVehicleDrift 44 | [Definitions]: 45 | - 46 | [Enumerations]: 47 | - 48 | [Macros]: 49 | - 50 | [Tags]: 51 | - 52 | [Variables]: 53 | Global scope: 54 | - 55 | Static scope: 56 | - TDW_g_sOnPlayerVehicleDrift 57 | - TDW_g_sCallbacks 58 | [Natives]: 59 | - 60 | [Operators]: 61 | - 62 | | Dependencies: 63 | - 64 | \* ========================================================================== */ 65 | 66 | #if defined _inc_tdw_vydrift 67 | // I remove this constant because the compiler automatically generates it. 68 | // github.com/Zeex/pawn/issues/107 69 | #undef _inc_tdw_vydrift 70 | #endif 71 | 72 | #if defined _TDW_VH_SYS_DRIFT 73 | #endinput 74 | #endif 75 | 76 | #define _TDW_VH_SYS_DRIFT 77 | 78 | #include "tdw_vehicle" 79 | 80 | // Modules 81 | #include "tdw_vsa_data" 82 | #include "tdw_vmath" 83 | 84 | // ----------------------------------------------------------------------------- 85 | // Static scope: 86 | 87 | static stock 88 | TDW_g_sOnPlayerVehicleDrift[] = !"OnPlayerVehicleDrift", 89 | TDW_g_sCallbacks; 90 | 91 | // ----------------------------------------------------------------------------- 92 | // Hooks: 93 | 94 | // OnPlayerStateChange hook 95 | #if defined TDWVH_DRIFT@OnPlayerStateChange 96 | forward TDWVH_DRIFT@OnPlayerStateChange(playerid, newstate, oldstate); 97 | #endif 98 | 99 | public OnPlayerStateChange(playerid, newstate, oldstate) 100 | { 101 | if (newstate == PLAYER_STATE_DRIVER) { 102 | new 103 | vehicleid = GetPlayerVehicleID(playerid); 104 | 105 | if (GetModelStaticType(GetVehicleModel(vehicleid)) == CAR) { 106 | if (TDW_g_sCallbacks & 1) { 107 | @_TDW_VEHICLE_DRIFT(playerid, vehicleid); 108 | } 109 | } 110 | } 111 | 112 | #if defined TDWVH_DRIFT@OnPlayerStateChange 113 | TDWVH_DRIFT@OnPlayerStateChange(playerid, newstate, oldstate); 114 | #endif 115 | 116 | return 1; 117 | } 118 | 119 | #if defined _ALS_OnPlayerStateChange 120 | #undef OnPlayerStateChange 121 | #else 122 | #define _ALS_OnPlayerStateChange 123 | #endif 124 | 125 | #define OnPlayerStateChange TDWVH_DRIFT@OnPlayerStateChange 126 | 127 | 128 | // OnFilterScriptInit / OnGameModeInit hook 129 | #if defined FILTERSCRIPT 130 | #if defined TDWVH_DRIFT@OnFilterScriptInit 131 | forward TDWVH_DRIFT@OnFilterScriptInit(); 132 | #endif 133 | 134 | public OnFilterScriptInit() 135 | { 136 | if (funcidx(TDW_g_sOnPlayerVehicleDrift) != -1) 137 | TDW_g_sCallbacks |= 1; 138 | 139 | #if defined TDWVH_DRIFT@OnFilterScriptInit 140 | TDWVH_DRIFT@OnFilterScriptInit(); 141 | #endif 142 | 143 | return 1; 144 | } 145 | 146 | #if defined _ALS_OnFilterScriptInit 147 | #undef OnFilterScriptInit 148 | #else 149 | #define _ALS_OnFilterScriptInit 150 | #endif 151 | 152 | #define OnFilterScriptInit TDWVH_DRIFT@OnFilterScriptInit 153 | #else 154 | #if defined TDWVH_DRIFT@OnGameModeInit 155 | forward TDWVH_DRIFT@OnGameModeInit(); 156 | #endif 157 | 158 | public OnGameModeInit() 159 | { 160 | if (funcidx(TDW_g_sOnPlayerVehicleDrift) != -1) 161 | TDW_g_sCallbacks |= 1; 162 | 163 | #if defined TDWVH_DRIFT@OnGameModeInit 164 | TDWVH_DRIFT@OnGameModeInit(); 165 | #endif 166 | 167 | return 1; 168 | } 169 | 170 | #if defined _ALS_OnGameModeInit 171 | #undef OnGameModeInit 172 | #else 173 | #define _ALS_OnGameModeInit 174 | #endif 175 | 176 | #define OnGameModeInit TDWVH_DRIFT@OnGameModeInit 177 | #endif 178 | 179 | // ----------------------------------------------------------------------------- 180 | // Functions: 181 | 182 | @_TDW_VEHICLE_DRIFT(playerid, vehicleid); 183 | @_TDW_VEHICLE_DRIFT(playerid, vehicleid) 184 | { 185 | static 186 | Float:speed, 187 | Float:direction, 188 | Float:drift_angle, 189 | Float:z_angle, 190 | bool:is_player_drifting[MAX_PLAYERS char]; 191 | 192 | if (0 == GetVehicleVelocityDirection(vehicleid, direction)) 193 | return 0; 194 | 195 | speed = GetVehicleSpeed(vehicleid); 196 | 197 | if (speed > 5.0) { 198 | GetVehicleZAngle(vehicleid, z_angle); 199 | 200 | drift_angle = floatabs(floatsub(direction, z_angle)); 201 | 202 | if (drift_angle >= 180.0) 203 | drift_angle = floatsub(360.0, drift_angle); 204 | 205 | static bool:is_drifting; 206 | is_drifting = is_player_drifting{playerid}; 207 | 208 | if (15.0 < drift_angle < 80.0) 209 | if (0 == _:is_drifting) 210 | CallLocalFunction(TDW_g_sOnPlayerVehicleDrift, !"iif", playerid, 211 | vehicleid, drift_angle); 212 | if (0 != _:is_drifting) 213 | is_player_drifting{playerid} = false; 214 | } 215 | return SetTimerEx(!"@_TDW_VEHICLE_DRIFT", 250, false, !"ii", playerid, 216 | vehicleid); 217 | } 218 | 219 | // ----------------------------------------------------------------------------- 220 | // Forwards: 221 | 222 | forward OnPlayerVehicleDrift(playerid, vehicleid, Float:drift_angle); 223 | -------------------------------------------------------------------------------- /tdw_vyengine.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Engine 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - StartVehicleEngine 30 | - StopVehicleEngine 31 | - IsVehicleEngineStarted 32 | Static: 33 | - ToggleVehicleEngineState 34 | - IsVehicleHasEngine 35 | Public: 36 | - OnFilterScriptInit 37 | - OnGameModeInit 38 | - OnPlayerStateChange 39 | - @_TDW_VEHICLE_ENGINE 40 | Hooks: 41 | - 42 | [Callbacks]: 43 | - TDWVH_ENGIN@OnFilterScriptInit 44 | - TDWVH_ENGIN@OnGameModeInit 45 | - TDWVH_ENGIN@OnPlayerStateChange 46 | - OnVehicleEngineStateChange 47 | [Definitions]: 48 | - TDW_ENGINE_TIMER_TICK 49 | [Enumerations]: 50 | - 51 | [Macros]: 52 | - 53 | [Tags]: 54 | - 55 | [Variables]: 56 | Global scope: 57 | - 58 | Static scope: 59 | - TDW_g_sIsVehicleEngineStarted 60 | - TDW_g_sCallbacks 61 | - TDW_g_sOnVehEngineStateChange 62 | - TDW_g_sVehicleTimerId 63 | [Natives]: 64 | - 65 | [Operators]: 66 | - 67 | | Dependencies: 68 | - 69 | \* ========================================================================== */ 70 | 71 | #if defined _inc_tdw_vyengine 72 | // I remove this constant because the compiler automatically generates it. 73 | // github.com/Zeex/pawn/issues/107 74 | #undef _inc_tdw_vyengine 75 | #endif 76 | 77 | #if defined _TDW_VH_SYS_VEHICLE_ENGINE 78 | #endinput 79 | #endif 80 | 81 | #define _TDW_VH_SYS_VEHICLE_ENGINE 82 | 83 | #include "tdw_vehicle" 84 | 85 | // Modules 86 | #include "tdw_vsa_data" 87 | 88 | // ----------------------------------------------------------------------------- 89 | // Definitions: 90 | 91 | #if !defined TDW_ENGINE_TIMER_TICK 92 | #define TDW_ENGINE_TIMER_TICK (1000) 93 | #endif 94 | 95 | // ----------------------------------------------------------------------------- 96 | // Static scope: 97 | 98 | static stock 99 | bool:TDW_g_sIsVehicleEngineStarted[MAX_VEHICLES char] = {false, ...}, 100 | TDW_g_sCallbacks; 101 | 102 | static stock const 103 | TDW_g_sOnVehEngineStateChange[] = !"OnVehicleEngineStateChange"; 104 | 105 | #if TDW_ENGINE_TIMER_TICK > 0 106 | static stock 107 | TDW_g_sVehicleTimerId[MAX_VEHICLES] = {-1, ...}; 108 | #endif 109 | 110 | // ----------------------------------------------------------------------------- 111 | // Hooks: 112 | 113 | // OnFilterScriptInit / OnGameModeInit hook 114 | #if defined FILTERSCRIPT 115 | #if defined TDWVH_ENGIN@OnFilterScriptInit 116 | forward TDWVH_ENGIN@OnFilterScriptInit(); 117 | #endif 118 | 119 | public OnFilterScriptInit() 120 | { 121 | ManualVehicleEngineAndLights(); 122 | 123 | if (-1 != funcidx(TDW_g_sOnVehEngineStateChange)) 124 | TDW_g_sCallbacks |= 1; 125 | 126 | #if defined TDWVH_ENGIN@OnFilterScriptInit 127 | TDWVH_ENGIN@OnFilterScriptInit(); 128 | #endif 129 | 130 | return 1; 131 | } 132 | 133 | #if defined _ALS_OnFilterScriptInit 134 | #undef OnFilterScriptInit 135 | #else 136 | #define _ALS_OnFilterScriptInit 137 | #endif 138 | 139 | #define OnFilterScriptInit TDWVH_ENGIN@OnFilterScriptInit 140 | #else 141 | #if defined TDWVH_ENGIN@OnGameModeInit 142 | forward TDWVH_ENGIN@OnGameModeInit(); 143 | #endif 144 | 145 | public OnGameModeInit() 146 | { 147 | ManualVehicleEngineAndLights(); 148 | 149 | if (-1 != funcidx(TDW_g_sOnVehEngineStateChange)) 150 | TDW_g_sCallbacks |= 1; 151 | 152 | #if defined TDWVH_ENGIN@OnGameModeInit 153 | TDWVH_ENGIN@OnGameModeInit(); 154 | #endif 155 | 156 | return 1; 157 | } 158 | 159 | #if defined _ALS_OnGameModeInit 160 | #undef OnGameModeInit 161 | #else 162 | #define _ALS_OnGameModeInit 163 | #endif 164 | 165 | #define OnGameModeInit TDWVH_ENGIN@OnGameModeInit 166 | #endif 167 | 168 | 169 | // OnPlayerStateChange hook 170 | #if defined TDWVH_ENGIN@OnPlayerStateChange 171 | forward TDWVH_ENGIN@OnPlayerStateChange(playerid, newstate, oldstate); 172 | #endif 173 | 174 | public OnPlayerStateChange(playerid, newstate, oldstate) 175 | { 176 | if (newstate == PLAYER_STATE_DRIVER) { 177 | new vehicleid = GetPlayerVehicleID(playerid); 178 | 179 | if (0 == IsVehicleHasEngine(vehicleid)) 180 | ToggleVehicleEngineState(vehicleid, VEHICLE_PARAMS_ON); 181 | } 182 | 183 | #if defined TDWVH_ENGIN@OnPlayerStateChange 184 | TDWVH_ENGIN@OnPlayerStateChange(playerid, newstate, oldstate); 185 | #endif 186 | 187 | return 1; 188 | } 189 | 190 | #if defined _ALS_OnPlayerStateChange 191 | #undef OnPlayerStateChange 192 | #else 193 | #define _ALS_OnPlayerStateChange 194 | #endif 195 | 196 | #define OnPlayerStateChange TDWVH_ENGIN@OnPlayerStateChange 197 | 198 | // ----------------------------------------------------------------------------- 199 | // Functions: 200 | 201 | /** ------------------------------------------------------------------------ **\ 202 | StartVehicleEngine 203 | The ID of the vehicle 204 | 205 | - 206 | 207 | 208 | 209 | \** ------------------------------------------------------------------------ **/ 210 | 211 | stock StartVehicleEngine(vehicleid) 212 | { 213 | if (0 == IsVehicleHasEngine(vehicleid)) 214 | return 0; 215 | if (TDW_g_sIsVehicleEngineStarted{vehicleid}) 216 | return 0; 217 | 218 | #if TDW_ENGINE_TIMER_TICK > 0 219 | if (TDW_g_sVehicleTimerId[vehicleid] != -1) 220 | return 0; 221 | TDW_g_sVehicleTimerId[vehicleid] = SetTimerEx(!"@_TDW_VEHICLE_ENGINE", 222 | TDW_ENGINE_TIMER_TICK, false, !"i", vehicleid); 223 | #else 224 | ToggleVehicleEngineState(vehicleid, VEHICLE_PARAMS_ON); 225 | #endif 226 | 227 | return 1; 228 | } 229 | 230 | /** ------------------------------------------------------------------------ **\ 231 | StopVehicleEngine 232 | The ID of the vehicle 233 | 234 | - 235 | 236 | 237 | 238 | \** ------------------------------------------------------------------------ **/ 239 | 240 | stock StopVehicleEngine(vehicleid) 241 | { 242 | if (0 == IsVehicleHasEngine(vehicleid)) 243 | return 0; 244 | if (0 == _:TDW_g_sIsVehicleEngineStarted{vehicleid}) 245 | return 0; 246 | 247 | #if TDW_ENGINE_TIMER_TICK > 0 248 | new timer_id = TDW_g_sVehicleTimerId[vehicleid]; 249 | 250 | if (timer_id != -1) 251 | KillTimer(timer_id); 252 | #endif 253 | 254 | ToggleVehicleEngineState(vehicleid, VEHICLE_PARAMS_OFF); 255 | 256 | return 1; 257 | } 258 | 259 | /** ------------------------------------------------------------------------ **\ 260 | IsVehicleEngineStarted 261 | The ID of the vehicle 262 | 263 | - 264 | 265 | 266 | 267 | \** ------------------------------------------------------------------------ **/ 268 | 269 | stock IsVehicleEngineStarted(vehicleid) 270 | { 271 | return IsValidVehicle(vehicleid) && 272 | TDW_g_sIsVehicleEngineStarted{vehicleid}; 273 | } 274 | 275 | // ----------------------------------------------------------------------------- 276 | // Internal: 277 | 278 | static stock IsVehicleHasEngine(vehicleid) 279 | { 280 | new model = GetVehicleModel(vehicleid); 281 | 282 | if (0 == model) 283 | return 0; 284 | 285 | return GetModelStaticType(model) != BIKE; 286 | } 287 | 288 | static stock ToggleVehicleEngineState(vehicleid, 289 | newstate = VEHICLE_PARAMS_UNSET) 290 | { 291 | new 292 | engine, 293 | lights, 294 | alarm, 295 | doors, 296 | bonnet, 297 | boot, 298 | objective; 299 | 300 | if (0 == GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 301 | boot, objective)) 302 | return 0; 303 | 304 | if (newstate == engine) 305 | return 0; 306 | 307 | if (newstate == VEHICLE_PARAMS_UNSET) 308 | newstate = engine ? VEHICLE_PARAMS_OFF : VEHICLE_PARAMS_ON; 309 | 310 | TDW_g_sIsVehicleEngineStarted{vehicleid} = 311 | bool:(newstate == VEHICLE_PARAMS_ON); 312 | 313 | SetVehicleParamsEx(vehicleid, newstate, lights, alarm, doors, bonnet, boot, 314 | objective); 315 | 316 | if (TDW_g_sCallbacks & 1) 317 | CallLocalFunction(TDW_g_sOnVehEngineStateChange, !"ii", vehicleid, 318 | newstate); 319 | 320 | return 1; 321 | } 322 | 323 | @_TDW_VEHICLE_ENGINE(vehicleid); 324 | @_TDW_VEHICLE_ENGINE(vehicleid) 325 | { 326 | ToggleVehicleEngineState(vehicleid, VEHICLE_PARAMS_ON); 327 | 328 | #if TDW_ENGINE_TIMER_TICK > 0 329 | TDW_g_sVehicleTimerId[vehicleid] = -1; 330 | #endif 331 | 332 | return 1; 333 | } 334 | 335 | // ----------------------------------------------------------------------------- 336 | // Forwards: 337 | 338 | forward OnVehicleEngineStateChange(vehicleid, engine); 339 | -------------------------------------------------------------------------------- /tdw_vyfuel.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Fuel 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - GetModelMaxFuel 30 | - SetModelMaxFuel 31 | - GetVehicleFuel 32 | - SetVehicleFuel 33 | Static: 34 | - 35 | Public: 36 | - OnVehicleMileageUpdate 37 | - OnFilterScriptInit 38 | - OnGameModeInit 39 | Hooks: 40 | - StartVehicleEngine 41 | [Callbacks]: 42 | - OnVehicleFuelEmpty 43 | - TDWVH_FUEL@OnFilterScriptInit 44 | - TDWVH_FUEL@OnGameModeInit 45 | - TDWVH_FUEL@OnVehicleMileageUpd 46 | [Definitions]: 47 | - TDW_VEHICLE_FUEL_FLOAT 48 | [Enumerations]: 49 | - 50 | [Macros]: 51 | - 52 | [Tags]: 53 | - 54 | [Variables]: 55 | Global scope: 56 | - 57 | Static scope: 58 | - TDW_g_sVehicleFuel 59 | - TDW_g_sCallbacks 60 | - TDW_g_sOnVehicleFuelEmpty 61 | - TDW_g_sModelMaxFuel 62 | [Natives]: 63 | - 64 | [Operators]: 65 | - 66 | | Dependencies: 67 | - 68 | \* ========================================================================== */ 69 | 70 | #if defined _inc_tdw_vyfuel 71 | // I remove this constant because the compiler automatically generates it. 72 | // github.com/Zeex/pawn/issues/107 73 | #undef _inc_tdw_vyfuel 74 | #endif 75 | 76 | #if defined _TDW_VH_SYS_VEHICLE_FUEL 77 | #endinput 78 | #endif 79 | 80 | #define _TDW_VH_SYS_VEHICLE_FUEL 81 | 82 | #include "tdw_vehicle" 83 | 84 | // Modules 85 | #include "tdw_vmath" 86 | #include "tdw_vyengine" 87 | #include "tdw_vymileage" 88 | 89 | // =============================== [ ATTENTION ] =============================== 90 | // If your vehicle is not moving, set the amount of the fuel, because when 91 | // spawned it is zero. 92 | // ============================================================================= 93 | 94 | // ----------------------------------------------------------------------------- 95 | // Definitions: 96 | 97 | #if !defined TDW_VEHICLE_FUEL_FLOAT 98 | #define TDW_VEHICLE_FUEL_FLOAT (20000.0) 99 | #endif 100 | 101 | // ----------------------------------------------------------------------------- 102 | // Static scope: 103 | 104 | static stock 105 | Float:TDW_g_sVehicleFuel[MAX_VEHICLES], 106 | TDW_g_sCallbacks, 107 | TDW_g_sOnVehicleFuelEmpty[] = !"OnVehicleFuelEmpty", 108 | Float:TDW_g_sModelMaxFuel[MAX_VEHICLE_MODELS + 1] = 109 | { 110 | 70.0, 45.0, 40.0, 298.0, 40.0, 40.0, 200.0, 80.0, 60.0, 40.0, 40.0, 111 | 40.0, 40.0, 45.0, 45.0, 40.0, 70.0, 100.0, 45.0, 40.0, 40.0, 40.0, 112 | 45.0, 45.0, 20.0, 200.0, 40.0, 70.0, 70.0, 40.0, 45.0, 60.0, 90.0, 113 | 100.0, 35.0, 0.0, 40.0, 50.0, 40.0, 40.0, 45.0, 5.0, 40.0, 50.0, 114 | 65.0, 40.0, 35.0, 90.0, 20.0, 60.0, 0.0, 40.0, 20.0, 20.0, 20.0, 115 | 60.0, 50.0, 20.0, 40.0, 45.0, 90.0, 30.0, 20.0, 35.0, 5.0, 5.0, 116 | 40.0, 40.0, 20.0, 90.0, 90.0, 20.0, 20.0, 20.0, 40.0, 40.0, 40.0, 117 | 40.0, 40.0, 45.0, 40.0, 0.0, 45.0, 45.0, 20.0, 20.0, 30.0, 90.0, 118 | 90.0, 70.0, 70.0, 40.0, 40.0, 20.0, 40.0, 45.0, 40.0, 90.0, 50.0, 119 | 50.0, 40.0, 5.0, 40.0, 40.0, 40.0, 50.0, 40.0, 40.0, 50.0, 0.0, 120 | 0.0, 90.0, 90.0, 90.0, 298.0, 298.0, 40.0, 40.0, 40.0, 400.0, 400.0, 121 | 30.0, 30.0, 30.0, 50.0, 50.0, 40.0, 40.0, 50.0, 40.0, 20.0, 20.0, 122 | 60.0, 40.0, 40.0, 40.0, 40.0, 50.0, 50.0, 20.0, 40.0, 40.0, 40.0, 123 | 50.0, 70.0, 40.0, 40.0, 40.0, 90.0, 40.0, 40.0, 40.0, 40.0, 300.0, 124 | 50.0, 40.0, 80.0, 80.0, 40.0, 40.0, 40.0, 40.0, 40.0, 90.0, 90.0, 125 | 40.0, 45.0, 45.0, 20.0, 0.0, 50.0, 10.0, 20.0, 50.0, 20.0, 40.0, 126 | 40.0, 300.0, 50.0, 50.0, 40.0, 30.0, 50.0, 20.0, 0.0, 40.0, 30.0, 127 | 40.0, 50.0, 40.0, 0.0, 0.0, 300.0, 200.0, 0.0, 20.0, 40.0, 40.0, 128 | 40.0, 50.0, 40.0, 60.0, 40.0, 40.0, 40.0, 45.0, 0.0, 0.0, 0.0, 129 | 50.0, 0.0, 0.0 130 | }; 131 | 132 | // ----------------------------------------------------------------------------- 133 | // Hooks: 134 | 135 | // OnFilterScriptInit / OnGameModeInit hook 136 | #if defined FILTERSCRIPT 137 | #if defined TDWVH_FUEL@OnFilterScriptInit 138 | forward TDWVH_FUEL@OnFilterScriptInit(); 139 | #endif 140 | 141 | public OnFilterScriptInit() 142 | { 143 | if (funcidx(TDW_g_sOnVehicleFuelEmpty) != -1) 144 | TDW_g_sCallbacks |= 1; 145 | 146 | #if defined TDWVH_FUEL@OnFilterScriptInit 147 | TDWVH_FUEL@OnFilterScriptInit(); 148 | #endif 149 | 150 | return 1; 151 | } 152 | 153 | #if defined _ALS_OnFilterScriptInit 154 | #undef OnFilterScriptInit 155 | #else 156 | #define _ALS_OnFilterScriptInit 157 | #endif 158 | 159 | #define OnFilterScriptInit TDWVH_FUEL@OnFilterScriptInit 160 | #else 161 | #if defined TDWVH_FUEL@OnGameModeInit 162 | forward TDWVH_FUEL@OnGameModeInit(); 163 | #endif 164 | 165 | public OnGameModeInit() 166 | { 167 | if (funcidx(TDW_g_sOnVehicleFuelEmpty) != -1) 168 | TDW_g_sCallbacks |= 1; 169 | 170 | #if defined TDWVH_FUEL@OnGameModeInit 171 | TDWVH_FUEL@OnGameModeInit(); 172 | #endif 173 | 174 | return 1; 175 | } 176 | 177 | #if defined _ALS_OnGameModeInit 178 | #undef OnGameModeInit 179 | #else 180 | #define _ALS_OnGameModeInit 181 | #endif 182 | 183 | #define OnGameModeInit TDWVH_FUEL@OnGameModeInit 184 | #endif 185 | 186 | 187 | // OnVehicleMileageUpdate hook 188 | #if defined TDWVH_FUEL@OnVehicleMileageUpd 189 | forward TDWVH_FUEL@OnVehicleMileageUpd(vehicleid); 190 | #endif 191 | 192 | public OnVehicleMileageUpdate(vehicleid) 193 | { 194 | if (IsVehicleEngineStarted(vehicleid)) { 195 | if (TDW_g_sVehicleFuel[vehicleid] <= 0.1) { 196 | StopVehicleEngine(vehicleid); 197 | TDW_g_sVehicleFuel[vehicleid] = 0.0; 198 | 199 | if (TDW_g_sCallbacks & 1) { 200 | CallLocalFunction(TDW_g_sOnVehicleFuelEmpty, !"i", vehicleid); 201 | } 202 | } else { 203 | TDW_g_sVehicleFuel[vehicleid] -= (GetVehicleSpeed(vehicleid) + 0.1)/ 204 | TDW_VEHICLE_FUEL_FLOAT; 205 | } 206 | } 207 | 208 | #if defined TDWVH_FUEL@OnVehicleMileageUpd 209 | TDWVH_FUEL@OnVehicleMileageUpd(vehicleid); 210 | #endif 211 | 212 | return 1; 213 | } 214 | 215 | #if defined _ALS_OnVehicleMileageUpdate 216 | #undef OnVehicleMileageUpdate 217 | #else 218 | #define _ALS_OnVehicleMileageUpdate 219 | #endif 220 | 221 | #define OnVehicleMileageUpdate TDWVH_FUEL@OnVehicleMileageUpd 222 | 223 | 224 | // StartVehicleEngine hook 225 | #if defined StartVehicleEngine 226 | stock TDWVH_FUEL@StartVehicleEngine(vehicleid) 227 | { 228 | if (0 == IsValidVehicle(vehicleid)) 229 | return 0; 230 | if (TDW_g_sVehicleFuel[vehicleid] == 0.0) 231 | return 0; 232 | return StartVehicleEngine(vehicleid); 233 | } 234 | 235 | #if defined _ALS_StartVehicleEngine 236 | #undef StartVehicleEngine 237 | #else 238 | #define _ALS_StartVehicleEngine 239 | #endif 240 | 241 | #define StartVehicleEngine TDWVH_FUEL@StartVehicleEngine 242 | #endif 243 | 244 | // ----------------------------------------------------------------------------- 245 | // Functions: 246 | 247 | /** ------------------------------------------------------------------------ **\ 248 | GetModelMaxFuel 249 | The ID of the model 250 | 251 | - 252 | 253 | 254 | 255 | \** ------------------------------------------------------------------------ **/ 256 | 257 | stock Float:GetModelMaxFuel(modelid) 258 | { 259 | if (0 == IS_VALID_MODEL(modelid)) 260 | return 0.0; 261 | 262 | return TDW_g_sModelMaxFuel[modelid - MIN_VEHICLE_MODEL]; 263 | } 264 | 265 | /** ------------------------------------------------------------------------ **\ 266 | SetModelMaxFuel 267 | The ID of the model 268 | 269 | - 270 | 271 | 272 | 273 | \** ------------------------------------------------------------------------ **/ 274 | 275 | stock SetModelMaxFuel(modelid, Float:amount) 276 | { 277 | if (0 == IS_VALID_MODEL(modelid)) 278 | return 0; 279 | 280 | TDW_g_sModelMaxFuel[modelid - MIN_VEHICLE_MODEL] = amount; 281 | 282 | return 1; 283 | } 284 | 285 | /** ------------------------------------------------------------------------ **\ 286 | GetVehicleFuel 287 | The ID of the vehicle 288 | 289 | - 290 | 291 | 292 | 293 | \** ------------------------------------------------------------------------ **/ 294 | 295 | stock Float:GetVehicleFuel(vehicleid) 296 | { 297 | if (0 == IsValidVehicle(vehicleid)) 298 | return 0.0; 299 | 300 | return TDW_g_sVehicleFuel[vehicleid]; 301 | } 302 | 303 | /** ------------------------------------------------------------------------ **\ 304 | SetVehicleFuel 305 | The ID of the vehicle 306 | 307 | - 308 | 309 | 310 | 311 | \** ------------------------------------------------------------------------ **/ 312 | 313 | stock SetVehicleFuel(vehicleid, Float:amount) 314 | { 315 | new modelid = GetVehicleModel(vehicleid); 316 | if (0 == modelid) 317 | return 0; 318 | 319 | new Float:max_fuel = GetModelMaxFuel(modelid); 320 | 321 | if (amount > max_fuel) 322 | amount = max_fuel; 323 | else if (amount < 0.0) 324 | amount = 0.0; 325 | 326 | TDW_g_sVehicleFuel[vehicleid] = amount; 327 | 328 | return 1; 329 | } 330 | 331 | // ----------------------------------------------------------------------------- 332 | // Forwards: 333 | 334 | forward OnVehicleFuelEmpty(vehicleid); 335 | -------------------------------------------------------------------------------- /tdw_vylabel.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | 3D Text Label 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - CreateVehicle3DTextLabel 30 | - DestroyVehicle3DTextLabel 31 | - UpdateVehicle3DTextLabel 32 | - ShowVehicle3DTextLabel 33 | - HideVehicle3DTextLabel 34 | - Is3DTextLabelHidden 35 | Static: 36 | - 37 | Public: 38 | - 39 | Hooks: 40 | - 41 | [Callbacks]: 42 | - 43 | [Definitions]: 44 | - TDW_VH_DestroyLabel 45 | - TDW_VH_UpdateLabel 46 | - MAX_VEHICLE_LABEL_SIZE 47 | [Enumerations]: 48 | - E_TDW_VH_LABEL_FLAGS 49 | [Macros]: 50 | - 51 | [Tags]: 52 | - 53 | [Variables]: 54 | Global scope: 55 | - 56 | Static scope: 57 | - TDW_g_sVehicle@LabelId 58 | - TDW_g_sVehicle@LabelText 59 | - TDW_g_sVehicle@Flags 60 | [Natives]: 61 | - 62 | [Operators]: 63 | - 64 | | Dependencies: 65 | - streamer (optional) 66 | \* ========================================================================== */ 67 | 68 | #if defined _inc_tdw_vylabel 69 | // I remove this constant because the compiler automatically generates it. 70 | // github.com/Zeex/pawn/issues/107 71 | #undef _inc_tdw_vylabel 72 | #endif 73 | 74 | #if defined _TDW_VH_SYS_3D_TEXT_LABEL 75 | #endinput 76 | #endif 77 | 78 | #define _TDW_VH_SYS_3D_TEXT_LABEL 79 | 80 | #include "tdw_vehicle" 81 | 82 | #if defined Streamer_IncludeFileVersion && !defined _TDW_VH_DETECT_STREAMER 83 | #define _TDW_VH_DETECT_STREAMER 84 | #endif 85 | 86 | // ----------------------------------------------------------------------------- 87 | // Enumerations: 88 | 89 | _TDW_STATIC_ENUM enum E_TDW_VH_LABEL_FLAGS(<<= 1) 90 | { 91 | EI_VH_LABEL_HIDDEN = 1 92 | }; 93 | 94 | // ----------------------------------------------------------------------------- 95 | // Definitions: 96 | 97 | #if defined _TDW_VH_DETECT_STREAMER 98 | #define TDW_VH_DestroyLabel DestroyDynamic3DTextLabel 99 | #define TDW_VH_UpdateLabel UpdateDynamic3DTextLabelText 100 | #else 101 | #define TDW_VH_DestroyLabel Delete3DTextLabel 102 | #define TDW_VH_UpdateLabel Update3DTextLabelText 103 | #endif 104 | 105 | #if !defined MAX_VEHICLE_LABEL_SIZE 106 | #define MAX_VEHICLE_LABEL_SIZE (144) 107 | #endif 108 | 109 | // ----------------------------------------------------------------------------- 110 | // Static scope: 111 | 112 | static stock 113 | Text3D:TDW_g_sVehicle@LabelId[MAX_VEHICLES], 114 | TDW_g_sVehicle@LabelText[MAX_VEHICLES][MAX_VEHICLE_LABEL_SIZE char], 115 | E_TDW_VH_LABEL_FLAGS:TDW_g_sVehicle@Flags[MAX_VEHICLES char]; 116 | 117 | // ----------------------------------------------------------------------------- 118 | // Functions: 119 | 120 | /** ------------------------------------------------------------------------ **\ 121 | CreateVehicle3DTextLabel 122 | The ID of the vehicle 123 | 124 | - 125 | 126 | 127 | 128 | \** ------------------------------------------------------------------------ **/ 129 | 130 | stock CreateVehicle3DTextLabel(vehicleid, const label[], color, Float:offset_x, 131 | Float:offset_y, Float:offset_z, Float:drawdistance, virtualworld, 132 | bool:testLos = false) 133 | { 134 | if (0 == IsValidVehicle(vehicleid)) 135 | return 0; 136 | 137 | new 138 | label_length = strlen(label); 139 | 140 | if (0 == _:(0 < label_length < MAX_VEHICLE_LABEL_SIZE)) 141 | return 0; 142 | 143 | #if defined _TDW_VH_DETECT_STREAMER 144 | TDW_g_sVehicle@LabelId[vehicleid] = CreateDynamic3DTextLabel(label, 145 | color, offset_x, offset_y, offset_z, drawdistance, _, vehicleid, 146 | _:testLos, virtualworld, _, _, _); 147 | #else 148 | new Text3D:Create3DTextLabel_ret; 149 | 150 | #emit PUSH.s testLos 151 | #emit PUSH.s virtualworld 152 | #emit PUSH.s drawdistance 153 | #emit PUSH.c 0 // Float value 154 | #emit PUSH.c 0 // Float value 155 | #emit PUSH.c 0 // Float value 156 | #emit PUSH.s color 157 | #emit PUSH.s label 158 | #emit PUSH.c 36 159 | #emit SYSREQ.c Create3DTextLabel 160 | 161 | #emit STOR.s.pri Create3DTextLabel_ret 162 | 163 | #emit PUSH.s offset_z 164 | #emit PUSH.s offset_y 165 | #emit PUSH.s offset_x 166 | #emit PUSH.s vehicleid 167 | #emit PUSH.pri 168 | #emit PUSH.c 20 169 | #emit SYSREQ.c Attach3DTextLabelToVehicle 170 | 171 | #emit STACK 64 // (36 + 4) + (20 + 4) 172 | 173 | TDW_g_sVehicle@LabelId[vehicleid] = Create3DTextLabel_ret; 174 | #endif 175 | 176 | strpack(TDW_g_sVehicle@LabelText[vehicleid], label, label_length); 177 | 178 | TDW_g_sVehicle@Flags{vehicleid} = E_TDW_VH_LABEL_FLAGS:0; 179 | 180 | return 1; 181 | } 182 | 183 | /** ------------------------------------------------------------------------ **\ 184 | DestroyVehicle3DTextLabel 185 | The ID of the vehicle 186 | 187 | - 188 | 189 | 190 | 191 | \** ------------------------------------------------------------------------ **/ 192 | 193 | stock DestroyVehicle3DTextLabel(vehicleid) 194 | { 195 | return IsValidVehicle(vehicleid) 196 | ? TDW_VH_DestroyLabel(TDW_g_sVehicle@LabelId[vehicleid]) 197 | : INVALID_VEHICLE_ID; 198 | } 199 | 200 | /** ------------------------------------------------------------------------ **\ 201 | UpdateVehicle3DTextLabel 202 | The ID of the vehicle 203 | 204 | - 205 | 206 | 207 | 208 | \** ------------------------------------------------------------------------ **/ 209 | 210 | stock UpdateVehicle3DTextLabel(vehicleid, const label[], color = -1, 211 | bool:replace_buffer = false) 212 | { 213 | if (0 == IsValidVehicle(vehicleid)) 214 | return 0; 215 | 216 | new 217 | label_length = strlen(label); 218 | 219 | if (0 == _:(0 < label_length < MAX_VEHICLE_LABEL_SIZE)) 220 | return 0; 221 | 222 | #emit PUSH.s label 223 | #emit PUSH.s color 224 | 225 | #emit CONST.alt TDW_g_sVehicle@LabelId 226 | #emit LOAD.s.pri vehicleid 227 | #emit LIDX 228 | 229 | #emit PUSH.pri 230 | #emit PUSH.c 12 231 | #if defined _TDW_VH_DETECT_STREAMER 232 | #emit SYSREQ.c UpdateDynamic3DTextLabelText 233 | #else 234 | #emit SYSREQ.c Update3DTextLabelText 235 | #endif 236 | #emit STACK 16 237 | 238 | if (replace_buffer) 239 | strpack(TDW_g_sVehicle@LabelText[vehicleid], label, label_length); 240 | 241 | return 1; 242 | } 243 | 244 | /** ------------------------------------------------------------------------ **\ 245 | ShowVehicle3DTextLabel 246 | The ID of the vehicle 247 | 248 | - 249 | 250 | 251 | 252 | \** ------------------------------------------------------------------------ **/ 253 | 254 | stock ShowVehicle3DTextLabel(vehicleid) 255 | { 256 | if (0 == IsValidVehicle(vehicleid)) 257 | return 0; 258 | 259 | if (TDW_g_sVehicle@Flags{vehicleid} & EI_VH_LABEL_HIDDEN) { 260 | UpdateVehicle3DTextLabel(vehicleid, TDW_g_sVehicle@LabelText[vehicleid], 261 | true); 262 | TDW_g_sVehicle@Flags{vehicleid} ^= EI_VH_LABEL_HIDDEN; 263 | } 264 | 265 | return 1; 266 | } 267 | 268 | /** ------------------------------------------------------------------------ **\ 269 | HideVehicle3DTextLabel 270 | The ID of the vehicle 271 | 272 | - 273 | 274 | 275 | 276 | \** ------------------------------------------------------------------------ **/ 277 | 278 | stock HideVehicle3DTextLabel(vehicleid) 279 | { 280 | if (0 == IsValidVehicle(vehicleid)) 281 | return 0; 282 | if (TDW_g_sVehicle@Flags{vehicleid} & EI_VH_LABEL_HIDDEN) 283 | return 0; 284 | 285 | UpdateVehicle3DTextLabel(vehicleid, !" ", true); 286 | TDW_g_sVehicle@Flags{vehicleid} ^= EI_VH_LABEL_HIDDEN; 287 | 288 | return 1; 289 | } 290 | 291 | /** ------------------------------------------------------------------------ **\ 292 | Is3DTextLabelHidden 293 | The ID of the vehicle 294 | 295 | - 296 | 297 | 298 | 299 | \** ------------------------------------------------------------------------ **/ 300 | 301 | stock Is3DTextLabelHidden(vehicleid) 302 | { 303 | return IsValidVehicle(vehicleid) && 304 | (TDW_g_sVehicle@Flags{vehicleid} & EI_VH_LABEL_HIDDEN); 305 | } 306 | 307 | // ----------------------------------------------------------------------------- 308 | // Internal: 309 | 310 | #undef TDW_VH_DestroyLabel 311 | #undef TDW_VH_UpdateLabel 312 | -------------------------------------------------------------------------------- /tdw_vylimit.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Speed Limiter 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - 30 | Static: 31 | - 32 | Public: 33 | - OnFilterScriptInit 34 | - OnGameModeInit 35 | - @_TDW_TIMER_@_LIMITER_ 36 | Hooks: 37 | - 38 | [Callbacks]: 39 | - TDWVH_L@OnFilterScriptInit 40 | - TDWVH_L@OnGameModeInit 41 | [Definitions]: 42 | - TDW_LIMITER_TIMER_INTERVAL 43 | [Enumerations]: 44 | - E_LIMITER_TDW_CALLBACKS 45 | [Macros]: 46 | - 47 | [Tags]: 48 | - 49 | [Variables]: 50 | Global scope: 51 | - 52 | Static scope: 53 | - TDW_g_sVehiclesWithLimit@Max 54 | - TDW_g_sVehiclesWithLimit@Min 55 | - TDW_g_sTimerName 56 | - TDW_g_sSpecifier@ii 57 | - TDW_g_sCallbacks 58 | - TDW_g_sOnPlayerReachSpeedLimit 59 | [Natives]: 60 | - 61 | [Operators]: 62 | - 63 | | Dependencies: 64 | - 65 | \* ========================================================================== */ 66 | 67 | #if defined _inc_tdw_vylimit 68 | // I remove this constant because the compiler automatically generates it. 69 | // github.com/Zeex/pawn/issues/107 70 | #undef _inc_tdw_vylimit 71 | #endif 72 | 73 | #if defined _TDW_VH_SYS_VEHICLE_SPEED_LIMIT 74 | #endinput 75 | #endif 76 | 77 | #define _TDW_VH_SYS_VEHICLE_SPEED_LIMIT 78 | 79 | #include "tdw_vehicle" 80 | 81 | // Modules 82 | #include "tdw_vmath" 83 | 84 | // ----------------------------------------------------------------------------- 85 | // Definitions 86 | 87 | #if !defined TDW_LIMITER_TIMER_INTERVAL 88 | #define TDW_LIMITER_TIMER_INTERVAL (450) 89 | #endif 90 | 91 | // ----------------------------------------------------------------------------- 92 | // Static scope: 93 | 94 | static stock 95 | Float:TDW_g_sVehiclesWithLimit@Max[MAX_VEHICLES] = {Float:-1.0, ...}, 96 | Float:TDW_g_sVehiclesWithLimit@Min[MAX_VEHICLES] = {Float:-1.0, ...}, 97 | TDW_g_sTimerName[] = !"@_TDW_TIMER_@_LIMITER_", 98 | TDW_g_sSpecifier@ii[] = !"ii", 99 | TDW_g_sCallbacks, 100 | TDW_g_sOnPlayerReachSpeedLimit[] = !"OnPlayerReachSpeedLimit"; 101 | 102 | // ----------------------------------------------------------------------------- 103 | // Hooks: 104 | 105 | // OnFilterScriptInit / OnGameModeInit hook 106 | #if defined FILTERSCRIPT 107 | #if defined TDWVH_L@OnFilterScriptInit 108 | forward TDWVH_L@OnFilterScriptInit(); 109 | #endif 110 | 111 | public OnFilterScriptInit() 112 | { 113 | if (funcidx(TDW_g_sOnPlayerReachSpeedLimit) != -1) 114 | TDW_g_sCallbacks |= 1; 115 | 116 | #if defined TDWVH_L@OnFilterScriptInit 117 | TDWVH_L@OnFilterScriptInit(); 118 | #endif 119 | 120 | return 1; 121 | } 122 | 123 | #if defined _ALS_OnFilterScriptInit 124 | #undef OnFilterScriptInit 125 | #else 126 | #define _ALS_OnFilterScriptInit 127 | #endif 128 | 129 | #define OnFilterScriptInit TDWVH_L@OnFilterScriptInit 130 | #else 131 | #if defined TDWVH_L@OnGameModeInit 132 | forward TDWVH_L@OnGameModeInit(); 133 | #endif 134 | 135 | public OnGameModeInit() 136 | { 137 | if (funcidx(TDW_g_sOnPlayerReachSpeedLimit) != -1) 138 | TDW_g_sCallbacks |= 1; 139 | 140 | #if defined TDWVH_L@OnGameModeInit 141 | TDWVH_L@OnGameModeInit(); 142 | #endif 143 | 144 | return 1; 145 | } 146 | 147 | #if defined _ALS_OnGameModeInit 148 | #undef OnGameModeInit 149 | #else 150 | #define _ALS_OnGameModeInit 151 | #endif 152 | 153 | #define OnGameModeInit TDWVH_L@OnGameModeInit 154 | #endif 155 | 156 | // OnPlayerStateChange hook 157 | #if defined TDWVH_L@OnPlayerStateChange 158 | forward TDWVH_L@OnPlayerStateChange(playerid, newstate, oldstate); 159 | #endif 160 | 161 | public OnPlayerStateChange(playerid, newstate, oldstate) 162 | { 163 | if (newstate == PLAYER_STATE_DRIVER) 164 | SetTimerEx(TDW_g_sTimerName, TDW_LIMITER_TIMER_INTERVAL, false, 165 | TDW_g_sSpecifier@ii, GetPlayerVehicleID(playerid), playerid); 166 | 167 | #if defined TDWVH_L@OnPlayerStateChange 168 | TDWVH_L@OnPlayerStateChange(playerid, newstate, oldstate); 169 | #endif 170 | 171 | return 1; 172 | } 173 | 174 | #if defined _ALS_OnPlayerStateChange 175 | #undef OnPlayerStateChange 176 | #else 177 | #define _ALS_OnPlayerStateChange 178 | #endif 179 | 180 | #define OnPlayerStateChange TDWVH_L@OnPlayerStateChange 181 | 182 | // ----------------------------------------------------------------------------- 183 | // Functions: 184 | 185 | stock Float:GetVehicleMaxLimit(vehicleid) 186 | { 187 | if (IsValidVehicle(vehicleid) == 0) 188 | return 0.0; 189 | 190 | return TDW_g_sVehiclesWithLimit@Max[vehicleid]; 191 | } 192 | 193 | stock SetVehicleMaxLimit(vehicleid, Float:max_limit) 194 | { 195 | if (IsValidVehicle(vehicleid) == 0) 196 | return 0; 197 | 198 | TDW_g_sVehiclesWithLimit@Max[vehicleid] = max_limit; 199 | 200 | return 1; 201 | } 202 | 203 | stock Float:GetVehicleMinLimit(vehicleid) 204 | { 205 | if (IsValidVehicle(vehicleid) == 0) 206 | return 0.0; 207 | 208 | return TDW_g_sVehiclesWithLimit@Min[vehicleid]; 209 | } 210 | 211 | stock SetVehicleMinLimit(vehicleid, Float:min_limit) 212 | { 213 | if (IsValidVehicle(vehicleid) == 0) 214 | return 0; 215 | 216 | TDW_g_sVehiclesWithLimit@Min[vehicleid] = min_limit; 217 | 218 | return 1; 219 | } 220 | 221 | // ----------------------------------------------------------------------------- 222 | // Internal 223 | 224 | @_TDW_TIMER_@_LIMITER_(vehicleid, playerid); 225 | @_TDW_TIMER_@_LIMITER_(vehicleid, playerid) 226 | { 227 | static 228 | Float:speed; 229 | 230 | if ((speed = GetVehicleSpeed(vehicleid)) > 231 | TDW_g_sVehiclesWithLimit@Max[vehicleid]) 232 | { 233 | SetVehicleSpeed(vehicleid, TDW_g_sVehiclesWithLimit@Max[vehicleid]); 234 | 235 | if (TDW_g_sCallbacks & 1) 236 | { 237 | CallLocalFunction(TDW_g_sOnPlayerReachSpeedLimit, !"iif", 238 | vehicleid, playerid, speed); 239 | } 240 | } 241 | else if (speed < TDW_g_sVehiclesWithLimit@Min[vehicleid]) 242 | SetVehicleSpeed(vehicleid, TDW_g_sVehiclesWithLimit@Min[vehicleid]); 243 | 244 | if (GetPlayerState(playerid) != PLAYER_STATE_DRIVER) 245 | return 0; 246 | 247 | return 248 | SetTimerEx(TDW_g_sTimerName, TDW_LIMITER_TIMER_INTERVAL, false, 249 | TDW_g_sSpecifier@ii, vehicleid, playerid); 250 | } 251 | 252 | // ----------------------------------------------------------------------------- 253 | // Forwards: 254 | 255 | forward OnPlayerReachSpeedLimit(vehicleid, playerid, Float:speed); 256 | -------------------------------------------------------------------------------- /tdw_vylock.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Lock 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - LockVehicleDoors 30 | - UnlockVehicleDoors 31 | - IsVehicleLocked 32 | Static: 33 | - 34 | Public: 35 | - OnFilterScriptInit 36 | - OnGameModeInit 37 | - OnPlayerEnterVehicle 38 | - OnPlayerStateChange 39 | Hooks: 40 | - 41 | [Callbacks]: 42 | - OnPlayerTryingEnterVehicle 43 | - TDWVH_LOCK@OnFilterScriptInit 44 | - TDWVH_LOCK@OnGameModeInit 45 | - TDWVH_LOCK@OnPlayerEnterVehicle 46 | - TDWVH_LOCK@OnPlayerStateChange 47 | [Definitions]: 48 | - 49 | [Enumerations]: 50 | - 51 | [Macros]: 52 | - 53 | [Tags]: 54 | - 55 | [Variables]: 56 | Global scope: 57 | - 58 | Static scope: 59 | - TDW_g_sOnPlayerTryEnterVehicle 60 | - TDW_g_sCallbacks 61 | - TDW_g_sSpecifier@ii 62 | - TDW_g_sIsVehicleDoorsLocked 63 | [Natives]: 64 | - 65 | [Operators]: 66 | - 67 | | Dependencies: 68 | - 69 | \* ========================================================================== */ 70 | 71 | #if defined _inc_tdw_vylock 72 | // I remove this constant because the compiler automatically generates it. 73 | // github.com/Zeex/pawn/issues/107 74 | #undef _inc_tdw_vylock 75 | #endif 76 | 77 | #if defined _TDW_VH_SYS_LOCK 78 | #endinput 79 | #endif 80 | 81 | #define _TDW_VH_SYS_LOCK 82 | 83 | #include "tdw_vehicle" 84 | 85 | // ----------------------------------------------------------------------------- 86 | // Static scope: 87 | 88 | static stock 89 | TDW_g_sOnPlayerTryEnterVehicle[] = !"OnPlayerTryingEnterVehicle", 90 | TDW_g_sCallbacks, 91 | TDW_g_sSpecifier@ii[] = !"ii", 92 | bool:TDW_g_sIsVehicleDoorsLocked[MAX_VEHICLES char] = {false, ...}; 93 | 94 | // ----------------------------------------------------------------------------- 95 | // Hooks: 96 | 97 | // OnFilterScriptInit / OnGameModeInit hook 98 | #if defined FILTERSCRIPT 99 | #if defined TDWVH_LOCK@OnFilterScriptInit 100 | forward TDWVH_LOCK@OnFilterScriptInit(); 101 | #endif 102 | 103 | public OnFilterScriptInit() 104 | { 105 | if (funcidx(TDW_g_sOnPlayerTryEnterVehicle) != -1) 106 | TDW_g_sCallbacks |= 1; 107 | 108 | #if defined TDWVH_LOCK@OnFilterScriptInit 109 | TDWVH_LOCK@OnFilterScriptInit(); 110 | #endif 111 | 112 | return 1; 113 | } 114 | 115 | #if defined _ALS_OnFilterScriptInit 116 | #undef OnFilterScriptInit 117 | #else 118 | #define _ALS_OnFilterScriptInit 119 | #endif 120 | 121 | #define OnFilterScriptInit TDWVH_LOCK@OnFilterScriptInit 122 | #else 123 | #if defined TDWVH_LOCK@OnGameModeInit 124 | forward TDWVH_LOCK@OnGameModeInit(); 125 | #endif 126 | 127 | public OnGameModeInit() 128 | { 129 | if (funcidx(TDW_g_sOnPlayerTryEnterVehicle) != -1) 130 | TDW_g_sCallbacks |= 1; 131 | 132 | #if defined TDWVH_LOCK@OnGameModeInit 133 | TDWVH_LOCK@OnGameModeInit(); 134 | #endif 135 | 136 | return 1; 137 | } 138 | 139 | #if defined _ALS_OnGameModeInit 140 | #undef OnGameModeInit 141 | #else 142 | #define _ALS_OnGameModeInit 143 | #endif 144 | 145 | #define OnGameModeInit TDWVH_LOCK@OnGameModeInit 146 | #endif 147 | 148 | 149 | // OnPlayerEnterVehicle hook 150 | #if defined TDWVH_LOCK@OnPlayerEnterVehicle 151 | forward TDWVH_LOCK@OnPlayerEnterVehicle(playerid, vehicleid, ispassenger); 152 | #endif 153 | 154 | public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) 155 | { 156 | if (IsVehicleLocked(vehicleid)) 157 | if (TDW_g_sCallbacks & 1) 158 | if (0 == CallLocalFunction(TDW_g_sOnPlayerTryEnterVehicle, 159 | TDW_g_sSpecifier@ii, playerid, vehicleid)) 160 | ClearAnimations(playerid, 1); 161 | 162 | #if defined TDWVH_LOCK@OnPlayerEnterVehicle 163 | TDWVH_LOCK@OnPlayerEnterVehicle(playerid, vehicleid, ispassenger); 164 | #endif 165 | 166 | return 1; 167 | } 168 | 169 | #if defined _ALS_OnPlayerEnterVehicle 170 | #undef OnPlayerEnterVehicle 171 | #else 172 | #define _ALS_OnPlayerEnterVehicle 173 | #endif 174 | 175 | #define OnPlayerEnterVehicle TDWVH_LOCK@OnPlayerEnterVehicle 176 | 177 | 178 | // OnPlayerStateChange hook 179 | #if defined TDWVH_LOCK@OnPlayerStateChange 180 | forward TDWVH_LOCK@OnPlayerStateChange(playerid, newstate, oldstate); 181 | #endif 182 | 183 | public OnPlayerStateChange(playerid, newstate, oldstate) 184 | { 185 | switch (newstate) { 186 | case PLAYER_STATE_PASSENGER, PLAYER_STATE_DRIVER: { 187 | if (IsVehicleLocked(GetPlayerVehicleID(playerid))) { 188 | RemovePlayerFromVehicle(playerid); 189 | ClearAnimations(playerid, 1); 190 | } 191 | } 192 | } 193 | 194 | #if defined TDWVH_LOCK@OnPlayerStateChange 195 | TDWVH_LOCK@OnPlayerStateChange(playerid, newstate, oldstate); 196 | #endif 197 | 198 | return 1; 199 | } 200 | 201 | #if defined _ALS_OnPlayerStateChange 202 | #undef OnPlayerStateChange 203 | #else 204 | #define _ALS_OnPlayerStateChange 205 | #endif 206 | 207 | #define OnPlayerStateChange TDWVH_LOCK@OnPlayerStateChange 208 | 209 | // ----------------------------------------------------------------------------- 210 | // Functions: 211 | 212 | /** ------------------------------------------------------------------------ **\ 213 | LockVehicleDoors 214 | The ID of the vehicle 215 | 216 | - 217 | 218 | 219 | 220 | \** ------------------------------------------------------------------------ **/ 221 | 222 | stock LockVehicleDoors(vehicleid) 223 | { 224 | if (0 == IsValidVehicle(vehicleid)) 225 | return 0; 226 | if (TDW_g_sIsVehicleDoorsLocked{vehicleid}) 227 | return 0; 228 | 229 | new 230 | engine, 231 | lights, 232 | alarm, 233 | doors, 234 | bonnet, 235 | boot, 236 | objective; 237 | 238 | GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, 239 | objective); 240 | SetVehicleParamsEx(vehicleid, engine, lights, alarm, VEHICLE_PARAMS_ON, 241 | bonnet, boot, objective); 242 | 243 | TDW_g_sIsVehicleDoorsLocked{vehicleid} = true; 244 | 245 | return 1; 246 | } 247 | 248 | /** ------------------------------------------------------------------------ **\ 249 | UnlockVehicleDoors 250 | The ID of the vehicle 251 | 252 | - 253 | 254 | 255 | 256 | \** ------------------------------------------------------------------------ **/ 257 | 258 | stock UnlockVehicleDoors(vehicleid) 259 | { 260 | if (0 == IsValidVehicle(vehicleid)) 261 | return 0; 262 | if (0 == _:TDW_g_sIsVehicleDoorsLocked{vehicleid}) 263 | return 0; 264 | 265 | new 266 | engine, 267 | lights, 268 | alarm, 269 | doors, 270 | bonnet, 271 | boot, 272 | objective; 273 | 274 | GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 275 | boot, objective); 276 | SetVehicleParamsEx(vehicleid, engine, lights, alarm, VEHICLE_PARAMS_OFF, 277 | bonnet, boot, objective); 278 | 279 | TDW_g_sIsVehicleDoorsLocked{vehicleid} = false; 280 | 281 | return 1; 282 | } 283 | 284 | /** ------------------------------------------------------------------------ **\ 285 | IsVehicleLocked 286 | The ID of the vehicle 287 | 288 | - 289 | 290 | 291 | 292 | \** ------------------------------------------------------------------------ **/ 293 | 294 | stock IsVehicleLocked(vehicleid) 295 | { 296 | return IsValidVehicle(vehicleid) && TDW_g_sIsVehicleDoorsLocked{vehicleid}; 297 | } 298 | 299 | // ----------------------------------------------------------------------------- 300 | // Forwards: 301 | 302 | forward OnPlayerTryingEnterVehicle(playerid, vehicleid); 303 | -------------------------------------------------------------------------------- /tdw_vymileage.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Vehicle Mileage 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - GetVehicleMileage 30 | - SetVehicleMileage 31 | Static: 32 | - 33 | Public: 34 | - @__TDW_TIMER_MILEAGE 35 | Hooks: 36 | - SetVehiclePos 37 | - DestroyVehicle 38 | [Callbacks]: 39 | - TDWVH_MILEG@OnFilterScriptInit 40 | - TDWVH_MILEG@OnGameModeInit 41 | - TDWVH_MILEG@OnPlayerStateChange 42 | - OnVehicleMileageUpdate 43 | [Definitions]: 44 | - TDW_MILEAGE_TIMER_UPDATE 45 | - TDW_VEHICLE_MILEAGE_MILE_FLOAT 46 | [Enumerations]: 47 | - 48 | [Macros]: 49 | - 50 | [Tags]: 51 | - 52 | [Variables]: 53 | Global scope: 54 | - 55 | Static scope: 56 | - TDW_g_sVehicleMileage 57 | - TDW_g_sVehicleOldPosX 58 | - TDW_g_sVehicleOldPosY 59 | - TDW_g_sVehicleOldPosZ 60 | - TDW_g_sVehicleTimerName 61 | - TDW_g_sCallbacks 62 | - TDW_g_sOnVehicleMileageUpdate 63 | - TDW_g_sSpecifier@i 64 | [Natives]: 65 | - BAD_DestroyVehicle 66 | - BAD_SetVehiclePos 67 | [Operators]: 68 | - 69 | | Dependencies: 70 | - 71 | \* ========================================================================== */ 72 | 73 | #if defined _inc_tdw_vymileage 74 | // I remove this constant because the compiler automatically generates it. 75 | // github.com/Zeex/pawn/issues/107 76 | #undef _inc_tdw_vymileage 77 | #endif 78 | 79 | #if defined _TDW_VH_SYS_VEHICLE_MILEAGE 80 | #endinput 81 | #endif 82 | 83 | #define _TDW_VH_SYS_VEHICLE_MILEAGE 84 | 85 | #include "tdw_vehicle" 86 | 87 | // Modules 88 | #include "tdw_vmath" 89 | 90 | // ----------------------------------------------------------------------------- 91 | // Definitions: 92 | 93 | #if !defined TDW_MILEAGE_TIMER_UPDATE 94 | #define TDW_MILEAGE_TIMER_UPDATE (950) 95 | #else 96 | #assert (0 < TDW_MILEAGE_TIMER_UPDATE) 97 | #endif 98 | 99 | #define TDW_VEHICLE_MILEAGE_MILE_FLOAT (1.609343) 100 | 101 | // ----------------------------------------------------------------------------- 102 | // Static scope: 103 | 104 | static stock 105 | Float:TDW_g_sVehicleMileage[MAX_VEHICLES], 106 | Float:TDW_g_sVehicleTotalMileage[MAX_VEHICLES], 107 | Float:TDW_g_sVehicleOldPosX[MAX_VEHICLES], 108 | Float:TDW_g_sVehicleOldPosY[MAX_VEHICLES], 109 | Float:TDW_g_sVehicleOldPosZ[MAX_VEHICLES], 110 | TDW_g_sVehicleTimerName[] = !"@__TDW_TIMER_MILEAGE", 111 | TDW_g_sCallbacks; 112 | 113 | static stock const 114 | TDW_g_sOnVehicleMileageUpdate[] = !"OnVehicleMileageUpdate", 115 | TDW_g_sSpecifier@i[] = !"i"; 116 | 117 | // ----------------------------------------------------------------------------- 118 | // Hooks: 119 | 120 | // OnFilterScriptInit / OnGameModeInit hook 121 | #if defined FILTERSCRIPT 122 | #if defined TDWVH_MILEG@OnFilterScriptInit 123 | forward TDWVH_MILEG@OnFilterScriptInit(); 124 | #endif 125 | 126 | public OnFilterScriptInit() 127 | { 128 | if (funcidx(TDW_g_sOnVehicleMileageUpdate) != -1) 129 | TDW_g_sCallbacks |= 1; 130 | 131 | #if defined TDWVH_MILEG@OnFilterScriptInit 132 | TDWVH_MILEG@OnFilterScriptInit(); 133 | #endif 134 | 135 | return 1; 136 | } 137 | 138 | #if defined _ALS_OnFilterScriptInit 139 | #undef OnFilterScriptInit 140 | #else 141 | #define _ALS_OnFilterScriptInit 142 | #endif 143 | 144 | #define OnFilterScriptInit TDWVH_MILEG@OnFilterScriptInit 145 | #else 146 | #if defined TDWVH_MILEG@OnGameModeInit 147 | forward TDWVH_MILEG@OnGameModeInit(); 148 | #endif 149 | 150 | public OnGameModeInit() 151 | { 152 | if (funcidx(TDW_g_sOnVehicleMileageUpdate) != -1) 153 | TDW_g_sCallbacks |= 1; 154 | 155 | #if defined TDWVH_MILEG@OnGameModeInit 156 | TDWVH_MILEG@OnGameModeInit(); 157 | #endif 158 | 159 | return 1; 160 | } 161 | 162 | #if defined _ALS_OnGameModeInit 163 | #undef OnGameModeInit 164 | #else 165 | #define _ALS_OnGameModeInit 166 | #endif 167 | 168 | #define OnGameModeInit TDWVH_MILEG@OnGameModeInit 169 | #endif 170 | 171 | 172 | // OnPlayerStateChange hook 173 | #if defined TDWVH_MILEG@OnPlayerStateChange 174 | forward TDWVH_MILEG@OnPlayerStateChange(playerid, newstate, oldstate); 175 | #endif 176 | 177 | public OnPlayerStateChange(playerid, newstate, oldstate) 178 | { 179 | if (newstate == PLAYER_STATE_DRIVER) { 180 | new vehicleid = GetPlayerVehicleID(playerid); 181 | 182 | if (0 == vehicleid) 183 | return 0; 184 | 185 | SetTimerEx(TDW_g_sVehicleTimerName, TDW_MILEAGE_TIMER_UPDATE, false, 186 | TDW_g_sSpecifier@i, vehicleid); 187 | } 188 | 189 | #if defined TDWVH_MILEG@OnPlayerStateChange 190 | TDWVH_MILEG@OnPlayerStateChange(playerid, newstate, oldstate); 191 | #endif 192 | 193 | return 1; 194 | } 195 | 196 | #if defined _ALS_OnPlayerStateChange 197 | #undef OnPlayerStateChange 198 | #else 199 | #define _ALS_OnPlayerStateChange 200 | #endif 201 | 202 | #define OnPlayerStateChange TDWVH_MILEG@OnPlayerStateChange 203 | 204 | 205 | // DestroyVehicle hook 206 | #if !defined BAD_DestroyVehicle 207 | native BAD_DestroyVehicle(vehicleid) = DestroyVehicle; 208 | #endif 209 | 210 | stock TDWVH_MILEG@DestroyVehicle(vehicleid) 211 | { 212 | if (0 == DestroyVehicle(vehicleid)) 213 | return 0; 214 | 215 | TDW_g_sVehicleOldPosX[vehicleid] = 216 | TDW_g_sVehicleOldPosY[vehicleid] = 217 | TDW_g_sVehicleOldPosZ[vehicleid] = 218 | TDW_g_sVehicleMileage[vehicleid] = 0.0; 219 | 220 | return 1; 221 | } 222 | 223 | #if defined _ALS_DestroyVehicle 224 | #undef DestroyVehicle 225 | #else 226 | #define _ALS_DestroyVehicle 227 | #endif 228 | 229 | #define DestroyVehicle TDWVH_MILEG@DestroyVehicle 230 | 231 | 232 | // SetVehiclePos hook 233 | #if !defined BAD_SetVehiclePos 234 | native BAD_SetVehiclePos(vehicleid, Float:x, Float:y, 235 | Float:z) = SetVehiclePos; 236 | #endif 237 | 238 | stock TDWVH_MILEG@SetVehiclePos(vehicleid, Float:x, Float:y, Float:z) 239 | { 240 | if (0 == SetVehiclePos(vehicleid, x, y, z)) 241 | return 0; 242 | 243 | TDW_g_sVehicleOldPosX[vehicleid] = x; 244 | TDW_g_sVehicleOldPosY[vehicleid] = y; 245 | TDW_g_sVehicleOldPosZ[vehicleid] = z; 246 | 247 | return 1; 248 | } 249 | 250 | #if defined _ALS_SetVehiclePos 251 | #undef SetVehiclePos 252 | #else 253 | #define _ALS_SetVehiclePos 254 | #endif 255 | 256 | #define SetVehiclePos TDWVH_MILEG@SetVehiclePos 257 | 258 | // ----------------------------------------------------------------------------- 259 | // Functions: 260 | 261 | /** ------------------------------------------------------------------------ **\ 262 | GetVehicleMileage 263 | The ID of the vehicle 264 | 265 | - 266 | 267 | 268 | 269 | \** ------------------------------------------------------------------------ **/ 270 | 271 | stock GetVehicleMileage(vehicleid) 272 | { 273 | return 274 | IsValidVehicle(vehicleid) 275 | ? floatround(TDW_g_sVehicleTotalMileage[vehicleid]) 276 | : INVALID_VEHICLE_ID; 277 | } 278 | 279 | /** ------------------------------------------------------------------------ **\ 280 | SetVehicleMileage 281 | The ID of the vehicle 282 | 283 | - 284 | 285 | 286 | 287 | \** ------------------------------------------------------------------------ **/ 288 | 289 | stock SetVehicleMileage(vehicleid, Float:mileage) 290 | { 291 | if (IsValidVehicle(vehicleid)) 292 | TDW_g_sVehicleTotalMileage[vehicleid] = mileage; 293 | 294 | return 0; 295 | } 296 | 297 | // ----------------------------------------------------------------------------- 298 | // Internal: 299 | 300 | @__TDW_TIMER_MILEAGE(vehicleid); 301 | @__TDW_TIMER_MILEAGE(vehicleid) 302 | { 303 | static 304 | Float:speed, 305 | Float:tmp___; 306 | 307 | speed = GetVehicleSpeed(vehicleid); 308 | tmp___ = TDW_g_sVehicleMileage[vehicleid] += (speed / 1.4) / 1000.0; 309 | 310 | if (tmp___ >= TDW_VEHICLE_MILEAGE_MILE_FLOAT) { 311 | TDW_g_sVehicleTotalMileage[vehicleid] += tmp___; 312 | TDW_g_sVehicleMileage[vehicleid] -= TDW_VEHICLE_MILEAGE_MILE_FLOAT; 313 | } 314 | 315 | if (TDW_g_sCallbacks & 1) 316 | CallLocalFunction(TDW_g_sOnVehicleMileageUpdate, TDW_g_sSpecifier@i, 317 | vehicleid); 318 | 319 | return SetTimerEx(TDW_g_sVehicleTimerName, TDW_MILEAGE_TIMER_UPDATE, false, 320 | TDW_g_sSpecifier@i, vehicleid); 321 | } 322 | 323 | // ----------------------------------------------------------------------------- 324 | // Forwards: 325 | 326 | forward OnVehicleMileageUpdate(vehicleid); 327 | -------------------------------------------------------------------------------- /tdw_vyradar.inc: -------------------------------------------------------------------------------- 1 | /* ========================================================================== *\ 2 | Speed Radar Controller (SRC) 3 | 4 | | Description: 5 | 6 | 7 | | License: 8 | Copyright (c) 2016-2017 Double V 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgement in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | | Metadata: 27 | [Functions]: 28 | Stock: 29 | - CreateRadar 30 | - DestroyRadar 31 | - SetRadarMaxDistance 32 | - GetRadarMaxDistance 33 | - IsValidRadar 34 | - SetRadarMaxSpeed 35 | - GetRadarMaxSpeed 36 | Static: 37 | - Radar_GetUnusedSlot 38 | Public: 39 | - @_TDW_RADAR_TIMER 40 | - OnGameModeInit 41 | - OnFilterScriptInit 42 | Hooks: 43 | - 44 | [Callbacks]: 45 | - TDWVH_RADAR@OnGameModeInit 46 | - TDWVH_RADAR@OnFilterScriptInit 47 | - OnVehicleRadarDetect 48 | [Definitions]: 49 | - TDW_RADAR_MAX_RADARS 50 | - TDW_RADAR_TIMER_COUNT 51 | - TDW_RADAR_MAX_DISTANCE 52 | - TDW_RADAR_MIN_DISTANCE 53 | - TDW_SRC_CreateObject 54 | - TDW_SRC_GetObjectPos 55 | - TDW_SRC_GetObjectRot 56 | [Enumerations]: 57 | - E_TDW_VH_RADAR 58 | [Macros]: 59 | - 60 | [Tags]: 61 | - 62 | [Variables]: 63 | Global scope: 64 | - 65 | Static scope: 66 | - TDW_g_sRadar@Data 67 | - TDW_g_sRadar@Id 68 | - TDW_g_sSpecifier@i 69 | - TDW_g_sRadar@TimerName 70 | - TDW_g_sCallbacks 71 | - TDW_g_sOnVehicleRadarDetect 72 | [Natives]: 73 | - 74 | [Operators]: 75 | - 76 | | Dependencies: 77 | - streamer (optional) 78 | - foreach (optional) 79 | \* ========================================================================== */ 80 | 81 | #if defined _inc_tdw_vyradar 82 | // I remove this constant because the compiler automatically generates it. 83 | // github.com/Zeex/pawn/issues/107 84 | #undef _inc_tdw_vyradar 85 | #endif 86 | 87 | #if defined _TDW_VH_SYS_SRC // (S)peed (R)adar (C)ontroller 88 | #endinput 89 | #endif 90 | 91 | #define _TDW_VH_SYS_SRC 92 | 93 | #include "tdw_vehicle" 94 | 95 | // Modules 96 | #include "tdw_vmath" 97 | 98 | #if defined Streamer_IncludeFileVersion && !defined _TDW_VH_DETECT_STREAMER 99 | #define _TDW_VH_DETECT_STREAMER 100 | #endif 101 | 102 | // ----------------------------------------------------------------------------- 103 | // Definitions: 104 | 105 | #if !defined TDW_RADAR_MAX_RADARS 106 | #define TDW_RADAR_MAX_RADARS (500) 107 | #endif 108 | 109 | #if !defined TDW_RADAR_TIMER_COUNT 110 | #define TDW_RADAR_TIMER_COUNT (350) 111 | #endif 112 | 113 | #if !defined TDW_RADAR_MAX_DISTANCE 114 | #define TDW_RADAR_MAX_DISTANCE (10.0) 115 | #endif 116 | 117 | #if !defined TDW_RADAR_MIN_DISTANCE 118 | #define TDW_RADAR_MIN_DISTANCE (0.0) 119 | #endif 120 | 121 | #if defined _TDW_VH_DETECT_STREAMER 122 | #define TDW_SRC_CreateObject CreateDynamicObject 123 | #define TDW_SRC_GetObjectPos GetDynamicObjectPos 124 | #define TDW_SRC_GetObjectRot GetDynamicObjectRot 125 | #else 126 | #define TDW_SRC_CreateObject CreateObject 127 | #define TDW_SRC_GetObjectPos GetObjectPos 128 | #define TDW_SRC_GetObjectRot GetObjectRot 129 | #endif 130 | 131 | // ----------------------------------------------------------------------------- 132 | // Enumerations: 133 | 134 | enum E_TDW_VH_RADAR 135 | { 136 | EI_RADAR_OBJECT_ID, 137 | EI_RADAR_TIMER_ID, 138 | Float:EI_RADAR_POS_X, 139 | Float:EI_RADAR_POS_Y, 140 | Float:EI_RADAR_POS_Z, 141 | Float:EI_RADAR_DISTANCE, 142 | Float:EI_RADAR_MAX_SPEED 143 | }; 144 | 145 | // ----------------------------------------------------------------------------- 146 | // Static scope: 147 | 148 | static stock 149 | TDW_g_sRadar@Data[TDW_RADAR_MAX_RADARS][E_TDW_VH_RADAR], 150 | TDW_g_sRadar@Id, 151 | TDW_g_sSpecifier@i[] = !"i", 152 | TDW_g_sRadar@TimerName[] = !"@_TDW_RADAR_TIMER", 153 | TDW_g_sCallbacks = 0, 154 | TDW_g_sOnVehicleRadarDetect[] = !"OnVehicleRadarDetect"; 155 | // TDW_g_sRadar@PlayerInStream[MAX_PLAYERS char]; 156 | 157 | // ----------------------------------------------------------------------------- 158 | // Hooks: 159 | 160 | // OnFilterScriptInit / OnGameModeInit hook 161 | #if defined FILTERSCRIPT 162 | #if defined TDWVH_RADAR@OnFilterScriptInit 163 | forward TDWVH_RADAR@OnFilterScriptInit(); 164 | #endif 165 | 166 | public OnFilterScriptInit() 167 | { 168 | if (funcidx(TDW_g_sOnVehicleRadarDetect) != -1) 169 | TDW_g_sCallbacks |= 1; 170 | 171 | #if defined TDWVH_RADAR@OnFilterScriptInit 172 | TDWVH_RADAR@OnFilterScriptInit(); 173 | #endif 174 | 175 | return 1; 176 | } 177 | 178 | #if defined _ALS_OnFilterScriptInit 179 | #undef OnFilterScriptInit 180 | #else 181 | #define _ALS_OnFilterScriptInit 182 | #endif 183 | 184 | #define OnFilterScriptInit TDWVH_RADAR@OnFilterScriptInit 185 | #else 186 | #if defined TDWVH_RADAR@OnGameModeInit 187 | forward TDWVH_RADAR@OnGameModeInit(); 188 | #endif 189 | 190 | public OnGameModeInit() 191 | { 192 | if (funcidx(TDW_g_sOnVehicleRadarDetect) != -1) 193 | TDW_g_sCallbacks |= 1; 194 | 195 | #if defined TDWVH_RADAR@OnGameModeInit 196 | TDWVH_RADAR@OnGameModeInit(); 197 | #endif 198 | 199 | return 1; 200 | } 201 | 202 | #if defined _ALS_OnGameModeInit 203 | #undef OnGameModeInit 204 | #else 205 | #define _ALS_OnGameModeInit 206 | #endif 207 | 208 | #define OnGameModeInit TDWVH_RADAR@OnGameModeInit 209 | #endif 210 | 211 | // ----------------------------------------------------------------------------- 212 | // Functions: 213 | 214 | /** ------------------------------------------------------------------------ **\ 215 | CreateRadar 216 | The ID of the radar 217 | 218 | - 219 | 220 | 221 | 222 | \** ------------------------------------------------------------------------ **/ 223 | 224 | stock CreateRadar(Float:x, Float:y, Float:z, Float:rX, Float:rY, Float:rZ, 225 | Float:distance, Float:max_speed) 226 | { 227 | TDW_g_sRadar@Id = Radar_GetUnusedSlot(); 228 | 229 | if (TDW_g_sRadar@Id != INVALID_OBJECT_ID) { 230 | TDW_g_sRadar@Data[TDW_g_sRadar@Id][EI_RADAR_OBJECT_ID] = 231 | TDW_SRC_CreateObject(18880, x, y, z, rX, rY, floatadd(rZ, 180.0)); 232 | 233 | if (TDW_g_sCallbacks & 1) { 234 | TDW_g_sRadar@Data[TDW_g_sRadar@Id][EI_RADAR_MAX_SPEED] = max_speed; 235 | TDW_g_sRadar@Data[TDW_g_sRadar@Id][EI_RADAR_DISTANCE] = distance; 236 | TDW_g_sRadar@Data[TDW_g_sRadar@Id][EI_RADAR_TIMER_ID] = SetTimerEx( 237 | TDW_g_sRadar@TimerName, TDW_RADAR_TIMER_COUNT, false, 238 | TDW_g_sSpecifier@i, TDW_g_sRadar@Id); 239 | } 240 | } 241 | 242 | return TDW_g_sRadar@Id; 243 | } 244 | 245 | /** ------------------------------------------------------------------------ **\ 246 | DestroyRadar 247 | The ID of the radar 248 | 249 | - 250 | 251 | 252 | 253 | \** ------------------------------------------------------------------------ **/ 254 | 255 | stock DestroyRadar(radarid) 256 | { 257 | if (0 == IsValidRadar(radarid)) 258 | return 0; 259 | 260 | DestroyObject(objectid); 261 | TDW_g_sRadar@Data[radarid][EI_RADAR_OBJECT_ID] = 0; 262 | KillTimer(TDW_g_sRadar@Data[radarid][EI_RADAR_TIMER_ID]); 263 | 264 | return 1; 265 | } 266 | 267 | /** ------------------------------------------------------------------------ **\ 268 | SetRadarMaxDistance 269 | The ID of the radar 270 | 271 | - 272 | 273 | 274 | 275 | \** ------------------------------------------------------------------------ **/ 276 | 277 | stock SetRadarMaxDistance(radarid, Float:distance) 278 | { 279 | if (0 == IsValidRadar(radarid)) 280 | return 0; 281 | TDW_g_sRadar@Data[radarid][EI_RADAR_DISTANCE] = clamp(distance, 282 | TDW_RADAR_MIN_DISTANCE, TDW_RADAR_MAX_DISTANCE); 283 | return 1; 284 | } 285 | 286 | /** ------------------------------------------------------------------------ **\ 287 | GetRadarMaxDistance 288 | The ID of the radar 289 | 290 | - 291 | 292 | 293 | 294 | \** ------------------------------------------------------------------------ **/ 295 | 296 | stock Float:GetRadarMaxDistance(radarid) 297 | { 298 | if (0 == IsValidRadar(radarid)) 299 | return 0; 300 | 301 | return TDW_g_sRadar@Data[radarid][EI_RADAR_DISTANCE]; 302 | } 303 | 304 | /** ------------------------------------------------------------------------ **\ 305 | IsValidRadar 306 | The ID of the radar 307 | 308 | - 309 | 310 | 311 | 312 | \** ------------------------------------------------------------------------ **/ 313 | 314 | stock IsValidRadar(radarid) 315 | { 316 | if (0 == _:(0 <= radarid <= TDW_RADAR_MAX_RADARS)) 317 | return 0; 318 | 319 | static objectid; 320 | 321 | if (0 == (objectid = TDW_g_sRadar@Data[radarid][EI_RADAR_OBJECT_ID])) 322 | return 0; 323 | 324 | return 1; 325 | } 326 | 327 | /** ------------------------------------------------------------------------ **\ 328 | SetRadarMaxSpeed 329 | The ID of the radar 330 | 331 | - 332 | 333 | 334 | 335 | \** ------------------------------------------------------------------------ **/ 336 | 337 | stock SetRadarMaxSpeed(radarid, Float:speed) 338 | { 339 | if (0 == IsValidRadar(radarid)) 340 | return 0; 341 | 342 | TDW_g_sRadar@Data[radarid][EI_RADAR_MAX_SPEED] = speed; 343 | 344 | return 1; 345 | } 346 | 347 | /** ------------------------------------------------------------------------ **\ 348 | GetRadarMaxSpeed 349 | The ID of the radar 350 | 351 | - 352 | 353 | 354 | 355 | \** ------------------------------------------------------------------------ **/ 356 | 357 | stock Float:GetRadarMaxSpeed(radarid) 358 | { 359 | if (0 == IsValidRadar(radarid)) 360 | return 0.0; 361 | 362 | return TDW_g_sRadar@Data[radarid][EI_RADAR_MAX_SPEED]; 363 | } 364 | 365 | // ----------------------------------------------------------------------------- 366 | // Internal: 367 | 368 | @_TDW_RADAR_TIMER(radarid); 369 | @_TDW_RADAR_TIMER(radarid) 370 | { 371 | static 372 | Float:x, 373 | Float:y, 374 | Float:z, 375 | objectid, 376 | Float:__, // It contains a useless value. 377 | Float:z_rot, 378 | Float:speed, 379 | Float:distance, 380 | vehicleid; 381 | 382 | objectid = TDW_g_sRadar@Data[radarid][EI_RADAR_OBJECT_ID]; 383 | 384 | TDW_SRC_GetObjectPos(objectid, x, y, z); 385 | TDW_SRC_GetObjectRot(objectid, __, __, z_rot); 386 | 387 | distance = TDW_g_sRadar@Data[radarid][EI_RADAR_DISTANCE]; 388 | 389 | x = floatadd(x, floatmul(floatadd(distance, 2.0), floatsin(floatadd(-z_rot, 390 | 135.0), degrees))); 391 | y = floatadd(y, floatmul(floatadd(distance, 2.0), floatcos(floatadd(-z_rot, 392 | 135.0), degrees))); 393 | 394 | #if defined foreach 395 | foreach (new i: Player) 396 | #else 397 | for (new i = _TDW_FOREACH_MAX_PLAYERS_; --i != -1;) 398 | #endif 399 | { 400 | if (IsPlayerInAnyVehicle(i) == 0) 401 | continue; 402 | 403 | vehicleid = GetPlayerVehicleID(i); 404 | speed = GetVehicleSpeed(vehicleid); 405 | 406 | if (speed >= TDW_g_sRadar@Data[radarid][EI_RADAR_MAX_SPEED]) 407 | CallLocalFunction(TDW_g_sOnVehicleRadarDetect, !"iiif", i, 408 | vehicleid, radarid, speed); 409 | } 410 | #pragma tabsize 0 411 | TDW_g_sRadar@Data[radarid][EI_RADAR_TIMER_ID] = SetTimerEx( 412 | TDW_g_sRadar@TimerName, TDW_RADAR_TIMER_COUNT, false, 413 | TDW_g_sSpecifier@i, radarid); 414 | #pragma tabsize 4 415 | return 0; 416 | } 417 | 418 | static stock Radar_GetUnusedSlot() 419 | { 420 | new i; 421 | 422 | do { 423 | if (TDW_g_sRadar@Data[i][EI_RADAR_OBJECT_ID] == 0) 424 | return i; 425 | } while (++i != TDW_RADAR_MAX_RADARS); 426 | 427 | return INVALID_OBJECT_ID; 428 | } 429 | 430 | // ----------------------------------------------------------------------------- 431 | // Forwards: 432 | 433 | forward OnVehicleRadarDetect(playerid, vehicleid, radarid, Float:speed); 434 | 435 | // ----------------------------------------------------------------------------- 436 | // Internal: 437 | 438 | #undef TDW_SRC_CreateObject 439 | #undef TDW_SRC_GetObjectPos 440 | #undef TDW_SRC_GetObjectRot 441 | --------------------------------------------------------------------------------