1
0

eventpoints.pwn 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Event Points System
  11. Next Generation Gaming, LLC
  12. (created by Next Generation Gaming Development Team)
  13. * Copyright (c) 2016, Next Generation Gaming, LLC
  14. *
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without modification,
  18. * are not permitted in any case.
  19. *
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  25. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. LoadEventPoints() {
  34. if(!fexist("eventpoints.cfg"))
  35. return 1;
  36. new
  37. szFileStr[256],
  38. File: fHandle = fopen("eventpoints.cfg", io_read),
  39. iIndex;
  40. while(iIndex < MAX_EVENTPOINTS && fread(fHandle, szFileStr)) {
  41. if(!sscanf(szFileStr, "p<|>fffiis[64]i",
  42. EventPoints[iIndex][epPosX],
  43. EventPoints[iIndex][epPosY],
  44. EventPoints[iIndex][epPosZ],
  45. EventPoints[iIndex][epVW],
  46. EventPoints[iIndex][epInt],
  47. EventPoints[iIndex][epPrize],
  48. EventPoints[iIndex][epFlagable]
  49. ) && EventPoints[iIndex][epPosX] != 0.0) {
  50. EventPoints[iIndex][epObjectID] = CreateDynamicPickup(1274, 1, EventPoints[iIndex][epPosX], EventPoints[iIndex][epPosY], EventPoints[iIndex][epPosZ], EventPoints[iIndex][epVW]);
  51. format(szFileStr,sizeof(szFileStr),"Event Point (ID: %d)\nPrize: %s\nType /claimpoint to claim your prize!", iIndex, EventPoints[iIndex][epPrize]);
  52. EventPoints[iIndex][epText3dID] = CreateDynamic3DTextLabel(szFileStr, COLOR_YELLOW, EventPoints[iIndex][epPosX], EventPoints[iIndex][epPosY], EventPoints[iIndex][epPosZ]+0.5, 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, EventPoints[iIndex][epVW], EventPoints[iIndex][epInt]);
  53. ++iIndex;
  54. }
  55. }
  56. printf("[LoadEventPoints] %i event points loaded.", iIndex);
  57. return fclose(fHandle);
  58. }
  59. SaveEventPoints() {
  60. new
  61. szFileStr[256],
  62. File: fHandle = fopen("eventpoints.cfg", io_write);
  63. if(fHandle)
  64. {
  65. for(new iIndex; iIndex < MAX_EVENTPOINTS; iIndex++) {
  66. format(szFileStr, sizeof(szFileStr), "%f|%f|%f|%d|%d|%s|%d\r\n",
  67. EventPoints[iIndex][epPosX],
  68. EventPoints[iIndex][epPosY],
  69. EventPoints[iIndex][epPosZ],
  70. EventPoints[iIndex][epVW],
  71. EventPoints[iIndex][epInt],
  72. EventPoints[iIndex][epPrize],
  73. EventPoints[iIndex][epFlagable]
  74. );
  75. fwrite(fHandle, szFileStr);
  76. }
  77. return fclose(fHandle);
  78. }
  79. return 0;
  80. }
  81. stock InitEventPoints()
  82. {
  83. for(new i = 0; i < MAX_EVENTPOINTS; i++)
  84. {
  85. EventPoints[i][epObjectID] = 0;
  86. }
  87. return 1;
  88. }
  89. CMD:gotopoint(playerid, params[])
  90. {
  91. if(PlayerInfo[playerid][pAdmin] < 4 && PlayerInfo[playerid][pASM] < 1)
  92. {
  93. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command!");
  94. return 1;
  95. }
  96. new points;
  97. if(sscanf(params, "d", points)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /gotopoint [pointid]");
  98. if(points >= MAX_EVENTPOINTS || points < 0)
  99. {
  100. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /gotopoint [pointid]");
  101. return 1;
  102. }
  103. SetPlayerPos(playerid, EventPoints[points][epPosX], EventPoints[points][epPosY], EventPoints[points][epPosZ]);
  104. SetPlayerVirtualWorld(playerid, EventPoints[points][epVW]);
  105. SetPlayerInterior(playerid, EventPoints[points][epInt]);
  106. return 1;
  107. }
  108. CMD:createpoint(playerid, params[])
  109. {
  110. if(PlayerInfo[playerid][pAdmin] < 4 && PlayerInfo[playerid][pASM] < 1)
  111. {
  112. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command!");
  113. return 1;
  114. }
  115. new string[128], objectid, flagable, pointid, prize[64];
  116. if(sscanf(params, "ddds[64]", objectid, flagable, pointid, prize)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /createpoint [objectid] [flagable] [pointid] [prize]");
  117. if(EventPoints[pointid][epObjectID] != 0)
  118. {
  119. DestroyDynamicPickup(EventPoints[pointid][epObjectID]);
  120. EventPoints[pointid][epObjectID] = 0;
  121. if(IsValidDynamic3DTextLabel(EventPoints[pointid][epText3dID]))
  122. {
  123. DestroyDynamic3DTextLabel(EventPoints[pointid][epText3dID]);
  124. }
  125. EventPoints[pointid][epPosX] = 0.0;
  126. EventPoints[pointid][epPosY] = 0.0;
  127. EventPoints[pointid][epPosZ] = 0.0;
  128. EventPoints[pointid][epVW] = 0;
  129. EventPoints[pointid][epInt] = 0;
  130. }
  131. new Float:x, Float:y, Float:z;
  132. GetPlayerPos(playerid, x, y, z);
  133. new tvw = GetPlayerVirtualWorld(playerid);
  134. new tint = GetPlayerInterior(playerid);
  135. EventPoints[pointid][epPosX] = x;
  136. EventPoints[pointid][epPosY] = y;
  137. EventPoints[pointid][epPosZ] = z;
  138. EventPoints[pointid][epVW] = tvw;
  139. EventPoints[pointid][epInt] = tint;
  140. EventPoints[pointid][epFlagable] = flagable;
  141. format(EventPoints[pointid][epPrize], 64, "%s", prize);
  142. format(string,sizeof(string),"Event Point (ID: %d)\nPrize: %s\nType /claimpoint to claim your prize!", pointid, EventPoints[pointid][epPrize]);
  143. EventPoints[pointid][epObjectID] = CreateDynamicPickup(objectid, 1, EventPoints[pointid][epPosX], EventPoints[pointid][epPosY], EventPoints[pointid][epPosZ], EventPoints[pointid][epVW]);
  144. EventPoints[pointid][epText3dID] = CreateDynamic3DTextLabel(string, COLOR_YELLOW, EventPoints[pointid][epPosX], EventPoints[pointid][epPosY], EventPoints[pointid][epPosZ]+0.5, 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, EventPoints[pointid][epVW], EventPoints[pointid][epInt]);
  145. format(string,sizeof(string),"You have placed PointID %d at your current position.", pointid);
  146. SendClientMessageEx(playerid, COLOR_GRAD2, string);
  147. return 1;
  148. }
  149. CMD:deletepoint(playerid, params[])
  150. {
  151. if(PlayerInfo[playerid][pAdmin] < 4 && PlayerInfo[playerid][pASM] < 1)
  152. {
  153. SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command!");
  154. return 1;
  155. }
  156. new string[128], pointid;
  157. if(sscanf(params, "d", pointid)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /deletepoint [pointid]");
  158. if(pointid >= MAX_EVENTPOINTS || pointid < 0)
  159. {
  160. return 1;
  161. }
  162. if(EventPoints[pointid][epObjectID] != 0)
  163. {
  164. DestroyDynamicPickup(EventPoints[pointid][epObjectID]);
  165. EventPoints[pointid][epObjectID] = 0;
  166. if(IsValidDynamic3DTextLabel(EventPoints[pointid][epText3dID]))
  167. {
  168. DestroyDynamic3DTextLabel(EventPoints[pointid][epText3dID]);
  169. }
  170. EventPoints[pointid][epPosX] = 0.0;
  171. EventPoints[pointid][epPosY] = 0.0;
  172. EventPoints[pointid][epPosZ] = 0.0;
  173. EventPoints[pointid][epVW] = 0;
  174. EventPoints[pointid][epInt] = 0;
  175. EventPoints[pointid][epFlagable] = 0;
  176. format(EventPoints[pointid][epPrize], 64, "");
  177. format(string,sizeof(string),"You have deleted PointID %d from the server.", pointid);
  178. SendClientMessageEx(playerid, COLOR_GRAD2, string);
  179. }
  180. return 1;
  181. }
  182. CMD:claimpoint(playerid, params[])
  183. {
  184. for(new p = 0; p < MAX_EVENTPOINTS; p++)
  185. {
  186. if(IsPlayerInRangeOfPoint(playerid, 5.0, EventPoints[p][epPosX], EventPoints[p][epPosY], EventPoints[p][epPosZ]))
  187. {
  188. if(EventPoints[p][epObjectID] != 0)
  189. {
  190. new string[128];
  191. format(string, sizeof(string), " Congratulations you have won a Special Prize (%s)!", EventPoints[p][epPrize]);
  192. SendClientMessageEx(playerid, COLOR_GRAD2, string);
  193. SendClientMessageEx(playerid, COLOR_GRAD2, " Note: This prize may take up to 48 hours to be rewarded..");
  194. if(EventPoints[p][epFlagable] == 1)
  195. {
  196. format(string, 128, "Special Prize (%s)", EventPoints[p][epPrize]);
  197. AddFlag(playerid, INVALID_PLAYER_ID, string);
  198. }
  199. format(string, sizeof(string), "{AA3333}AdmWarning{FFFF00}: %s has just found PointID %d, they are now pending a special prize.", GetPlayerNameEx(playerid), p);
  200. ABroadCast(COLOR_YELLOW, string, 4);
  201. format(string, sizeof(string), "AdmCmd: %s(%d) has just found PointID %d, Prize: %s", GetPlayerNameEx(playerid), GetPlayerSQLId(playerid), p, EventPoints[p][epPrize]);
  202. Log("logs/gifts.log", string);
  203. DestroyDynamicPickup(EventPoints[p][epObjectID]);
  204. EventPoints[p][epObjectID] = 0;
  205. if(IsValidDynamic3DTextLabel(EventPoints[p][epText3dID]))
  206. {
  207. DestroyDynamic3DTextLabel(EventPoints[p][epText3dID]);
  208. }
  209. EventPoints[p][epPosX] = 0.0;
  210. EventPoints[p][epPosY] = 0.0;
  211. EventPoints[p][epPosZ] = 0.0;
  212. EventPoints[p][epVW] = 0;
  213. EventPoints[p][epInt] = 0;
  214. EventPoints[p][epFlagable] = 0;
  215. format(EventPoints[p][epPrize], 64, "");
  216. }
  217. }
  218. }
  219. return 1;
  220. }
  221. CMD:claimpoints(playerid, params[])
  222. {
  223. new amount;
  224. for(new i; i < MAX_EVENTPOINTS; i++)
  225. {
  226. if(EventPoints[i][epPosX] != 0.0) amount++;
  227. }
  228. new string[48];
  229. format(string, sizeof(string), "There are %d available claim points on the map!", amount);
  230. SendClientMessageEx(playerid, -1, string);
  231. return 1;
  232. }