Using different inventoryitems on Ego

Started by Mouth for war, Mon 09/03/2009 16:45:08

Previous topic - Next topic

Mouth for war

ok this is in the globalscript and no problems here, but AFTER all that scripting i want to be able to use other stuff on the character...on the next screen for example he gets a shovel and if i use that on Ego i want him to say something like "No i can't use that on myself" what should i script? the else if doesn't seem to work...and i'm new to scripting so a little help would be very nice hehe....so...I need help to be able to add more stuff that can be used on my character :)


function cEgo_UseInv()
{
if(player.ActiveInventory == ibook){
  cEgo.LockView(4);
cEgo.Animate(3, 1, 0, eBlock, eForwards);
cEgo.UnlockView();
  cEgo.FaceLocation(cEgo.x -10, cEgo.y);
  Display("Let's see what we have here");
  cEgo.LockView(4);
cEgo.Animate(3, 1, 0, eBlock, eForwards);
cEgo.UnlockView();
cEgo.FaceLocation(cEgo.x -10, cEgo.y);
  Display ("Hmm...I recognise Grampa's handwriting. He actually managed to translate this");
   cEgo.LockView(4);
cEgo.Animate(3, 1, 0, eBlock, eForwards);
cEgo.UnlockView();
cEgo.FaceLocation(cEgo.x, cEgo.y +10);
  Display ("This spell opens a gate to another world. I've never spoken these words out loud");
  Display ("Who knows what might happen? Whoever's reading this...Be extremely careful");
   cEgo.LockView(4);
cEgo.Animate(3, 1, 0, eBlock, eForwards);
cEgo.UnlockView();
cEgo.FaceLocation(cEgo.x, cEgo.y +10);
  Display ("Ah get real gramps...don't say you actually believed in this?");
  cEgo.Walk(282, 401, eBlock);
  cEgo.FaceLocation(cEgo.x, cEgo.y +10);
  Display ("Here goes nothing");
  Display ("in circulus vitiosus,  abiit, excessit, evasit, erupit");
cEgo.Transparency = 100;
object[3].Visible = true;
PlaySound (4);
object[3].SetView(5, 3);
object[3].Animate(3, 1);
object[3].Visible = false;
Wait (40);
cEgo.LoseInventory(ibook);
cEgo.LoseInventory(iKey);
player.ChangeRoom(2, 200, 580);
}
mass genocide is the most exhausting activity one can engage in, next to soccer

thezombiecow

Hello! Just keep on adding in 'if' statements!

Code: ags

function cEgo_UseInv()
{
   if(player.ActiveInventory == ibook)
   {
    cEgo.Say("You used the book!");
   }

   if(player.ActiveInventory == ishovel)
   {
    cEgo.Say("You used the shovel!");
   }

   if(player.ActiveInventory == iunusualTrousers)
   {
    cEgo.Say("You used the unusual trousers!");
   }

   if(player.ActiveInventory == iwhateverYouWant)
   {
    // whatever, and so on!
   }

}


Mouth for war

Ah yeah i tried that before and didn't get it to work...probably missed something. works now. Thanks for the quick reply :)
mass genocide is the most exhausting activity one can engage in, next to soccer

thezombiecow

You're missing a close bracket } on your original post, that might have something to do with it...

Trent R

Related topic: To save space in my global script, I created a function called c_UseInv in a module script. I then passed Character.GetAtScreenXY as the parameter, and put all my interactions in that script.

You could do a similar thing, like this:
Code: ags

//global script
import playerUseInv(InventoryItem *item); //since you'll only use this function here, no need to put the import in the module header
function cEgo_UseInv() {
  playerUseInv(player.ActiveInventory);
}


//module script
function playerUseInv(InventoryItem *item){
  if(player.ActiveInventory == ibook)
  {
  cEgo.Say("You used the book!");
  }
  if(player.ActiveInventory == ishovel)
  {
   cEgo.Say("You used the shovel!");
  }
  if(player.ActiveInventory == iunusualTrousers)
  {
  cEgo.Say("You used the unusual trousers!");
  }
  if(player.ActiveInventory == iwhateverYouWant)
  {
  // whatever, and so on!
  }
}




~Trent
PS-I stole a piece zombiecow's code :)
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

SMF spam blocked by CleanTalk