Code:
//The SOC. This is simple enough to read, so not going in-depth.
freeslot(
"MT_MOBJSHADOW",
"S_MOBJSHADOW",
"SPR_OSHD"
)
states[S_MOBJSHADOW] = {
sprite = SPR_THOK, //Use SPR_OSHD if the sprite is provided
frame = A,
tics = 1,
nextstate = S_MOBJSHADOW,
}
mobjinfo[MT_MOBJSHADOW] = {
spawnstate = S_MOBJSHADOW,
dispoffset = -1,
flags = MF_NOCLIP|MF2_SHADOW,
}
//If the "player.spawncheck" variable has been set to "false", then the object will spawn.
//If it has been spawned, then it will set the variable to "true" so it does not spawn again.
//If the shadow has been spawned and is valid,
//then teleport the shadow to the floor (or ceiling if flipped) underneath the player's position.
//If the player dies, then set the variable to "false" and remove the shadow,
//so that a new shadow may spawn when the player respawns.
//Debug prints are included; they are supposed to print when something is working.
//Note that the P_TeleportMove ones are supposed to print every tic.
addHook("ThinkFrame", function()
for player in players.iterate do
if player.spawncheck == false and (player.mo.flags2 & MF2_OBJECTFLIP) and player.playerstate == PST_LIVE then
player.spawnedshadow = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.ceilingz, MT_MOBJSHADOW)
player.spawncheck = true
print("Spawn check is true; a player spawned on the ceiling and the shadow has spawned accordingly.")
elseif player.spawncheck == false and player.playerstate == PST_LIVE then
player.spawnedshadow = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.floorz, MT_MOBJSHADOW)
player.spawncheck = true
print("Spawn check is true; a player spawned on the floor and the shadow has spawned accordingly.")
end
if player.spawnedshadow and player.spawnedshadow.valid and (player.mo.flags2 & MF2_OBJECTFLIP) then
P_TeleportMove(player.spawnedshadow, player.mo.x, player.mo.y, player.mo.ceilingz)
print("Teleporting the shadow to the ceiling beneath the player...")
elseif player.spawnedshadow and player.spawnedshadow.valid then
P_TeleportMove(player.spawnedshadow, player.mo.x, player.mo.y, player.mo.floorz)
print("Teleporting the shadow to the floor beneath the player...")
end
if player.spawnedshadow and player.spawnedshadow.valid then
print(player.name)
end
if player.spawnedshadow and player.spawnedshadow.valid and player.playerstate == PST_DEAD then
P_RemoveMobj(player.spawnedshadow)
player.spawncheck = false
print("Spawn check is false; a player died and the shadow can now spawn once the player does.")
end
end
end)
I'm trying to create a script that spawns an object below the player that follows the player along the ground (ignoring height differences is intentional). However, I cannot figure out how to get the object to both spawn once per life and to follow the player. The closest I gotten to it is an object spawning every tic at the spawn position of the player, without it following.
Thanks in advance!