Advertisement
valych

windosi.com

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