Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pinfo <- { };
- class Player
- {
- instance = null;
- Password = null;
- Inventory = array(36);
- constructor( player ) {
- pinfo.rawset( player.ID, this );
- this.instance = player;
- }
- }
- function onPlayerJoin( player )
- {
- ClientMessageToAll(player.Name+" joined.",255,255,255);
- player.Cash = 100;
- pinfo[player.ID] <- Player(player);
- }
- function GiveItem(player,item,quantity){
- local e=0;
- for (local i = 0; i <= 35; i++){
- if (pinfo[player.ID].Inventory[i] == null) {
- if (quantity <= 64) {
- pinfo[player.ID].Inventory[i] = item+"|"+quantity;
- quantity = 0;
- break;
- }
- else {
- pinfo[player.ID].Inventory[i] = item+"|"+64;
- quantity -= 64;
- }
- }
- else if ( split(pinfo[player.ID].Inventory[i],"|")[0] == item ) {
- local splitinv = split(pinfo[player.ID].Inventory[i],"|")
- if ( ( splitinv[1].tointeger() + quantity ) <= 64) {
- pinfo[player.ID].Inventory[i] = splitinv[0]+"|"+(splitinv[1].tointeger()+quantity);
- quantity = 0;
- break;
- }
- else if ( splitinv[1].tointeger() < 64 ) {
- quantity -= 64 - splitinv[1].tointeger();
- pinfo[player.ID].Inventory[i] = item+"|"+64;
- }
- }
- else e++;
- }
- if (quantity.tointeger() > 0) print("Not enough space for "+quantity+" more pieces of "+item+".");
- if (e==35) print("No more slots available in "+player.Name+"'s inventory for "+quantity+" pieces of "+item+".");
- }
- function GetInventory(player){
- local y=0,n=0,q=0;
- for (local i = 0; i <= 35; i++){
- if (pinfo[player.ID].Inventory[i]) {
- print( "Item "+split(pinfo[player.ID].Inventory[i],"|")[0]+", "+ split(pinfo[player.ID].Inventory[i],"|")[1] +" pieces." );
- y++;
- q += split(pinfo[player.ID].Inventory[i],"|")[1].tointeger();
- }
- else n++;
- }
- print("Found "+y+" items and "+n+" empty slots. Total stack of "+q+" items.");
- }
- function ClearInventory(player){
- pinfo[player.ID].Inventory = array(36);
- }
- function onPlayerPart( player, reason )
- {
- ClientMessageToAll(player.Name+" left.",255,255,255);
- }
- function onPlayerChat( player, text )
- {
- print( player.Name + ": " + text );
- ClientMessageToAll(player.Name+": "+text,255,255,255);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement