payphones.pwn 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Pay Phones System
  11. by Jingles
  12. Next Generation Gaming, LLC
  13. (created by Next Generation Gaming Development Team)
  14. * Copyright (c) 2016, Next Generation Gaming, LLC
  15. *
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms, with or without modification,
  19. * are not permitted in any case.
  20. *
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <YSI\y_hooks>
  35. hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  36. if(newkeys & KEY_YES) {
  37. new areaid[1];
  38. GetPlayerDynamicAreas(playerid, areaid); //Assign nearest areaid
  39. // new a = Streamer_GetIntData(STREAMER_TYPE_AREA, areaid[1], E_STREAMER_EXTRA_ID);
  40. if(areaid[0] != INVALID_STREAMER_ID) {
  41. for(new a; a < MAX_PAYPHONES; ++a) {
  42. if(areaid[0] == arrPayPhoneData[a][pp_iAreaID]) {
  43. if(IsPlayerInAnyVehicle(playerid)) return 1;
  44. SetPVarInt(playerid, "AtPayPhone", a);
  45. break;
  46. }
  47. }
  48. }
  49. if(GetPVarType(playerid, "AtPayPhone")) {
  50. if(GetPVarType(playerid, "PayPhone")) return SendClientMessageEx(playerid, COLOR_GRAD1, "You are already communicating with a pay phone.");
  51. new i = GetPVarInt(playerid, "AtPayPhone");
  52. if(arrPayPhoneData[i][pp_iCallerID] != INVALID_PLAYER_ID) {
  53. SetPVarInt(playerid, "PayPhone", i);
  54. cmd_pickup(playerid, "");
  55. return 1;
  56. }
  57. PayPhone_Menu(playerid, i);
  58. DeletePVar(playerid, "AtPayPhone");
  59. }
  60. }
  61. return 1;
  62. }
  63. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  64. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  65. switch(dialogid) {
  66. case DIALOG_PAYPHONE: {
  67. if(!response || isnull(inputtext)) return DeletePVar(playerid, "PayPhone"), 1;
  68. if(strval(inputtext) == PlayerInfo[playerid][pPnumber]) return DeletePVar(playerid, "PayPhone"), SendClientMessageEx(playerid, COLOR_GRAD1, "You shouldn't call yourself, dumbo.");
  69. if(strval(inputtext) == 0) return DeletePVar(playerid, "PayPhone"), SendClientMessageEx(playerid, COLOR_GRAD1, "You shouldn't call 0, weirdo.");
  70. cmd_call(playerid, inputtext);
  71. return 1;
  72. }
  73. case DIALOG_PAYPHONE_ADMIN: {
  74. if(!response) return 1;
  75. new Float:fPos[3],
  76. i = ListItemTrackId[playerid][listitem];
  77. GetDynamicObjectPos(arrPayPhoneData[i][pp_iObjectID], fPos[0], fPos[1], fPos[2]);
  78. Player_StreamPrep(playerid, fPos[0], fPos[1], fPos[2], FREEZE_TIME);
  79. SetPlayerVirtualWorld(playerid, Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrPayPhoneData[i][pp_iObjectID], E_STREAMER_WORLD_ID));
  80. SetPlayerInterior(playerid, Streamer_GetIntData(STREAMER_TYPE_OBJECT, arrPayPhoneData[i][pp_iObjectID], E_STREAMER_INTERIOR_ID));
  81. return 1;
  82. }
  83. }
  84. return 0;
  85. }
  86. GetPhoneZone(id, zone[], len) {
  87. new Float:x, Float:y, Float:z;
  88. GetDynamicObjectPos(arrPayPhoneData[id][pp_iObjectID], x, y, z);
  89. for(new i = 0; i != sizeof(gMainZones); i++) {
  90. if(x >= gMainZones[i][SAZONE_AREA][0]
  91. && x <= gMainZones[i][SAZONE_AREA][3]
  92. && y >= gMainZones[i][SAZONE_AREA][1]
  93. && y <= gMainZones[i][SAZONE_AREA][4]
  94. && z >= gMainZones[i][SAZONE_AREA][2]
  95. && z <= gMainZones[i][SAZONE_AREA][5]) {
  96. format(zone, len, gMainZones[i][SAZONE_NAME], 0);
  97. }
  98. }
  99. for(new i = 0; i != sizeof(gSAZones); i++) {
  100. if(x >= gSAZones[i][SAZONE_AREA][0]
  101. && x <= gSAZones[i][SAZONE_AREA][3]
  102. && y >= gSAZones[i][SAZONE_AREA][1]
  103. && y <= gSAZones[i][SAZONE_AREA][4]
  104. && z >= gSAZones[i][SAZONE_AREA][2]
  105. && z <= gSAZones[i][SAZONE_AREA][5]) {
  106. return format(zone, len, gSAZones[i][SAZONE_NAME], 0);
  107. }
  108. }
  109. return 0;
  110. }
  111. GetPhoneAreaCode(i) {
  112. new iAreaCode;
  113. GetPhoneZone(i, szMiscArray, sizeof(szMiscArray));
  114. if(strcmp(szMiscArray, "DOC", true) == 0) iAreaCode = 420;
  115. if(strcmp(szMiscArray, "Los Santos", true) == 0) iAreaCode = 500;
  116. if(strcmp(szMiscArray, "Red County", true) == 0) iAreaCode = 300;
  117. if(strcmp(szMiscArray, "Flint County", true) == 0) iAreaCode = 400;
  118. if(strcmp(szMiscArray, "San Fierro", true) == 0) iAreaCode = 600;
  119. if(strcmp(szMiscArray, "Las Venturas", true) == 0) iAreaCode = 700;
  120. if(strcmp(szMiscArray, "Bone County", true) == 0) iAreaCode = 666;
  121. if(strcmp(szMiscArray, "Tiera Robada", true) == 0) iAreaCode = 999;
  122. if(strcmp(szMiscArray, "Downtown Los Santos", true) == 0) iAreaCode = 502;
  123. if(strcmp(szMiscArray, "Pershing Square", true) == 0) iAreaCode = 503;
  124. if(strcmp(szMiscArray, "Temple", true) == 0) iAreaCode = 504;
  125. if(strcmp(szMiscArray, "Market", true) == 0) iAreaCode = 505;
  126. if(strcmp(szMiscArray, "Rodeo", true) == 0) iAreaCode = 540;
  127. if(strcmp(szMiscArray, "Idlewood", true) == 0) iAreaCode = 569;
  128. if(strcmp(szMiscArray, "Glen Park", true) == 0) iAreaCode = 570;
  129. if(strcmp(szMiscArray, "Jefferson", true) == 0) iAreaCode = 572;
  130. if(strcmp(szMiscArray, "East Los Santos", true) == 0) iAreaCode = 580;
  131. if(strcmp(szMiscArray, "Blueberry", true) == 0) iAreaCode = 444;
  132. if(strcmp(szMiscArray, "Angel Pine", true) == 0) iAreaCode = 838;
  133. return iAreaCode;
  134. }
  135. PayPhone_Menu(playerid, i) {
  136. szMiscArray[0] = 0;
  137. SetPVarInt(playerid, "PayPhone", i);
  138. GetPhoneZone(i, szMiscArray, sizeof(szMiscArray));
  139. format(szMiscArray, sizeof(szMiscArray), "Number: %d\nArea Code: %d | {FFFF00}%s\n\n{FFFFFF}Please enter the number you would like to dial.", arrPayPhoneData[i][pp_iNumber], GetPhoneAreaCode(i), szMiscArray);
  140. ShowPlayerDialogEx(playerid, DIALOG_PAYPHONE, DIALOG_STYLE_INPUT, "Pay Phone", szMiscArray, "Dial", "<<");
  141. }
  142. LoadPayPhones() {
  143. print("[Pay Phones] Loading pay phones from database...");
  144. mysql_tquery(MainPipeline, "SELECT * FROM `payphones`", "OnLoadPayPhones", "");
  145. }
  146. forward OnLoadPayPhones();
  147. public OnLoadPayPhones()
  148. {
  149. new iRows;
  150. cache_get_row_count(iRows);
  151. if(!iRows) return print("[Pay Phones] No pay phones were found in the database.");
  152. new iRow, value, Float:fValue;
  153. while(iRow < iRows) {
  154. cache_get_value_name_int(iRow, "number", arrPayPhoneData[iRow][pp_iNumber]);
  155. arrPayPhoneData[iRow][pp_iCallerID] = INVALID_PLAYER_ID;
  156. ProcessPayPhone(iRow,
  157. cache_get_value_name_float(iRow, "posx", fValue),
  158. cache_get_value_name_float(iRow, "posy", fValue),
  159. cache_get_value_name_float(iRow, "posz", fValue),
  160. cache_get_value_name_float(iRow, "rotz", fValue),
  161. cache_get_value_name_int(iRow, "vw", value),
  162. cache_get_value_name_int(iRow, "int", value));
  163. iRow++;
  164. }
  165. return printf("[MySQL] Loaded %i pay phones from database.", iRows);
  166. }
  167. forward OnCreatePayPhone(playerid, i, Float:X, Float:Y, Float:Z, Float:RZ, iVW, iINT);
  168. public OnCreatePayPhone(playerid, i, Float:X, Float:Y, Float:Z, Float:RZ, iVW, iINT) {
  169. if(mysql_errno(MainPipeline)) return SendClientMessageEx(playerid, COLOR_GRAD1, "Something went wrong. Please contact the development team.");
  170. ProcessPayPhone(i, X, Y, Z, RZ, iVW, iINT);
  171. format(szMiscArray, sizeof szMiscArray, "You have created a pay phone using ID %i.", i);
  172. SendClientMessageEx(playerid, COLOR_GRAD1, szMiscArray);
  173. format(szMiscArray, sizeof szMiscArray, "%s has creatd a pay phone using ID %i.", GetPlayerNameEx(playerid), i);
  174. Log("logs/payphones.log", szMiscArray);
  175. return 1;
  176. }
  177. forward OnDeletePayPhone(playerid, i);
  178. public OnDeletePayPhone(playerid, i) {
  179. if(mysql_errno(MainPipeline)) return SendClientMessageEx(playerid, COLOR_GRAD1, "Something went wrong. Please contact the development team.");
  180. DestroyDynamicObject(arrPayPhoneData[i][pp_iObjectID]);
  181. #if defined TEXTLABEL_DEBUG
  182. Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, arrPayPhoneData[i][pp_iTextID], E_STREAMER_EXTRA_ID, 7);
  183. #endif
  184. DestroyDynamic3DTextLabel(arrPayPhoneData[i][pp_iTextID]);
  185. DestroyDynamicArea(arrPayPhoneData[i][pp_iAreaID]);
  186. format(szMiscArray, sizeof szMiscArray, "You have deleted pay phone ID %i.", i);
  187. SendClientMessageEx(playerid, COLOR_LIGHTRED, szMiscArray);
  188. format(szMiscArray, sizeof szMiscArray, "%s (%d) has deleted pay phone ID %i.", GetPlayerNameEx(playerid), PlayerInfo[playerid][pId], i);
  189. Log("logs/payphones.log", szMiscArray);
  190. return 1;
  191. }
  192. PayPhone_UpdateTextLabel(i, choice) {
  193. switch(choice) {
  194. case 0: {
  195. format(szMiscArray, sizeof(szMiscArray), "Pay Phone {DDDDDD}(ID: %d)\n{FFFF00} Number: %d\n\n{DDDDDD}Press ~k~~CONVERSATION_YES~ to dial.", i, arrPayPhoneData[i][pp_iNumber]);
  196. UpdateDynamic3DTextLabelText(arrPayPhoneData[i][pp_iTextID], COLOR_YELLOW, szMiscArray);
  197. }
  198. case 1: UpdateDynamic3DTextLabelText(arrPayPhoneData[i][pp_iTextID], COLOR_PURPLE, "** The pay phone is ringing **\nPress ~k~~CONVERSATION_YES~ to answer.");
  199. }
  200. }
  201. ProcessPayPhone(i, Float:X, Float:Y, Float:Z, Float:RZ, iVW, iINT) {
  202. if(X != 0 && Y != 0) {
  203. arrPayPhoneData[i][pp_iCallerID] = INVALID_PLAYER_ID;
  204. arrPayPhoneData[i][pp_iObjectID] = CreateDynamicObject(1216, X, Y, Z - 0.3, 0.0, 0.0, RZ + 180.0, .worldid = iVW, .interiorid = iINT);
  205. format(szMiscArray, sizeof(szMiscArray), "Pay Phone {DDDDDD}(ID: %d)\n{FFFF00} Number: %d\n\n{DDDDDD}Press ~k~~CONVERSATION_YES~ to dial.", i, arrPayPhoneData[i][pp_iNumber]);
  206. arrPayPhoneData[i][pp_iTextID] = CreateDynamic3DTextLabel(szMiscArray, COLOR_YELLOW, X, Y, Z + 1.0, 5.0, .worldid = iVW, .interiorid = iINT);
  207. arrPayPhoneData[i][pp_iAreaID] = CreateDynamicSphere(X, Y, Z, 3.0, iVW, iINT);
  208. }
  209. }
  210. PayPhone_Save(i, Float:X, Float:Y, Float:Z, Float:RZ, iVW, iINT) {
  211. if(!IsValidDynamicArea(arrPayPhoneData[i][pp_iAreaID])) return 1;
  212. mysql_format(MainPipeline, szMiscArray, sizeof szMiscArray, "UPDATE `payphones` SET\
  213. `number` = %d, \
  214. `vw` = %i, \
  215. `int` = %i, \
  216. `posx` = %f, \
  217. `posy` = %f, \
  218. `posz` = %f, \
  219. `rotz` = %f",
  220. arrPayPhoneData[i][pp_iNumber],
  221. iVW,
  222. iINT,
  223. X,
  224. Y,
  225. Z,
  226. RZ
  227. );
  228. mysql_tquery(MainPipeline, szMiscArray, "OnQueryFinish", "i", SENDDATA_THREAD);
  229. return 1;
  230. }
  231. CMD:phones(playerid, params[]) {
  232. if(!IsAdminLevel(playerid, ADMIN_GENERAL)) return 1;
  233. szMiscArray[0] = 0;
  234. new x,
  235. szZone[MAX_ZONE_NAME];
  236. for(new i = 0; i < MAX_PAYPHONES; ++i) {
  237. if(IsValidDynamicArea(arrPayPhoneData[i][pp_iAreaID])) {
  238. GetPhoneZone(i, szZone, sizeof(szZone));
  239. format(szMiscArray, sizeof(szMiscArray), "%s\n%d - Number: %d - Location: %s", szMiscArray, i, arrPayPhoneData[i][pp_iNumber], szZone);
  240. ListItemTrackId[playerid][x] = i;
  241. x++;
  242. }
  243. }
  244. if(isnull(szMiscArray)) return SendClientMessageEx(playerid, COLOR_GRAD1, "There are no pay phones.");
  245. ShowPlayerDialogEx(playerid, DIALOG_PAYPHONE_ADMIN, DIALOG_STYLE_LIST, "Pay Phones", szMiscArray, "Teleport", "Cancel");
  246. return 1;
  247. }
  248. CMD:createphone(playerid, params[]) {
  249. if(!IsAdminLevel(playerid, ADMIN_SENIOR)) return 1;
  250. for(new i = 0; i < MAX_PAYPHONES; ++i) {
  251. if(!IsValidDynamicArea(arrPayPhoneData[i][pp_iAreaID])) {
  252. new Float:fPos[4],
  253. iVW = GetPlayerVirtualWorld(playerid),
  254. iINT = GetPlayerInterior(playerid);
  255. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  256. GetPlayerFacingAngle(playerid, fPos[3]);
  257. arrPayPhoneData[i][pp_iObjectID] = CreateDynamicObject(1216, fPos[0], fPos[1], fPos[2] - 0.3, 0.0, 0.0, fPos[3] + 180.0); // temp object to get zone
  258. format(szMiscArray, sizeof(szMiscArray), "024%d%d", GetPhoneAreaCode(i), Random(100, 999));
  259. arrPayPhoneData[i][pp_iNumber] = strval(szMiscArray);
  260. for(new x; x < MAX_PAYPHONES; ++x) {
  261. if(!IsValidDynamicArea(arrPayPhoneData[i][pp_iAreaID])) continue;
  262. if(arrPayPhoneData[i][pp_iNumber] == arrPayPhoneData[x][pp_iNumber]) {
  263. DestroyDynamicObject(arrPayPhoneData[i][pp_iObjectID]);
  264. arrPayPhoneData[i][pp_iNumber] = -1;
  265. return SendClientMessageEx(playerid, COLOR_GRAD1, "Please try again. The system generated an already existing number.");
  266. }
  267. }
  268. DestroyDynamicObject(arrPayPhoneData[i][pp_iObjectID]);
  269. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "UPDATE `payphones` SET `number` = '%d', `posx` = '%f', `posy` = '%f', `posz` = '%f', `rotz` = '%f', `vw` = '%d', `int` = '%d' WHERE `id` = '%d'",
  270. arrPayPhoneData[i][pp_iNumber],
  271. fPos[0],
  272. fPos[1],
  273. fPos[2],
  274. fPos[3],
  275. iVW,
  276. iINT,
  277. i+1);
  278. return mysql_tquery(MainPipeline, szMiscArray, "OnCreatePayPhone", "iiffffii", playerid, i, fPos[0], fPos[1], fPos[2], fPos[3], iVW, iINT);
  279. }
  280. }
  281. SendClientMessageEx(playerid, COLOR_GRAD1, "There are no more pay phone slots available.");
  282. return 1;
  283. }
  284. CMD:destroyphone(playerid, params[]) {
  285. if(!IsAdminLevel(playerid, ADMIN_SENIOR)) return 1;
  286. new i;
  287. if(sscanf(params, "i", i))
  288. return SendClientMessageEx(playerid, COLOR_GRAD1, "/destroyphone [phoneid]");
  289. if(!IsValidDynamicArea(arrPayPhoneData[i][pp_iAreaID]))
  290. return SendClientMessageEx(playerid, COLOR_GRAD1, "The specified pay phone ID has not been used.");
  291. mysql_format(MainPipeline, szMiscArray, sizeof szMiscArray, "UPDATE `payphones` SET `number` = '-1', `posx` = '0', `posy` = '0', `posz` = '0', `vw` = '0', `int` = '0' WHERE `id` = %i", i+1);
  292. mysql_tquery(MainPipeline, szMiscArray, "OnDeletePayPhone", "ii", playerid, i);
  293. return 1;
  294. }
  295. CMD:editphone(playerid, params[])
  296. {
  297. if(!IsAdminLevel(playerid, ADMIN_SENIOR)) return 1;
  298. new i;
  299. if(sscanf(params, "i", i))
  300. return SendClientMessageEx(playerid, COLOR_GRAD1, "/editphone [id]");
  301. if(!IsValidDynamicArea(arrPayPhoneData[i][pp_iAreaID]))
  302. return SendClientMessageEx(playerid, COLOR_GRAD1, "The specified pay phone ID has not been used.");
  303. new Float:fPos[4];
  304. GetDynamicObjectPos(arrPayPhoneData[i][pp_iObjectID], fPos[0], fPos[1], fPos[2]);
  305. if(!IsPlayerInRangeOfPoint(playerid, 50.0, fPos[0], fPos[1], fPos[2]))
  306. return SendClientMessageEx(playerid, COLOR_GRAD1, "You need to be near the specified pay phone to edit the position.");
  307. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  308. GetPlayerFacingAngle(playerid, fPos[3]);
  309. new iVW = GetPlayerVirtualWorld(playerid),
  310. iINT = GetPlayerInterior(playerid);
  311. PayPhone_Save(i, fPos[0], fPos[1], fPos[2], fPos[3], iVW, iINT);
  312. DestroyDynamicObject(arrPayPhoneData[i][pp_iObjectID]);
  313. DestroyDynamicArea(arrPayPhoneData[i][pp_iAreaID]);
  314. DestroyDynamic3DTextLabel(arrPayPhoneData[i][pp_iTextID]);
  315. ProcessPayPhone(i, fPos[0], fPos[1], fPos[2], fPos[3], iVW, iINT);
  316. format(szMiscArray, sizeof(szMiscArray), "You have edited phone ID %i's position.", i);
  317. SendClientMessageEx(playerid, COLOR_GRAD1, szMiscArray);
  318. return 1;
  319. }