61
Technical forum / Re: inventory items
« on: October 16, 2004, 02:21:06 AM »
Ok, I'll try this as best as I can...
>ok I need to know how to combine items.
>1. Items combined in inventory to make a new item.
>Example: I have an empty bottle and a cork. I pick up the cork (left click) from inventory and place >it on the cork in inventory and (left click) - result = cork item in inventory gone, bottle item with
>mouse pointer gone, item in inventory is now bottle with cork.
In the bottle's script, make an event called <on "cork"> (if that's the name of the cork)
and then write a little code, like:
on "cork"
{ Game.DropItem("cork");
Game.TakeItem("cork_bottle");
actor.Talk("Here I am supposed to say something interesting.");
}
So now the actor dropped the bottle and instead you got the new bottle with the cork (you should make this bottle separately, it's easier to script and keep track of.
Just a note about the "on" thing: it seems really backwards-intuitive.
If you use the cork on the bottle you might think that it's the cork that should have on "bottle"
instead of the other way around. But it's the object you're using things on that has the "on something" in it.
And also, you don't have to declare the on "cork" or anything, it's automatic when you use an object on another. So whenever you have a new item, like an apple, you can just write in some object's script: on "apple" {here's what happens}.
>2. Items combined from inventory into a scene.
>Example: I have an empty bottle and in the scene is a fountain. I pick up the empty bottle (left >clcik) from inventory and place it on the scene on the fountain (entity in scene) the empty bottle >changes to bottle of water against my mouse pointer. (left click) puts bottle of water in inventory.
Ok. This is more tricky. The bottle have to have two different sprites or pictures for this.
And then you need a variable to keep track of the bottle's state (empty, full, etc...)
You have two ways to do this, you can either have different bottles, or the same bottle and change it's pictures dynamically.
(the second one is a bit more tricky and requires more scripting)
[... lots of code goes to waste]
No scrap that, I tried it out and came to the conclusion that it's easier to have separate bottles for full, empty, blood, wine, whatever.
So then in the fountains script you just say:
on "fullbottle" {...}
on "emptybottle" {...}
and so on, where fullbottle and emptybottle is different items.
so in your case you say:
(in the fountains script)
on "fullbottle"
{ actor.Talk("But it's already full of water."; }
on "emptybottle"
{ Game.TakeItem("fullbottle", "emptybottle");
Game.DropItem("emptybottle");
Game.SelectedItem = "fullbottle";
actor.Talk("Here, finally I say something cool...";
}
the "emptybottle" in
Game.TakeItem("fullbottle", "emptybottle");
is which object you're to insert it after in the inventory (this is optional, works with just "Game.TakeItem("fullbottle");").
then you just remove the old bottle with
Game.DropItem("emptybottle");
and then you make the new bottle selected from the inventory with
Game.SelectedItem = "fullbottle";
and then finally the actor says something cool.
the bad thing about this is that you have to have four differen bottles if
you can use the cork on each of them.
>3. Item combined with NPC
>Example: I have a bottle of water and in the scene is an old man. I pick up the bottle of water (left >click) from inventory and place it on the NPC (in the scene) and left click. The bottle of water >disappears and the NPC animates a response.
in the old man's script:
on "emptybottle"
{ Game.Interactive=false;
this.Talk("This bottle is empty.");
actor.Talk("I can see that..");
this.Talk("What would I want an empty bottle with?");
actor.Talk("Drink it??...");
this.Talk("OK.");
this.Talk("I now drink this bottle and give it back to you... the player that is...");
actor.Talk("Was it any good?");
this.Talk("Perfect. But I'm still thirsty. And I won't give you the apple until I get my dose of H2O.");
actor.Talk("Ok.");
Game.Interactive=true;
}
on "fullbottle"
{ Game.Interactive=false;
Game.DropItem("fullbottle");
this.Talk("Hey, thanx!");
actor.Talk("Glad you liked it.");
this.Talk("Here, have an apple. It's still fresh...");
actor.Talk("This is it!! Now I can finally solve the Wilhelm tell puzzle, where he's supposed to shoot an arrow throught my head but misses...");
Game.TakeItem("apple");
Game.Interactive=true;
}
The Game.Interactive=false is just so you can't go somewhere or do other things while they're talking. The "this.Talk" means that whoever this script's attached to talks.
Hope this helps..
(edit: I wrote actor.DropItem two times here... changed it to Game.Drop... (I use actor.TakeItem in my game myself... both works, but Game.TakeItem and Game.DropItem, and so on, is standard)
>ok I need to know how to combine items.
>1. Items combined in inventory to make a new item.
>Example: I have an empty bottle and a cork. I pick up the cork (left click) from inventory and place >it on the cork in inventory and (left click) - result = cork item in inventory gone, bottle item with
>mouse pointer gone, item in inventory is now bottle with cork.
In the bottle's script, make an event called <on "cork"> (if that's the name of the cork)
and then write a little code, like:
on "cork"
{ Game.DropItem("cork");
Game.TakeItem("cork_bottle");
actor.Talk("Here I am supposed to say something interesting.");
}
So now the actor dropped the bottle and instead you got the new bottle with the cork (you should make this bottle separately, it's easier to script and keep track of.
Just a note about the "on" thing: it seems really backwards-intuitive.
If you use the cork on the bottle you might think that it's the cork that should have on "bottle"
instead of the other way around. But it's the object you're using things on that has the "on something" in it.
And also, you don't have to declare the on "cork" or anything, it's automatic when you use an object on another. So whenever you have a new item, like an apple, you can just write in some object's script: on "apple" {here's what happens}.
>2. Items combined from inventory into a scene.
>Example: I have an empty bottle and in the scene is a fountain. I pick up the empty bottle (left >clcik) from inventory and place it on the scene on the fountain (entity in scene) the empty bottle >changes to bottle of water against my mouse pointer. (left click) puts bottle of water in inventory.
Ok. This is more tricky. The bottle have to have two different sprites or pictures for this.
And then you need a variable to keep track of the bottle's state (empty, full, etc...)
You have two ways to do this, you can either have different bottles, or the same bottle and change it's pictures dynamically.
(the second one is a bit more tricky and requires more scripting)
[... lots of code goes to waste]
No scrap that, I tried it out and came to the conclusion that it's easier to have separate bottles for full, empty, blood, wine, whatever.
So then in the fountains script you just say:
on "fullbottle" {...}
on "emptybottle" {...}
and so on, where fullbottle and emptybottle is different items.
so in your case you say:
(in the fountains script)
on "fullbottle"
{ actor.Talk("But it's already full of water."; }
on "emptybottle"
{ Game.TakeItem("fullbottle", "emptybottle");
Game.DropItem("emptybottle");
Game.SelectedItem = "fullbottle";
actor.Talk("Here, finally I say something cool...";
}
the "emptybottle" in
Game.TakeItem("fullbottle", "emptybottle");
is which object you're to insert it after in the inventory (this is optional, works with just "Game.TakeItem("fullbottle");").
then you just remove the old bottle with
Game.DropItem("emptybottle");
and then you make the new bottle selected from the inventory with
Game.SelectedItem = "fullbottle";
and then finally the actor says something cool.
the bad thing about this is that you have to have four differen bottles if
you can use the cork on each of them.
>3. Item combined with NPC
>Example: I have a bottle of water and in the scene is an old man. I pick up the bottle of water (left >click) from inventory and place it on the NPC (in the scene) and left click. The bottle of water >disappears and the NPC animates a response.
in the old man's script:
on "emptybottle"
{ Game.Interactive=false;
this.Talk("This bottle is empty.");
actor.Talk("I can see that..");
this.Talk("What would I want an empty bottle with?");
actor.Talk("Drink it??...");
this.Talk("OK.");
this.Talk("I now drink this bottle and give it back to you... the player that is...");
actor.Talk("Was it any good?");
this.Talk("Perfect. But I'm still thirsty. And I won't give you the apple until I get my dose of H2O.");
actor.Talk("Ok.");
Game.Interactive=true;
}
on "fullbottle"
{ Game.Interactive=false;
Game.DropItem("fullbottle");
this.Talk("Hey, thanx!");
actor.Talk("Glad you liked it.");
this.Talk("Here, have an apple. It's still fresh...");
actor.Talk("This is it!! Now I can finally solve the Wilhelm tell puzzle, where he's supposed to shoot an arrow throught my head but misses...");
Game.TakeItem("apple");
Game.Interactive=true;
}
The Game.Interactive=false is just so you can't go somewhere or do other things while they're talking. The "this.Talk" means that whoever this script's attached to talks.
Hope this helps..
(edit: I wrote actor.DropItem two times here... changed it to Game.Drop... (I use actor.TakeItem in my game myself... both works, but Game.TakeItem and Game.DropItem, and so on, is standard)