Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: inventory  (Read 6926 times)

0 Members and 1 Guest are viewing this topic.

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
inventory
« on: March 01, 2005, 12:56:07 AM »

ok all the time talking in 3d character...
I want to make something like Grim Fandango, so when i touch ctrl (or other key) the character scrab in a bag (animation that i make) and then all the thing of the inventory apear one at a time moving the arrows, and when i select what i want you have the object in the hand(another thing that i already know)...
please some help
 Martin
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: inventory
« Reply #1 on: March 01, 2005, 09:26:39 AM »

Cycling the inventory items in character's hand should be easy to do, simply by calling actor.PlayAnim() for the movements and attaching the items as sub-meshes to his hand-bone using actor.AddMesh(). But if you wanted to change the camera view like GF does, you'd probably have to have a special geometry file for this very purpose, with a fixed camera/lighting. Perhaps a separate scene for the inventory display would work the best here.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
Re: inventory
« Reply #2 on: March 02, 2005, 04:47:02 AM »

not only i need the part of changing objcts...
but how can i do that... cose the thing of the animg i´m already know but how to assign a key for that, and how to know with the inventory wich animation and wich things to do... have some example with one or two objects???
thanks
 MArtin
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: inventory
« Reply #3 on: March 02, 2005, 10:54:32 AM »

Ok, here's some code. Untested, but hopefully it will give you the idea... Place this to game.script:

Code: [Select]
// some variables to keep track of inventory state
global InvActive = false;
global InvCurrItem = -1;
global InvCurrItemName = "";


////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // we activate/deactivate the inventory using the "I" key
  if(Keyboard.Key == "i")
  {
    InvActive = !InvActive;
   
    if(InvActive)
    {
      // no items to show
      if(Game.NumItems==0)
      {
        actor.Talk("I don't have anything.");
        InvActive = false;
        return;
      }
     
      // let the actor pull out the right item
      ShowItem();
           
    }
    else
    {
       actor.PlayAnim("hide_item");
       actor.RemoveMesh(InvCurrItemName);
       InvCurrItemName = "";
    }
  }


  // we switch items using the page-up/page-down keys
  if(InvActive)
  {
    if(Keyboard.KeyCode==VK_PRIOR)
    {
      InvCurrItem = InvCurrItem - 1;
      if(InvCurrItem < 0) InvCurrItem = Game.NumItems - 1;
      ShowItem();
    }
    else if(Keyboard.KeyCode==VK_NEXT)
    {
      InvCurrItem = InvCurrItem + 1;
      if(InvCurrItem >= Game.NumItems) InvCurrItem = 0;
      ShowItem();
    }   
  }
}

////////////////////////////////////////////////////////////////////////////////
function ShowItem() // this function will make the actor hide the old item and pull out the new one
{
  if(InvCurrItemName!="")
  {
    actor.PlayAnim("hide_item");
    actor.RemoveMesh(InvCurrItemName);
    InvCurrItemName = "";   
  }
 
  var CurrItem = Game.GetItem(InvCurrItem);
  if(CurrItem!=null)
  {
    InvCurrItemName = CurrItem.Name;
   
    // we assume the item model is stored in a MS3D file with the same name
    // we load it and attach it to actor's hand-bone
    actor.AddMesh("path\" + InvCurrItemName + ".ms3d", InvCurrItemName, "some_bone_name");
    actor.PlayAnim("show_item");
  }
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
Re: inventory
« Reply #4 on: March 08, 2005, 12:22:04 AM »

Ok thanks Mnemonic but i found some problems, first all the keyboard it´s bloked i change some keys like pg:up and down with othes cose i have the selection of the actions with those keys, and the other it´s it´s make all the moving of the inventory but doesn´t look the objects... I try a lot of combinations and didn´t work...
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: inventory
« Reply #5 on: March 08, 2005, 06:50:45 PM »

Ok thanks Mnemonic but i found some problems, first all the keyboard it´s bloked i change some keys like pg:up and down with othes cose i have the selection of the actions with those keys, and the other it´s it´s make all the moving of the inventory but doesn´t look the objects... I try a lot of combinations and didn´t work...
Well, notice the "if(InvActive)..." piece of code in the "Keypress" handler. It means this code will only be executed if the inventory is activated. To combine it with your old code you will need to write something like:

if(InvActive)
{
  // the inventory handling here
}
else
{
  // your old code here, to handle actions etc.
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
Re: inventory
« Reply #6 on: March 19, 2005, 05:42:16 AM »

that´s the code:
// some variables to keep track of inventory state
#include "scripts\base.inc"
#include "scripts\keys.inc"
global InvActive = false;
global InvCurrItem = -1;
global InvCurrItemName = "";
global ClickStarted;
global ClickStartTime;
global ClickObject;


// store some of the game's attributes in global variables for convenience
Keyboard = Game.Keyboard;
Scene = Game.Scene;


// load the right-click menu
global WinMenu = Game.LoadWindow("interface\actions\actions.window");
WinMenu.Visible = false;

// load the "caption" window
var win = Game.LoadWindow("interface\system\caption.window");
global WinCaption = win.GetWidget("caption");

// load the keyboard actions menu
global WinActions = Game.LoadWindow("interface\actions.window");



global MenuObject = null;


// load our main actor
actor = Game.LoadActor3D("actors\miguel\miguel.act3d");
Game.MainObject = actor;

// run the "daemon" script
Game.AttachScript("scripts\game_daemon.script");


// which scene to load first?
Game.ChangeScene("scenes\baredificio\baredificio.scene");



////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // we activate/deactivate the inventory using the "I" key
  if(Keyboard.Key == "i")
  {
    InvActive = !InvActive;
   
    if(InvActive)
    {
      // no items to show
      if(Game.NumItems==0)
      {
        actor.Talk("No tengo Nada");
        InvActive = false;
        return;
      }
     
      // let the actor pull out the right item
      ShowItem();
           
    }
    else
    {
       actor.PlayAnim("inevntario");
       actor.RemoveMesh(InvCurrItemName);
       InvCurrItemName = "";
       if(Keyboard.KeyCode==VK_ESCAPE)
       {
       WinCaption.Visible = false;
       var WinMainMenu = Game.LoadWindow("interface\system\mainmenu.window");
       WinMainMenu.Center();
       WinMainMenu.GoSystemExclusive();
       Game.UnloadObject(WinMainMenu);
       }
       if(Keyboard.KeyCode==VK_PRIOR) WinActions.PrevCommand();
       else if(Keyboard.KeyCode==VK_NEXT) WinActions.NextCommand();
       else if(Keyboard.KeyCode==VK_RETURN) WinActions.ExecuteCommand();
       }
  }
  }
  // we switch items using the page-up/page-down keys
  if(InvActive)
  {
    if(Keyboard.Key== "u")
    {
      InvCurrItem = InvCurrItem - 1;
      if(InvCurrItem < 0) InvCurrItem = Game.NumItems - 1;
      ShowItem();
    }
    else if(Keyboard.Key== "j")
    {
      InvCurrItem = InvCurrItem + 1;
      if(InvCurrItem >= Game.NumItems) InvCurrItem = 0;
      ShowItem();
    }   
  }


////////////////////////////////////////////////////////////////////////////////
function ShowItem() // this function will make the actor hide the old item and pull out the new one
{
  if(InvCurrItemName!="")
  {
    actor.PlayAnim("inventario");
    actor.RemoveMesh(InvCurrItemName);
    InvCurrItemName = "";   
  }
 
  var CurrItem = Game.GetItem(InvCurrItem);
  if(CurrItem!=null)
  {
    InvCurrItemName = CurrItem.Name;
   
    // we assume the item model is stored in a MS3D file with the same name
    // we load it and attach it to actor's hand-bone
    actor.AddMesh("actors\teapot\" + InvCurrItemName, "Bip01 R Finger12");
    actor.PlayAnim("inventario");
  }
}

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // no object selected, apply click to scene
  if(Game.ActiveObject==null)
  {
    Scene.ApplyEvent("LeftClick");
    return;
  }

  // perform click start
  ClickObject = Game.ActiveObject;


  // do we need to show the verb window at all?   
  if(!ClickObject.CanHandleEvent("LookAt") &&
     !ClickObject.CanHandleEvent("Talk") &&
     !ClickObject.CanHandleEvent("Take") )
  {
     // nah, just click it
    ClickObject.ApplyEvent("LeftClick");
    ClickStarted = false;
    ClickObject = null;
  }
  else
  {
     // mark click start and remember the time
    ClickStarted = true;
    ClickStartTime = Game.CurrentTime;
  }
}

////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
   // 'obj' is actually the verb button the mouse was over when we released the left button
  var obj = Game.ActiveObject;
  ClickStarted = false;
 
  // we are leaving the verbs window, handle the selected verb
  if(WinMenu.Visible)
  {
     // hide the window
    WinMenu.Visible = false;
   
    // this is necessary, because we can left-click earlier than this stuff finishes
    var TempClickObj = ClickObject;
    ClickObject = null;

    // apply the verb if the object can handle it
    if(TempClickObj.CanHandleEvent(obj.Name)) TempClickObj.ApplyEvent(obj.Name);
    else
    {
      // otherwise use default event handling
      if(obj.Name=="LookAt")
      {
        actor.Talk("Looks nice.");
      }
      else if(obj.Name=="Talk")
      {
        actor.Talk("Hello...");
      }
      else if (obj.Name=="Take")
      {
         actor.Talk("I won't pick that up.");
      }
    }
  }
 
  // verbcoin is NOT visible, i.e. we go for a normal click
  else if(Game.ValidObject(ClickObject))
  {
    // did we click using an inventory item?
    if(Game.SelectedItem != null && Game.SelectedItem!=ClickObject)
    {
      var item = Game.SelectedItem;
      if(ClickObject.CanHandleEvent(item.Name)) ClickObject.ApplyEvent(item.Name);
      else
      {
        // default use handlers, same as in WME demo
        if(item.CanHandleEvent("default-use")) item.ApplyEvent("default-use");
        else if (ClickObject.CanHandleEvent("default-use")) ClickObject.ApplyEvent("default-use");
        else
        {
          ClickObject = null;
          actor.Talk("I can't use these things together.");
        }
      }
    }
    // perform normal click
    else ClickObject.ApplyEvent("LeftClick");
    ClickObject = null;
  }
}


////////////////////////////////////////////////////////////////////////////////
on "RightClick"
{
   var ActObj = Game.ActiveObject;
  if(Game.SelectedItem != null) Game.SelectedItem = null;
  else if(ActObj!=null) ActObj.ApplyEvent("RightClick");
}


on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  if(QuestionBox("Do you really want to quit?")) Game.QuitGame();

}




////////////////////////////////////////////////////////////////////////////////
method QuestionBox(Message, SystemExclusive)
{
   if(SystemExclusive==null) SystemExclusive = true;
   
   var Window = Game.LoadWindow("interface\system\question.window");
   Window.Center();
   Window.xMessage = Game.ExpandString(Message);
   
   if(SystemExclusive) Window.GoSystemExclusive();
   else Window.GoExclusive();
   
   var Result = Window.xResult;
   Game.UnloadObject(Window);
   
   return Result;
}

doesn´t work the man don´t show the objects, and i can´t touch keys...
any magical solutions, that you always have... ;)
thanks
  MArtín
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: inventory
« Reply #7 on: March 19, 2005, 04:59:05 PM »

I reorganized the code a little (it got a little complicated, didn't it? :)) I hope that helps.

Code: [Select]
// some variables to keep track of inventory state
#include "scripts\base.inc"
#include "scripts\keys.inc"
global InvActive = false;
global InvCurrItem = -1;
global InvCurrItemName = "";
global ClickStarted;
global ClickStartTime;
global ClickObject;


// store some of the game's attributes in global variables for convenience
Keyboard = Game.Keyboard;
Scene = Game.Scene;


// load the right-click menu
global WinMenu = Game.LoadWindow("interface\actions\actions.window");
WinMenu.Visible = false;

// load the "caption" window
var win = Game.LoadWindow("interface\system\caption.window");
global WinCaption = win.GetWidget("caption");

// load the keyboard actions menu
global WinActions = Game.LoadWindow("interface\actions.window");



global MenuObject = null;


// load our main actor
actor = Game.LoadActor3D("actors\miguel\miguel.act3d");
Game.MainObject = actor;

// run the "daemon" script
Game.AttachScript("scripts\game_daemon.script");


// which scene to load first?
Game.ChangeScene("scenes\baredificio\baredificio.scene");



////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // we activate/deactivate the inventory using the "I" key
  if(Keyboard.Key == "i")
  {
    InvActive = !InvActive;
   
    if(InvActive)
    {
      // no items to show
      if(Game.NumItems==0)
      {
        actor.Talk("No tengo Nada");
        InvActive = false;
        return;
      }
     
      // let the actor pull out the right item
      ShowItem();
           
    }
    else
    {
      actor.PlayAnim("inevntario");
      actor.RemoveMesh(InvCurrItemName);
      InvCurrItemName = "";
    }
  }

  // we switch items using the page-up/page-down keys
  if(InvActive)
  {
    if(Keyboard.Key== "u")
    {
      InvCurrItem = InvCurrItem - 1;
      if(InvCurrItem < 0) InvCurrItem = Game.NumItems - 1;
      ShowItem();
    }
    else if(Keyboard.Key== "j")
    {
      InvCurrItem = InvCurrItem + 1;
      if(InvCurrItem >= Game.NumItems) InvCurrItem = 0;
      ShowItem();
    }   
  }
  else
  {
    if(Keyboard.KeyCode==VK_ESCAPE)
    {
      WinCaption.Visible = false;
      var WinMainMenu = Game.LoadWindow("interface\system\mainmenu.window");
      WinMainMenu.Center();
      WinMainMenu.GoSystemExclusive();
      Game.UnloadObject(WinMainMenu);
    }
    if(Keyboard.KeyCode==VK_PRIOR) WinActions.PrevCommand();
    else if(Keyboard.KeyCode==VK_NEXT) WinActions.NextCommand();
    else if(Keyboard.KeyCode==VK_RETURN) WinActions.ExecuteCommand();
  }
}

