Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 24.00 KB | None | 0 0
  1. //------------------------------------------------------------------------------
  2.  
  3. /*
  4.     SA-MP Vending Machine include
  5.  
  6.     Description:
  7.         This include provide code to create server-side vending machines in SA-MP.
  8.  
  9.     License:
  10.         The MIT License (MIT)
  11.         Copyright (c) 2014 Larceny
  12.         Permission is hereby granted, free of charge, to any person obtaining a copy
  13.         of this software and associated documentation files (the "Software"), to deal
  14.         in the Software without restriction, including without limitation the rights
  15.         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16.         copies of the Software, and to permit persons to whom the Software is
  17.         furnished to do so, subject to the following conditions:
  18.         The above copyright notice and this permission notice shall be included in all
  19.         copies or substantial portions of the Software.
  20.         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21.         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22.         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23.         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24.         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25.         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26.         SOFTWARE.
  27.  
  28.     Author:
  29.         Larceny
  30.  
  31.     Contributors:
  32.         Y_Less
  33.         Abagail
  34.         J'Zargo
  35.         Slice
  36.  
  37.     Version:
  38.         2.2(Updated by Abagail)
  39. */
  40.  
  41. //------------------------------------------------------------------------------
  42.  
  43. #if !defined _samp_included
  44.     #tryinclude <a_samp>
  45. #endif
  46.  
  47. #if defined _vendingm_included
  48.     #endinput
  49. #endif
  50. #define _vendingm_included
  51.  
  52. //------------------------------------------------------------------------------
  53.  
  54. #if !defined MAX_MACHINES
  55.     #define MAX_MACHINES            128
  56. #endif
  57.  
  58. #define OBJECT_TYPE_NORMAL          0
  59. #define OBJECT_TYPE_DYNAMIC         1
  60.  
  61. #define MACHINE_SNACK               956
  62. #define MACHINE_SNACK2              1776
  63. #define MACHINE_SPRUNK              955
  64. #define MACHINE_SPRUNK2             1775
  65. #define MACHINE_SODA                1302
  66. #define MACHINE_SODA2               1209
  67. #define MACHINE_BLACK               1977
  68.  
  69. #define SODA_RADIUS                 1.2
  70. #define SPRUNK_RADIUS               1.05
  71. #define SNACK_RADIUS                1.05
  72.  
  73. #define INVALID_MACHINE_ID          -1
  74.  
  75. //------------------------------------------------------------------------------
  76.  
  77. /*Natives
  78. native CreateVendingMachine(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  79. native GetVendingMachineRot(machineid, &Float:rx, &Float:ry, &Float:rz);
  80. native SetVendingMachineRot(machineid, Float:rx, Float:ry, Float:rz);
  81. native GetVendingMachinePos(machineid, &Float:x, &Float:y, &Float:z);
  82. native SetVendingMachinePos(machineid, Float:x, Float:y, Float:z);
  83. native SetVendingMachineColor(machineid, color);
  84. native OnPlayerUseVendinMachine(playerid, machineid);
  85. native GetVendingMachineColor(machineid);
  86. native DestroyVendingMachine(machineid);
  87. native GetVendingMachineType(machineid);
  88. native IsValidVendingMachine(machineid);*/
  89.  
  90. //------------------------------------------------------------------------------
  91.  
  92. // Temporary:
  93.  
  94. #define CreateMachine       CreateVendingMachine
  95. #define DestroyMachine      DestroyVendingMachine
  96.  
  97. #define GetMachineRot       GetVendingMachineRot
  98. #define SetMachineRot       SetVendingMachineRot
  99.  
  100. #define GetMachinePos       GetVendingMachinePos
  101. #define SetMachinePos       SetVendingMachinePos
  102.  
  103. #define GetMachineType      GetVendingMachineType
  104. #define IsValidMachine      IsValidVendingMachine
  105.  
  106. //------------------------------------------------------------------------------
  107.  
  108. // Thanks to Slice:
  109.  
  110. enum E_VENDING_MACHINE
  111. {
  112.     e_Model,
  113.     e_Interior,
  114.     Float:e_PosX,
  115.     Float:e_PosY,
  116.     Float:e_PosZ,
  117.     Float:e_RotX,
  118.     Float:e_RotY,
  119.     Float:e_RotZ,
  120.     Float:e_FrontX,
  121.     Float:e_FrontY
  122. }
  123.  
  124. stock const Float:sc_VendingMachines[][E_VENDING_MACHINE] =
  125. {
  126.     {955, 0, -862.82, 1536.60, 21.98, 0.00, 0.00, 180.00, -862.84, 1537.60},
  127.     {956, 0, 2271.72, -76.46, 25.96, 0.00, 0.00, 0.00, 2271.72, -77.46},
  128.     {955, 0, 1277.83, 372.51, 18.95, 0.00, 0.00, 64.00, 1278.73, 372.07},
  129.     {956, 0, 662.42, -552.16, 15.71, 0.00, 0.00, 180.00, 662.41, -551.16},
  130.     {955, 0, 201.01, -107.61, 0.89, 0.00, 0.00, 270.00, 200.01, -107.63},
  131.     {955, 0, -253.74, 2597.95, 62.24, 0.00, 0.00, 90.00, -252.74, 2597.95},
  132.     {956, 0, -253.74, 2599.75, 62.24, 0.00, 0.00, 90.00, -252.74, 2599.75},
  133.     {956, 0, -76.03, 1227.99, 19.12, 0.00, 0.00, 90.00, -75.03, 1227.99},
  134.     {955, 0, -14.70, 1175.35, 18.95, 0.00, 0.00, 180.00, -14.72, 1176.35},
  135.     {1977, 7, 316.87, -140.35, 998.58, 0.00, 0.00, 270.00, 315.87, -140.36},
  136.     {1775, 17, 373.82, -178.14, 1000.73, 0.00, 0.00, 0.00, 373.82, -179.14},
  137.     {1776, 17, 379.03, -178.88, 1000.73, 0.00, 0.00, 270.00, 378.03, -178.90},
  138.     {1775, 17, 495.96, -24.32, 1000.73, 0.00, 0.00, 180.00, 495.95, -23.32},
  139.     {1776, 17, 500.56, -1.36, 1000.73, 0.00, 0.00, 0.00, 500.56, -2.36},
  140.     {1775, 17, 501.82, -1.42, 1000.73, 0.00, 0.00, 0.00, 501.82, -2.42},
  141.     {956, 0, -1455.11, 2591.66, 55.23, 0.00, 0.00, 180.00, -1455.13, 2592.66},
  142.     {955, 0, 2352.17, -1357.15, 23.77, 0.00, 0.00, 90.00, 2353.17, -1357.15},
  143.     {955, 0, 2325.97, -1645.13, 14.21, 0.00, 0.00, 0.00, 2325.97, -1646.13},
  144.     {956, 0, 2139.51, -1161.48, 23.35, 0.00, 0.00, 87.00, 2140.51, -1161.53},
  145.     {956, 0, 2153.23, -1016.14, 62.23, 0.00, 0.00, 127.00, 2154.03, -1015.54},
  146.     {955, 0, 1928.73, -1772.44, 12.94, 0.00, 0.00, 90.00, 1929.73, -1772.44},
  147.     {1776, 1, 2222.36, 1602.64, 1000.06, 0.00, 0.00, 90.00, 2223.36, 1602.64},
  148.     {1775, 1, 2222.20, 1606.77, 1000.05, 0.00, 0.00, 90.00, 2223.20, 1606.77},
  149.     {1775, 1, 2155.90, 1606.77, 1000.05, 0.00, 0.00, 90.00, 2156.90, 1606.77},
  150.     {1775, 1, 2209.90, 1607.19, 1000.05, 0.00, 0.00, 270.00, 2208.90, 1607.17},
  151.     {1776, 1, 2155.84, 1607.87, 1000.06, 0.00, 0.00, 90.00, 2156.84, 1607.87},
  152.     {1776, 1, 2202.45, 1617.00, 1000.06, 0.00, 0.00, 180.00, 2202.43, 1618.00},
  153.     {1776, 1, 2209.24, 1621.21, 1000.06, 0.00, 0.00, 0.00, 2209.24, 1620.21},
  154.     {1776, 3, 330.67, 178.50, 1020.07, 0.00, 0.00, 0.00, 330.67, 177.50},
  155.     {1776, 3, 331.92, 178.50, 1020.07, 0.00, 0.00, 0.00, 331.92, 177.50},
  156.     {1776, 3, 350.90, 206.08, 1008.47, 0.00, 0.00, 90.00, 351.90, 206.08},
  157.     {1776, 3, 361.56, 158.61, 1008.47, 0.00, 0.00, 180.00, 361.54, 159.61},
  158.     {1776, 3, 371.59, 178.45, 1020.07, 0.00, 0.00, 0.00, 371.59, 177.45},
  159.     {1776, 3, 374.89, 188.97, 1008.47, 0.00, 0.00, 0.00, 374.89, 187.97},
  160.     {1775, 2, 2576.70, -1284.43, 1061.09, 0.00, 0.00, 270.00, 2575.70, -1284.44},
  161.     {1775, 15, 2225.20, -1153.42, 1025.90, 0.00, 0.00, 270.00, 2224.20, -1153.43},
  162.     {955, 0, 1154.72, -1460.89, 15.15, 0.00, 0.00, 270.00, 1153.72, -1460.90},
  163.     {956, 0, 2480.85, -1959.27, 12.96, 0.00, 0.00, 180.00, 2480.84, -1958.27},
  164.     {955, 0, 2060.11, -1897.64, 12.92, 0.00, 0.00, 0.00, 2060.11, -1898.64},
  165.     {955, 0, 1729.78, -1943.04, 12.94, 0.00, 0.00, 0.00, 1729.78, -1944.04},
  166.     {956, 0, 1634.10, -2237.53, 12.89, 0.00, 0.00, 0.00, 1634.10, -2238.53},
  167.     {955, 0, 1789.21, -1369.26, 15.16, 0.00, 0.00, 270.00, 1788.21, -1369.28},
  168.     {956, 0, -2229.18, 286.41, 34.70, 0.00, 0.00, 180.00, -2229.20, 287.41},
  169.     {955, 256, -1980.78, 142.66, 27.07, 0.00, 0.00, 270.00, -1981.78, 142.64},
  170.     {955, 256, -2118.96, -423.64, 34.72, 0.00, 0.00, 255.00, -2119.93, -423.40},
  171.     {955, 256, -2118.61, -422.41, 34.72, 0.00, 0.00, 255.00, -2119.58, -422.17},
  172.     {955, 256, -2097.27, -398.33, 34.72, 0.00, 0.00, 180.00, -2097.29, -397.33},
  173.     {955, 256, -2092.08, -490.05, 34.72, 0.00, 0.00, 0.00, -2092.08, -491.05},
  174.     {955, 256, -2063.27, -490.05, 34.72, 0.00, 0.00, 0.00, -2063.27, -491.05},
  175.     {955, 256, -2005.64, -490.05, 34.72, 0.00, 0.00, 0.00, -2005.64, -491.05},
  176.     {955, 256, -2034.46, -490.05, 34.72, 0.00, 0.00, 0.00, -2034.46, -491.05},
  177.     {955, 256, -2068.56, -398.33, 34.72, 0.00, 0.00, 180.00, -2068.58, -397.33},
  178.     {955, 256, -2039.85, -398.33, 34.72, 0.00, 0.00, 180.00, -2039.86, -397.33},
  179.     {955, 256, -2011.14, -398.33, 34.72, 0.00, 0.00, 180.00, -2011.15, -397.33},
  180.     {955, 2048, -1350.11, 492.28, 10.58, 0.00, 0.00, 90.00, -1349.11, 492.28},
  181.     {956, 2048, -1350.11, 493.85, 10.58, 0.00, 0.00, 90.00, -1349.11, 493.85},
  182.     {955, 0, 2319.99, 2532.85, 10.21, 0.00, 0.00, 0.00, 2319.99, 2531.85},
  183.     {956, 0, 2845.72, 1295.04, 10.78, 0.00, 0.00, 0.00, 2845.72, 1294.04},
  184.     {955, 0, 2503.14, 1243.69, 10.21, 0.00, 0.00, 180.00, 2503.12, 1244.69},
  185.     {956, 0, 2647.69, 1129.66, 10.21, 0.00, 0.00, 0.00, 2647.69, 1128.66},
  186.     {1209, 0, -2420.21, 984.57, 44.29, 0.00, 0.00, 90.00, -2419.21, 984.57},
  187.     {1302, 0, -2420.17, 985.94, 44.29, 0.00, 0.00, 90.00, -2419.17, 985.94},
  188.     {955, 0, 2085.77, 2071.35, 10.45, 0.00, 0.00, 90.00, 2086.77, 2071.35},
  189.     {956, 0, 1398.84, 2222.60, 10.42, 0.00, 0.00, 180.00, 1398.82, 2223.60},
  190.     {956, 0, 1659.46, 1722.85, 10.21, 0.00, 0.00, 0.00, 1659.46, 1721.85},
  191.     {955, 0, 1520.14, 1055.26, 10.00, 0.00, 0.00, 270.00, 1519.14, 1055.24},
  192.     {1775, 6, -19.03, -57.83, 1003.63, 0.00, 0.00, 180.00, -19.05, -56.83},
  193.     {1775, 18, -16.11, -91.64, 1003.63, 0.00, 0.00, 180.00, -16.13, -90.64},
  194.     {1775, 16, -15.10, -140.22, 1003.63, 0.00, 0.00, 180.00, -15.11, -139.22},
  195.     {1775, 17, -32.44, -186.69, 1003.63, 0.00, 0.00, 180.00, -32.46, -185.69},
  196.     {1775, 16, -35.72, -140.22, 1003.63, 0.00, 0.00, 180.00, -35.74, -139.22},
  197.     {1776, 6, -36.14, -57.87, 1003.63, 0.00, 0.00, 180.00, -36.16, -56.87},
  198.     {1776, 18, -17.54, -91.71, 1003.63, 0.00, 0.00, 180.00, -17.56, -90.71},
  199.     {1776, 16, -16.53, -140.29, 1003.63, 0.00, 0.00, 180.00, -16.54, -139.29},
  200.     {1776, 17, -33.87, -186.76, 1003.63, 0.00, 0.00, 180.00, -33.89, -185.76},
  201.     {1775, 6, -19.03, -57.83, 1003.63, 0.00, 0.00, 180.00, -19.05, -56.83},
  202.     {1776, 6, -36.14, -57.87, 1003.63, 0.00, 0.00, 180.00, -36.16, -56.87},
  203.     {1775, 18, -16.11, -91.64, 1003.63, 0.00, 0.00, 180.00, -16.13, -90.64},
  204.     {1776, 18, -17.54, -91.71, 1003.63, 0.00, 0.00, 180.00, -17.56, -90.71},
  205.     {1776, 16, -16.53, -140.29, 1003.63, 0.00, 0.00, 180.00, -16.54, -139.29},
  206.     {1775, 16, -15.10, -140.22, 1003.63, 0.00, 0.00, 180.00, -15.11, -139.22},
  207.     {1776, 17, -33.87, -186.76, 1003.63, 0.00, 0.00, 180.00, -33.89, -185.76},
  208.     {1775, 17, -32.44, -186.69, 1003.63, 0.00, 0.00, 180.00, -32.46, -185.69},
  209.     {1775, 16, -35.72, -140.22, 1003.63, 0.00, 0.00, 180.00, -35.74, -139.22}
  210. };
  211.  
  212. //------------------------------------------------------------------------------
  213.  
  214. enum E_VENDING_DATA
  215. {
  216.     Float:E_VENDING_X,
  217.     Float:E_VENDING_Y,
  218.     Float:E_VENDING_Z,
  219.     Float:E_VENDING_RX,
  220.     Float:E_VENDING_RY,
  221.     Float:E_VENDING_RZ,
  222.     Float:E_VENDING_RADIUS,
  223.     E_VENDING_COLOR,
  224.     E_VENDING_TYPE,
  225.     E_VENDING_ID,
  226.     STREAMER_TAG_AREA E_VENDING_AREA
  227. }
  228. static g_eVendingData[MAX_MACHINES][E_VENDING_DATA];
  229.  
  230. //------------------------------------------------------------------------------
  231. static g_eLastDrink[MAX_PLAYERS] = 0;
  232. //------------------------------------------------------------------------------
  233.  
  234. forward OnPlayerUseVendingMachine(playerid, machineid);
  235. #if !defined NO_SPRUNK_ACTION
  236. forward OnPlayerDrinkSprunk(playerid);
  237. forward ven_SetPlayerAnimation(playerid);
  238. #endif
  239.  
  240. //------------------------------------------------------------------------------
  241.  
  242. stock CreateVendingMachine(modelid, Float:x, Float:y, Float:z, Float:vx, Float:vy, Float:vz)
  243. {
  244.     new machineid = GetFreeMachineID();
  245.  
  246.     if(machineid == INVALID_MACHINE_ID)
  247.     {
  248.         print("ERROR: Limit of vending machines exceeded! Increase the limit or reduce the created machines.");
  249.         return 0;
  250.     }
  251.  
  252.     switch(modelid)
  253.     {
  254.         case MACHINE_SPRUNK2:
  255.             g_eVendingData[machineid][E_VENDING_RADIUS] = SPRUNK_RADIUS;
  256.         case MACHINE_SPRUNK:
  257.             g_eVendingData[machineid][E_VENDING_RADIUS] = SPRUNK_RADIUS;
  258.         case MACHINE_SNACK:
  259.             g_eVendingData[machineid][E_VENDING_RADIUS] = SNACK_RADIUS;
  260.         case MACHINE_SNACK2:
  261.             g_eVendingData[machineid][E_VENDING_RADIUS] = SNACK_RADIUS;
  262.         case MACHINE_SODA:
  263.             g_eVendingData[machineid][E_VENDING_RADIUS] = SODA_RADIUS;
  264.         case MACHINE_SODA2:
  265.             g_eVendingData[machineid][E_VENDING_RADIUS] = SODA_RADIUS;
  266.         case MACHINE_BLACK:
  267.             g_eVendingData[machineid][E_VENDING_RADIUS] = SPRUNK_RADIUS;
  268.         default:
  269.         {
  270.             printf("ERROR: Invalid vending object id! (Used ID: %i - Valid IDs: 955, 956 or 1302)", modelid);
  271.             return 0;
  272.         }
  273.     }
  274.  
  275.     #if defined Streamer_IncludeFileVersion
  276.         g_eVendingData[machineid][E_VENDING_ID] = CreateDynamicObject(modelid, x, y, z, vx, vy, vz);
  277.         g_eVendingData[machineid][E_VENDING_AREA] = STREAMER_TAG_AREA CreateDynamicRectangle(x, y, x+g_eVendingData[machineid][E_VENDING_RADIUS], y+g_eVendingData[machineid][E_VENDING_RADIUS]);
  278.     #else
  279.         g_eVendingData[machineid][E_VENDING_ID] = CreateObject(modelid, x, y, z, vx, vy, vz, 300.0);
  280.     #endif
  281.  
  282.     g_eVendingData[machineid][E_VENDING_X]  = x;
  283.     g_eVendingData[machineid][E_VENDING_Y]  = y;
  284.     g_eVendingData[machineid][E_VENDING_Z]  = z;
  285.  
  286.     g_eVendingData[machineid][E_VENDING_RX] = vx;
  287.     g_eVendingData[machineid][E_VENDING_RY] = vy;
  288.     g_eVendingData[machineid][E_VENDING_RZ] = vz;
  289.  
  290.     g_eVendingData[machineid][E_VENDING_TYPE] = modelid;
  291.     return machineid;
  292. }
  293.  
  294. //------------------------------------------------------------------------------
  295.  
  296. stock DestroyVendingMachine(machineid)
  297. {
  298.     if(!IsValidVendingMachine(machineid))
  299.         return 0;
  300.  
  301.     #if defined Streamer_IncludeFileVersion
  302.     DestroyDynamicObject(g_eVendingData[machineid][E_VENDING_ID]);
  303.     #else
  304.     DestroyObject(g_eVendingData[machineid][E_VENDING_ID]);
  305.     #endif
  306.  
  307.     g_eVendingData[machineid][E_VENDING_ID] = INVALID_MACHINE_ID;
  308.  
  309.     g_eVendingData[machineid][E_VENDING_X] = 0.0;
  310.     g_eVendingData[machineid][E_VENDING_Y] = 0.0;
  311.     g_eVendingData[machineid][E_VENDING_Z] = 0.0;
  312.  
  313.     g_eVendingData[machineid][E_VENDING_RX] = 0.0;
  314.     g_eVendingData[machineid][E_VENDING_RY] = 0.0;
  315.     g_eVendingData[machineid][E_VENDING_RZ] = 0.0;
  316.  
  317.     g_eVendingData[machineid][E_VENDING_TYPE] = 0;
  318.     g_eVendingData[machineid][E_VENDING_AREA] = -1;
  319.     return 1;
  320. }
  321.  
  322. //------------------------------------------------------------------------------
  323.  
  324. stock SetVendingMachineColor(machineid, color)
  325. {
  326.     if(!IsValidVendingMachine(machineid) || GetVendingMachineType(machineid) == MACHINE_SNACK)
  327.         return 0;
  328.  
  329.     if(GetVendingMachineType(machineid) == MACHINE_SODA)
  330.     {
  331.         #if defined Streamer_IncludeFileVersion
  332.         SetDynamicObjectMaterial(g_eVendingData[machineid][E_VENDING_ID], 0, -1, "none", "none", color);
  333.         SetDynamicObjectMaterial(g_eVendingData[machineid][E_VENDING_ID], 1, -1, "none", "none", color);
  334.         #else
  335.         SetObjectMaterial(g_eVendingData[machineid][E_VENDING_ID], 0, -1, "none", "none", color);
  336.         SetObjectMaterial(g_eVendingData[machineid][E_VENDING_ID], 1, -1, "none", "none", color);
  337.         #endif
  338.     }
  339.     else
  340.     {
  341.         #if defined Streamer_IncludeFileVersion
  342.         SetDynamicObjectMaterial(g_eVendingData[machineid][E_VENDING_ID], 0, -1, "none", "none", color);
  343.         #else
  344.         SetObjectMaterial(g_eVendingData[machineid][E_VENDING_ID], 0, -1, "none", "none", color);
  345.         #endif
  346.     }
  347.  
  348.     g_eVendingData[machineid][E_VENDING_COLOR] = color;
  349.     return 1;
  350. }
  351.  
  352. //------------------------------------------------------------------------------
  353.  
  354. stock GetVendingMachineColor(machineid)
  355.     return g_eVendingData[machineid][E_VENDING_COLOR];
  356.  
  357. //------------------------------------------------------------------------------
  358.  
  359. stock GetVendingMachineObjectType()
  360. {
  361.     #if defined Streamer_IncludeFileVersion
  362.     return OBJECT_TYPE_DYNAMIC;
  363.     #else
  364.     return OBJECT_TYPE_NORMAL;
  365.     #endif
  366. }
  367.  
  368. //------------------------------------------------------------------------------
  369. stock IsValidVendingMachine(machineid)
  370.     return !(g_eVendingData[machineid][E_VENDING_X] == 0.0 && g_eVendingData[machineid][E_VENDING_Y] == 0.0);
  371.  
  372. //------------------------------------------------------------------------------
  373.  
  374. stock GetVendingMachineType(machineid)
  375.     return g_eVendingData[machineid][E_VENDING_TYPE];
  376.  
  377. //------------------------------------------------------------------------------
  378.  
  379. stock GetFreeMachineID()
  380. {
  381.     for(new i; i < MAX_MACHINES; i++)
  382.         if(g_eVendingData[i][E_VENDING_X] == 0.0 && g_eVendingData[i][E_VENDING_Y] == 0.0)
  383.             return i;
  384.  
  385.     return INVALID_MACHINE_ID;
  386. }
  387.  
  388. //------------------------------------------------------------------------------
  389.  
  390. stock SetVendingMachinePos(machineid, Float:x, Float:y, Float:z)
  391. {
  392.     if(!IsValidVendingMachine(machineid))
  393.         return 0;
  394.  
  395.     g_eVendingData[machineid][E_VENDING_X] = x;
  396.     g_eVendingData[machineid][E_VENDING_Y] = y;
  397.     g_eVendingData[machineid][E_VENDING_Z] = z;
  398.  
  399.     #if defined Streamer_IncludeFileVersion
  400.     SetDynamicObjectPos(g_eVendingData[machineid][E_VENDING_ID], x, y, z);
  401.     #else
  402.     SetObjectPos(g_eVendingData[machineid][E_VENDING_ID], x, y, z);
  403.     #endif
  404.     return 1;
  405. }
  406.  
  407. //------------------------------------------------------------------------------
  408.  
  409. stock SetVendingMachineRot(machineid, Float:vx, Float:vy, Float:vz)
  410. {
  411.     if(!IsValidVendingMachine(machineid))
  412.         return 0;
  413.  
  414.     g_eVendingData[machineid][E_VENDING_RX] = vx;
  415.     g_eVendingData[machineid][E_VENDING_RY] = vy;
  416.     g_eVendingData[machineid][E_VENDING_RZ] = vz;
  417.  
  418.  
  419.     #if defined Streamer_IncludeFileVersion
  420.     SetDynamicObjectRot(g_eVendingData[machineid][E_VENDING_ID], vx, vy, vz);
  421.     #else
  422.     SetObjectRot(g_eVendingData[machineid][E_VENDING_ID], vx, vy, vz);
  423.     #endif
  424.     return 1;
  425. }
  426.  
  427. //------------------------------------------------------------------------------
  428.  
  429. stock GetVendingMachinePos(machineid, &Float:x, &Float:y, &Float:z)
  430. {
  431.     if(!IsValidVendingMachine(machineid))
  432.         return 0;
  433.  
  434.     x = g_eVendingData[machineid][E_VENDING_X];
  435.     y = g_eVendingData[machineid][E_VENDING_Y];
  436.     z = g_eVendingData[machineid][E_VENDING_Z];
  437.     return 1;
  438. }
  439.  
  440. //------------------------------------------------------------------------------
  441.  
  442. stock GetVendingMachineRot(machineid, &Float:vx, &Float:vy, &Float:vz)
  443. {
  444.     if(!IsValidVendingMachine(machineid))
  445.         return 0;
  446.  
  447.     vx = g_eVendingData[machineid][E_VENDING_RX];
  448.     vy = g_eVendingData[machineid][E_VENDING_RY];
  449.     vz = g_eVendingData[machineid][E_VENDING_RZ];
  450.     return 1;
  451. }
  452.  
  453. //------------------------------------------------------------------------------
  454.  
  455. stock GetVendingMachineObjectID(machineid)
  456.     return g_eVendingData[machineid][E_VENDING_ID];
  457.  
  458. //------------------------------------------------------------------------------
  459.  
  460. #if !defined Streamer_IncludeFileVersion
  461. GetXYInFrontOfVending(machineid, &Float:x, &Float:y, Float:distance)
  462. {
  463.     new Float:a, Float:z;
  464.     GetVendingMachineRot(machineid, x, y, a);
  465.     GetVendingMachinePos(machineid, x, y, z);
  466.  
  467.     a += 180.0;
  468.     if(a > 359.0) a -= 359.0;
  469.  
  470.     x += (distance * floatsin(-a, degrees));
  471.     y += (distance * floatcos(-a, degrees));
  472. }
  473.  
  474. //------------------------------------------------------------------------------
  475. #else
  476. stock STREAMER_TAG_AREA GetVendingMachineDynamicArea(machineid)
  477. {
  478.     if(!IsValidVendingMachine(machineid))
  479.     {
  480.         return INVALID_MACHINE_ID;
  481.     }
  482.    
  483.     else return g_eVendingData[machineid][E_VENDING_AREA];
  484. }
  485. //------------------------------------------------------------------------------
  486. #endif
  487.  
  488. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  489. {
  490.     if((newkeys & KEY_SECONDARY_ATTACK) && (GetPlayerAnimationIndex(playerid) != 1660))
  491.     {
  492.         for(new i; i < MAX_MACHINES; i++)
  493.         {
  494.             if(!IsValidVendingMachine(i))
  495.                 continue;
  496.  
  497.             #if defined Streamer_IncludeFileVersion
  498.             if(!IsPlayerInDynamicArea(playerid, g_eVendingData[i][E_VENDING_AREA]))
  499.                 continue;
  500.             #else
  501.             new Float:x, Float:y;
  502.             GetXYInFrontOfVending(i, x, y, 0.5);
  503.             if(!IsPlayerInRangeOfPoint(playerid, g_eVendingData[i][E_VENDING_RADIUS], x, y, g_eVendingData[i][E_VENDING_Z]))
  504.                 continue;
  505.             #endif
  506.  
  507.             SetPlayerFacingAngle(playerid, g_eVendingData[i][E_VENDING_RZ]);
  508.             if(OnPlayerUseVendingMachine(playerid, i) != 0)
  509.             {
  510.                 ApplyAnimation(playerid, "VENDING", "VEND_USE", 10.0, 0, 0, 0, 0, 0, 1);
  511.                 if(g_eVendingData[i][E_VENDING_TYPE] == MACHINE_SNACK) PlayerPlaySound(playerid, 42601, 0.0, 0.0, 0.0);
  512.                 else PlayerPlaySound(playerid, 42600, 0.0, 0.0, 0.0);
  513.  
  514.                 #if !defined NO_SPRUNK_ACTION
  515.                 if(g_eVendingData[i][E_VENDING_TYPE] == MACHINE_SPRUNK) SetTimerEx("ven_SetPlayerAnimation", 2500, false, "i", playerid);
  516.                 #endif
  517.             }
  518.             else ClearAnimations(playerid);
  519.         }
  520.     }
  521.     #if !defined NO_SPRUNK_ACTION
  522.     else if((newkeys & KEY_FIRE) && g_eLastDrink[playerid] < GetTickCount() && (GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DRINK_SPRUNK))
  523.     {
  524.         OnPlayerDrinkSprunk(playerid);
  525.         g_eLastDrink[playerid] = GetTickCount() + 2350;
  526.     }
  527.     #endif
  528.     #if defined inc_Ven_OnPlayerKeyStateChange
  529.         return inc_Ven_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  530.     #else
  531.         return 0;
  532.     #endif
  533. }
  534. #if defined _ALS_OnPlayerKeyStateChange
  535.     #undef OnPlayerKeyStateChange
  536. #else
  537.     #define _ALS_OnPlayerKeyStateChange
  538. #endif
  539.  
  540. #define OnPlayerKeyStateChange inc_Ven_OnPlayerKeyStateChange
  541. #if defined inc_Ven_OnPlayerKeyStateChange
  542.     forward inc_Ven_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  543. #endif
  544.  
  545. //------------------------------------------------------------------------------
  546.  
  547. #if !defined NO_SPRUNK_ACTION
  548. public ven_SetPlayerAnimation(playerid)
  549. {
  550.     SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_SPRUNK);
  551.     return 1;
  552. }
  553. #endif
  554.  
  555. //------------------------------------------------------------------------------
  556.  
  557. public OnPlayerConnect(playerid)
  558. {
  559.     for(new i; i < sizeof(sc_VendingMachines); i++)
  560.     {
  561.         RemoveBuildingForPlayer(playerid, sc_VendingMachines[i][e_Model], sc_VendingMachines[i][e_PosX], sc_VendingMachines[i][e_PosY], sc_VendingMachines[i][e_PosZ], 0.25);
  562.     }
  563.     #if defined inc_Ven_OnPlayerConnect
  564.         return inc_Ven_OnPlayerConnect(playerid);
  565.     #else
  566.         return 0;
  567.     #endif
  568. }
  569. #if defined _ALS_OnPlayerConnect
  570.     #undef OnPlayerConnect
  571. #else
  572.     #define _ALS_OnPlayerConnect
  573. #endif
  574.  
  575. #define OnPlayerConnect inc_Ven_OnPlayerConnect
  576. #if defined inc_Ven_OnPlayerConnect
  577.     forward inc_Ven_OnPlayerConnect(playerid);
  578. #endif
  579.  
  580. //------------------------------------------------------------------------------
  581.  
  582. public OnPlayerDisconnect(playerid, reason)
  583. {
  584.     g_eLastDrink[playerid] = 0;
  585.     #if defined inc_Ven_OnPlayerDisconnect
  586.         return inc_Ven_OnPlayerDisconnect(playerid, reason);
  587.     #else
  588.         return 0;
  589.     #endif
  590. }
  591. #if defined _ALS_OnPlayerDisconnect
  592.     #undef OnPlayerDisconnect
  593. #else
  594.     #define _ALS_OnPlayerDisconnect
  595. #endif
  596.  
  597. #define OnPlayerDisconnect inc_Ven_OnPlayerDisconnect
  598. #if defined inc_Ven_OnPlayerDisconnect
  599.     forward inc_Ven_OnPlayerDisconnect(playerid, reason);
  600. #endif
  601.  
  602. //------------------------------------------------------------------------------
  603.  
  604. #if defined FILTERSCRIPT
  605.     public OnFilterScriptInit()
  606.     {
  607.         for(new i; i < sizeof(sc_VendingMachines); i++)
  608.         {
  609.             CreateVendingMachine(sc_VendingMachines[i][e_Model], sc_VendingMachines[i][e_PosX], sc_VendingMachines[i][e_PosY], sc_VendingMachines[i][e_PosZ], sc_VendingMachines[i][e_RotX], sc_VendingMachines[i][e_RotY], sc_VendingMachines[i][e_RotZ]);
  610.         }
  611.  
  612.         #if defined inc_Ven_OnFilterScriptInit
  613.             return inc_Ven_OnFilterScriptInit();
  614.         #else
  615.             return 0;
  616.         #endif
  617.     }
  618.     #if defined _ALS_OnFilterScriptInit
  619.         #undef OnFilterScriptInit
  620.     #else
  621.         #define _ALS_OnFilterScriptInit
  622.     #endif
  623.  
  624.     #define OnFilterScriptInit inc_Ven_OnFilterScriptInit
  625.     #if defined inc_Ven_OnFilterScriptInit
  626.         forward inc_Ven_OnFilterScriptInit();
  627.     #endif
  628.  
  629.     public OnFilterScriptExit()
  630.     {
  631.         for(new i; i < sizeof(sc_VendingMachines); i++)
  632.         {
  633.             DestroyVendingMachine(i);
  634.         }
  635.  
  636.         #if defined inc_Ven_OnFilterScriptExit
  637.             return inc_Ven_OnFilterScriptExit();
  638.         #else
  639.             return 0;
  640.         #endif
  641.     }
  642.     #if defined _ALS_OnFilterScriptExit
  643.         #undef OnFilterScriptExit
  644.     #else
  645.         #define _ALS_OnFilterScriptExit
  646.     #endif
  647.  
  648.     #define OnFilterScriptExit inc_Ven_OnFilterScriptExit
  649.     #if defined inc_Ven_OnFilterScriptExit
  650.         forward inc_Ven_OnFilterScriptExit();
  651.     #endif
  652. #else
  653.     public OnGameModeInit()
  654.     {
  655.         for(new i; i < sizeof(sc_VendingMachines); i++)
  656.         {
  657.             CreateVendingMachine(sc_VendingMachines[i][e_Model], sc_VendingMachines[i][e_PosX], sc_VendingMachines[i][e_PosY], sc_VendingMachines[i][e_PosZ], sc_VendingMachines[i][e_RotX], sc_VendingMachines[i][e_RotY], sc_VendingMachines[i][e_RotZ]);
  658.         }
  659.  
  660.         #if defined inc_Ven_OnGameModeInit
  661.             return inc_Ven_OnGameModeInit();
  662.         #else
  663.             return 0;
  664.         #endif
  665.     }
  666.     #if defined _ALS_OnGameModeInit
  667.         #undef OnGameModeInit
  668.     #else
  669.         #define _ALS_OnGameModeInit
  670.     #endif
  671.  
  672.     #define OnGameModeInit inc_Ven_OnGameModeInit
  673.     #if defined inc_Ven_OnGameModeInit
  674.         forward inc_Ven_OnGameModeInit();
  675.     #endif
  676. #endif
  677.  
  678. //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement