Mission Changing code in Trigger - difficult?
by Eric Morata · in Technical Issues · 03/20/2005 (9:31 pm) · 26 replies
Hello guys.I'm trying to make a functional warp to ANOTHER mission. It would unload the actual mission from memory and then load up an specified mission.
Doesn't work: application closes on my face with error. Here's the trigger code i'm trying to run:
at ...fps/server/scripts/trigger.cs :
]code start
datablock TriggerData(Teleporter1)
{
tickPeriodMS = 100;
};
$cenario1="starter.fps/data/missions/MissionOne.mis";
function Teleporter1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
endMission(%this);
//endMission();
//loadMission( $cenario1, true ) ;
}
function Teleporter1::onLeaveTrigger(%this,%trigger,%obj)
{
Parent::onLeaveTrigger(%this,%trigger,%obj);
}
function Teleporter1::onTickTrigger(%this,%trigger) {
Parent::onTickTrigger(%this,%trigger);
}
]code end
Any help would be apreciated... I changed a load of things, but no sucess...
Thanks in advance;
Ericmor
Doesn't work: application closes on my face with error. Here's the trigger code i'm trying to run:
at ...fps/server/scripts/trigger.cs :
]code start
datablock TriggerData(Teleporter1)
{
tickPeriodMS = 100;
};
$cenario1="starter.fps/data/missions/MissionOne.mis";
function Teleporter1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
endMission(%this);
//endMission();
//loadMission( $cenario1, true ) ;
}
function Teleporter1::onLeaveTrigger(%this,%trigger,%obj)
{
Parent::onLeaveTrigger(%this,%trigger,%obj);
}
function Teleporter1::onTickTrigger(%this,%trigger) {
Parent::onTickTrigger(%this,%trigger);
}
]code end
Any help would be apreciated... I changed a load of things, but no sucess...
Thanks in advance;
Ericmor
#2
This seemed like the obvious and simple implementation that should work, but insted it crashed hard. The lesson is that you should never call loadMission from within a trigger! This rule can be expanded to..
See when you call loadMission the current mission is unloaded and the new one is loaded. Well when your trigger returns it continues with processing of the old scene objects... all which have been deleted... hence my nasty crash.
If you look at how cycleGame() works it uses the schedule() command to avoid this problem. So i copied what cycleGame() does:
This works great. The "$Game::LaunchingMission" check is there to prevent two mission launch events to be scheduled at the same time.
UPDATE: I forgot my change to pickSpawnPoint()... see my post below.
03/23/2005 (3:15 pm)
Here is one problem i ran into which should have been obvious to me, but wasn't and caused me lots of grief until i figured it out. So at first i just called this function from my trigger:function LaunchMission( %mission, %spawn )
{
$Game::NextSpawn = %spawn;
loadMission( %mission );
}This seemed like the obvious and simple implementation that should work, but insted it crashed hard. The lesson is that you should never call loadMission from within a trigger! This rule can be expanded to..
Quote:
Object callbacks have to be carefull about invoking server functions that could cause their object to be deleted.
See when you call loadMission the current mission is unloaded and the new one is loaded. Well when your trigger returns it continues with processing of the old scene objects... all which have been deleted... hence my nasty crash.
If you look at how cycleGame() works it uses the schedule() command to avoid this problem. So i copied what cycleGame() does:
// Launches another %mission after %timeout milliseconds at
// the %spawn point desired. %timeout and %spawn can be zero.
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 );
}This works great. The "$Game::LaunchingMission" check is there to prevent two mission launch events to be scheduled at the same time.
UPDATE: I forgot my change to pickSpawnPoint()... see my post below.
#3
Forgive my lack of codewise assembling, i still mapping the entire script structure of torque and my C++ is very basic. I've just recently completed the art development and started the basic gameflow control...
Thanks a bunch, Chris!
Tom, you code worked. Gonna put your name on the credits when my game get finished.
Thanks again guys;
Ericmor
03/24/2005 (4:46 pm)
... Server instructions that still try to access deleted objects?!? Jee! I was even UNLOADING the mission before loading the new one!!!Forgive my lack of codewise assembling, i still mapping the entire script structure of torque and my C++ is very basic. I've just recently completed the art development and started the basic gameflow control...
Thanks a bunch, Chris!
Tom, you code worked. Gonna put your name on the credits when my game get finished.
Thanks again guys;
Ericmor
#4
03/24/2005 (9:42 pm)
OK, ur welcome i think. My server is a little different as when my mission ends most of my delete scripts and schedules are put there instead of in the game.cs. I do agree with Tom's coding though. It is a very nice and clean way of switching maps. I have noticed however that is you have an on parent enter and switch the map as I had listed, it doesnt go back to look for delted objects as much as it does for schedules and ray cast loops. Which I add into the end missoin scripts which is why the code I left may be buggy. Excellent scripting Tom. Very nice and clean.
#5
on ...game\server\scripts\markers.cs
on ...game.fps\server\scripts\trigger.cs
I know i'm overlooking something really simple and important somwhere... $Game::NextSpawn on Tom's code is what's making me wonder: it's an example on how the code could be developed or an actual instruction interpreted by loadmission?!? If i'm being a fool in here, please don't get angry: i looked around at the whole documentation and i NEVER found nothing about those instructions... If isn't creating a new kind of missionmarker data, then how?
Thanks in advance...
Oh, by the way, sorry for "thanks a bunch", my english is a little rusty sometimes :P
03/30/2005 (8:42 pm)
I do believe this one doesn't require a new thread: positioning selection over mission changing. You see, when you load a new mission, there's no way to select in wich spawnsphere the player will appear. I tried this:on ...game\server\scripts\markers.cs
datablock MissionMarkerData(SpawnSphereMarker)
{
category = "Misc";
shapeFile = "~/data/shapes/markers/octahedron.dts";
};
datablock MissionMarkerData(SpawnSphere_pos1) //this one i created from nowhere...
{
category = "Misc";
shapeFile = "~/data/shapes/markers/octahedron.dts";
};
datablock MissionMarkerData(SpawnSphere_pos2) //this one too...
{
category = "Misc";
shapeFile = "~/data/shapes/markers/octahedron.dts";
};
//------------------------------------------------------------------------------
// - serveral marker types may share MissionMarker datablock type
function MissionMarkerData::create(%block)
{
switch$(%block)
{
case "WayPointMarker":
%obj = new WayPoint() {
dataBlock = %block;
};
return(%obj);
case "SpawnSphereMarker":
%obj = new SpawnSphere() {
datablock = %block;
};
return(%obj);
case "SpawnSphere_pos1":
%obj = new SpawnSphere() {
datablock = %block;
};
return(%obj);
case "SpawnSphere_pos2":
%obj = new SpawnSphere() {
datablock = %block;
};
return(%obj);
}
return(-1);
}on ...game.fps\server\scripts\trigger.cs
$cenario0="starter.fps/data/missions/fps.mis";
$cenario1="starter.fps/data/missions/Ericfirst.mis";
$spawnpoint1="SpawnSphere_pos1";
$spawnpoint2="SpawnSphere_pos2";
//-----------to mission"0"(/fps.mis), entrance1
datablock TriggerData(Teleporte_cen0_ent1)
{
tickPeriodMS = 100;
};
function Teleporte_cen0_ent1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
LaunchMission( $cenario0, $spawnpoint1, 1 );
}
//-----------To mission0(/fps.mis), entrance2
datablock TriggerData(Teleporte_cen0_ent2)
{
tickPeriodMS = 100;
};
function Teleporte_cen0_ent2::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
LaunchMission( $cenario0,$spawnpoint2, 1 );
}
//Tom Spilman code snipet
// Launches another %mission after %timeout milliseconds at
// the %spawn point desired. %timeout and %spawn can be zero.
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 know i'm overlooking something really simple and important somwhere... $Game::NextSpawn on Tom's code is what's making me wonder: it's an example on how the code could be developed or an actual instruction interpreted by loadmission?!? If i'm being a fool in here, please don't get angry: i looked around at the whole documentation and i NEVER found nothing about those instructions... If isn't creating a new kind of missionmarker data, then how?
Thanks in advance...
Oh, by the way, sorry for "thanks a bunch", my english is a little rusty sometimes :P
#6
If you look int pickSpawnPoint() you'll see it checks $Game::NextSpawn first to decide on a spawn location to use. Note it assumes all spawn points are part of the "MissionGroup/PlayerDropPoints" group.
03/30/2005 (9:47 pm)
Just pass the name of the spawn into the LaunchMission and the code can do the rest.LaunchMission( "Frontier/data/missions/Mothership.mis", "DockSpawn" );
If you look int pickSpawnPoint() you'll see it checks $Game::NextSpawn first to decide on a spawn location to use. Note it assumes all spawn points are part of the "MissionGroup/PlayerDropPoints" group.
#7
Thanks for the groups tip, i was making that mistake.
Okay, the player goes to the new mission and appears in the spawnpoint, but in random positions. I put the code, like this:
...but it doesn't matter wich trigger you enter , you randonly appear on SpawnSphere_pos1 or SpawnSphere_pos2.
Im obviously making a declaration mistake here:"the name of the spawn" is the datablock name, the name_Tag name or an specific pointer field that must be created inside the datablock an should be declared on LaunchMission? I triyed all combinations.
Is a completely new kind of datablock used in this specific case?
I searched the documentation again in vain... any help is welcome.
Sorry my lack of code understanding... Thanks in advance;
Ericmor
04/02/2005 (7:44 pm)
Thanks again Tom, but... is not working right...Thanks for the groups tip, i was making that mistake.
Okay, the player goes to the new mission and appears in the spawnpoint, but in random positions. I put the code, like this:
//on ...game\server\scripts\markers.cs
datablock MissionMarkerData(SpawnSphere_pos1)
{
category = "Misc";
shapeFile = "~/data/shapes/markers/octahedron.dts";
};
datablock MissionMarkerData(SpawnSphere_pos2)
{
category = "Misc";
shapeFile = "~/data/shapes/markers/octahedron.dts";
};
//on ...game.fps\server\scripts\trigger.cs
function Teleport_cen0_ent1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
LaunchMission( $cenario0,"SpawnSphere_pos1" );
}
function Teleport_cen0_ent2::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
LaunchMission( $cenario0, "SpawnSphere_pos2" );
}...but it doesn't matter wich trigger you enter , you randonly appear on SpawnSphere_pos1 or SpawnSphere_pos2.
Im obviously making a declaration mistake here:"the name of the spawn" is the datablock name, the name_Tag name or an specific pointer field that must be created inside the datablock an should be declared on LaunchMission? I triyed all combinations.
Is a completely new kind of datablock used in this specific case?
I searched the documentation again in vain... any help is welcome.
Sorry my lack of code understanding... Thanks in advance;
Ericmor
#8
04/03/2005 (5:19 pm)
@Eric - Humm... i suggest putting some echo calls in the pickSpawnPoint() function to see what it's doing. At the very begining of the function it checks $Game::NextSpawn and if it isn't blank it tries to use that to select the spawn point. The code should be fairly self explanitory.
#9
This means that "%index = getRandom(%count-1);" will not run only if doesn't even found spawnpoints! Maybe your code is different somehow? Most code packs changes original codes, meaning that i suppose your pickspanwpoint() and mine are not the same?
Anyway, i quit my complaints and tryied a load of combinations... grrr, no success!!! This is the pickspawnpoint im trying now:
I am no programmer... The .getobject() and .nameToID() instructions i used where most guessed after hundreds of crashs and bad results. Maybe Torque is still too programmer directioned... i only managed to make something like a game in the past with Acknetix scripts, and even that wasn't easy! I know that the correct developing procedures are with teams and such... i only tought that maybe a lonewolf with 3d skills could make a simple shotter in Torque without much trouble.
Well, don't want to change the thread subject, but if in you guys opinion deep C++ knowledge and at least more than one skilled programmer is required to develop even sinple shotters in Torque script, maybe i better change my developing procedures... fast!
Thanks once again;
Ericmor
04/04/2005 (7:04 pm)
Thanks Tom. I should know that the problem was in pickSpawnpoint(). The code will pick randomly between spawnpoints no matter what you do (of course, that's just my impression...)You see, this is the original function i have in my game.cs:function pickSpawnPoint()
{
%groupName = "MissionGroup/PlayerDropPoints";
%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 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";
}This means that "%index = getRandom(%count-1);" will not run only if doesn't even found spawnpoints! Maybe your code is different somehow? Most code packs changes original codes, meaning that i suppose your pickspanwpoint() and mine are not the same?
Anyway, i quit my complaints and tryied a load of combinations... grrr, no success!!! This is the pickspawnpoint im trying now:
function pickSpawnPoint()
{
echo("Eric: pickspawnpoint- beginning:");
%groupName = "MissionGroup/PlayerDropPoints";
echo("Eric:pickspawnpoint- %groupName:"@ %groupName);
%group = nameToID(%groupName);
echo("Eric:pickspawnpoint- %group:"@ %group);
if (%group != -1) {
%count = %group.getCount();
echo("Eric:pickspawnpoint- %count:"@ %count);
if (%count != 0) {
%index = getRandom(%count-1);
echo("Eric:pickspawnpoint- %index:"@ %index);
if($Game::NextSpawn==void)
{%spawn = %group.getObject(%index);}
else
{%spawn = %group.getObject($Game::NextSpawn);}
echo("Eric:pickspawnpoint- %spawn:"@ %spawn);
echo("Eric:pickspawnpoint- return %spawn.getTransform():"@ %spawn.getTransform());
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";
}I am no programmer... The .getobject() and .nameToID() instructions i used where most guessed after hundreds of crashs and bad results. Maybe Torque is still too programmer directioned... i only managed to make something like a game in the past with Acknetix scripts, and even that wasn't easy! I know that the correct developing procedures are with teams and such... i only tought that maybe a lonewolf with 3d skills could make a simple shotter in Torque without much trouble.
Well, don't want to change the thread subject, but if in you guys opinion deep C++ knowledge and at least more than one skilled programmer is required to develop even sinple shotters in Torque script, maybe i better change my developing procedures... fast!
Thanks once again;
Ericmor
#10
I see the problem now. My pickSpawnPoint() is different... because i changed it, but forgot about that. Anyway... use this one:
You can see that i added a check for $Game::NextSpawn if it is not null. This should make it work properly for you. Sorry i overlooked it.
04/04/2005 (7:12 pm)
First of all you will have to know at least some basic Torque script. There isn't any getting past that if you want to do more than what already exists in the starter.fps mod.I see the problem now. My pickSpawnPoint() is different... because i changed it, but forgot about that. Anyway... use this one:
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";
}You can see that i added a check for $Game::NextSpawn if it is not null. This should make it work properly for you. Sorry i overlooked it.
#11
No logical reason for that! I carefully read your code: for some reason, any declaration of the $Game::NextSpawn is COMPLETELY ignored by pickSpawnPoint()!!! It look to $Game::NextSpawn as a local created, empty variable! Tom, i believe that the instructions and variables inside your function LaunchMission are using something more... maybe you changed something on your SDK code? Mine is pure, i compiled it with no changes (except the icon), so maybe those variables mean nothing to my loadmission...
Well, i said that i no programmer, but i managed to caught up a little trick: on your code, %index variable where being keeping value 0. That made my character always spawn on the first spawsphere of the mission. Its all right to the connecting passageway to the first spawnpoint, but not to the second passageway (where you should spawn in spawsphere2).
I just added a small variable - $SPAWNSELECT - and told the teleport functions of the triggers to change $SPAWNSELECT value accordlingly.
I then added the following line in pickspawnpoint:
if($SPAWNSELECT==0){%index = 0;}
if($SPAWNSELECT==1){%index = 1;}
If you enter on trigger1, it will send you to the first spawnsphere added in the mission, if you go to trigger2, you'll go to the second spawnsphere, etc. Its a half-efficient solution, since it requires you to add the spawspheres in the mission in a correct order... but at leats it works.
Tom, if you can, find out if there is more code added to your launchmission, since it's such a good, clean code. I'll stick to my cheap script for now, but i'd like to add a resource of mission changing code to the guys in the forums with your working code... Nonetheless, gonna credit you for all your help in my game release.
Thanks once again;
Ericmor
04/04/2005 (9:44 pm)
Thank you very much once again Tom! But... Jesus Christ, it didn't work!!!!No logical reason for that! I carefully read your code: for some reason, any declaration of the $Game::NextSpawn is COMPLETELY ignored by pickSpawnPoint()!!! It look to $Game::NextSpawn as a local created, empty variable! Tom, i believe that the instructions and variables inside your function LaunchMission are using something more... maybe you changed something on your SDK code? Mine is pure, i compiled it with no changes (except the icon), so maybe those variables mean nothing to my loadmission...
Well, i said that i no programmer, but i managed to caught up a little trick: on your code, %index variable where being keeping value 0. That made my character always spawn on the first spawsphere of the mission. Its all right to the connecting passageway to the first spawnpoint, but not to the second passageway (where you should spawn in spawsphere2).
I just added a small variable - $SPAWNSELECT - and told the teleport functions of the triggers to change $SPAWNSELECT value accordlingly.
I then added the following line in pickspawnpoint:
if($SPAWNSELECT==0){%index = 0;}
if($SPAWNSELECT==1){%index = 1;}
If you enter on trigger1, it will send you to the first spawnsphere added in the mission, if you go to trigger2, you'll go to the second spawnsphere, etc. Its a half-efficient solution, since it requires you to add the spawspheres in the mission in a correct order... but at leats it works.
//at trigger.cs:
//------------to mission0(/fps.mis), entrance1
datablock TriggerData(Teleport_cen0_ent1)
{
tickPeriodMS = 100;
};
function Teleport_cen0_ent1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
$SPAWNSELECT=0;
LaunchMission( $cenario0, "APOS1" );
}
//at game.cs:
//Tom Spillman pickspawnpoint():
function pickSpawnPoint()
{
%groupName = "MissionGroup/PlayerDropPoints";
%group = nameToID(%groupName);
if (%group != -1) {
%count = %group.getCount();
if (%count != 0) {
//%index = 0; //getRandom(%count-1);
if($SPAWNSELECT==0){%index = 0;}
if($SPAWNSELECT==1){%index = 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";
}Tom, if you can, find out if there is more code added to your launchmission, since it's such a good, clean code. I'll stick to my cheap script for now, but i'd like to add a resource of mission changing code to the guys in the forums with your working code... Nonetheless, gonna credit you for all your help in my game release.
Thanks once again;
Ericmor
#12
Aside from that make sure you delete the game.cs.dso file before running to be sure it's rebuilding it.
04/04/2005 (10:38 pm)
Ok try adding this to the top of the game.cs file:$Game::NextMission = ""; $Game::NextSpawn = "";
Aside from that make sure you delete the game.cs.dso file before running to be sure it's rebuilding it.
#13
Now i'm angry! >:(
I added those echos to pickspawnpoint:
Check out what i find in the console.log...
...
Mission lighting done
Eric: =.MissionGroup/PlayerDropPoints/APOS1
Eric: =.-1
Eric: you reading this? the code didn't work.
*** Initial Control Object
...
The string is correct!!!! $Game::NextSpawn have the correct string loaded!!! And nameToId is turning its ID to -1!!! What the hell!
I can't believe that the real index value of the spawnpoint could be a negative number. NameToID is not working, for some reason. The only explanation is... your SDK is different. Aside from that, i have... no idea! :6
But thanks anyway,Tom. I'll stick to my simple code for now - since %spawn = %group.getObject($SPAWNSELECT) still works...
Thanks again,
Ericmor
04/05/2005 (6:25 am)
Thanks again, Tom. No, that didn't work... Now i'm angry! >:(
I added those echos to pickspawnpoint:
function pickSpawnPoint()
{
%groupName = "MissionGroup/PlayerDropPoints";
if ( $Game::NextSpawn !$= "" )
{
%spawn = nameToID( %groupName @ "/" @ $Game::NextSpawn );
echo("Ericmor: =" %groupName @ "/" @ $Game::NextSpawn );
echo("Ericmor: =" nameToID( %groupName @ "/" @ $Game::NextSpawn ));
$Game::NextSpawn = "";
if ( %spawn != -1 )
return %spawn.getTransform();
}
%group = nameToID(%groupName);
if (%group != -1) {
%count = %group.getCount();
if (%count != 0) {
echo("Ericmor: you reading this? the code didn't work.");
%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";
}Check out what i find in the console.log...
...
Mission lighting done
Eric: =.MissionGroup/PlayerDropPoints/APOS1
Eric: =.-1
Eric: you reading this? the code didn't work.
*** Initial Control Object
...
The string is correct!!!! $Game::NextSpawn have the correct string loaded!!! And nameToId is turning its ID to -1!!! What the hell!
I can't believe that the real index value of the spawnpoint could be a negative number. NameToID is not working, for some reason. The only explanation is... your SDK is different. Aside from that, i have... no idea! :6
But thanks anyway,Tom. I'll stick to my simple code for now - since %spawn = %group.getObject($SPAWNSELECT) still works...
Thanks again,
Ericmor
#14
04/05/2005 (6:32 am)
The -1 means that 'MissionGroup/PlayerDropPoints/APOS1' does not exist. Open up your mission file in the text editor. Is the SpawnSphere APOS1 declared within the PlayerDropPoints SimGroup?
#15
I created spawnsphere DATABLOCKS with the names APOS1 and BPOS2. When i put those in the scene, both the datablock and the nametags where named APOS1, but NOT the LIST name (wich appear in the editor list on the game editing screen)... whenever i typed APOS1 to the list name, the datablock field reset to NONE right in front of me! So nameToId works, after all... with the LIST name field. I switched my useless APOS1 datablock to a simple spawnsphere datablock and it worked perfectly!!!
And that's all, folks! Mission changing code, not easy but now possible - AND working.
Just for Grandfinale, here goes the complete mission changing code:
in... game.fps/server/scripts/trigger.cs:
in... game.fps/server/scripts/game.cs:
Inside the mission, you add a spawnpoint with the list name 'spawnsphere_name' INSIDE the mission group "MissionGroup/PlayerDropPoints" (specified in the pickSpawnPoint(),%groupName variable).
...and that's it! The link between scenarios and missions is at large.
Thank you very much, Tom. Without you... no code at all. Gonna resource this Baby right now :D
Thank you!
Ericmor
04/05/2005 (7:25 am)
Thanks Tom!!! Now its VERY clear what i've done wrong...I created spawnsphere DATABLOCKS with the names APOS1 and BPOS2. When i put those in the scene, both the datablock and the nametags where named APOS1, but NOT the LIST name (wich appear in the editor list on the game editing screen)... whenever i typed APOS1 to the list name, the datablock field reset to NONE right in front of me! So nameToId works, after all... with the LIST name field. I switched my useless APOS1 datablock to a simple spawnsphere datablock and it worked perfectly!!!
And that's all, folks! Mission changing code, not easy but now possible - AND working.
Just for Grandfinale, here goes the complete mission changing code:
in... game.fps/server/scripts/trigger.cs:
$scene0="starter.fps/data/missions/fps.mis";
//------------to mission zero(/fps.mis), entrance 1
datablock TriggerData(name_of_teleport)
{
tickPeriodMS = 100;
};
function name_of_teleport::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
LaunchMission( $scene0, "spawnsphere_name" );
}
//this triggerdata and function must be cretated
// for every exit that connects to a specifc spawnsphere.
//in this case, you'll be sent to $scene0, in the spawnpoint named "spawnsphere_name"
//Tom Spilman code snipet
// Launches another %mission after %timeout milliseconds at
// the %spawn point desired. %timeout and %spawn can be zero.
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 );
}
//-------------in... game.fps/server/scripts/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";
}Inside the mission, you add a spawnpoint with the list name 'spawnsphere_name' INSIDE the mission group "MissionGroup/PlayerDropPoints" (specified in the pickSpawnPoint(),%groupName variable).
...and that's it! The link between scenarios and missions is at large.
Thank you very much, Tom. Without you... no code at all. Gonna resource this Baby right now :D
Thank you!
Ericmor
#16
Using the above code I get my loading screen with a rather static "waiting for server" message... and then nothing - you get stuck!
Is this compatible with TGEA 1.7.1 ?? OR I need to add something else in addition to the code in the above post by Eric...
Cheers!
08/10/2009 (9:49 am)
Hey!Using the above code I get my loading screen with a rather static "waiting for server" message... and then nothing - you get stuck!
Is this compatible with TGEA 1.7.1 ?? OR I need to add something else in addition to the code in the above post by Eric...
Cheers!
#17
Are there any takers for this one as it's really bugging me ??
Thanks.
08/12/2009 (12:15 pm)
Hey guys!Are there any takers for this one as it's really bugging me ??
Thanks.
#18
08/13/2009 (12:08 am)
friend just tested, says it works fine.
#19
Does anyone have a working example of a single player mission loader ??
08/13/2009 (8:32 am)
hmmmmm, and this was tested on TGEA 1.7.1 ? The above code gives me a "waiting for server" message on the loading screen (my code is identical to above).Does anyone have a working example of a single player mission loader ??
#20
My problem was that I hadn't properly initialised the "$Game::NextMission" and "$Game::NextSpawn" elements. Also, if you're using TGEA you need to make sure the "$scene" mission path starts with the scriptsAndAssets folder, such as:
$scene0="scriptsAndAssets/data/missions/mymission.mis";
Starting with your project folder in the path will result in a "mission file not found" console message each time.
Cheers!
08/13/2009 (11:32 am)
Success!!! Thank god for that!My problem was that I hadn't properly initialised the "$Game::NextMission" and "$Game::NextSpawn" elements. Also, if you're using TGEA you need to make sure the "$scene" mission path starts with the scriptsAndAssets folder, such as:
$scene0="scriptsAndAssets/data/missions/mymission.mis";
Starting with your project folder in the path will result in a "mission file not found" console message each time.
Cheers!
Chris Ratliff
//------------------------------------------------------ // Map Change Trigger //------------------------------------------------------ datablock TriggerData(changemap) { tickPeriodMS = 100; }; //------------------------------------------------------ function chat::onEnterTrigger(%this,%trigger,%obj) { Parent::onEnterTrigger(%this,%trigger,%obj); loadMission("rw/data/missions/filename.mis"); }or you could even do
//------------------------------------------------------ datablock TriggerData(changemap) { tickPeriodMS = 100; }; //------------------------------------------------------ function chat::onEnterTrigger(%this,%trigger,%obj) { Parent::onEnterTrigger(%this,%trigger,%obj); cycleGame(); }Either of these would change the maps to a new map, it would just depend on if you want a specific mission to load or your next mission in the loop to load.
EDIT: after a number of emails about this and how silly I was about not ending the mission, I did note that in the second code I posted, it did cycle the game, where as it would end and unload the mission. I was only posting a quick change rather than thinking it out. Also, the script I posted did not include scores or spawns. Please do not email me for bad coding as it was just a quick post for a idea starter.