Allows for runtime script execution for DayZ SA through loading new script modules. There are two methods that can be used, both for convenience, fire and forget method style execution and complex instance execution. This script is public, and will most likely be used in various different mods/addons, so renaming would need to be considered to prevent collision. This is currently setup for execution on the Mission script module, mainly for simplicity and to allow for access to all vanilla script modules.
Execution only happens on the side you execute on! If you execute on script on server it will only effect the server, and does not propagate to clients! You will need RPCs to pass anything to clients.
Using the fire and forget method might require you to use escape characters if you're executing programatically, if you're reading from a EditBoxWidget or MultilineEditBoxWidget, you should not have to escape characters. Note, that the # character can not be used, as it's used for string translation and can NOT be escaped!
Example of method style execution:
BashExecutor.ExecuteEnf("Print(\"Hello World!\");");
Using file execution can be a bit more complexed, as it allows you to have instances of new types which can allow for more complexed code. You must store the ScriptModule and output class if you're wanting to hold the instance to use it in other methods, or else the reference counter will clean up the instance. Refer to 1_Core/proto/EnScript.c
class ScriptModule
for more information on CallFunction
and CallFunctionParams
.
Example of instance execution:
modded class MissionServer
{
// strong ref to prevent the ref counter clean up
protected ref ScriptModule m_CustomBashModule;
protected ref Class m_CustomBashInstance;
override void OnMissionStart()
{
super.OnMissionStart(); // propagate hierarchy
// load our module and intialize
m_CustomBashModule = BashExecutor.ExecuteEnf_File("$profile:PathToCustomScript.c", m_CustomBashInstance);
}
override void InvokeOnConnect(PlayerBase player, PlayerIdentity identity)
{
super.InvokeOnConnect(player, identity); // propagate hierarchy
// execute method called PlayerConnected with parameter of PlayerBase
m_CustomBashModule.CallFunction(m_CustomBashInstance, "PlayerConnected", null, player);
}
}
class CustomPlayerConnected
{
private static ref CustomPlayerConnected s_Instance;
void Init() {}
void PlayerConnected(PlayerBase player)
{
Print("A new player connected! " + player);
}
static CustomPlayerConnected GetInstance()
{
if (!s_Instance)
{
s_Instance = new CustomPlayerConnected();
}
return s_Instance;
}
}
DaOne helped quite a bit with the initial idea, as it's being used similarly in VPP Admin Tools. If you have any issues or questions, I'm sorry, neither me nor DaOne are going to be providing support on how to use this, the above documentation should suffice. If you're having a hard time understanding or using this, then you probably do not need it. This gist is subject to change.