windosi.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. Vehicle Windows/Doors/Siren Control (WinDoSi Control)
  3. _______________________________________
  4. | |
  5. | Name: WinDoSi Control |
  6. | Version: 1.0.0 |
  7. | Release date: |
  8. | Credits: |
  9. | - valych - author of this include |
  10. |_______________________________________|
  11. * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  12. * This section here should include and extremely long *
  13. * and immensely boring formal text regarding licensing. *
  14. * But since we know how nobody ever gives a single *
  15. * rat's behind about such stuff, you are free to skip *
  16. * this part. *
  17. * And this I didn't quite make out, sorry. *
  18. * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  19. ------------- Additional information ----------------
  20. Official forum's thread: http://forum.sa-mp.com/showthread.php?p=3549532
  21. Change Log: https://github.com/valychbreak/SAMP-WinDoSi.inc/commits/master
  22. Documentation: *link*
  23. -----------------------------------------------------
  24. */
  25. #if defined veh_WinDoSi_control_included
  26. #endinput
  27. #endif
  28. #define veh_WinDoSi_control_included
  29. //-------- Debug -------
  30. #if defined VEHICLE_WDS_DEBUG
  31. #define WDS::Debug(%0,%1) printf(%0,%1)
  32. #else
  33. #define WDS::Debug(%0,%1) gettime()
  34. #endif
  35. //-------- Definitions --------
  36. #define WDS_MAX_VEHICLE_DOORS 4 // Amount of doors (Just to avoid using literals)
  37. // Doors
  38. #define FL_DOOR 0 // Front Left (Driver's door)
  39. #define FR_DOOR 1 // Front Right (Passenger's door)
  40. #define BL_DOOR 2 // Back Left
  41. #define BR_DOOR 3 // Back Right
  42. // Door states
  43. #define WDS_DOOR_STATE_OPENED 1 // Opened state
  44. #define WDS_DOOR_STATE_CLOSED 0 // Closed state
  45. #define WDS_DOOR_STATE_NOT_SET -1 // Not set
  46. // Window states
  47. #define WDS_WINDOW_STATE_OPENED 0 // Opened state
  48. #define WDS_WINDOW_STATE_CLOSED 1 // Closed state
  49. #define WDS_WINDOW_STATE_NOT_SET -1 // Not set
  50. // Siren states
  51. #define WDS_SIREN_STATE_ON 1 // On
  52. #define WDS_SIREN_STATE_OFF 0 // Off
  53. #define WDS_SIREN_STATE_NOT_INSTALLED -1 // Not installed - means, that the siren was not set in AddStaticVehicleEx/CreateVehicle functions (parameter addsiren = 0).
  54. //------------------------------
  55. // Enumeration to store specific vehicle infomation
  56. enum E_veh_windosi_info
  57. {
  58. bool:wdsIsStatic, // true - vehicle was created by AddStaticVehicle(Ex) function, false - vehicle was created by CreateVehicle
  59. // Needed to recreate a vehicle after installing/removing a siren
  60. wdsColor1, // color1
  61. wdsColor2, // color2
  62. wdsRespawnDelay // respawn_delay
  63. }
  64. new wdsVehicleInfo[MAX_VEHICLES][E_veh_windosi_info]; // Stores specific vehicle information
  65. /*
  66. * Sets a new vehicle's window state
  67. *
  68. * Parameters:
  69. * vehicleid - vehicle's ID
  70. * door - vehicle's door ID (see Definitions -> Doors)
  71. * newstate - new state of vehicle's window (see Definitions -> Window states)
  72. *
  73. * Returns 1, if succeeded, otherwise 0.
  74. */
  75. stock SetVehicleWindowState(vehicleid, door, newstate)
  76. {
  77. // In case of invalid vehicleid
  78. if(vehicleid < 0 || vehicleid > MAX_VEHICLES - 1) return 0;
  79. // In case of invalid door number
  80. if(door < 0 || door > 3) return 0;
  81. // In case of invalid state value. WDS_STATE_NOT_SET state is also treated as INVALID.
  82. if(newstate != WDS_WINDOW_STATE_OPENED && newstate != WDS_WINDOW_STATE_CLOSED) return 0;
  83. new wds_WindowsTemp[WDS_MAX_VEHICLE_DOORS]; // To store current doors states
  84. // Get cuurent state of each window
  85. GetVehicleParamsCarWindows(vehicleid,
  86. wds_WindowsTemp[FL_DOOR], wds_WindowsTemp[FR_DOOR],
  87. wds_WindowsTemp[BL_DOOR], wds_WindowsTemp[BR_DOOR]
  88. );
  89. // Set a new state for the door and update vehicle"s doors states
  90. wds_WindowsTemp[door] = newstate;
  91. WDS::Debug("SetVehicleWindowState - vehicleid = %d, door = %d, newstate = %d, newwindowstate = %d", vehicleid, door, newstate, wds_WindowsTemp[door]);
  92. SetVehicleParamsCarWindows(vehicleid,
  93. wds_WindowsTemp[FL_DOOR], wds_WindowsTemp[FR_DOOR],
  94. wds_WindowsTemp[BL_DOOR], wds_WindowsTemp[BR_DOOR]
  95. );
  96. return 1;
  97. }
  98. /*
  99. * Sets a new vehicle's door state
  100. *
  101. * Parameters:
  102. * vehicleid - vehicle's ID
  103. * door - vehicle's door ID (see Definitions -> Doors)
  104. * newstate - new state of vehicle window (see Definitions -> Door states)
  105. *
  106. * Returns 1, if succeeded, otherwise 0.
  107. */
  108. stock SetVehicleDoorState(vehicleid, door, newstate)
  109. {
  110. // In case of invalid vehicleid
  111. if(vehicleid < 0 || vehicleid > MAX_VEHICLES - 1) return 0;
  112. // In case of invalid door number
  113. if(door < 0 || door > 3) return 0;
  114. // In case of invalid state value
  115. if(newstate != WDS_DOOR_STATE_OPENED && newstate != WDS_DOOR_STATE_CLOSED)
  116. {
  117. newstate = WDS_DOOR_STATE_CLOSED;
  118. }
  119. new wds_WindowsTemp[WDS_MAX_VEHICLE_DOORS]; // To store current doors states
  120. // Get cuurent state of each door
  121. GetVehicleParamsCarDoors(vehicleid,
  122. wds_WindowsTemp[FL_DOOR], wds_WindowsTemp[FR_DOOR],
  123. wds_WindowsTemp[BL_DOOR], wds_WindowsTemp[BR_DOOR]
  124. );
  125. // Set a new state for the door and update vehicle's doors states
  126. wds_WindowsTemp[door] = newstate;
  127. WDS::Debug("SetVehicleDoorState - vehicleid = %d, door = %d newstate = %d, newdoorstate = %d", vehicleid, door, newstate, wds_WindowsTemp[door]);
  128. SetVehicleParamsCarDoors(vehicleid,
  129. wds_WindowsTemp[FL_DOOR], wds_WindowsTemp[FR_DOOR],
  130. wds_WindowsTemp[BL_DOOR], wds_WindowsTemp[BR_DOOR]
  131. );
  132. GetVehicleParamsCarDoors(vehicleid,
  133. wds_WindowsTemp[FL_DOOR], wds_WindowsTemp[FR_DOOR],
  134. wds_WindowsTemp[BL_DOOR], wds_WindowsTemp[BR_DOOR]
  135. );
  136. WDS::Debug("SetVehicleDoorState2 - vehicleid = %d, door = %d getdoorstate = %d", vehicleid, door, wds_WindowsTemp[door]);
  137. return 1;
  138. }
  139. /*
  140. * Sets a new vehicle's siren state.
  141. * Note: it can be used only to install/uninstall siren. There is no possibility to turn siren on/off yet.
  142. *
  143. * Parameters:
  144. * vehicleid - vehicle's ID
  145. * newstate - new state for the siren (see Definitions -> Siren states)
  146. *
  147. * Returns 1, if succeeded, otherwise 0.
  148. */
  149. stock SetVehicleSirenState(vehicleid, newstate)
  150. {
  151. // In case of invalid vehicleid
  152. if(vehicleid < 0 || vehicleid > MAX_VEHICLES - 1) return 0;
  153. // In case of invalid state value. WDS_SIREN_STATE_ON is treated as INVALID, because
  154. // there is no possibility to turn the siren on yet.
  155. if(newstate != WDS_SIREN_STATE_OFF && newstate != WDS_SIREN_STATE_NOT_INSTALLED) return 0;
  156. // If current siren state is the same as a new one
  157. if(GetVehicleParamsSirenState(vehicleid) == newstate) return 0;
  158. // Get info about vehicle
  159. new Float:x,Float:y,Float:z,Float:a, // to store position
  160. modelid = GetVehicleModel(vehicleid); // vehicle's modelid
  161. GetVehiclePos(vehicleid, x,y,z);
  162. GetVehicleZAngle(vehicleid, a);
  163. // If vehicle is "destroyable"
  164. if(DestroyVehicle(vehicleid))
  165. {
  166. if(wdsVehicleInfo[vehicleid][wdsIsStatic])
  167. {
  168. // Re-create a static vehicle
  169. WDS_AddStaticVehicleEx(modelid, x,y,z,a,
  170. wdsVehicleInfo[vehicleid][wdsColor1], wdsVehicleInfo[vehicleid][wdsColor2],
  171. wdsVehicleInfo[vehicleid][wdsRespawnDelay],
  172. newstate == WDS_SIREN_STATE_NOT_INSTALLED ? 0 : 1
  173. );
  174. }
  175. else
  176. {
  177. // Re-create a vehicle
  178. WDS_AddStaticVehicleEx(modelid, x,y,z,a,
  179. wdsVehicleInfo[vehicleid][wdsColor1], wdsVehicleInfo[vehicleid][wdsColor2],
  180. wdsVehicleInfo[vehicleid][wdsRespawnDelay],
  181. newstate == WDS_SIREN_STATE_NOT_INSTALLED ? 0 : 1
  182. );
  183. }
  184. return 1;
  185. }
  186. return 0;
  187. }
  188. /*
  189. * Gets a current state of vehicle's window
  190. *
  191. * Parameters:
  192. * vehicleid - vehicle's ID
  193. * door - vehicle's door ID (see Definitions -> Doors)
  194. *
  195. * Returns current state of the window (see Definitions -> Window states)
  196. */
  197. stock GetVehicleWindowState(vehicleid, door)
  198. {
  199. // In case of invalid vehicleid
  200. if(vehicleid < 0 || vehicleid > MAX_VEHICLES - 1) return WDS_WINDOW_STATE_CLOSED;
  201. // In case of invalid door number
  202. if(door < 0 || door > 3) return WDS_WINDOW_STATE_CLOSED;
  203. new wds_WindowsTemp[WDS_MAX_VEHICLE_DOORS]; // To store current doors states
  204. // Get cuurent state of each window
  205. GetVehicleParamsCarWindows(vehicleid,
  206. wds_WindowsTemp[FL_DOOR], wds_WindowsTemp[FR_DOOR],
  207. wds_WindowsTemp[BL_DOOR], wds_WindowsTemp[BR_DOOR]
  208. );
  209. WDS::Debug("GetVehicleWindowState - vehicleid = %d, door = %d, state = %d", vehicleid, door, wds_WindowsTemp[door]);
  210. return wds_WindowsTemp[door];
  211. }
  212. /*
  213. * Gets a current state of vehicle's door
  214. *
  215. * Parameters:
  216. * vehicleid - vehicle's ID
  217. * door - vehicle's door ID (see Definitions -> Doors)
  218. *
  219. * Returns current state of the window (see Definitions -> Door states)
  220. */
  221. stock GetVehicleDoorState(vehicleid, door)
  222. {
  223. // In case of invalid door number
  224. if(door < 0 || door > 3) return WDS_DOOR_STATE_CLOSED;
  225. new wds_WindowsTemp[WDS_MAX_VEHICLE_DOORS]; // To store current doors states
  226. // Get cuurent state of each door
  227. GetVehicleParamsCarDoors(vehicleid,
  228. wds_WindowsTemp[FL_DOOR], wds_WindowsTemp[FR_DOOR],
  229. wds_WindowsTemp[BL_DOOR], wds_WindowsTemp[BR_DOOR]
  230. );
  231. WDS::Debug("GetVehicleDoorState - vehicleid = %d, door = %d, state = %d", vehicleid, door, wds_WindowsTemp[door]);
  232. return wds_WindowsTemp[door];
  233. }
  234. // ------------ Macros -------------
  235. /* OpenVehicleDoor(vehicleid, door):
  236. * Opens a vehicle's door
  237. *
  238. * Parameters:
  239. * vehicleid - vehicle's ID
  240. * door - vehicle's door ID (see Definitions -> Doors)
  241. *
  242. * Returns 1, if succeeded, otherwise 0.
  243. */
  244. #define OpenVehicleDoor(%1,%2) SetVehicleDoorState(%1, %2, WDS_DOOR_STATE_OPENED)
  245. /* CloseVehicleDoor(vehicleid, door)
  246. * Closes a vehicle's door
  247. *
  248. * Parameters:
  249. * vehicleid - vehicle's ID
  250. * door - vehicle's door ID (see Definitions -> Doors)
  251. *
  252. * Returns 1, if succeeded, otherwise 0.
  253. */
  254. #define CloseVehicleDoor(%1,%2) SetVehicleDoorState(%1, %2, WDS_DOOR_STATE_CLOSED)
  255. /* IsVehicleDoorOpened(vehicleid, door)
  256. * Checks, whether a door is opened or not
  257. *
  258. * Parameters:
  259. * vehicleid - vehicle's ID
  260. * door - vehicle's door ID (see Definitions -> Doors)
  261. *
  262. * Returns true, if opened, otherwise false.
  263. */
  264. #define IsVehicleDoorOpened(%1,%2) GetVehicleDoorState(%1, %2) == WDS_DOOR_STATE_OPENED
  265. /* IsVehicleDoorClosed(vehicleid, door)
  266. * Checks, whether a door is closed or not
  267. *
  268. * Parameters:
  269. * vehicleid - vehicle's ID
  270. * door - vehicle's door ID (see Definitions -> Doors)
  271. *
  272. * Returns true, if closed, otherwise false.
  273. */
  274. #define IsVehicleDoorClosed(%1,%2) GetVehicleDoorState(%1, %2) != WDS_DOOR_STATE_OPENED
  275. /* OpenVehicleWindow(vehicleid, door)
  276. * Opens a vehicle's window
  277. *
  278. * Parameters:
  279. * vehicleid - vehicle's ID
  280. * door - vehicle's door ID (see Definitions -> Doors)
  281. *
  282. * Returns 1, if succeeded, otherwise 0.
  283. */
  284. #define OpenVehicleWindow(%1,%2) SetVehicleWindowState(%1, %2, WDS_WINDOW_STATE_OPENED)
  285. /* OpenVehicleWindow(vehicleid, door)
  286. * Opens a vehicle's window
  287. *
  288. * Parameters:
  289. * vehicleid - vehicle's ID
  290. * door - vehicle's door ID (see Definitions -> Doors)
  291. *
  292. * Returns 1, if succeeded, otherwise 0.
  293. */
  294. #define CloseVehicleWindow(%1,%2) SetVehicleWindowState(%1, %2, WDS_WINDOW_STATE_CLOSED)
  295. /* IsVehicleWindowOpened(vehicleid, door)
  296. * Checks, whether a window is opened or not
  297. *
  298. * Parameters:
  299. * vehicleid - vehicle's ID
  300. * door - vehicle's door ID (see Definitions -> Doors)
  301. *
  302. * Returns true, if opened, otherwise false.
  303. */
  304. #define IsVehicleWindowOpened(%1,%2) GetVehicleWindowState(%1, %2) == WDS_WINDOW_STATE_OPENED
  305. /* IsVehicleWindowClosed(vehicleid, door)
  306. * Checks, whether a window is closed or not
  307. *
  308. * Parameters:
  309. * vehicleid - vehicle's ID
  310. * door - vehicle's door ID (see Definitions -> Doors)
  311. *
  312. * Returns true, if closed, otherwise false.
  313. */
  314. #define IsVehicleWindowClosed(%1,%2) GetVehicleWindowState(%1, %2) != WDS_WINDOW_STATE_OPENED
  315. /* InstallVehicleSiren(vehicleid)
  316. * Intalles a siren on a vehicle
  317. *
  318. * Parameters:
  319. * vehicleid - vehicle's ID
  320. *
  321. * Returns 1, if succeeded, otherwise 0.
  322. */
  323. #define InstallVehicleSiren(%1) SetVehicleSirenState(%1, WDS_SIREN_STATE_OFF)
  324. /* UninstallVehicleSiren(vehicleid)
  325. * Removes a siren from a vehicle
  326. *
  327. * Parameters:
  328. * vehicleid - vehicle's ID
  329. *
  330. * Returns 1, if succeeded, otherwise 0.
  331. */
  332. #define UninstallVehicleSiren(%1) SetVehicleSirenState(%1, WDS_SIREN_STATE_NOT_INSTALLED)
  333. /* GetVehicleSirenState(vehicleid)
  334. * Gets a current state of vehicle's siren
  335. *
  336. * Parameters:
  337. * vehicleid - vehicle's ID
  338. *
  339. * Returns current state of the siren (see Definitions -> Siren states)
  340. */
  341. #define GetVehicleSirenState(%1) GetVehicleParamsSirenState(%1)
  342. /* IsVehicleSirenOn(vehicleid)
  343. * Checks, whether a siren is on or not
  344. *
  345. * Parameters:
  346. * vehicleid - vehicle's ID
  347. *
  348. * Returns true, if turned on, otherwise false.
  349. */
  350. #define IsVehicleSirenOn(%1) GetVehicleSirenState(%1) == WDS_SIREN_STATE_ON
  351. /* IsVehicleSirenOff(vehicleid)
  352. * Checks, whether a siren is off or not
  353. *
  354. * Parameters:
  355. * vehicleid - vehicle's ID
  356. *
  357. * Returns true, if turned off, otherwise false.
  358. */
  359. #define IsVehicleSirenOff(%1) GetVehicleSirenState(%1) != WDS_SIREN_STATE_ON
  360. // -------------- Standart functions replacement -----------
  361. stock WDS_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay, addsiren=0)
  362. {
  363. // Create vehicle
  364. new vehicleid = CreateVehicle(modelid, x,y,z,angle, color1,color2, respawn_delay, addsiren);
  365. WDS_InitVehicleInfo(vehicleid, color1, color2, respawn_delay);
  366. return vehicleid;
  367. }
  368. stock WDS_AddStaticVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay, addsiren=0)
  369. {
  370. // Create vehicle
  371. new vehicleid = AddStaticVehicleEx(modelid, x,y,z,angle, color1,color2, respawn_delay, addsiren);
  372. WDS_InitVehicleInfo(vehicleid, color1, color2, respawn_delay, true);
  373. return vehicleid;
  374. }
  375. stock WDS_AddStaticVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2)
  376. {
  377. // Create vehicle
  378. return WDS_AddStaticVehicleEx(modelid, x,y,z,angle, color1,color2, -1, 0);
  379. }
  380. stock WDS_InitVehicleInfo(vehicleid, color1, color2, respawn_delay, bool:isstatic = false)
  381. {
  382. wdsVehicleInfo[vehicleid][wdsIsStatic] = isstatic;
  383. wdsVehicleInfo[vehicleid][wdsColor1] = color1;
  384. wdsVehicleInfo[vehicleid][wdsColor2] = color2;
  385. wdsVehicleInfo[vehicleid][wdsRespawnDelay] = respawn_delay;
  386. }
  387. #define CreateVehicle WDS_CreateVehicle
  388. #define AddStaticVehicle WDS_AddStaticVehicle
  389. #define AddStaticVehicleEx WDS_AddStaticVehicleEx