Guest User

Pickup System 2.0 (c) by Kaliber

a guest
Apr 29th, 2012
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. /* SA-MP Filterscript
  2. *
  3. * (c) Copyright 2012, Kaliber
  4. *
  5. */
  6. #include <a_samp>
  7. #define COLOR_LIGHTRED 0xFF6347AA
  8. #define COLOR_LIGHTBLUE 0x33CCFFAA
  9. #define COLOR_WHITE 0xFFFFFFAA
  10. #define COLOR_LIGHTGREEN 0x7CFC00AA
  11. #define COLOR_YELLOW 0xFFFF00AA
  12. #define Dialog0 921
  13. #define Dialog1 922
  14. #define Dialog2 923
  15.  
  16. enum pInfo{
  17. Float:pX,
  18. Float:pY,
  19. Float:pZ,
  20. pworld,
  21. pModel,
  22. pType,
  23. };
  24. new Pickup[MAX_PICKUPS][pInfo];
  25. new pickupid[MAX_PLAYERS];
  26. public OnFilterScriptInit()
  27. {
  28. LoadPickups();
  29. print("\n\tCopyright (c) by Kaliber\n");
  30. return 1;
  31. }
  32. public OnFilterScriptExit()
  33. {
  34. return 1;
  35. }
  36.  
  37. stock SavePickup(string[])
  38. {
  39. new entry[256];
  40. format(entry, sizeof(entry), "%s\n",string);
  41. new File:hFile;
  42. hFile = fopen("pickups.cfg", io_append);
  43. fwrite(hFile, entry);
  44. fclose(hFile);
  45. }
  46.  
  47. stock LoadPickups()
  48. {
  49. new arrCoords[30][64];
  50. new strFromFile2[256];
  51. new File: file = fopen("pickups.cfg", io_read);
  52. if (file)
  53. {
  54. new idx;
  55. while (idx < sizeof(Pickup))
  56. {
  57. fread(file, strFromFile2);
  58. split(strFromFile2, arrCoords, ',');
  59. Pickup[idx][pX] = floatstr(arrCoords[0]);
  60. Pickup[idx][pY] = floatstr(arrCoords[1]);
  61. Pickup[idx][pZ] = floatstr(arrCoords[2]);
  62. Pickup[idx][pworld] = strval(arrCoords[3]);
  63. Pickup[idx][pModel] = strval(arrCoords[4]);
  64. Pickup[idx][pType] = strval(arrCoords[5]);
  65. CreatePickup(Pickup[idx][pModel], Pickup[idx][pType], Pickup[idx][pX], Pickup[idx][pY], Pickup[idx][pZ], Pickup[idx][pworld]);
  66. idx++;
  67. }
  68. fclose(file);
  69. }
  70. return 1;
  71. }
  72.  
  73. stock split(const strsrc[], strdest[][], delimiter)
  74. {
  75. new i, li;
  76. new aNum;
  77. new len;
  78. while(i <= strlen(strsrc)){
  79. if(strsrc[i]==delimiter || i==strlen(strsrc)){
  80. len = strmid(strdest[aNum], strsrc, li, i, 128);
  81. strdest[aNum][len] = 0;
  82. li = i+1;
  83. aNum++;
  84. }
  85. i++;
  86. }
  87. return 1;
  88. }
  89.  
  90. public OnPlayerCommandText(playerid, cmdtext[])
  91. {
  92. new cmd[256], idx, tmp[256];
  93. cmd = strtok(cmdtext, idx);
  94. if(strcmp(cmd, "/createpickup", true) == 0)
  95. {
  96. tmp = strtok(cmdtext, idx);
  97. if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_LIGHTRED, "Benutzung: /createpickup [modelid] [typid]");
  98. new typ, model;
  99. model = strval(tmp);
  100. tmp = strtok(cmdtext, idx);
  101. if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_LIGHTRED, "Benutzung: /createpickup [modelid] [typid]");
  102. typ = strval(tmp);
  103. new Float: X, Float: Y, Float: Z, world;
  104. GetPlayerPos(playerid, X, Y, Z);
  105. world = GetPlayerVirtualWorld(playerid);
  106. CreatePickup(model, typ, X, Y, Z, world);
  107. for(new i; i<sizeof(Pickup); i++)
  108. {
  109. Pickup[i][pX] = X;
  110. Pickup[i][pY] = Y;
  111. Pickup[i][pZ] = Z;
  112. Pickup[i][pworld] = world;
  113. Pickup[i][pModel] = model;
  114. Pickup[i][pType] = typ;
  115. }
  116. new string[128];
  117. format(string, sizeof string,"%f, %f, %f, %d, %d, %d",X,Y,Z,world,model,typ);
  118. SavePickup(string);
  119. SendClientMessage(playerid, COLOR_LIGHTBLUE,"Pickup erfolgreich erstellt !");
  120. return 1;
  121. }
  122. if(strcmp(cmd, "/editpickup", true) == 0)
  123. {
  124. for(new i; i<sizeof(Pickup); i++)
  125. {
  126. if(IsPlayerInRangeOfPoint(playerid, 2.0, Pickup[i][pX], Pickup[i][pY], Pickup[i][pZ]))
  127. {
  128. pickupid[playerid] = i;
  129. ShowPlayerDialog(playerid,Dialog0,DIALOG_STYLE_LIST,"{FF0000}Pickup System","{FFFFFF}Modelid\nType","Bestätigen","Abbrechen");
  130. return 1;
  131. }
  132. }
  133. return SendClientMessage(playerid, COLOR_LIGHTRED,"Du bist nicht in der Nähe von einem Pickup !");
  134. }
  135. return 0;
  136. }
  137. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  138. {
  139. if(dialogid == Dialog0)
  140. {
  141. if(response == 1)
  142. {
  143. switch (listitem)
  144. {
  145. case 0:
  146. {
  147. ShowPlayerDialog(playerid,Dialog1,DIALOG_STYLE_INPUT,"{FF0000}Pickup System","{FFFFFF}Gib hier nun die {FF0000}Modelid{FFFFFF} ein:","Bestätigen","Abbrechen");
  148. }
  149. case 1:
  150. {
  151. ShowPlayerDialog(playerid,Dialog2,DIALOG_STYLE_INPUT,"{FF0000}Pickup System","{FFFFFF}Gib hier nun den {FF0000}Type{FFFFFF} ein:","Bestätigen","Abbrechen");
  152. }
  153. }
  154. }
  155. else
  156. {
  157. return 1;
  158. }
  159. }
  160. if(dialogid == Dialog1)
  161. {
  162. if(response == 1 && strval(inputtext) > 1)
  163. {
  164. DestroyPickup(pickupid[playerid]);
  165. CreatePickup(strval(inputtext), Pickup[pickupid[playerid]][pType], Pickup[pickupid[playerid]][pX], Pickup[pickupid[playerid]][pY], Pickup[pickupid[playerid]][pZ], Pickup[pickupid[playerid]][pworld]);
  166. SendClientMessage(playerid, COLOR_LIGHTBLUE,"Pickup erfolgreich editiert !");
  167. }
  168. else
  169. {
  170. return 1;
  171. }
  172. }
  173. if(dialogid == Dialog2)
  174. {
  175. if(response == 1 && strval(inputtext) > 1)
  176. {
  177. DestroyPickup(pickupid[playerid]);
  178. CreatePickup(Pickup[pickupid[playerid]][pModel], strval(inputtext), Pickup[pickupid[playerid]][pX], Pickup[pickupid[playerid]][pY], Pickup[pickupid[playerid]][pZ], Pickup[pickupid[playerid]][pworld]);
  179. SendClientMessage(playerid, COLOR_LIGHTBLUE,"Pickup erfolgreich editiert !");
  180. }
  181. else
  182. {
  183. return 1;
  184. }
  185. }
  186. return 1;
  187. }
  188. strtok(const string[], &index)
  189. {
  190. new length = strlen(string);
  191. while ((index < length) && (string[index] <= ' '))
  192. {
  193. index++;
  194. }
  195.  
  196. new offset = index;
  197. new result[20];
  198. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  199. {
  200. result[index - offset] = string[index];
  201. index++;
  202. }
  203. result[index - offset] = EOS;
  204. return result;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment