Opening and using the inventory while talking

Started by The Creator, Fri 18/01/2013 19:50:17

Previous topic - Next topic

The Creator

Hello, i want to be able to talk to a character and while still talking being able to open the inventory and select an item to give to the NPC. Pretty similar to what you do in the Ace Attorney games when you have to present some kind of evidence.

Is it possible to command the inventory through script, while talking, and still be possible for the player to use normally?

The Creator

By using the function show_inventory_window (), i was able to open the window mid-dialog but after opening it, the game remains paused and you cannot select any items or buttons. Since the function already sets the mouse in interact mode (mouse.Mode = eModeInteract) i thought that the mouse would behave like normally, but it does not.

Any suggestions?

Khris

You can try the setting in General settings -> Dialog: "Run game loops while dialog options are displayed".

Also note that in case you're processing inventory clicks yourself using eMouseLeft/RightInv, on_mouse_click doesn't do anything if IsGamePaused() == true, which could well be the case while the Dialog GUI is displayed.

MurrayL

#3
The alternative method is to have a 'give item' option that exits the dialog, stores the character you're talking to (global Character*), and shows a separate inventory window (which may look identical to the normal one, if you want it to be consistent/undetectable).

When you click an item in this GUI, it sets the active inventory and a global 'talkAbout' boolean, and runs a function to interact with the stored character. The 'on use inventory' function for the character then needs to check for the 'talkAbout' boolean (so it knows whether or not you're trying to use the item on them outside of a dialog) and react appropriately (hiding the inventory GUI). This interaction will be your standard inventory use structure (if player.activeinventory==iInterestingItem then...).
After whatever the interaction involves, set 'talkAbout' back to false and resume the dialog where you left off.

Code: AGS

// In the dialog script, when you click the '[Show Item]' option
option 6:
Ego: Let me show you something...
    gcInventory_TalkAbout.visible = true;
    storedChar = cfriendlyMan;
stop


Code: AGS

// Global script

function gcInventory_TalkAbout_Items_OnClick(){ // Clicked an inventory item in the custom GUI
    gInventory_TalkAbout.visible=false;
    talkAbout = true;
    storedChar.RunInteraction(eModeUseInv);
}

function friendlyMan_UseInv(){
    if(talkAbout){
        if(player.ActiveInventory == iInterestingObject){
            player.Say("Look at this!");
            friendlyMan.Say("My my, that is interesting!");
        }
        
        talkAbout = false;
        dFriendlyTalk.Start(); // Resume the dialog at this point - if there is more than one, you'll have to store which one was active, as with storedChar
    }else{
        // Player is trying to actually use an item on this guy
    }
}

function gcInventory_TalkAbout_Cancel_OnClick(){ // Allow player to cancel the show action, and go straight back to the dialog
    gInventory_TalkAbout.visible=false;
    player.Say("Actually, never mind.");
    dFriendlyTalk.Start();
}

The Creator

I've created a copy of inventory and i'm calling it like you suggested. Problem is when i select the item, after the cursors changes into the lil' version of the item, i click the ok button (that calls the useInv function on the npc) and nothing happens. Do i have to specify something else? If i use the key on the npc the dialogue i specified for that interaction (which is different from the one it is supposed to appear if you give the item while talking) is triggered and it shows normally =S.

The Creator

I managed to find the problem. When i was onClick Event for the OK button my call to the function was using brackets () and it's supposed not to. I have another problem now, whenever the function is called the game crashes and i got this message:



I don't understand why those 2 parameters are being passed. I'm not passing any parameters at all.

I tried creating a new button (without copying anything) but i still got that error message.

Khris

Sounds like you put "cNpc_UseInv" in a button's onClick event field.
If you do that, you have to declare the function like this:

Code: ags
function cNpc_UseInv(GUIControl* control, MouseButton button) {


However, it will now no longer work for the character's "use inv on" event, and its name isn't really accurate any longer.

Here's a better way:
Create a second function for the button, and call the other one inside:

Code: ags
function buttonName_onClick(GUIControl* control, MouseButton button) {
  cNpc_UseInv();
}


Make sure it is below cNpc_UseInv() in the global script, otherwise it won't "see" it.

The Creator

Thanks a lot.

It worked beautifully. I've already been able to open the inventory, select an item and gave it to the npc, while triggering a short conversation and making available a new option on the original conversation.
All that while using my custom dialog modifications. :D

SMF spam blocked by CleanTalk