Hello! I am looking to write a plugin that upon server restart, the server also resets (wipes all saved data except permissions/plugins). With some help from the community I just made a plugin that restarts the server when Bradley dies, but I would like it to completely reset it as well. The problem is I have esssentially no idea what I'm doing in c#, any guidance in my endeavor is warmly welcomed and greatly appreciated!
Below my Bradley Plugin, if I could do it in the same cs file, that would be amazing.
-Produce
using System;
using Oxide.Plugins;
using Facepunch;
using Oxide.Core;
using System.Configuration;
using Unity;
namespace Oxide.Plugins
{
[Info("Bradley Dies and the Server Resets", "Produce", "1.0")]
public class BradReset : RustPlugin
{
void OnEntityDestroy(BradleyAPC entity)
{
if (entity is BradleyAPC)
{
Server.Command("restart 60 GAME-OVER");
}
}
}
}
Wipe server data on server restart?
To start with, that command is just a quit command with a message; it isn't actually starting the server. Just keep that in mind.
As far as resetting files goes, you can set various plugin data to null, but you won't be able to physically remove any files via a plugin with the security sandbox enabled.
Yep! I understand that is it just quitting out, but if i were to add on the secondary "wipe" aspect it would appear that it is in fact reseting the server.
Is there a functionality somewhere I can take advantage of to only remove player buildings/items/blueprints?
Thank you again for the help, I've been reading for almost 2 weeks on how to use plugins, starting up with c# and it is pretty overwhelming, but I have to say at this point you are almost a celebrity to me Wulf! haha Cheers!
If Rust has methods to natively wipe those files interally, those may be an option; otherwise you'd need to disable the security sandbox in order to access the filesystem via plugins to physically remove files. There are likely ways to wipe buildings, items, and blueprints via a plugin, but not in the sense of actually removing the files; more so of erasing the contents and finding/removing entities instead. Plugins such as Auto Purge, Blueprint Manager, etc. would give you an idea of how that works.
Do keep in mind that you likely won't have much time to do what you want, as that command will trigger a shutdown before you may get a chance to remove/reset all of what you want.
As far as leaning C#, just take it a day at a time and tinker. I started here not knowing any C#, but get along well enough now.
I'll keep at it and check out those plugins! I'm sure I can find a way to get to where I'm going. I'll be back here with some more questions soon enough I'm sure.
if your hosting your own server you can delete the flies with in your startup script.