Scripting Introduction: Difference between revisions
No edit summary |
|||
Line 41: | Line 41: | ||
<syntaxhighlight lang="C#"> | <syntaxhighlight lang="C#"> | ||
[JsonProperty("FlagDamagePerSecond")] public float flagDPS = 5.0; | [JsonProperty("FlagDamagePerSecond")] public float flagDPS = 5.0; | ||
</ | </syntaxhighlight> | ||
Revision as of 13:27, 2 February 2023
Scripting in Soldat 2 is done in a Unity/C# environment. For a script to be usable in-game, the script file must be placed under Soldat2/Scripts/
and there needs to be a ruleset that specifies that script in the GameScript object in its json - for example, see Soldat2/Rules/Standard/Climb.json
. The script can be tested by starting a game that uses that ruleset.
Scripting Resources
The Soldat 2 engine uses Unity, so it may be useful to familiarise yourself with the Unity Manual.
There is some preliminary documentation for the Soldat 2 engine, however it is currently rather limited.
Some examples of scripts can be found in your Soldat 2 game directory under the path Soldat2/Scripts/Standard/
. Some unofficial examples are available at Scripting Examples.
More documentation is added to this wiki under Category:Scripting.
Using Scripts
A script can be applied to a match via Modifiers or via a Game Mode ("Rules").
In a modifier
Example of a modifier Modifiers/Custom/FlagIsPoison.json
applying the Scripts/Custom/FlagIsPoison.cs
script:
{
"Objects": {
"Rules": {
"FlagIsPoison": {
"FlagDamagePerSecond": 3.0
}
}
},
"Meta": {
"Description": "(applies the FlagIsPoison script)",
"Author": "noerw",
"Version": 1.0
}
}
A script can be parametrized, where the parameters are defined in the modifier or rule definition. In the above example the FlagDamagePerSecond
parameter is applied when the script class contains a JsonProperty
with a default value:
[JsonProperty("FlagDamagePerSecond")] public float flagDPS = 5.0;
In a rule / game mode
Add the script name to the GameRules
section of the rule definition in Rules/Custom/YourGameMode.json
:
{
"Objects": {
"YourGameMode": {
"GameScript": {
"Scripts": [
... potentially other scripts ...,
"YourScriptName"
]
}
}
}
}
- TODO: check if parameters can be passed in this syntax too (eg
"Scripts": [{ "YourScriptName": { MyParam: false } }]