Game Development Community

changing spawnpoints depending on where you entered from

by Eric Thomas Patton · in Torque Game Engine Advanced · 09/06/2009 (6:38 pm) · 11 replies

ok, this is the scenario i'm trying to do:

i am trying to make a floor of a building with each of the rooms as instances that you enter into from a hallway. there are triggers at each door that load a new mission for each room and triggers in each of the rooms that lead you back into the hallway.

there is an original spawnpoint at the beginning of the hallway and spawnpoints outside of each of the doors. i am trying to get it to where when i exit back into the hallway from one of the rooms, the spawnpoint i appear at is the one right outside of the door that i entered from.


i have figured out how to load into the rooms and back into the hallway, but i can't figure out how to set the spawnpoint to the one i want. just an fyi, i'm a total trigger noob.

#1
09/06/2009 (6:53 pm)
You would have to specify a named spawnpoint to use in your trigger code.

function ChangeLevelTrigger::onEnterTrigger(%this, %trigger, %obj)
{
    %client = %obj.client;
    if (!%client)
    {
        // We do not want NPC's or other AIplayers walking into our trigger and
        // seting off the ChangeLevelTrigger.
        return;
    }

    // Change "YOURLEVEL.mis" to the name of your level and filepath!
    %levelName = "YOURLEVEL.mis";

    // Spawn marker in the level to start at.  To make use of this simply add
    // this field to your trigger object and give it a named spawnPoint.  If one
    // isn't given then it will simply drop you at the first found spawn marker.
    %spawnPoint = %trigger.spawnPoint;

    echo("\c4Transferring client: "@ %client @" to "@ %levelName @" at "@ %spawnPoint);
    schedule(0, 0, loadMission, "levels/"@ %levelName, false, %spawnPoint);
}
#2
09/06/2009 (7:30 pm)
for this part:

" To make use of this simply add this field to your trigger object and give it a named spawnPoint."

i'm a trigger noob and am not entirely sure how to give this a named spawnpoint. i think i need to add a dynamic field called "spawnPoint" and obviously name my spawnpoints, but how do i assign is the spawnpoint name i want to the dynamic field? all i see in the mission file for the dynamic field is the name i put for it.
#3
09/06/2009 (7:54 pm)
You're on the right track. Create your dynamic field in the trigger, call it spawnPoint, then just set the field value to the name of a spawnpoint, like so
Trigger(Doorway1) 
{
   // all other relevant fields....
   spawnPoint = "DoorspawnXX"; // change this for each unique spawn location
};
And make sure you have a spawnpoint/marker called DoorspawnXX in your mission file
SpawnSphere(DoorspawnXX) 
{
   // spawnmarker stuff goes here      
};
#4
09/06/2009 (8:40 pm)
function ChangeLevelTrigger::onEnterTrigger(%this, %trigger, %obj)  
{  
    %client = %obj.client;  
    if (!%client)  
    {  
        // We do not want NPC's or other AIplayers walking into our trigger and  
        // seting off the ChangeLevelTrigger.  
        return;  
    }  
  
    // Change "YOURLEVEL.mis" to the name of your level and filepath!	
    %levelName = "simple.mis";  
  
    // Spawn marker in the level to start at.  To make use of this simply add  
    // this field to your trigger object and give it a named spawnPoint.  If one  
    // isn't given then it will simply drop you at the first found spawn marker.  
      spawnPoint = "OutsideHouse";
	%spawnPoint = %trigger.spawnPoint;  
  
    echo("c4Transferring client: "@ %client @" to "@ %levelName @" at "@ %spawnPoint);  
    schedule(0, 0, loadMission, "scriptsAndAssets/data/missions/"@ %levelName, false, %spawnPoint);  
}


this is what i have and i'm not sure i'm doing the spawnpoint correctly. if i have it this way it does nothing. i've tried a few different ways of putting the spawnsphere name in there like replacing %trigger.spawnPoint with it, but I can't get it to happen right. it either does nothing or seems to place me randomly among the spawnspheres.
#5
09/06/2009 (9:21 pm)
after going back over it, i now am pretty sure i was supposed to put the spawnPoint name in the actual trigger in the .mis file. i did that and it still is randomly placing me at different spawnpoints so i figure i'm still missing something
#6
09/07/2009 (12:37 am)
yeah i just can't seem to figure it out. i know now i have to declare the spawnPoint in the trigger in the mission file and have also implemented a missionFileName for it which works, but the spawnpoint never does it right.
#7
09/07/2009 (1:46 am)
This was bad of me but I gave you incomplete code, sorry for not remembering that sooner. I had modified my launchMission() function to accept the additional spawnpoint parameter -- and without that addition once you get to the point of spawning a player pickSpawnPoint simply picks one at random.

My changes actually carried over and into several different functions, but in order to keep things simple give this resource a try. It does what you want, but in a slightly different manner from which I did mine. It will work in TGEa just fine once you've made the appropriate changes for differing filpaths.
#8
09/07/2009 (2:02 am)
ahh lol well this makes me feel less stupid :) was wracking my brain trying to figure out why the mission file name variable worked but the spawnpoint one didn't


thanks for clearing that up :)
#9
09/07/2009 (6:02 pm)
i implemented it, but it's still randomly placing me in spawnspheres. i'll include my relevant code, maybe you can see what i'm doing wrong.

trigger.cs
//============================================================================
//============================================================================
$scene0="scriptsAndAssets/data/missions/jakehatesthisname.mis";
$scene1="scriptsAndAssets/data/missions/simple.mis";
  
datablock TriggerData(ToInside)  
{  
tickPeriodMS = 100;  
};  
  
function ToInside::onEnterTrigger(%this,%trigger,%obj)  
{  
Parent::onEnterTrigger(%this,%trigger,%obj);  
LaunchMission( $scene0, "Inside_House" );  
}  

datablock TriggerData(ToOutside)  
{  
tickPeriodMS = 100;  
};  
  
function ToOutside::onEnterTrigger(%this,%trigger,%obj)  
{  
Parent::onEnterTrigger(%this,%trigger,%obj);  
LaunchMission( $scene1, "Outside_House" );  
}  
  
function LaunchMission( %mission, %spawn, %timeout )  
{  
   if ( !$Game::LaunchingMission ) {  
  
      $Game::NextMission = %mission;  
      $Game::NextSpawn = %spawn;  
      $Game::LaunchingMission = true;  
      schedule( %timeout, 0, "onLaunchMission" );  
   }  
}  
  
  
function onLaunchMission()  
{  
   $Game::LaunchingMission = false;  
   loadMission( $Game::NextMission );  
}
//============================================================================
//============================================================================

game.cs
//Tom Spilman pickspawnpoint():  
function pickSpawnPoint()   
{  
   %groupName = "MissionGroup/PlayerDropPoints";  
  
   if ( $Game::NextSpawn !$= "" ) {  
  
      %spawn = nameToID( %groupName @ "/" @ $Game::NextSpawn );  
      $Game::NextSpawn = "";  
      if ( %spawn != -1 )  
         return %spawn.getTransform();  
   }  
  
   %group = nameToID(%groupName);  
   if (%group != -1) {  
      %count = %group.getCount();  
      if (%count != 0) {  
         %index = 0;  //getRandom(%count-1);  
         %spawn = %group.getObject(%index);  
         return %spawn.getTransform();  
      }  
      else  
         error("No spawn points found in " @ %groupName);  
   }  
   else  
      error("Missing 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";  
}

both mission file triggers
first

new Trigger(port) {
      canSaveDynamicFields = "1";
      Enabled = "1";
      position = "369.724 679.566 143.489";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      dataBlock = "ToInside";
      polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         dynamicField = "MissionName";
         dynamicField001 = "spawn";
         MissionName = "jakehatesthisname.mis";
         spawnPoint = "Inside_House";
   };

=====================
=====================
second

new Trigger(savvybrown) {
      canSaveDynamicFields = "1";
      Enabled = "1";
      position = "756.027 636.811 48.205";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      dataBlock = "ToOutside";
      polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         dynamicField = "MissionName";
         MissionName = "simple.mis";
         spawn = "Outside_House";
   };
#10
09/07/2009 (6:03 pm)
and here are my two spawnsphere parts for my mission files:

first

new SimGroup(PlayerDropPoints) {
      canSaveDynamicFields = "1";
      Enabled = "1";

      new SpawnSphere(start) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         position = "494.578 728.707 162.496";
         rotation = "-0.0102508 -0.0207517 0.999732 232.564";
         scale = "0.940827 1.97505 1";
         dataBlock = "SpawnSphereMarker";
         enableUse = "1";
         Radius = "5";
         sphereWeight = "1";
         indoorWeight = "1";
         outdoorWeight = "1";
            homingCount = "0";
            lockCount = "0";
      };
      new SpawnSphere(Outside_House) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         position = "380.544 678.434 145.735";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         nameTag = "Outside_House";
         dataBlock = "SpawnSphereMarker";
         enableUse = "1";
         Radius = "5";
         sphereWeight = "100";
         indoorWeight = "100";
         outdoorWeight = "100";
      };



=====================
=====================

second


new SimGroup(PlayerDropPoints) {
      canSaveDynamicFields = "1";
      Enabled = "1";

      new SpawnSphere(Inside_House) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         position = "755.022 616.222 50.2412";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         nameTag = "Inside_House";
         dataBlock = "SpawnSphereMarker";
         enableUse = "1";
         Radius = "100";
         sphereWeight = "100";
         indoorWeight = "100";
         outdoorWeight = "100";
      };
      new SpawnSphere(original) {
         canSaveDynamicFields = "1";
         Enabled = "1";
         position = "740.771 668.907 57.8428";
         rotation = "0.03379 0.088947 0.995463 221.43";
         scale = "0.940827 1.97505 1";
         dataBlock = "SpawnSphereMarker";
         enableUse = "1";
         Radius = "10";
         sphereWeight = "1";
         indoorWeight = "1";
         outdoorWeight = "1";
            homingCount = "0";
            lockCount = "0";
            TypeBool locked = "False";
      };
   };
#11
09/17/2009 (1:54 pm)
ok i finally got it to work, though in a roundabout way.

in game.cs i changed the pickspawnpoint() to just this and put a global variable for the first spawnpoint
$Game::NextSpawn = "original";



function pickSpawnPoint()  

{ 

   %groupName = "MissionGroup/PlayerDropPoints";

   %spawn = nameToID( %groupName @ "/" @ $Game::NextSpawn );

   return %spawn.getTransform();

}


then for the trigger i did this:
datablock TriggerData(InstanceChange)
{
	tickPeriodMS = 100;
};

function InstanceChange::onEnterTrigger(%this,%trigger,%obj)
{
	%scene = %trigger.Scene;
	%spawnloc = %trigger.SpawnLocation;
	LaunchMission(%scene,%spawnloc);
}
 

function LaunchMission( %mission, %spawn, %timeout ){ 

   if ( !$Game::LaunchingMission ) { 

 

      $Game::NextMission = %mission; 

      $Game::NextSpawn = %spawn; 

      $Game::LaunchingMission = true; 

      schedule( %timeout, 0, "onLaunchMission" ); 

   } 

} 

 

function onLaunchMission(){ 

   $Game::LaunchingMission = false; 

   loadMission( $Game::NextMission ); 

}

i used a lot of the code from that link you gave me, but this was the only way i could get the spawn points to work properly. it isn't the best code since you have to have a spawnpoint called "original" in the first map you spawn at, but it was all i could think to do to make it work.