Advertisement
Guest User

a

a guest
Nov 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. pinfo <- { };
  2.  
  3. class Player
  4. {
  5. instance = null;
  6. Password = null;
  7.  
  8. Inventory = array(36);
  9.  
  10. constructor( player ) {
  11. pinfo.rawset( player.ID, this );
  12. this.instance = player;
  13. }
  14. }
  15.  
  16. function onPlayerJoin( player )
  17. {
  18. ClientMessageToAll(player.Name+" joined.",255,255,255);
  19. player.Cash = 100;
  20. pinfo[player.ID] <- Player(player);
  21. }
  22.  
  23. function GiveItem(player,item,quantity){
  24. local e=0;
  25. for (local i = 0; i <= 35; i++){
  26.  
  27. if (pinfo[player.ID].Inventory[i] == null) {
  28. if (quantity <= 64) {
  29. pinfo[player.ID].Inventory[i] = item+"|"+quantity;
  30. quantity = 0;
  31. break;
  32. }
  33. else {
  34. pinfo[player.ID].Inventory[i] = item+"|"+64;
  35. quantity -= 64;
  36. }
  37. }
  38.  
  39. else if ( split(pinfo[player.ID].Inventory[i],"|")[0] == item ) {
  40.  
  41. local splitinv = split(pinfo[player.ID].Inventory[i],"|")
  42.  
  43. if ( ( splitinv[1].tointeger() + quantity ) <= 64) {
  44. pinfo[player.ID].Inventory[i] = splitinv[0]+"|"+(splitinv[1].tointeger()+quantity);
  45. quantity = 0;
  46. break;
  47. }
  48. else if ( splitinv[1].tointeger() < 64 ) {
  49. quantity -= 64 - splitinv[1].tointeger();
  50. pinfo[player.ID].Inventory[i] = item+"|"+64;
  51. }
  52.  
  53.  
  54. }
  55.  
  56. else e++;
  57.  
  58. }
  59. if (quantity.tointeger() > 0) print("Not enough space for "+quantity+" more pieces of "+item+".");
  60. if (e==35) print("No more slots available in "+player.Name+"'s inventory for "+quantity+" pieces of "+item+".");
  61. }
  62.  
  63. function GetInventory(player){
  64. local y=0,n=0,q=0;
  65. for (local i = 0; i <= 35; i++){
  66. if (pinfo[player.ID].Inventory[i]) {
  67. print( "Item "+split(pinfo[player.ID].Inventory[i],"|")[0]+", "+ split(pinfo[player.ID].Inventory[i],"|")[1] +" pieces." );
  68. y++;
  69. q += split(pinfo[player.ID].Inventory[i],"|")[1].tointeger();
  70. }
  71. else n++;
  72. }
  73. print("Found "+y+" items and "+n+" empty slots. Total stack of "+q+" items.");
  74. }
  75.  
  76. function ClearInventory(player){
  77. pinfo[player.ID].Inventory = array(36);
  78. }
  79.  
  80. function onPlayerPart( player, reason )
  81. {
  82. ClientMessageToAll(player.Name+" left.",255,255,255);
  83. }
  84.  
  85. function onPlayerChat( player, text )
  86. {
  87. print( player.Name + ": " + text );
  88. ClientMessageToAll(player.Name+": "+text,255,255,255);
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement