I'm trying to covert the code scorpiorus posted here:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=6074.msg74146#msg74146
But i'm having problems, i'm guessing it's because of the new ags language so i've been trying to convert the code across with no luck really.
see my code below:
#sectionstart on_mouse_click // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(int button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (mouse.IsButtonDown(eMouseLeft)) {
// if player has an item then unselect:
if (character[EGO].ActiveInventory != -1)
character[EGO].ActiveInventory = -1;
// otherwise process look or walk:
else ProcessClickSpecial(mouse.x, mouse.y, MODE_LOOK, MODE_WALK);
}
else if (mouse.IsButtonDown(eMouseRight)) {
// if player has an item then try to use it:
if (character[EGO].ActiveInventory != -1)
ProcessClickSpecial(mouse.x, mouse.y, MODE_USEINV, MODE_WALK);
// otherwise just interact as usual:
else ProcessClickSpecial(mouse.x, mouse.y, MODE_USE, MODE_WALK);
}
// handling inventory clicks: (Handle inventory clicks in script must be on!)
else if (mouse.IsButtonDown(eMouseRightInv)) {//for right inv. click:
// select the item player has clicked on
SetActiveInventory(game.inv_activated);
}
else if (mouse.IsButtonDown(eMouseLeftInv)) { //for left inv. click:
// run look at inventory interaction
RunInventoryInteraction (game.inv_activated, MODE_LOOK);
}
}
Help please? It takes me hours to get my head round this stuff...
Edit by Ashen: Descriptive titles, please.
Here is a new-style-friendly version of the script:
ProcessClickSpecial() function
import function ProcessClickSpecial( int x, int y, CursorMode cursor_mode, CursorMode default_mode = eModeWalkto );
function ProcessClickSpecial( int x, int y, CursorMode cursor_mode, CursorMode default_mode ) {
if ( IsInteractionAvailable(x, y, cursor_mode) )
{
ProcessClick( x, y, cursor_mode );
}
else
{
ProcessClick( x, y, default_mode );
}
}
on_mouse_click() function
function on_mouse_click( int button ) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
//-----------------------------------------------------------------------------
if (button == eMouseRight)
{
if ( player.ActiveInventory != null )
{
// if player has an item then try to use it:
ProcessClickSpecial( mouse.x, mouse.y, eModeUseinv );
}
else
{
// otherwise just interact as usual:
ProcessClickSpecial( mouse.x, mouse.y, eModeInteract );
}
}
//-----------------------------------------------------------------------------
else if (button == eMouseLeft)
{
// handles a situation when left-clicking is over anything but GUI
if (player.ActiveInventory != null)
{
player.ActiveInventory = null;
}
else
{
ProcessClickSpecial( mouse.x, mouse.y, eModeLookat );
}
}
//-----------------------------------------------------------------------------
else if (button == eMouseLeftInv)
{
if (player.ActiveInventory == null)
{
inventory[ game.inv_activated ].RunInteraction( eModeLookat );
}
}
//-----------------------------------------------------------------------------
else if (button == eMouseRightInv)
{
if (player.ActiveInventory == null)
{
player.ActiveInventory = inventory[ game.inv_activated ];
}
else
{
inventory[ game.inv_activated ].RunInteraction( eModeUseinv );
}
}
//-----------------------------------------------------------------------------
}
on_event() function
function on_event(EventType event, int data) {
// handles a situation when left-clicking is over GUI
// actually duplicates eMouseLeft script in on_mouse_click to work over GUIs
if (event == eEventGUIMouseDown)
{
if ( mouse.IsButtonDown( eMouseLeft ) )
{
if (player.ActiveInventory != null)
{
player.ActiveInventory = null;
}
}
}
}
But make sure the Handle inventory clicks in script option is ticked.
Thanks Scorpiorus, worked a treat!
You're welcome, nice to see it worked for you :)