SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Releases > Lua

Reply
 
Thread Tools
Resource: Respawning objects and bustable FOF Details »»
Resource: Respawning objects and bustable FOF
Version: 1, by Kaysakado Kaysakado is offline
Developer Last Online: Oct 2020

Version: SRB2 Rating: (2 votes - 3.60 average)
Released: 08-08-2020 Last Update: Never Favourites: 1
Scripts Re-Useable Content

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:
Spoiler:
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:
Spoiler:
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:
Spoiler:
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.

Download Now

File Type: zip L_respawn-v1.zip (4.4 KB, 39 views)

Screenshots

Click image for larger version

Name:	srb20323.gif
Views:	41
Size:	2.34 MB
ID:	36496   Click image for larger version

Name:	srb20324.gif
Views:	37
Size:	6.54 MB
ID:	36497   Click image for larger version

Name:	srb20325.gif
Views:	45
Size:	4.93 MB
ID:	36498   Click image for larger version

Name:	srb20329.gif
Views:	34
Size:	3.37 MB
ID:	36499  

Show Your Support

  • The author of this addon has given explicit permission for its content to be re-used and/or reproduced.

Comments
Old 08-09-2020   #2
D00D64
Probably Responsible
Moderator
 
D00D64's Avatar
Default

Welcome to releases!
D00D64 is online now   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:48 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.