NpcGenerator.pwn 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. NPC Generator
  3. By Yuri_
  4. Copyright © Balkan Role-Play Team. All Rights Reserved.
  5. */
  6. #define FILTERSCRIPT
  7. #include <a_samp>
  8. #define red 0xFF4500AA
  9. #define royalblue 0x4169FFAA
  10. new IsInNpcMode[MAX_PLAYERS];
  11. new IsInNpcRecordMode[MAX_PLAYERS];
  12. #if defined FILTERSCRIPT
  13. public OnFilterScriptInit()
  14. {
  15. print("\n--------------------------------------");
  16. print(" NPC Generator Loaded");
  17. print("--------------------------------------\n");
  18. return 1;
  19. }
  20. public OnFilterScriptExit()
  21. {
  22. print("\n--------------------------------------");
  23. print(" NPC Generator Unloaded");
  24. print("--------------------------------------\n");
  25. return 1;
  26. }
  27. #endif
  28. public OnPlayerConnect(playerid)
  29. {
  30. IsInNpcRecordMode[playerid] = 0;
  31. IsInNpcMode[playerid] = 0;
  32. return 1;
  33. }
  34. public OnPlayerDisconnect(playerid, reason)
  35. {
  36. IsInNpcRecordMode[playerid] = 0;
  37. IsInNpcMode[playerid] = 0;
  38. return 1;
  39. }
  40. public OnPlayerCommandText(playerid, cmdtext[])
  41. {
  42. new cmd[256];
  43. new idx;
  44. cmd = strtok(cmdtext, idx);
  45. if (strcmp(cmd, "/createnpc", true) == 0)
  46. {
  47. if(!IsPlayerAdmin(playerid))
  48. {
  49. SendClientMessage(playerid,red," Only Rcon Administrator Can use this command!");
  50. }
  51. else if(IsInNpcMode[playerid] == 1)
  52. {
  53. SendClientMessage(playerid,red," You are already in NPC Mode!");
  54. }
  55. else
  56. {
  57. IsInNpcMode[playerid] = 1;
  58. ShowPlayerDialog(playerid,0,DIALOG_STYLE_MSGBOX,"Npc Creator","Hello and welcome to the NPC Creator.\nUsing this NPC Creator, creating a NPC will be very simple.\nPlease follow all the steps, so you can create your own NPC.\nClick 'Ok' to proced to the NPC Creator and 'Exit' to exit the NPC Creator.","Ok","Exit");
  59. }
  60. return 1;
  61. }
  62. if (strcmp(cmd, "/sr", true) == 0)
  63. {
  64. if(IsInNpcRecordMode[playerid] == 0)
  65. {
  66. return 1;
  67. }
  68. else if(IsInNpcRecordMode[playerid] == 1)
  69. {
  70. ShowPlayerDialog(playerid,6,DIALOG_STYLE_MSGBOX,"Step 5","Step 5:\nYour NPC is Created.\nClick on ' Done ' to exit or on ' More '\nto create another NPC.","Done","More");
  71. StopRecordingPlayerData(playerid);
  72. IsInNpcRecordMode[playerid] = 0;
  73. }
  74. return 1;
  75. }
  76. return 0;
  77. }
  78. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  79. {
  80. new string[248];
  81. new idx;
  82. new tmp[256];
  83. tmp = strtok(inputtext, idx);
  84. new skin = strval(tmp);
  85. new weapon = strval(tmp);
  86. if(dialogid == 0)
  87. {
  88. if(response)
  89. {
  90. ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Step 1","Step 1:\nSelect your NPC Mode.\nIf you want to exit, click ' Exit '.","On Foot","Exit");
  91. }
  92. else
  93. {
  94. IsInNpcMode[playerid] = 0;
  95. SendClientMessage(playerid,royalblue," You've exited the NPC Creator.");
  96. }
  97. }
  98. else if(dialogid == 1)
  99. {
  100. if(response)
  101. {
  102. format(string,sizeof(string),"Write below your NPC Skin ID then click ' Use Skin '.\nTo return back, click on ' Back '");
  103. ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Step 2",string,"Use Skin","Back");
  104. }
  105. else
  106. {
  107. IsInNpcMode[playerid] = 0;
  108. SendClientMessage(playerid,royalblue," You've exited the NPC Creator.");
  109. }
  110. }
  111. else if(dialogid == 2)
  112. {
  113. if(response)
  114. {
  115. if(skin < 0 || skin > 289 || IsInvalidSkin(skin))
  116. {
  117. format(string,sizeof(string),"The Skin ID you did inserted is invalid.\n Try an other skin.");
  118. ShowPlayerDialog(playerid,3,DIALOG_STYLE_INPUT,"Step 2",string,"Use Skin","Back");
  119. }
  120. else
  121. {
  122. SetPlayerSkin(playerid,skin);
  123. format(string,sizeof(string),"Skin ID Selected! \nStep 3: Write down an Weapon ID for your NPC.\n If you want no weapon, click on ' No Weapon '.");
  124. ShowPlayerDialog(playerid,4,DIALOG_STYLE_INPUT,"Step 3",string,"Select","No Weapon");
  125. }
  126. }
  127. else
  128. {
  129. ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Step 1","Step 1:\nSelect your NPC Mode.\nIf you want to exit, click ' Exit '.","On Foot","Exit");
  130. }
  131. }
  132. else if(dialogid == 3)
  133. {
  134. if(response)
  135. {
  136. if(skin < 0 || skin > 289 || IsInvalidSkin(skin))
  137. {
  138. format(string,sizeof(string),"The Skin ID you did inserted is invalid.\n Try an other skin.");
  139. ShowPlayerDialog(playerid,3,DIALOG_STYLE_INPUT,"Step 2",string,"Use Skin","Back");
  140. new bigstring[456];
  141. new string2[256];
  142. format(bigstring,sizeof(bigstring),"#include <a_npc>\n\n\n\nmain() {}\n\n\n\nNextPlayBack()\n{\n StartRecordingPlayback(PLAYER_RECORDING_TYPE_ONFOOT,NPC);\n}\n\npublic OnRecordingPlaybackEnd()\n{\n NextPlayBack();\n}\npublic OnNPCSpawn()\n{\n NextPlayBack();\n}\npublic OnNPCExitVehicle()\n{\n StopRecordingPlayback();\n}");
  143. format(string2,sizeof(string2),"NPC.pwn");
  144. new File: PwnFile;
  145. PwnFile = fopen(string2,io_write);
  146. fwrite(PwnFile,bigstring);
  147. fclose(PwnFile);
  148. }
  149. else
  150. {
  151. SetPlayerSkin(playerid,skin);
  152. format(string,sizeof(string),"Skin ID Selected! \nStep 3: Write down an Weapon ID for your NPC.\n If you want no weapon, click on ' No Weapon '.");
  153. ShowPlayerDialog(playerid,4,DIALOG_STYLE_INPUT,"Step 3",string,"Use Weapon","No Weapon");
  154. new bigstring[456];
  155. new string2[256];
  156. format(bigstring,sizeof(bigstring),"#include <a_npc>\n\n\n\nmain() {}\n\n\n\nNextPlayBack()\n{\n StartRecordingPlayback(PLAYER_RECORDING_TYPE_ONFOOT,NPC);\n}\n\npublic OnRecordingPlaybackEnd()\n{\n NextPlayBack();\n}\npublic OnNPCSpawn()\n{\n NextPlayBack();\n}\npublic OnNPCExitVehicle()\n{\n StopRecordingPlayback();\n}");
  157. format(string2,sizeof(string2),"NPC.pwn");
  158. new File: PwnFile;
  159. PwnFile = fopen(string2,io_write);
  160. fwrite(PwnFile,bigstring);
  161. fclose(PwnFile);
  162. }
  163. }
  164. else
  165. {
  166. ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Step 1","Step 1:\nSelect your NPC Mode Bettwen ' On Foot ' and ' On Vehicle '.","On Foot","On Vehicle");
  167. }
  168. }
  169. else if(dialogid == 4)
  170. {
  171. if(response)
  172. {
  173. if(weapon < 0 || weapon > 46)
  174. {
  175. format(string,sizeof(string),"The Weapon ID you did inserted is invalid.\n Try an other Weapon.");
  176. ShowPlayerDialog(playerid,4,DIALOG_STYLE_INPUT,"Step 3",string,"Use Weapon","Back");
  177. }
  178. else
  179. {
  180. ResetPlayerWeapons(playerid);
  181. GivePlayerWeapon(playerid,weapon,9999999);
  182. format(string,sizeof(string),"Weapon ID Selected! \nStep 4: Write down the File Name for the NPC.\n Once you will click ' Save ', the record will start.\n Click on ' Back ' to go Back.");
  183. ShowPlayerDialog(playerid,5,DIALOG_STYLE_INPUT,"Step 4",string,"Save","Back");
  184. new bigstring[456];
  185. new string2[256];
  186. format(bigstring,sizeof(bigstring),"#include <a_npc>\n\n\n\nmain() {}\n\n\n\nNextPlayBack()\n{\n StartRecordingPlayback(PLAYER_RECORDING_TYPE_ONFOOT,NPC);\n}\n\npublic OnRecordingPlaybackEnd()\n{\n NextPlayBack();\n}\npublic OnNPCSpawn()\n{\n NextPlayBack();\n}\npublic OnNPCExitVehicle()\n{\n StopRecordingPlayback();\n}");
  187. format(string2,sizeof(string2),"NPC.pwn");
  188. new File: PwnFile;
  189. PwnFile = fopen(string2,io_write);
  190. fwrite(PwnFile,bigstring);
  191. fclose(PwnFile);
  192. new bigstring2[456];
  193. new string3[256];
  194. format(bigstring2,sizeof(bigstring2),"Add This To Your GameMode Under OnPlayerSpawn: \nif(!IsPlayerNpc(playerid)) retunrn 0;\nSetPlayerSkin(playerid,%d);\nGivePlayerWeapon(playerid,%d);",skin,weapon);
  195. format(string3,sizeof(string3),"AddMeToYourGM.txt");
  196. new File: OtherFile;
  197. OtherFile = fopen(string2,io_write);
  198. fwrite(OtherFile,bigstring);
  199. fclose(OtherFile);
  200. }
  201. }
  202. else
  203. {
  204. ResetPlayerWeapons(playerid);
  205. format(string,sizeof(string),"Weapon ID Selected! \nStep 4: Write down the File Name for the NPC.\n Once you will click ' Save ', the record will start.\n Click on ' Back ' to go Back.");
  206. ShowPlayerDialog(playerid,5,DIALOG_STYLE_INPUT,"Step 4",string,"Save","Back");
  207. new bigstring[456];
  208. new string2[256];
  209. format(bigstring,sizeof(bigstring),"#include <a_npc>\n\n\n\nmain() {}\n\n\n\nNextPlayBack()\n{\n StartRecordingPlayback(PLAYER_RECORDING_TYPE_ONFOOT,NPC);\n}\npublic OnRecordingPlaybackEnd()\n{\n NextPlayBack();\n}\npublic OnNPCSpawn()\n{\n NextPlayBack();\n}\npublic OnNPCExitVehicle()\n{\n StopRecordingPlayback();\n}");
  210. format(string2,sizeof(string2),"NPC.pwn");
  211. new File: PwnFile;
  212. PwnFile = fopen(string2,io_write);
  213. fwrite(PwnFile,bigstring);
  214. fclose(PwnFile);
  215. }
  216. }
  217. else if(dialogid == 5)
  218. {
  219. if(response)
  220. {
  221. if(!strlen(inputtext))
  222. {
  223. format(string,sizeof(string),"Missed File Name. Please Write a Name:");
  224. ShowPlayerDialog(playerid,4,DIALOG_STYLE_INPUT,"Step 3",string,"Save","Back");
  225. }
  226. else
  227. {
  228. IsInNpcRecordMode[playerid] = 1;
  229. SendClientMessage(playerid,royalblue," Record Started! Write /sr to stop it.");
  230. StartRecordingPlayerData(playerid,PLAYER_RECORDING_TYPE_ONFOOT,inputtext);
  231. }
  232. }
  233. else
  234. {
  235. format(string,sizeof(string),"Skin ID Selected! \nStep 3: Write down an Weapon ID for your NPC.\n If you want no weapon, click on ' No Weapon '.");
  236. ShowPlayerDialog(playerid,4,DIALOG_STYLE_INPUT,"Step 3",string,"Use Weapon","No Weapon");
  237. }
  238. }
  239. else if(dialogid == 6)
  240. {
  241. if(response)
  242. {
  243. IsInNpcMode[playerid] = 0;
  244. SendClientMessage(playerid,royalblue," NPC Was successfuly created.Check your ' scriptfiles ' folder for more informations.");
  245. SendClientMessage(playerid,royalblue," To create another NPC, use /createnpc.");
  246. }
  247. else
  248. {
  249. ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Step 1","Step 1:\nSelect your NPC Mode.\nIf you want to exit, click ' Exit '.","On Foot","Exit");
  250. }
  251. }
  252. return 1;
  253. }
  254. IsInvalidSkin(skinid)
  255. {
  256. #define MAX_BAD_SKINS 22
  257. new InSkin[MAX_BAD_SKINS] = {
  258. 0, 3, 4, 5, 6, 8, 42, 65, 74, 86,
  259. 119, 149, 208, 273, 289};
  260. for (new i = 0; i < MAX_BAD_SKINS; i++) {
  261. if (skinid == InSkin[i]) return true;}
  262. return 0;
  263. }
  264. stock strtok(const string[], &index,seperator=' ')
  265. {
  266. new length = strlen(string);
  267. new offset = index;
  268. new result[128];
  269. while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
  270. {
  271. result[index - offset] = string[index];
  272. index++;
  273. }
  274. result[index - offset] = EOS;
  275. if ((index < length) && (string[index] == seperator))
  276. {
  277. index++;
  278. }
  279. return result;
  280. }