[Solved} How to script double-click to instant transport to different room?

Started by TD2345, Sun 19/11/2023 03:45:11

Previous topic - Next topic

TD2345

Hi,

I'm using AGS 3.6.0 (latest patch), BASS, and Double Click V 1.0 module.

I'm trying to figure out how to script an immediate (or at least as close as one can get) change room when I double click on either a hotspot or an edge.

Seen this done in a few modern games using the engine, but for the life of me unable to figure it out and not been able find any posts on how to programme it with my configuration.

Any help is tremendously appreciated.

Crimson Wizard

Please tell, which exactly part of the above you are stuck with, is that using the double click module, or scripting interaction with a hotspot, or instant change room?


EDIT:
I suppose that the problem here is that AGS hotspots do not provide "on double click event" kind of interaction by default which you could run.
But AGS supports custom "verbs". This is not very obvious, but they may be added by editing existing "Cursor modes", starting with ones called "usermode1" and "usermode2".

I guess this may be done like:
1. Choose one Cursor mode and rename it to "DoubleClk" or else what you think is appropriate.
2. Now for every hotspot that would support double click you may create a event function for this custom event "DoubleClk".
3. When using Double click you determine whether there's a hotspot under mouse, and run "double click" event it:

Code: ags
function on_mouse_click(MouseButton mb)
{
    if (mb = eMouseLeft)
    {
        if (DoubleClick.Event[eMouseLeft])
        {
             LocationType loc = GetLocationType(mouse.x, mouse.y);
             if (loc == eLocationHotspot)
             {
                  Hotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
                  h.RunInteraction(eModeDoubleClk);
             }
        }
    }
}

TD2345

Many thanks for your response.  To answer your first question, I can write a script to leave the room once the PC walks into the designated edge e.g. going to the right edge leads to X room, what I'm not certain on is how to write a script for a hotspot so a double click immediately changes room so they don't have to wait for the PC to walk over. Apologies, I do have some basic follow-up questions.

I've followed step one and renamed the cursor, and I've called the hotspot QuickExit. So going to set up the event, and it takes me to the room script which is below:

Code: ags
function QuickExit_Mode8()
{

}

So my questions are:

1) Where should the code you have provided be going? In the Room script, Global Script DoubleClick script, or TwoClick script?

2) What kind of code should I be inputting in the above function being created so a double click now takes me straight away to a different room? Is it just your regular change room script or is it something else?


Many thanks for your patience.

Khris

I believe you need to take lines 5-13 and put them in the Global Script's on_mouse_click function, inside the eMouseLeft block.
The basic idea is
- player clicks somewhere using the left mouse button
- is it a double click?
  - if yes, run hotspot's mode8 function
  - else: regular behavior

In a hotspot's QuickExit handle you basically just put the ChangeRoom command, yes.

TD2345

Many thanks both for your help on this, glad to say I've successfully managed to implement the double click now into the game thanks to you.

Just in case this might prove useful to anybody in the future who searches for this, here's a quick guide on how to implement using all the fantastic steps provided by others above (please note this has only been tested with the configuration listed in initial post active)

Step 1: a) Choose one Cursor mode and rename it to "DoubleClk" or else what you think is appropriate.
b) Now for every hotspot that would support double click you may create a event function for this custom event "DoubleClk".

Step 2:You need to edit line 163 (or wherever function on_mouse_click is) in the Global Script so it looks like below. I know that the note says all clicks handled by TwoClickHandler script, but ignore that.

Code: ags
// called when a mouse button is clicked
function on_mouse_click(MouseButton button)
{
  {  
  if (DoubleClick.Event[eMouseLeft])
    {
    LocationType loc = GetLocationType(mouse.x, mouse.y);
    if (loc == eLocationHotspot)
      {
        Hotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
        h.RunInteraction(eModeDoubleClk);
      }
    }
  }
  // all clicks handled by TwoClickHandler script
}

Step 3:The TwoClickHandler script has an automatic script to run on a left (interact) or right (look) click on a hotspot. If you're planning on having invisible hotspots (e.g. a PC is walking through the woods rather than a door) then to get rid of the automatic interact/like dialogue, click on the hospot any for each event (interact & look at events) enter the following code:

Code: ags
function QuickExit_Interact() //Quickexit is name of my hotspot, change it to whatever you've called hotspot
{
 Display("");
}

Code: ags
function QuickExit_Look()
{
 Display("");
}

This will mean that the PC won't interact with hotspots and only a double-click on side of screen where hotspot is will automatically transport them to new room. Hope that helps!


SMF spam blocked by CleanTalk