Sign in to follow this  
Boomray

Menu

Recommended Posts

Posted (edited)

Hello,
 

I want to create an inventory system.

 

mp.events.addCommand("inventory", (player) => {
    gm.mysql.handle.query('SELECT * FROM items', [], function (error, results, fields) {
		for(let i = 0; i < results.length; i++) {
		if(results[i].owner == player.name)
		{
		player.call("Inv", [player,results[i].name);
		player.call("Inventory", [player, "test"]);
		}
	}
	});
	
	
	
});

This is the Command to call the Inventory.


And this the Inventory:


 

mp.events.add({
	"Inv": (player,name) => {

		inventory.AddItem(Inv = new UIMenuItem(""+name,""));

			
	
	
	}
});

 

Every time I go to the menu, the same menu items are created again.

Have anyone a solution?

 

Thanks.

 

Greetings Boomray

 
Edited by Boomray

Share this post


Link to post
Share on other sites

Well you should think in general about what you want to do here. Why do you fetch all results in Database ans WHILE fetching you check if the item is for the player? Also do you think its a good idea to always make a direct mysql interaction everytime somebody opens inventory? Why not caching in a player variable? There is to less code to help you out but i guess you always overwrite the inventory . You have to set a variable on client side above your function and let the function fill it. But as i said i wouldn't do it this way

 

Share this post


Link to post
Share on other sites

Ok thanks.

I have found this, and will try to use it:

 
My Server-Side Code: 

mp.events.addCommand("inventory", (player) => {
    const inventory = player.getInventory();

    player.outputChatBox("Your inventory:");
    inventory.forEach((item, index) => {
		player.call("Inv", [player,invAPI.getItemName(item.key)]);
		player.call("Inventory", [player, "test"]);
    });
});


and the Client-Side Code:

 

mp.events.add({
	"Inv": (player,name) => {

		inventory.AddItem(inventor = new UIMenuItem(""+name,""));

			
	
	
	}
});

mp.events.add({
	"Inventory": (player) => {
		if (playerMenu.Visible |
			inventory.Visible) {
			pMenus.forEach(function(element, index, array){element.Close()});
		} else {
			
			inventory.Open();
			mp.gui.chat.show(false);
			mp.gui.cursor.visible = false;
		}
	}
});
What I have to do so that the "AddItems" do not always recreate?

Greetings Boomray

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.