Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory sending #232

Closed
ItsSachan opened this issue Aug 28, 2023 · 11 comments
Closed

Inventory sending #232

ItsSachan opened this issue Aug 28, 2023 · 11 comments
Labels
question Further information is requested

Comments

@ItsSachan
Copy link

How can we send same inventory to different player but the inside content that first user saved can only be seen by him if other open he sees his placed items

@Muqsit
Copy link
Owner

Muqsit commented Aug 28, 2023

Use a listener to handle transactions occurring within the menu.

$menu->setListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{
	$player = $transaction->getPlayer();
	if(/* $player is not allowed */){
		return $transaction->discard();
	}
	return $transaction->continue();
});

@Muqsit Muqsit added the question Further information is requested label Aug 28, 2023
@ItsSachan
Copy link
Author

ItsSachan commented Aug 28, 2023

It is not working
https://github.com/inxomnyaa/Backpack/tree/master like this when we interact with different it opens different inventory but the whole code is same

@Muqsit
Copy link
Owner

Muqsit commented Aug 28, 2023

Can you clarify what's not working exactly?

@ItsSachan
Copy link
Author

yep it was sending same inv

@Muqsit
Copy link
Owner

Muqsit commented Aug 28, 2023

Menus can be sent to multiple players, you must store the menu instance in memory to pass it around.

@ItsSachan
Copy link
Author

Menus can be sent to multiple players, you must store the menu instance in memory to pass it around.

You mean in that player game it should store?

@Muqsit
Copy link
Owner

Muqsit commented Aug 29, 2023

Store it within the plugin temporarily, in an array. https://github.com/BlockHorizons/InvSee as an example allows permission-based control over player inventories in real-time.

@Muqsit
Copy link
Owner

Muqsit commented Aug 29, 2023

If you want to send the same menu with different inventories, it is not possible. You'd need to create a different menu for each inventory. Plugins usually construct a new menu at request: https://github.com/search?q=InvMenu%3A%3Acreate+language%3APHP&type=code

If you want to send the same menu to multiple players, you may want to cache the menu somewhere in memory so you retain an instance to the menu. InvMenu::send() lets you send the same menu to different players.

$menu = InvMenu::create(InvMenu::TYPE_CHEST);
$menu->send($player1);
$menu->send($player2);

// allow only $player1 to make changes
$menu->setListener(function(InvMenuTransaction $transaction) use($player1) : InvMenuTransactionResult{
	$player = $transaction->getPlayer();
	if($player === $player1){
		return $transaction->continue();
	}
	return $transaction->discard();
});

@ItsSachan
Copy link
Author

ItsSachan commented Aug 30, 2023

How can we full whole gui with one line code and also add some item in particular slots

@ItsSachan
Copy link
Author

Please reply

@Muqsit
Copy link
Owner

Muqsit commented Aug 30, 2023

How can we full whole gui with one line code and also add some item in particular slots

Why not just write a function that builds a menu?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants