TGE 1.5.2 Demo - Loading Missions via triggers
by Dan · in Torque Game Engine · 10/05/2013 (7:09 pm) · 15 replies
Hi, I've decided to take on a pretty simplistic project using the TGE 1.5.2 Demo (Yes I somehow still have still have this version on my computer from an old computer backup) and one of the questions I have is how to use a trigger in mission to load a different mission. How exactly would this be done, Would i need to make a new unique triggers.cs or would it go in the one that is already there. I would appreciate it if you go in depth as to how I should script this, as I have nil knowledge of this language. Thank you in advanced!
#2
10/06/2013 (6:35 pm)
Thanks, I'll look into it, I've found a few resources for other issues I've found but they are unfortunately for T3D and I get a bit lost. Hopefully I'll be able to make enough sense of it.
#3
10/07/2013 (9:33 am)
Oh, so It appears I don't have a spawn.cs file, what would you suggest I do in place of editing that file?
#4
The key is to find out where the game picks the player's spawn point and inject the code from the example into that spot.
10/07/2013 (11:54 am)
<shrug> Have to wait until I get home to look, but if you're using Torsion to edit your scripts you could search the project for "pickPlayerSpawnPoint" or just "spawnpoint" and see what comes up. Otherwise you could use Grep or Windows Explorer's search I guess....The key is to find out where the game picks the player's spawn point and inject the code from the example into that spot.
#5
I couldn't find "pickPlayerSpawnPoint" in the server folder I have yet to check the others, but I did find "spawnpoint" in AIplayer.cs, bot.cs (I don't think those are relevant though)scene.cs, and in game.cs I found this.
"
function GameConnection::spawnPlayer(%this)
{
// Combination create player and drop him somewhere
%spawnPoint = pickSpawnPoint();
%this.createPlayer(%spawnPoint);
}
"
10/07/2013 (12:46 pm)
I'm using a software that can search the lines of code for specific text, I'll go through all the .cs files in the server folder and look for that function.I couldn't find "pickPlayerSpawnPoint" in the server folder I have yet to check the others, but I did find "spawnpoint" in AIplayer.cs, bot.cs (I don't think those are relevant though)scene.cs, and in game.cs I found this.
"
function GameConnection::spawnPlayer(%this)
{
// Combination create player and drop him somewhere
%spawnPoint = pickSpawnPoint();
%this.createPlayer(%spawnPoint);
}
"
#6
So as long as you put your spawn points in the MissionGroup/PlayerDropPoints group they'll be found.
I decided to leave the old code there so if you don't have a target spawn point you'll still spawn at a random existing spawn point.
10/07/2013 (6:21 pm)
I'd suggest using the pickSpawnPoint() function at the end of /server/scripts/game.cs://-----------------------------------------------------------------------------
// Support functions
//-----------------------------------------------------------------------------
function pickSpawnPoint()
{
%groupName = "MissionGroup/PlayerDropPoints";
%group = nameToID(%groupName);
if (%group != -1) {
%count = %group.getCount();
// insert target trigger search code here
for(%j = 0; %j < %count; %j++)
{
%spawnPoint = %group.getObject(%j);
if(%spawnPoint.getName() $= $Server::TargetSpawn)
{
if(isObject(%spawnPoint))
{
// found it, return it.
return %spawnPoint;
}
}
}
// end target trigger search. if not found, spawn at random point.
if (%count != 0) {
%index = 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";
}So as long as you put your spawn points in the MissionGroup/PlayerDropPoints group they'll be found.
I decided to leave the old code there so if you don't have a target spawn point you'll still spawn at a random existing spawn point.
#7
10/07/2013 (10:36 pm)
Hmm, It seems I overlooked the first step. I'm not entirely sure how to create new datablocks in TGE 1.5.2.
#8
10/08/2013 (6:46 am)
Just use a text editor. Look in /server/scripts/trigger.cs for the default trigger datablock, duplicate it and add the callback methods there.datablock TriggerData(transitionTrigger)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};That should work for the transition trigger definition....
#9
The second problem I came across is after the character enters the trigger it shows a GUI with the game score for about 10 seconds then shows a loading bar "Waiting for server" which doesn't load.
I opened the developer console to see if I could determine what the issue was and it says, "could not find mission levels/testmission.mis" I think the problem is that I'm not directing it to where the mission is. I tried changing the value "levels/testmission.mis" to "mission(s)/testmission.mis", "testmission.mis" and even just "testmission" none of which worked. Do you know if this is actually the problem and how it can be fixed?
10/09/2013 (9:58 pm)
Okay so, I managed to follow your resource pretty well. I have come across 2 problems. One was that when a spawn point didn't have a name the character would just randomly spawn, even outside of the mission area, and usually underneath the terrain. I solved this just by naming them and giving the newmission.mis spawn point a name so it would no longer do this. The second problem I came across is after the character enters the trigger it shows a GUI with the game score for about 10 seconds then shows a loading bar "Waiting for server" which doesn't load.
I opened the developer console to see if I could determine what the issue was and it says, "could not find mission levels/testmission.mis" I think the problem is that I'm not directing it to where the mission is. I tried changing the value "levels/testmission.mis" to "mission(s)/testmission.mis", "testmission.mis" and even just "testmission" none of which worked. Do you know if this is actually the problem and how it can be fixed?
#10
10/13/2013 (12:45 am)
It sounds like that is indeed the problem and you have to use the correct path to your mission files. By default in TGE they're in data/missions/
#11
10/13/2013 (7:22 am)
Ah, yes that seems to have been it, I had to go one directory backwards for it to work "demo/data/missions/" but thank you for pointing that out! Ok so the only problem that remains is the one I mentioned earlier that I thought I had puzzled out. I am still being spawned underneath the terrain outside of the mission area when I switch missions using a trigger, do you want me to show you what edits I had made to my .cs files or can you figure it out without them. And Thank you very much for all the help so far!
#12
10/13/2013 (8:06 am)
Are your spawn points above ground? They should be a few "feet" above the actors head. If they are too close to the ground, you will spawn underground.
#13
10/13/2013 (8:35 am)
When I open the missions normally by just loading them without switching using a trigger, the character spawns at the spawn points just fine. If I use the triggers to switch missions, the game seems to completely ignore spawn points and just puts the avatar anywhere.
#14
Also, ensure you added the "target" spawn point to the properties of the trigger so that the global variable gets the name of the spawn point it's supposed to be looking for.
10/13/2013 (6:25 pm)
Are your spawn points in the correct simgroup? Looking at post #6 they should all be added to "MissionGroup/PlayerDropPoints" in each mission. Otherwise it can't find them. Check your console.log file for the errors that should be emitted in this case.Also, ensure you added the "target" spawn point to the properties of the trigger so that the global variable gets the name of the spawn point it's supposed to be looking for.
#15
Hopefully I get as much useful help on my next question as you provided here.
I was trying to add a sprint feature but the only resource I could really find was for T3D and I wouldn't know how to apply it to TGE.
10/13/2013 (7:15 pm)
I wasn't really able to find the error in the console.log file but my previous problem got me thinking that maybe I just need to be more specific with the location/title of the object. I had to add "spawnsphere -" in front of the spawn spheres name which I guess was sort of obvious. In your T3D resource you just had the target as the name of the spawn sphere without that in front of it and so it's either different for TGE or it's just a rookie mistake I made. Anyway, I think this problem is all solved, thank you very much for your time!Hopefully I get as much useful help on my next question as you provided here.
I was trying to add a sprint feature but the only resource I could really find was for T3D and I wouldn't know how to apply it to TGE.
Torque Owner Richard Ranft
Roostertail Games
If you run into trouble let me know - I have TGE 1.5.2, TGEA 1.8.2, T3D 1.1, T3D 1.2 and T3D MIT all on tap....