////////////////////////////////////////////////////////////////////////////////
function ShowItem() // this function will make the actor hide the old item and pull out the new one
{
  if(InvCurrItemName!="")
  {
    actor.PlayAnim("inventario");
    actor.RemoveMesh(InvCurrItemName);
    InvCurrItemName = "";   
  }
 
  var CurrItem = Game.GetItem(InvCurrItem);
  if(CurrItem!=null)
  {
    InvCurrItemName = CurrItem.Name;
   
    // we assume the item model is stored in a MS3D file with the same name
    // we load it and attach it to actor's hand-bone
    actor.AddMesh("actors\teapot\" + InvCurrItemName, "Bip01 R Finger12");
    actor.PlayAnim("inventario");
  }
}

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // no object selected, apply click to scene
  if(Game.ActiveObject==null)
  {
    Scene.ApplyEvent("LeftClick");
    return;
  }

  // perform click start
  ClickObject = Game.ActiveObject;


  // do we need to show the verb window at all?   
  if(!ClickObject.CanHandleEvent("LookAt") &&
     !ClickObject.CanHandleEvent("Talk") &&
     !ClickObject.CanHandleEvent("Take") )
  {
     // nah, just click it
    ClickObject.ApplyEvent("LeftClick");
    ClickStarted = false;
    ClickObject = null;
  }
  else
  {
     // mark click start and remember the time
    ClickStarted = true;
    ClickStartTime = Game.CurrentTime;
  }
}

////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
   // 'obj' is actually the verb button the mouse was over when we released the left button
  var obj = Game.ActiveObject;
  ClickStarted = false;
 
  // we are leaving the verbs window, handle the selected verb
  if(WinMenu.Visible)
  {
     // hide the window
    WinMenu.Visible = false;
   
    // this is necessary, because we can left-click earlier than this stuff finishes
    var TempClickObj = ClickObject;
    ClickObject = null;

    // apply the verb if the object can handle it
    if(TempClickObj.CanHandleEvent(obj.Name)) TempClickObj.ApplyEvent(obj.Name);
    else
    {
      // otherwise use default event handling
      if(obj.Name=="LookAt")
      {
        actor.Talk("Looks nice.");
      }
      else if(obj.Name=="Talk")
      {
        actor.Talk("Hello...");
      }
      else if (obj.Name=="Take")
      {
         actor.Talk("I won't pick that up.");
      }
    }
  }
 
  // verbcoin is NOT visible, i.e. we go for a normal click
  else if(Game.ValidObject(ClickObject))
  {
    // did we click using an inventory item?
    if(Game.SelectedItem != null && Game.SelectedItem!=ClickObject)
    {
      var item = Game.SelectedItem;
      if(ClickObject.CanHandleEvent(item.Name)) ClickObject.ApplyEvent(item.Name);
      else
      {
        // default use handlers, same as in WME demo
        if(item.CanHandleEvent("default-use")) item.ApplyEvent("default-use");
        else if (ClickObject.CanHandleEvent("default-use")) ClickObject.ApplyEvent("default-use");
        else
        {
          ClickObject = null;
          actor.Talk("I can't use these things together.");
        }
      }
    }
    // perform normal click
    else ClickObject.ApplyEvent("LeftClick");
    ClickObject = null;
  }
}


////////////////////////////////////////////////////////////////////////////////
on "RightClick"
{
   var ActObj = Game.ActiveObject;
  if(Game.SelectedItem != null) Game.SelectedItem = null;
  else if(ActObj!=null) ActObj.ApplyEvent("RightClick");
}


on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  if(QuestionBox("Do you really want to quit?")) Game.QuitGame();

}




////////////////////////////////////////////////////////////////////////////////
method QuestionBox(Message, SystemExclusive)
{
   if(SystemExclusive==null) SystemExclusive = true;
   
   var Window = Game.LoadWindow("interface\system\question.window");
   Window.Center();
   Window.xMessage = Game.ExpandString(Message);
   
   if(SystemExclusive) Window.GoSystemExclusive();
   else Window.GoExclusive();
   
   var Result = Window.xResult;
   Game.UnloadObject(Window);
   
   return Result;
}

Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
Re: inventory
« Reply #8 on: March 19, 2005, 05:10:35 PM »

Nothing happend, it´s the same problem and it doesn´t show the item...  ???
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: inventory
« Reply #9 on: March 19, 2005, 06:47:37 PM »

Any chance you could make some simplified version of your project for me to try? Just the actor, one scene and the scripts? It's hard to debug this without being able to test it...
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
Re: inventory
« Reply #10 on: March 19, 2005, 07:20:03 PM »

Ok i can send you bymail???
thanks
 MArtin
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: inventory
« Reply #11 on: March 19, 2005, 07:34:09 PM »

Yes, you can. Thanks.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.109 seconds with 23 queries.