Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: nims on Mon 06/04/2015 13:51:06

Title: MODULE: ObjectInteractions
Post by: nims on Mon 06/04/2015 13:51:06
Hi,

This is a script I've created to simplify the usage of your games for the user. It does automatic object and hotspot interactions with the objects in a room. It also shortens the code you have to use for the events of the objects. When installed, you have a new class called OI, that you can call.

The following code can be used:
Code (ags) Select

//Simple look code
function oCharacterSelector_Look()
{
OI.LookObject(oCharacterSelector, "It looks like a globe. I wonder if I can use it.");
}

//Simple interaction code
function oCharacterSelector_Interact()
{
  OI.UseObject(oCharacterSelector, "I picked up the globe and added it to my inventory",true, iCharacterSelector,false);
}


Set WalkWhenLooking to true, to automatically walk to an object when you look at it.
Set WalkWhenUsing to true, to automatically walk to an object when you look at it.

LookObject() walks towards an object and says the text
UseOnbject() walks towards the object and uses it.

Set AutoView to true, to automatically call the "view" event of the object when the user walks to it.
Set AutoUse to true, to automatically call the "use" event of the object when the user walks to it.

Note! To enable the automatic view and use, make sure you add the following line to your GlobalScript.asc:
Code (ags) Select

else if (button == eMouseLeft) {
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode );
    //Hook the automatic view method here
    OI.ProcessClick(mouse.x, mouse.y, mouse.Mode );
}

Download the ObjectInteractions script (https://dl.dropboxusercontent.com/u/20918686/ags/ObjectInteractions.scm)

Update 0.2:
I've updated the code to also support hotspots and added some checks to check first if there is an interaction defined. If not, it just ignores the interaction. It also supports now the usage of multiple characters and share inventiry items between them. But then make sure you have installed: http://www.adventuregamestudio.co.uk/forums/index.php?topic=51969.msg636510747#msg636510747

If you don't have or don't need it, just simple comment out these lines:
Code (ags) Select

        CS.AddSharedInventory(aItemToAdd);

Title: Re: MODULE: ObjectInteractions
Post by: Monsieur OUXX on Tue 07/04/2015 08:25:28
nice one.
Title: Re: MODULE: ObjectInteractions
Post by: Mehrdad on Tue 07/04/2015 15:01:57
Thanks a lot nims. great job.
Title: Re: MODULE: ObjectInteractions
Post by: nims on Wed 08/04/2015 10:51:57
I've updated the code to also support hotspots and added some checks to check first if there is an interaction defined. If not, it just ignores the interaction. It also supports now the usage of multiple characters and share inventiry items between them. But then make sure you have installed: http://www.adventuregamestudio.co.uk/forums/index.php?topic=51969.msg636510747#msg636510747

If you don't have or don't need it, just simple comment out these lines:
Code (ags) Select

        CS.AddSharedInventory(aItemToAdd);