Resource icon

[Reusable] Resource: Respawning objects and bustable FOF

This thread contains content that may be reused, modified, or ported by anyone.

Kaysakado

Member
This script provides a framework to add respawning to arbitrary objects and crumbling FOFs, e.g., to make destructible but respawning terrain for MP maps. Inside the WAD are three lumps - LUA_RSPN, LUA_EXAM, and SOC_EXAM. LUA_RSPN is the one you want to put into your own add-on! The other two are example scripts.

The included example scripts do these five things:
In GFZ1, bustable blocks are set to respawn, but only under the circumstances that, say, weapon panels would respawn. You must be in multiplayer, the cvar respawnitem must be turned on, and they'll respawn after the amount of seconds respawnitemtime is set to.

In ACZ1, bustable blocks are set to respawn, but override the default checks on how to respawn. They will always respawn, even in single player, and always respawn in one second.

Blue crawlas are set to respawn, but again, only under the default circumstances for respawning. Must be in multiplayer, the cvar respawnitem must be turned on, and they'll respawn after the amount of seconds respawnitemtime is set to.

Red crawlas are set to respawn, but override the default checks on how to respawn. They will always respawn, even in single player, and always respawn in one second.

Spikes and wallspikes are set to respawn, but override the default checks on how to respawn. They will always respawn, even in single player, and always respawn in three seconds. They also use a custom function that correctly sets up the spike object based on the options set by the Thing.

Respawning Bustable FOFs:
FOF respawning is controlled by the level header. To enable, simply include the line Lua.RoverCheck = true in your level header. This will cause Bustable FOFs to respawn using a default function. Basically, this means they will only respawn in multiplayer, when the respawnitem cvar is turned on, and will wait for the value of respawnitemtime before respawning. You can see this in action in GFZ1 in the example script.

You can also specify a custom function to handle respawning. This is used for ACZ1 in the example script. Rawset your function to the global table:
Code:
rawset(_G, "ExampleCheck", do
	return TICRATE
end)
and refer to it in the level header:
Code:
Lua.RoverCheck = ExampleCheck
This function is called when a bustable block no longer exists - it receives the ffloor_t itself as an argument (note that the example doesn't use this) and should return a tic_t, which is how long to wait before respawning the FOF. If the function returns 0, false, or nil, the FOF will not be respawned.

Respawning Objects:
You can add a hook to respawn a given object type with the function AddObjectTypeRespawn. For safety, you may check that this function actually exists first:
Code:
assert(AddObjectTypeRespawn, "This must be loaded after respawn.lua!")
The function takes five arguments:
Code:
AddObjectTypeRespawn(objecttype, [shouldrespawnfunc], [timerfunc], [spawnfunc], [setupfunc])

objecttype: enum (MT_)
The only required argument. The object type to add an MobjRemoved hook for and respawn.

shouldrespawnfunc: boolean function(mo, mo.spawnpoint)
Defaults to RegularShouldRespawn. When an object of objecttype is removed, this function should return whether or not to actually add it to the respawn queue. Note that an object will never be added to the queue without a valid spawnpoint.

timerfunc: tic_t function(mo, mo.spawnpoint)
Defaults to RegularTimer. When an object of objecttype is removed, this function should return the time before respawning, in tics.

spawnfunc: mobj_t function(spawnpoint, objecttype)
Defaults to RegularSpawn. This function is called when it's time to respawn the object. It spawns the object in the correct position, links the object to its spawnpoint and vice-versa, and returns the object. Most objects can use the default spawnfunc.

setupfunc: void function(spawnpoint, mo)
Defaults to RegularSetUp. This function is called after the object is spawned to correctly set things such as its angle and flags. Objects with special properties, such as spikes, will need to use a custom setupfunc.

In the example script, the Blue Crawla uses all the default functions. The Red Crawla uses its own shouldrespawnfunc and timerfunc, while using the default spawnfunc and setupfunc. Spikes and wallspikes use their own shouldrespawnfunc, timerfunc, and setupfunc, but use the default spawnfunc.

You can take a look at the script itself for additional documentation, and the examples to see how they work in practice.
 

Attachments

  • srb20323.gif
    srb20323.gif
    2.3 MB · Views: 139
  • srb20324.gif
    srb20324.gif
    6.5 MB · Views: 129
  • srb20325.gif
    srb20325.gif
    4.9 MB · Views: 143
  • srb20329.gif
    srb20329.gif
    3.4 MB · Views: 134
  • L_respawn-v1.zip
    4.4 KB · Views: 129
Last edited:

FoxDude

lazy person
Why is this a resource but it is in the lua section? Isn't this supposed to be on the resources tab?
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Top