Script for "Use inventory on object" *SOLVED*

Started by a157thhokage, Tue 07/09/2010 16:08:53

Previous topic - Next topic

a157thhokage

What should the script look like for Use inventory on object"?

Matti

Like this:

Code: ags

function oOBJECTNAME_UseInv()
{

}


BUT you don't have to write that yourself. Just go the object's events pane to the right and select "Use inventory on object" .. then the section above will be created automatically.

Tip: Do the tutorial  ;)

hedgefield

#2
You select the object or hotspot you want, then click the Use Inventory On Object option in the Events tab and you should get a script similar to:

function oOBJECTNAME_UseInv() {
}


Then change that to say:

function oOBJECTNAME_UseInv() {
 if (cEgo.ActiveInventory == iITEMNAME) {
   // put your code here
 }
}

a157thhokage

Thnx anyway but that's not what i mean. I want to use a stick(already in inventory) and use the stick on an apple(object in room) so when i use the stick on the apple the apple goes in my inventory.What should be the script?         

Matti

It's exactly what you meant:

Code: ags

function oApple_UseInv() {
  if (cEgo.ActiveInventory == iStick) {
    player.AddInventory(iApple);
    oApple.Visible=false;
  }
}

Khris

In case this isn't clear, there's no technical connection whatsoever between a room object and an inventory item. Them representing the same thing is a concept outside of AGS.

a157thhokage

I tried the script u gave me but i cant drag the inventory item "Stick" out of the inventory box and click the stick with the apple.How should I proceed from here?

Khris

You don't need a special script unless you actually want to drag items. Usually the player clicks on an inventory item and the mouse cursor turns into it (mouse.Mode is now eModeUseinv). Now the player clicks on the object, and the object's _Useinv() is called, with player.ActiveInventory being the selected inv item.

This is all built-in default behavior and doesn't need to be scripted.

a157thhokage

Aghhhhhhhhh! I still dont get it. I really suck at scripting.

Khris

What does and doesn't work?
Please be more specific so we can help you.


SMF spam blocked by CleanTalk