...
Bloque de código |
---|
|
void AddSC_my_script(); // this is a declaration
AddSC_my_script(); // this is a call |
Open the file: /src/server/gamescripts/Scripting/ScriptLoaderCustom/custom_script_loader.cpp and scroll to the bottom of it.
The declaration needs to be added below the line that says/* : This is where custom scripts' loading functions should be declared. */
Here is an example of how the code in ScriptLoader.cpp the file can look after adding the function declaration to it:
Bloque de código |
---|
|
#ifdef SCRIPTS
//* This is where custom scripts' loading functions should be declared. */:
void AddSC_my_script();
#endif |
Next you add the function call under the line that says /* This is where custom scripts should be added. */inside the function called AddCustomScripts
Again here is an example of how the code could look afterwards:
Bloque de código |
---|
|
void AddCustomScripts(){
#ifdef SCRIPTS
/* This is where custom scripts should be added. */
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
AddSC_my_script();
#endif
} |
Now
you need to link the script file to the compilation with cmake. Lets do that for our example script. Open up the file /src/server/scripts/Custom/CMakeLists.txt
Our script file is located in /src/server/scripts/Custom and it is called My_script.cpp so we need to add the line "Custom/My_script.cpp" to the file.
ExampleHere is a final example of how the file could look after both edits:
Bloque de código |
---|
| # file(GLOB_RECURSE sources_Custom Custom/*.cpp Custom/*.h)
set(scripts_STAT_SRCS
${scripts_STAT_SRCS}
# ${sources_Custom}
"Custom/My_script.cpp"
)
message(" -> Prepared: Custom") |
// This is where scripts' loading functions should be declared:
void AddSC_my_script();
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
AddSC_my_script();
} |
Next you need to use cmake and compile.
...