Advertisement
Seregamil

DYM_ENG

Apr 4th, 2013
1,978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. #include <a_samp>
  2. #include mxINI
  3.  
  4. new WeaponNames[47][] = {
  5. "Unarmed","Brass Knuckless","Golf Club","Night Stick","Knife","Basketball Bat","Shovel","Pool Cue",
  6. "Katana","Chainsaw","Purple Dildo","White Dildo","Long White Dildo","White Dildo 2","Flowers","Cane",
  7. "Grenades","Tear Gas","Molotovs","Missle1","Missle2","Missle3","Pistol","Silenced Pistol","Desert Eagle","Shotgun",
  8. "Sawn Off Shotgun","Combat Shotgun","Micro UZI","MP5","AK-47","M4","Tec9","Rifle","Sniper Rifle","RPG",
  9. "Rocket Launcher","Flame Thrower","Minigun","Sachet Chargers","Detonator","Spry Paint","Fire Extinguer",
  10. "Camera","Nightvision Goggles","Thermal Goggles","Parachute"};
  11.  
  12. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  13.  
  14. #define MAX_ITEMS 60
  15. #define MAX_PLAYER_ITEM 20
  16.  
  17. new item[MAX_PLAYERS][MAX_ITEMS];
  18. new used[MAX_PLAYERS];
  19. new np[MAX_PLAYERS][MAX_ITEMS];
  20. new npname[MAX_ITEMS][100];
  21. new ida[MAX_ITEMS];
  22. new loading[MAX_ITEMS];
  23.  
  24. main()
  25. {
  26. print("\n----------------------------------");
  27. print(" Dynamic Inventory system by Seregamil");
  28. print("----------------------------------\n");
  29. }
  30.  
  31.  
  32. public OnGameModeInit()
  33. {
  34. for(new i;i!=47;i++) format(npname[i],100,"%s",WeaponNames[i])/*,printf("NAME: %s | ID: %d",WeaponNames[i],i)*/;
  35. return 1;
  36. }
  37.  
  38. addItem(playerid,id,name[],value)
  39. {
  40. if(GetPVarInt(playerid,name) != 0) SetPVarInt(playerid,name,GetPVarInt(playerid,name)+value);
  41. else SetPVarInt(playerid,name,value);
  42. new str[128];
  43. format(str,128,"{a3ff00}%s {ffffff}have been updated in the inventory. {a3ff00}[%d]",name,GetPVarInt(playerid,name));
  44. SendClientMessage(playerid,-1,str);
  45. item[playerid][id]+=value;
  46. used[playerid]++;
  47. np[playerid][id] = GetPVarInt(playerid,name);
  48. }
  49.  
  50. removeItem(playerid,name[],id)
  51. {
  52. SetPVarInt(playerid,name,0);
  53. new str[128];
  54. format(str,128,"{a3ff00}%s{ffffff} were removed from the inventory",npname[id]);
  55. SendClientMessage(playerid,-1,str);
  56. item[playerid][id]=0;
  57. used[playerid]--;
  58. np[playerid][id] = 0;
  59. }
  60.  
  61. infoAllItem(playerid)
  62. {
  63. new str[300];
  64. for(new q;q!=MAX_ITEMS;q++) ida[q]=0;
  65. for(new i;i!=MAX_ITEMS;i++)
  66. {
  67. if(item[playerid][i]!=0)
  68. {
  69. format(str,sizeof(str),"{ffffff}%s%s | {a3ff00}%d\n",str, npname[i],np[playerid][i]);
  70. ida[i] = 1;
  71. }
  72. }
  73. ShowPlayerDialog(playerid,15,DIALOG_STYLE_LIST," ",str,"Okay","");
  74. return 1;
  75. }
  76.  
  77. funcItem(playerid,id)
  78. {
  79. new name[24];
  80. GetPlayerName(playerid,name,24);
  81. new str1[100];
  82. format(str1,100,"{a3ff00}]%s[ {ffffff}subject {a3ff00}[%s {ffffff}| {a3ff00}%d]",name,npname[id],np[playerid][id]);
  83. ShowPlayerDialog(playerid,22,DIALOG_STYLE_LIST,str1,"Use\nSend\nDrop","Âûáîð","Îòìåíà");
  84. SetPVarInt(playerid,"Clicked",id);
  85. }
  86.  
  87. public OnPlayerConnect(playerid)
  88. {
  89. for(new x;x!=MAX_ITEMS;x++) item[playerid][x] = 0,np[playerid][x] = 0;
  90. used[playerid] = 0;
  91. loadInt(playerid);
  92. return 1;
  93. }
  94.  
  95. loadInt(playerid)
  96. {
  97. for(new q;q!=MAX_ITEMS;q++) loading[q] = 0;
  98. new name[24];
  99. GetPlayerName(playerid,name,24);
  100. new str[100];
  101. format(str,100,"inventory/%s.ini",name);
  102. if(!fexist(str))
  103. {
  104. new file = ini_createFile(str);
  105. if(file<0) ini_openFile(str);
  106. for(new x;x!=MAX_ITEMS;x++)
  107. {
  108. new str2[100];
  109. format(str2,100,"Inv%d",x);
  110. ini_setInteger(playerid,str2,0);
  111. }
  112. ini_closeFile(file);
  113. }
  114. else
  115. {
  116. new file = ini_openFile(str);
  117. for(new x;x!=MAX_ITEMS;x++)
  118. {
  119. new str2[100];
  120. format(str2,100,"Inv%d",x);
  121. ini_getInteger(playerid,str2,loading[x]);
  122. if(loading[x] != 0) addItem(playerid,x,npname[x],loading[x]);
  123. }
  124. ini_closeFile(file);
  125. }
  126. }
  127.  
  128. public OnPlayerDisconnect(playerid, reason)
  129. {
  130. saveInt(playerid);
  131. for(new x;x!=MAX_ITEMS;x++) item[playerid][x] = 0,np[playerid][x] = 0;
  132. used[playerid] = 0;
  133. return 1;
  134. }
  135.  
  136. saveInt(playerid)
  137. {
  138. new name[24];
  139. GetPlayerName(playerid,name,24);
  140. new str[100];
  141. format(str,100,"inventory/%s.ini",name);
  142. if(fexist(str))
  143. {
  144. new file = ini_openFile(str);
  145. for(new x;x!=MAX_ITEMS;x++)
  146. {
  147. new str2[100];
  148. format(str2,100,"Inv%d",x);
  149. ini_setInteger(playerid,str2,item[playerid][x]);
  150. removeItem(playerid,npname[x],x);
  151. }
  152. ini_closeFile(file);
  153. }
  154. }
  155.  
  156. public OnPlayerCommandText(playerid, cmdtext[])
  157. {
  158. dcmd(add,3,cmdtext);
  159. dcmd(info,4,cmdtext);
  160. return 0;
  161. }
  162.  
  163. dcmd_add(playerid,params[])
  164. {
  165. #pragma unused params
  166. if(used[playerid] == MAX_PLAYER_ITEM) return SendClientMessage(playerid,-1,"MAX");
  167. if(GetPlayerWeapon(playerid)!=0) addItem(playerid,GetPlayerWeapon(playerid),WeaponNames[GetPlayerWeapon(playerid)],GetPlayerAmmo(playerid));
  168. RemovePlayerWeapon(playerid, GetPlayerWeapon(playerid));
  169. return 1;
  170. }
  171.  
  172. RemovePlayerWeapon(playerid, weaponid)
  173. {
  174. if(!IsPlayerConnected(playerid) || weaponid < 0 || weaponid > 50) return;
  175. new saveweapon[13], saveammo[13];
  176. for(new slot = 0; slot < 13; slot++) GetPlayerWeaponData(playerid, slot, saveweapon[slot], saveammo[slot]);
  177. ResetPlayerWeapons(playerid);
  178. for(new slot; slot < 13; slot++)
  179. {
  180. if(saveweapon[slot] == weaponid || saveammo[slot] == 0) continue;
  181. GivePlayerWeapon(playerid, saveweapon[slot], saveammo[slot]);
  182. }
  183. GivePlayerWeapon(playerid, 0, 1);
  184. }
  185.  
  186. dcmd_info(playerid,params[])
  187. {
  188. #pragma unused params
  189. infoAllItem(playerid);
  190. return 1;
  191. }
  192.  
  193. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  194. {
  195. if(dialogid == 15)
  196. {
  197. if(response)
  198. {
  199. new listid = 0;
  200. for(new i;i!=MAX_ITEMS;i++)
  201. {
  202. if(ida[i] == 1)
  203. {
  204. if(item[playerid][i] != 0)
  205. {
  206. if(listitem!=listid) listid++;
  207. else
  208. {
  209. funcItem(playerid,i);
  210. for(new x;x!=MAX_ITEMS;x++) ida[x]=0;
  211. break;
  212. }
  213. }
  214. }
  215. }
  216. return true;
  217. }
  218. }
  219. if(dialogid == 22)
  220. {
  221. if(!response) return infoAllItem(playerid);
  222. if(response)
  223. {
  224. if(listitem == 0)
  225. {
  226. if(switchItem(GetPVarInt(playerid,"Clicked")) == 0)
  227. {
  228. GivePlayerWeapon(playerid,GetPVarInt(playerid,"Clicked"),item[playerid][GetPVarInt(playerid,"Clicked")]);
  229. removeItem(playerid,npname[GetPVarInt(playerid,"Clicked")],GetPVarInt(playerid,"Clicked"));
  230. SendClientMessage(playerid,-1,"You started using object");
  231. }
  232. }
  233. if(listitem == 1) ShowPlayerDialog(playerid,23,DIALOG_STYLE_INPUT," ","Enter the ID of the player you want to send this item","Îê","Íàçàä");
  234. if(listitem == 2) removeItem(playerid,npname[GetPVarInt(playerid,"Clicked")],GetPVarInt(playerid,"Clicked"));
  235. }
  236. return true;
  237. }
  238. if(dialogid == 23)
  239. {
  240. if(!response) return infoAllItem(playerid);
  241. if(response)
  242. {
  243. new id = strval(inputtext);
  244. if(!IsPlayerConnected(id)) return SendClientMessage(playerid,-1,"INVALID_PLAYERID");
  245. if(id == playerid) return SendClientMessage(playerid,-1,"This is you");
  246. if(used[id] == MAX_PLAYER_ITEM) return SendClientMessage(playerid,-1,"This player is full inventory");
  247. addItem(id,GetPVarInt(playerid,"Clicked"),npname[GetPVarInt(playerid,"Clicked")],np[playerid][GetPVarInt(playerid,"Clicked")]);
  248. new str[256],name[24];
  249. GetPlayerName(playerid,name,24);
  250. format(str,256,"{ffffff}Player {a3ff00}%s {ffffff}gave you the subject {a3ff00}%s [%d]",name,npname[GetPVarInt(playerid,"Clicked")],np[playerid][GetPVarInt(playerid,"Clicked")]);
  251. ShowPlayerDialog(id,24,DIALOG_STYLE_MSGBOX," ",str,"Îê","");
  252. removeItem(playerid,npname[GetPVarInt(playerid,"Clicked")],GetPVarInt(playerid,"Clicked"));
  253. }
  254. return true;
  255. }
  256. return 1;
  257. }
  258.  
  259. switchItem(id)
  260. {
  261. #define WEAPON_ITEM 0
  262. switch(id)
  263. {
  264. case 0..46: return WEAPON_ITEM;
  265. }
  266. return -1;
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement