- To avoid too many instructions that terminate the script (a runaway), a random search is conducted in a decreasing radius to 64 units
- The PlayerCheck dummy actor must be within line of sight using CheckSight
- The new location has a sector height > 64
- The floor texture isn't blank and the terrain is SOLID (probably not necessary)
Code: Select all
Actor PlayerCheck
{
+Invisible
}
Code: Select all
#library "randomstart"
#include "zcommon.acs"
script "randomstart" ENTER
{
int tid = 21000;
int pid = tid;
Thing_ChangeTID(0, pid);
int x = GetActorX(0) >> 16;
int y = GetActorY(0) >> 16;
int rad = GetUserCVar(0, "rand_radius");
bool debug = GetUserCVar(0, "rand_debug");
if (debug)
{
Log(f:GetActorFloorZ(pid), s:", ", f:GetActorCeilingZ(pid), s:", ", s:GetActorFloorTexture(pid));
}
while (1==1)
{
if (debug)
{
Log(s:"Checking radius: ", d:rad);
}
int new_x = x + Random(0, rad) - Random(0, rad);
int new_y = y + Random(0, rad) - Random(0, rad);
int ceilingZ = GetSectorCeilingZ(0, new_x, new_y) >> 16;
int floorZ = GetSectorFloorZ(0, new_x, new_y) >> 16;
int sectorHeight = ceilingZ - floorZ;
if (sectorHeight > 64)
{
tid++;
Spawn("PlayerCheck", new_x << 16, new_y << 16, floorZ << 16, tid);
if (debug)
{
Log(f:GetActorFloorZ(tid), s:", ", f:GetActorCeilingZ(tid), s:", ", s:GetActorFloorTexture(tid));
}
if (CheckSight(tid, pid, 0)==true && GetActorFloorTexture(tid)!="" && GetActorFloorTerrain(tid)=="SOLID")
{
if (debug)
{
Log(s:"x: ", d:new_x, s:" y: ", d:new_y, s:" sector height: ", d:sectorHeight, s:" floor: ", s:GetActorFloorTexture(tid));
Log(s:"moving...");
}
SetActorPosition(pid, new_x << 16, new_y << 16, floorZ << 16, false);
break;
}
rad -= 2;
if (rad < 64)
{
break;
}
}
}
}
Anyway still playing with this. I'm not sure, for example, if it would crash with multiple hops around the room to (perhaps) start down a corridor. If the script runs too long the player may appear at the mapped spawn point, breaking the effect.
Update
I've added rand_hops as a loop variable to allow the random start to hop around the spawn area. Seems to work.