- Code: Select all • Expand view
class Cam_Point : SecurityCamera
{
Default
{
CameraHeight 60;
}
}
class End_Level : ProgLevelEnder
{
Default
{
+Inventory.Autoactivate;
}
}
// endcam event handler
class endcam_EventHandler : EventHandler
{
PlayerInfo player;
Actor cam;
int playertid;
int camtid;
int counter;
override void WorldTick()
{
// if the return = cameratid we are at the end
int tid = ACS_NamedExecuteWithResult("getcameratid", 0);
if (tid == camtid)
{
if (counter-- == 0)
{
player.mo.GiveInventory("End_Level", 1);
}
}
}
override void WorldLoaded(WorldEvent e)
{
for(int i = 0; i < Level.Sectors.Size(); i++)
{
for (int ii = 0; ii < Level.Sectors[i].Lines.Size(); ii++)
{
int special = Level.Sectors[i].Lines[ii].Special;
if (special == 243)
{
Level.Sectors[i].Lines[ii].Special = 237;
Level.Sectors[i].Lines[ii].Args[0] = camtid;
Level.Sectors[i].Lines[ii].Args[1] = 1;
Level.Sectors[i].Lines[ii].Args[2] = 1;
}
}
}
}
override void WorldUnloaded(WorldEvent e)
{
}
override void PlayerSpawned(PlayerEvent e)
{
player = players[e.PlayerNumber];
counter = 35 * 5;
cam = Actor.Spawn("Cam_Point", player.mo.pos);
cam.args[1] = 180;
cam.args[2] = 200;
camtid = ACS_NamedExecuteWithResult("gettid");
cam.ChangeTid(camtid);
int i = ACS_NamedExecuteWithResult("gettid");
playertid = ACS_NamedExecuteWithResult("gettid");
player.mo.ChangeTid(playertid);
}
}
How this works is simple. A camera is spawned at the player location (although these can and should be spawned at several places e.g. large outdoor sectors, areas with a lot of monsters, etc.) and given a unique tid. I haven't started working out the camera placement algorithm, so for now it's the player start position. In WorldLoaded a 243 line special is changed to a 237 with appropriate arguments. 244 (Exit_Secret) can also be done, of course. When the player comes to an exit and activates the line, the view switches to the spawned, at which point anything can be done.
Currently this is programmed to return to the player when the player moves, but that doesn't have to happen. The player will have to be morphed somewhere until the next level starts, of course, to avoid getting killed.
- HUD messages and stats can be displayed (I assume)
- The level can actually end by activating or giving an inventory item (https://zdoom.org/wiki/Classes:ProgLevelEnder), for example.
Similar solutions exist, I'm sure, but this should be universal for all other cases.
WIP.
Update
Spoiler: