Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: iamlowlikeyou on Thu 04/11/2010 12:10:09

Title: "Use inventory item with character, only if cursorgraphic=inv item"? [SOLVED]
Post by: iamlowlikeyou on Thu 04/11/2010 12:10:09
Sorry for posting so much, but once again after hours of searching, I can't find anything on this anywhere...

I want to make a basic "use inventory with NPC" function, that only applies when the mouse cursor is set to the inventory item graphic, like in Sam n Max Freelance Police (and most probably many other games).

I have tried figuring out the code myself, and ended up with this, but apparently it is not entirely correct;

function Girl_AnyClick(){
 if (iTeddyBear.CursorGraphic){
    //some scripting
}
 else{}
}



I don't know if it's AnyClick I should use, or if there's a better option, and I don't know if the (iTeddyBear.CursorGraphic) makes any sense in this context either...

Any help would be greatly appreciated.
Title: Re: How to make "use inventory item with character, only if cursorgraphic=inv item"?
Post by: Sslaxx on Thu 04/11/2010 12:28:20
Depending on the settings you've picked, the cursor item should be the inventory graphic item anyway, so player.ActiveInventory would work?

function Girl_AnyClick()
{
if (player.ActiveInventory == iTeddyBear)
{
     //some scripting
}
else
{
}
}
Title: Re: How to make "use inventory item with character, only if cursorgraphic=inv item"?
Post by: Dualnames on Thu 04/11/2010 12:29:09
This is a direct approach, though I think player.ActiveInventory==iTeddyBear inside the if would work better, but well, there you go anyhow.


function Girl_AnyClick(){
 if (mouse.GetModeGraphic(mouse.Mode)==iTeddyBear.CursorGraphic){
    //some scripting
}
 else{
}
}


OR


function Girl_AnyClick(){
  if (player.ActiveInventory==iTeddyBear){
     //some scripting
}
  else{
}
}

Title: Re: How to make "use inventory item with character, only if cursorgraphic=inv item"?
Post by: Khris on Thu 04/11/2010 14:42:08
  if (iTeddyBear.CursorGraphic){

This will always be true unless the CursorGraphic is set to 0, in which case it'll always be false.
The correct method was pointed out already, just wanted to say that the proper event would be "Use inventory on character" which will create a function named "Girl_Useinv()".

Girl_AnyClick on the other hand will react to any mouse mode (except Walk I believe).
Title: Re: How to make "use inventory item with character, only if cursorgraphic=inv item"?
Post by: iamlowlikeyou on Thu 04/11/2010 15:08:19
Thanks a lot for the kind replies!

I have tried the ActiveInventory function, and it worked - BUT;
when ActiveInventory is active, it still applies even if one of the other cursors are visible (walk, talk, use, etc)...
What I want, is the function only to apply, when the inventory item is the cursor graphic. That's why I thought it would work better, if I used the CursorGraphic function...
I hope I explained this properly.

@Khris: I have actually tried to use the Useinv function also, but that didn't do anything. Obviously I made a mistake somewhere. Can you give me the full script for this function?

Anyone have an idea how to fix this?
Title: Re: How to make "use inventory item with character, only if cursorgraphic=inv item"?
Post by: Matti on Thu 04/11/2010 15:18:25
The function is empty when it's created. But if you just use Girl_Useinv instead of Girl_AnyClick (and ActiveInventory instead of CursorGraphic), then everything should work just fine.

Edit: Like this.


function cGirl_UseInv()
{
  if (player.ActiveInventory==iTeddyBear) {
  // whatever
  }
}
Title: Re: How to make "use inventory item with character, only if cursorgraphic=inv item"?
Post by: iamlowlikeyou on Thu 04/11/2010 15:27:00
Oooh I see, so simple  ;D
Thank you!