Hallo everybody and sorry for my very poor english.
I have a problem when i try to use an inventory item with any other thing (characters, hotspot, object...)
Seems like AGS doesn't recognise the item selected by the player.
For example, I try to give an apple to someone and I want him to answer "Thank you", otherwise,
if I give him any other inventory item, I'll have the answer written in unhandled event function,
for example "bad idea".
function cPescatore_UseInv()
{
if (cLaura.ActiveInventory==iApple){
cPescatore.Say("Thank you!");
cLaura.LoseInventory(iApple);
}
else unhandled_event(3, 3);
}
AGS always answer with the unhandled function "bad idea", even if I give the apple to the NPG...
I solved the problem adding, at the beginning of the function, the code:
player.ActiveInventory = inventory[game.inv_activated];
and it works fine now, but I don't understand why i have to write that line for every Use_Inv function
in order to make it works!
This is my code for on_mouse_click:
function on_mouse_click(MouseButton button)
{
//....here there is the 'eMouseLeft and Right' button code, then:
else if ((button == eMouseLeftInv)&&(mouse.Mode != eModeLookat)&&(player.ActiveInventory == null)) {
player.ActiveInventory = inventory[game.inv_activated];
Mouse.ChangeModeGraphic(eModeUseinv,inventory[game.inv_activated].Graphic);
Mouse.Mode = eModeUseinv;
}
else if ((button == eMouseLeftInv)&&(mouse.Mode == eModeLookat)) {
inventory[game.inv_activated].RunInteraction(eModeLookat);
}
else if ((button == eMouseLeftInv)&&(mouse.Mode == eModeUseinv)&&(player.ActiveInventory != null)) {
player.ActiveInventory.RunInteraction(eModeUseinv);
}
else if ((button == eMouseRightInv)&&(player.ActiveInventory != null)) {
player.ActiveInventory = null;
}
else {
//player.ActiveInventory = inventory[game.inv_activated];
player.ActiveInventory=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
mouse.Mode=eModeUseinv;
}
}
Can anyone help me?
You shouldn't have to do all that extra code; when you change player.ActiveInventory, eModeUseinv becomes the active mode and it should also use the correct graphic by default.
Try this code in on_mouse_click
function on_mouse_click(MouseButton button) {
InventoryItem* ia = inventory[game.inv_activated];
InventoryItem* ai = player.ActiveInventory;
... // left / right click handling
else if (button == eMouseLeftInv) {
if (ai == ia) return; // do nothing if item used on self
if (mouse.mode == eModeInteract) player.ActiveInventory = ia; // "pick up" item
else ia.RunInteraction(mouse.mode);
}
else if (button == eMouseRightInv) {
if (ai != null) player.ActiveInventory = null; // "drop" item
// else change mode to eModeInteract / next mode / call lookat?
}
Thank you Khris for your reply.
It work perfectly now for every Use_inv function on other things like NPC or objects.
But the problem for using an inventory item on another one is still the same:
Ags answer me using the unhundled function instead of combining the items.
Here is an example of the code I use for combining two items, Ags seems to ignore all the 'if lines', using only the last one,
even if I use 'iPesce' on 'iSonnifero':
function iPesce_UseInv()
{
if (cLaura.ActiveInventory==iSonnifero){
cLaura.LoseInventory(iPesce);
cLaura.LoseInventory(iSonnifero);
cLaura.AddInventory(iPesceSonn);
Display("Hai aggiunto il sonnifero al pesce.");
}
else unhandled_event(5, 3);
}
I don't think that code is wrong...
Maybe should I add any other code lines in my on_mouse_click function to solve this?
Thank you in advance for any useful reply!
Since it works for everything else now, and I assume that cLaura is actually the player character, the problem must be something else.
The code you posted is only called if you use iSonnifero on iPesce, not iPesce on iSonnifero.
When you add the "use inv" event code to item A, you're telling the game what to do if some item is used on A, not what to do if you use item A on something else.
Hi Khris, thank you for your reply!
:) Now i'm feeling a little bit stupid :-D
You're right! I forgot to write that code for the other item too!
Everything works fine now.
I'm a very beginner with AGS :)
Great, you're welcome :)