I have a second inventory added to dummy character. There are some items in it, but when I click on any item, it gives me this message: Error: SetActiveInventory: character doesn´t have any of that inventory. I understand I should probably chcek the "handle inventory clicks in script" but i dunno what to do after i check it. I simply want a script to run after i click on the inventory items in the second inventory.
TY
I'd say, based on that error message, that the problem is caused when you try to use eModeInteract on the items in the second inventory. By default that'll set player's the ActiveInventory, obviously giving you the error you're getting if the player doesn't have the item - and potentially causing weirdness if they do, switching their ActiveInventory at the wrong times. Other cursor modes should work, though, so how is your dummy inventory set up - is it possible to just not allow the player to use eModeInteract on it? If so, that's probably the easiest way to go.
If not - if it's displayed on the same GUI as the player's inventory, for example - then yes, you're probably going to have to use 'Handle inventory clicks in script". What you do then, depends on what you what to happen. I think this code, pasted into on_mouse_click, will match the way it works by default, minus the crashing
if (button == eMouseLeftInv) {
InventoryItem *InvAt = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (mouse.Mode != eModeInteract) InvAt.RunInteraction(mouse.Mode);
else {
GUIControl *tempGC = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
InvWindow *InvOver = tempGC.AsInvWindow;
if (InvOver.CharacterToUse == player || InvOver.CharacterToUse == null) player.ActiveInventory = InvAt;
// CharacterToUse = null means the InvWindow follows the player character if you change them in-game, rather than sticking with a specific char
}
}
else if (button == eMouseRightInv) {
InventoryItem *InvAt = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
InvAt.RunInteraction(eModeLookat);
}
(Works for me, under very quick testing...)
EDIT:
To add 'right-click = Look', which I'd forgotten about...
Question to other AGSers:
That else seems a little clunky, but there doesn't seem to be an InvWindow.GetAtScreenXY that you could use to simplify it. Am I missing something?
Thank you. Your first suggestion solved it. But I will also try the second one only to get better in scripting. THX!
The most basic way to handle this is to set the player character to the dummy, but this can have ramifications such as changing the room, but can also be easily worked around. A very easily solution is to use the same view for both characters.
Guy: InvWindow.GetAt can be done with GUIControl.GetAt and .AsType. You could even script and extender if you plan on using it often.
~Trent
Quote
InvWindow.GetAt can be done with GUIControl.GetAt and .AsType
That's the way I did it in that code, surely? If you try to compress it down to
InvOver = GUIControl.GetAtScreenXY(mouse.x, mouse.y).AsInvWindow; there's an error, so you need both lines (GUIControl and InvWindow) - which is why I called it clunky :)
I played around with the extender function idea, but it seemed overly complicated for this case...
About your other suggestions:
Quote
set the player character to the dummy
You mean set the dummy character as the player before interacting with their inventory (avoiding the 'character doesn't have item' error), then switch it back afterwards? That'd work if the dummy inventory is on a separate GUI that has to be opened and closed, but not if the dummy and player shared a GUI (which, OK, it sounds like they don't), or if the dummy inventory was always on display. I don't see that would have ramifications for changing rooms, but it might complicate other things. Or have I missed your meaning?
Quote
use the same view for both characters
I don't see what the view has to do with inventories?
EDIT after KhrisMUC's post:
Unless you were thinking along similar lines, and the 'same view' suggestion is to hide the dummy character? Actually, if you're thinking of the dummy character as shadowing the player, the bit about changing rooms makes sense now as well... But unless there's a need for the dummy to be following the player, I still think the GUI manipulation or 'handle clicks in script' options are easier. Well, less chance of unforeseen complications, at any rate.
A feasible way would be to have the dummy character follow the player character like shadow using the special setting and making him invisible.
The player character could then be set back to the original character after the interaction, in rep_ex.
It might indeed still complicate things in special situations though.