Advertisement
Private200

Drugger job - Fast and comfortable + saving system

May 24th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <YSI\y_ini>
  4.  
  5.  
  6. // Defining the path where the user accounts will go
  7.  
  8. #define PATH "/Drugger/%s.ini"
  9.  
  10.  
  11. // Some configurations for the script to work
  12.  
  13. new HasMaterials[MAX_PLAYERS];
  14. new IsDrunk[MAX_PLAYERS];
  15. new lightblue = 0xADD8E6FF;
  16. new red = 0xFF0000AA;
  17.  
  18. // Defining the user Information script-related
  19. enum pInfo
  20. {
  21. pJob,
  22. pDrugs
  23. }
  24.  
  25. new PlayerInfo[MAX_PLAYERS][pInfo];
  26.  
  27. forward LoadUser_data(playerid,name[],value[]);
  28. public LoadUser_data(playerid,name[],value[])
  29. {
  30. INI_Int("IsDrugger",PlayerInfo[playerid][pJob]);
  31. INI_Int("AmountOfDrugs",PlayerInfo[playerid][pDrugs]);
  32. return 1;
  33. }
  34.  
  35. stock UserPath(playerid)
  36. {
  37. new string[128],playername[MAX_PLAYER_NAME];
  38. GetPlayerName(playerid, playername, sizeof(playername));
  39. format(string, sizeof(string), PATH, playername);
  40. return string;
  41. }
  42.  
  43. /*Credits to Dracoblue*/
  44. stock udb_hash(buf[]) {
  45. new length=strlen(buf);
  46. new s1 = 1;
  47. new s2 = 0;
  48. new n;
  49. for (n=0; n<length; n++)
  50. {
  51. s1 = (s1 + buf[n]) % 65521;
  52. s2 = (s2 + s1) % 65521;
  53. }
  54. return (s2 << 16) + s1;
  55. }
  56.  
  57.  
  58. public OnFilterScriptInit()
  59. {
  60. // Takejob configurations
  61.  
  62. CreatePickup(1239, 1, 2065.2837,-1558.5857,13.4369, -1);
  63. Create3DTextLabel("Drugger job\n/takedruggerjob | /quitdruggerjob", 0xFF0000AA, 2065.2837,-1558.5857,13.4369, 5.0, 0, 0);
  64.  
  65. // pickupmaterials configurations
  66.  
  67. CreatePickup(1254, 1, 2067.4619, -1561.9774, 13.4270, -1);
  68. Create3DTextLabel("Drugger job\n/pickupmaterials", 0xFF0000AA, 2067.4619,-1561.9774,13.4270, 5.0, 0, 0);
  69.  
  70. // createdrugs configurations
  71.  
  72. CreatePickup(1279, 1, 2355.3733, -648.4775, 128.0547, -1);
  73. Create3DTextLabel("Drugger job\n/createdrugs", 0xFF0000AA, 2355.3733, -648.4775, 128.0547, 5.0, 0, 0);
  74.  
  75. return 1;
  76. }
  77.  
  78. public OnPlayerSpawn(playerid)
  79. {
  80. return 1;
  81. }
  82.  
  83. COMMAND:takedruggerjob(playerid, params[])
  84. {
  85. if(PlayerInfo[playerid][pJob] == 0)
  86. {
  87. if(IsPlayerInRangeOfPoint(playerid, 1.0, 2065.2837, -1558.5857, 13.4369))
  88. {
  89. PlayerInfo[playerid][pJob] = 1;
  90. SendClientMessage(playerid, lightblue, "Congratulations. You're now an Drugger. For more help about your job please use '/druggerhelp'.");
  91. }
  92. else
  93. SendClientMessage(playerid, red, "[ERROR] You're not at the place to take the Drugger job.");
  94. }
  95. else
  96. SendClientMessage(playerid, red, "[ERROR] You're already an Drugger.");
  97. return 1;
  98. }
  99.  
  100. COMMAND:quitdruggerjob(playerid, params[])
  101. {
  102. if(PlayerInfo[playerid][pJob] == 1)
  103. {
  104. SendClientMessage(playerid, lightblue, "You left your drugger job.");
  105. PlayerInfo[playerid][pJob] = 0;
  106. }
  107. else
  108. SendClientMessage(playerid, red, "[ERROR] You're not an drugger.");
  109.  
  110. return 1;
  111. }
  112.  
  113. COMMAND:druggerhelp(playerid, params[])
  114. {
  115. new msg[2000];
  116.  
  117. format(msg, 2000, "%s{FFFFFF}Hello Drugger,\n\n\n", msg);
  118. format(msg, 2000, "%s{FFFFFF}These are the commands of your job:\n\n", msg);
  119. format(msg, 2000, "%s{FF0000}1. {FFFFFF}/takedruggerjob -> Takes the Drugger job\n", msg);
  120. format(msg, 2000, "%s{FF0000}2. {FFFFFF}/pickupmaterials -> Picks up the required materials for creating drugs\n", msg);
  121. format(msg, 2000, "%s{FF0000}3. {FFFFFF}/quitdruggerjob -> Quits the Drugger job\n", msg);
  122. format(msg, 2000, "%s{FF0000}4. {FFFFFF}/createdrugs -> Creates drugs\n", msg);
  123. format(msg, 2000, "%s{FF0000}5. {FFFFFF}/givedrugs -> You can trade drugs for cash with other players near you\n", msg);
  124. format(msg, 2000, "%s{FF0000}6. {FFFFFF}/usedrugs -> You can use the drugs you got\n", msg);
  125. format(msg, 2000, "%s{FF0000}7. {FFFFFF}/mydrugs -> Checks if you got drugs or not\n\n", msg);
  126. format(msg, 2000, "%s{FFFFFF}Thank you for reading the help menu", msg);
  127.  
  128. if(PlayerInfo[playerid][pJob] == 1)
  129. {
  130. ShowPlayerDialog(playerid, 5678, DIALOG_STYLE_MSGBOX, "{FFFFFF}Drugger Help", msg, "Okay", "");
  131. return 1;
  132. }
  133. else
  134. SendClientMessage(playerid, red, "[ERROR] You're not an Drugger.");
  135.  
  136. return 1;
  137. }
  138. COMMAND:pickupmaterials(playerid, params[])
  139. {
  140. if(PlayerInfo[playerid][pJob] == 0)
  141. {
  142. if(HasMaterials[playerid] == 0)
  143. {
  144. if(IsPlayerInRangeOfPoint(playerid, 1.0, 2067.4619,-1561.9774,13.4270))
  145. {
  146. SetPlayerSpecialAction(playerid, SPECIAL_ACTION_CARRY);
  147. SetTimer("pickingmaterials", 5000, false);
  148. SendClientMessage(playerid, lightblue, "You started loading part of drugs materials.");
  149. TogglePlayerControllable(playerid, 0);
  150. }
  151. else
  152. SendClientMessage(playerid, red, "[ERROR] You're not at the materials pickup position.");
  153. }
  154. else
  155. SendClientMessage(playerid, red, "[ERROR] You can only load 1 pack of materials at one time.");
  156. }
  157. else
  158. SendClientMessage(playerid, red, "[ERROR] You're not a Drugger.");
  159. }
  160.  
  161. forward pickingmaterials(playerid);
  162.  
  163. public pickingmaterials(playerid)
  164. {
  165. HasMaterials[playerid] = 1;
  166. SendClientMessage(playerid, lightblue, "You have loaded the materials successfully. Take care of police.");
  167. TogglePlayerControllable(playerid, 1);
  168. SetPlayerCheckpoint(playerid, 2355.3733, -648.4775, 128.0547, 1.0);
  169. SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
  170. return 1;
  171. }
  172.  
  173. COMMAND:createdrugs(playerid, params[])
  174. {
  175. if(PlayerInfo[playerid][pJob] == 1)
  176. {
  177. if(IsPlayerInRangeOfPoint(playerid, 1.0, 2355.3733, -648.4775, 128.0547))
  178. {
  179. PlayerInfo[playerid][pDrugs]++;
  180. SendClientMessage(playerid, lightblue, "Congratulations. You've created drugs.");
  181. }
  182. else
  183. SendClientMessage(playerid, red, "[ERROR] You're not at the drugs creation place.");
  184. }
  185. else
  186. SendClientMessage(playerid, red, "[ERROR] You're not an Drugger.");
  187. }
  188.  
  189. COMMAND:usedrugs(playerid, params[])
  190. {
  191. if(PlayerInfo[playerid][pDrugs] >= 1)
  192. {
  193. PlayerInfo[playerid][pDrugs]--;
  194. SetTimer("drunkstart", 5000, false);
  195. TogglePlayerControllable(playerid, 0);
  196. SendClientMessage(playerid, lightblue, "You're now using the drugs. It will take a while till you finish it all.");
  197. }
  198. else
  199. SendClientMessage(playerid, red, "[ERROR] You don't have drugs. Ask someone who has it to give it to you.");
  200. }
  201.  
  202. forward drunkstart(playerid);
  203.  
  204. public drunkstart(playerid)
  205. {
  206. IsDrunk[playerid] = 1;
  207. TogglePlayerControllable(playerid, 1);
  208. SetPlayerDrunkLevel(playerid, 50000);
  209. SendClientMessage(playerid, lightblue, "You're now under effects of drugs. Be sure the cops wont bust you.");
  210. SetTimer("drunkmiddle", 15000, false);
  211. return 1;
  212. }
  213.  
  214. forward drunkmiddle(playerid);
  215.  
  216. public drunkmiddle(playerid)
  217. {
  218. SendClientMessage(playerid, lightblue, "You've slowly recovering your self from the drugs.");
  219. SetPlayerDrunkLevel(playerid, 25000);
  220. SetTimer("drunkend", 7500, false);
  221. return 1;
  222. }
  223.  
  224. forward drunkend(playerid);
  225.  
  226. public drunkend(playerid)
  227. {
  228. SetPlayerDrunkLevel(playerid, 0);
  229. SendClientMessage(playerid, lightblue, "You fully recovered your self from the drugs.");
  230. IsDrunk[playerid] = 0;
  231. return 1;
  232. }
  233.  
  234. COMMAND:mydrugs(playerid, params[])
  235. {
  236. new string[256];
  237.  
  238. if(PlayerInfo[playerid][pDrugs] >= 1)
  239. {
  240. format(string, 256, "Drugs in your bag: %i", PlayerInfo[playerid][pDrugs]);
  241. SendClientMessage(playerid, lightblue, string);
  242. }
  243. else if(PlayerInfo[playerid][pDrugs] < 1)
  244. {
  245. SendClientMessage(playerid, lightblue, "You don't have any drugs in your bag.");
  246. }
  247. return 1;
  248. }
  249.  
  250. COMMAND:givedrugs(playerid, params[])
  251. {
  252. new OtherPlayer, OtherPlayerName[24], msg[2000], YourName[24];
  253. new Float:x, Float:y, Float:z;
  254. GetPlayerPos(playerid, x, y, z);
  255.  
  256. if(PlayerInfo[playerid][pDrugs] >= 1)
  257. {
  258. if(IsPlayerInRangeOfPoint(OtherPlayer, 2.0, x, y, z))
  259. {
  260. GetPlayerName(OtherPlayer, OtherPlayerName, sizeof(OtherPlayerName));
  261. GetPlayerName(playerid, YourName, sizeof(YourName));
  262. PlayerInfo[OtherPlayer][pDrugs]++;
  263. PlayerInfo[OtherPlayer][pDrugs]--;
  264. format(msg, 2000, "You've sent drugs to %s.", OtherPlayerName);
  265. SendClientMessage(playerid, lightblue, msg);
  266. format(msg, 2000, "You've recieved drugs from %s.", YourName);
  267. SendClientMessage(OtherPlayer, lightblue, msg);
  268. }
  269. else
  270. SendClientMessage(playerid, red, "[ERROR] You're not near that person.");
  271. }
  272. else
  273. SendClientMessage(playerid, red, "[ERROR] You can't send drugs you don't own.");
  274. return 1;
  275. }
  276.  
  277. public OnPlayerEnterCheckpoint(playerid)
  278. {
  279. DisablePlayerCheckpoint(playerid);
  280. return 1;
  281. }
  282.  
  283. // Saving everything when player get's dissconected.
  284.  
  285. public OnPlayerDisconnect(playerid, reason)
  286. {
  287. new INI:File = INI_Open(UserPath(playerid));
  288. INI_SetTag(File,"data");
  289. INI_WriteInt(File,"IsDrugger",PlayerInfo[playerid][pJob]);
  290. INI_WriteInt(File,"AmountOfDrugs",PlayerInfo[playerid][pDrugs]);
  291. INI_Close(File);
  292. return 1;
  293. }
  294.  
  295. public OnPlayerConnect(playerid)
  296. {
  297. if(fexist(UserPath(playerid)))
  298. {
  299. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  300. }
  301. else
  302. {
  303. new INI:File = INI_Open(UserPath(playerid));
  304. INI_SetTag(File,"data");
  305. INI_WriteInt(File,"IsDrugger", 0);
  306. INI_WriteInt(File,"AmountOfDrugs",0);
  307. INI_Close(File);
  308. }
  309. return 1;
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement