Game Development Community

Object pickup

by Kasey McIntosh · in Technical Issues · 09/13/2007 (11:15 pm) · 2 replies

O.K. I here's what i want to do, Essentially I want to put several different objects in my mission area, and once they are all collected, I would like for the character to get a key. Any Ideas on how that might be done?

Here's what I've tried
" All follow the tutorial that came with the engine"
1. Create seperate items for each, and put them in one SimGroup --- Didn't work.

2. Didi the same thing, but initalized variables for each item, and added them up --- Didn't work.

ITS DRIVING ME CRAZY

#1
10/12/2007 (12:29 am)
The most simple way I can think of is to create an emtpy SimSet and every time your player picks up one item you add it to the SimSet. Then check the size of the SimSet and if you for example dropped 10 items in your mission and on the pickup event your simset reached 10 items, all are collected. That is the most bloody simplest way. Once you understood that path you might want to pimp it and extend it a bit more maybe.

Pseudo code:

Create the items:
...
new StaticShape(YourSuperItem1)
{
type = "PickupItem";
... bla bla
};

new StaticShape(YourSuperItem2)
{
type = "PickupItem";
... bla bla
};

Player initialization (server/script/game.cs)
%player.myItemList = new SimSet();

Player.cs onCollision event:
if (collision.type $= "PickupItem")
{
%player.myItemList.add(%collisionObject);
}

Ah, well, something like this... :-)
#2
10/13/2007 (5:17 am)
Yeah, that would work, exept make it something like

Player.cs onCollision event:
if (collision.type $= "PickupItem")
{
%player.itemsPickedUp += 1;
if (%player.itemsPickedUp = 10)
Key.setTransform(%player.getTransform());
}

or

Player.cs onCollision event:
if (collision.type $= "PickupItem")
{
%player.itemsPickedUp += 1;
if (%player.itemsPickedUp = 10)
%player.pickup(Key);
}