0

Free script - Reset the scene

Some of you have seen me force the scene server to reset at HoverDerby using my scripts. While this is in principle very easy to add to your own scripts, there is a key restriction right now that says you can't resell scripts that use the scene-reset API call. So if you intend to do so, you should create a separate script and ask your users to upload it.

I am offering the following as a universal solution for you and your customers. Just have them copy and paste the code below into Notecard and save the file as "Reflex_ResetScene.cs". Make sure it does not have a ".txt" extension! Then you can upload this file directly to Sansar as a script. Make sure it is named "Reflex_ResetScene" on import and in your inventory.

Once it's in your inventory, you can drop this into any of your scenes and use your own scripts to invoke it. See the sample code embedded right in the file for instructions on how to trigger a reset and even let you know if the script is missing.

Note that this is not tied to any other Reflex script. This is just a standalone freebie that any Sansar script can invoke without any other requirements.

 

Reflex_ResetScene.cs

/**********************************************************************
Purpose: Reset the current scene
Created: 4/26/2018 by Galen

This script cannot be sold in the store because of its use of the
restricted ScenePrivate.ResetScene() method. Upload this file to your
inventory. Drop it into any object in your scene. Add the following
to your script's main class:

public interface IResetScene {
void ResetScene();
}
public void ResetScene() {
foreach (var Scr in ScenePrivate.FindReflective<IResetScene>("Reflex_ResetScene")) {
Scr.ResetScene();
return;
}
ScenePrivate.Chat.MessageAllUsers("Can't find the 'Reflex_ResetScene' script in this scene, so can't reset the server");
}

You can call it in your own code like this:

ResetScene();

**********************************************************************/

using Sansar.Script;
using Sansar.Simulation;

[RegisterReflective]
public class Reflex_ResetScene : SceneObjectScript {

public override void Init() {
}

public void ResetScene() {
ScenePrivate.ResetScene();
}

}

 

8 comments

Please sign in to leave a comment.