Game Development Community

Health Kit Spawn Question - Help

by Samarie · in Torque Game Engine · 10/14/2009 (3:55 pm) · 3 replies

Hey guys,

In the FPS Starter kit, does anyone know how to make the health kit spawn at different places when you load the game? I want to create 6 spawn spheres and have the health kit spawn at those different locations when the player loads the game. Just like when you load the FPS Starter kit and the player spawns at different locations, I want the health kit to do the same thing.

About the author

I'm an undergraduate student studying game and simulation programming at a university.


#1
10/14/2009 (5:35 pm)
I just place a health kit in my mission and it respawns its self even after I pick it up. I checked my health script to see if it has any respawn code but none I see........Donnie
#2
10/14/2009 (6:45 pm)
there should be a respawn = 1 or something like that
as well as a rotate = 1 that rotates the object.
#3
10/14/2009 (8:31 pm)
Take note of these three functions:(inside of game.cs)
GameConnection::spawnPlayer()
GameConnection::createPlayer()
pickSpawnPoint()

and create new functions, something like this:
//-----------------------------------------------------------------------------

function GameConnection::spawnHealthPacks(%this)
{
   // Combination create health and drop it somewhere
   %healthspawnPoint = pickHealthSpawnPoints();
   %this.createHealthPacks(%healthspawnPoint);
}   


//-----------------------------------------------------------------------------

function GameConnection::createHealthPacks(%this, %healthspawnPoint)
{


   // Create the health object
   %health = new Item() {  // this may be incorrect. (ItemData)???
      dataBlock = HealthKit;
   };
   MissionCleanup.add(%health);

   // place health...
   %health.setTransform(%healthspawnPoint);
}


//-----------------------------------------------------------------------------
// Support functions
//-----------------------------------------------------------------------------

function pickHealthSpawnPoint() 
{
   %groupName = "MissionGroup/HealthDropPoints";  //note this as well
   %group = nameToID(%groupName);

   if (%group != -1) {
      %count = %group.getCount();
      if (%count != 0) {
         %index = getRandom(%count-1);
         %spawn = %group.getObject(%index);
         return %spawn.getTransform();
      }
      else
         error("No health spawn points found in " @ %groupName);
   }
   else
      error("Missing health spawn points group " @ %groupName);

   // Could be no spawn points, in which case we'll stick the
   // player at the center of the world.
   return "0 0 300 1 0 0 0";
}

This may or may not work, but it should point you in the right direction. :)