<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.soldat2.com/index.php?action=history&amp;feed=atom&amp;title=Scripting_Examples</id>
	<title>Scripting Examples - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.soldat2.com/index.php?action=history&amp;feed=atom&amp;title=Scripting_Examples"/>
	<link rel="alternate" type="text/html" href="https://wiki.soldat2.com/index.php?title=Scripting_Examples&amp;action=history"/>
	<updated>2026-05-05T17:08:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.4</generator>
	<entry>
		<id>https://wiki.soldat2.com/index.php?title=Scripting_Examples&amp;diff=155&amp;oldid=prev</id>
		<title>Nerf cardboard: move to Category:Modding</title>
		<link rel="alternate" type="text/html" href="https://wiki.soldat2.com/index.php?title=Scripting_Examples&amp;diff=155&amp;oldid=prev"/>
		<updated>2023-06-10T11:48:59Z</updated>

		<summary type="html">&lt;p&gt;move to Category:Modding&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:48, 10 June 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l68&quot;&gt;Line 68:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 68:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Scripting&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Modding&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key soldat2wiki:diff::1.12:old-98:rev-155 --&gt;
&lt;/table&gt;</summary>
		<author><name>Nerf cardboard</name></author>
	</entry>
	<entry>
		<id>https://wiki.soldat2.com/index.php?title=Scripting_Examples&amp;diff=98&amp;oldid=prev</id>
		<title>AL: Created page with &quot;This page contains a selection of unofficial scripts to demonstrate the usage of various aspects of Soldat 2's scripting API.  == Team Balancer == &lt;syntaxhighlight lang=&quot;C#&quot;&gt; // a basic team-balancing script to illustrate how to implement simple // chat-commands using S2 scripting  // 'using' directives let you omit namespacing // eg: Player rather than the full Teal.Player using System.Collections; using System.Collections.Generic; using UnityEngine; using Teal;  [Disal...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.soldat2.com/index.php?title=Scripting_Examples&amp;diff=98&amp;oldid=prev"/>
		<updated>2023-02-02T13:21:23Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This page contains a selection of unofficial scripts to demonstrate the usage of various aspects of Soldat 2&amp;#039;s scripting API.  == Team Balancer == &amp;lt;syntaxhighlight lang=&amp;quot;C#&amp;quot;&amp;gt; // a basic team-balancing script to illustrate how to implement simple // chat-commands using S2 scripting  // &amp;#039;using&amp;#039; directives let you omit namespacing // eg: Player rather than the full Teal.Player using System.Collections; using System.Collections.Generic; using UnityEngine; using Teal;  [Disal...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page contains a selection of unofficial scripts to demonstrate the usage of various aspects of Soldat 2's scripting API.&lt;br /&gt;
&lt;br /&gt;
== Team Balancer ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
// a basic team-balancing script to illustrate how to implement simple&lt;br /&gt;
// chat-commands using S2 scripting&lt;br /&gt;
&lt;br /&gt;
// 'using' directives let you omit namespacing&lt;br /&gt;
// eg: Player rather than the full Teal.Player&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using UnityEngine;&lt;br /&gt;
using Teal;&lt;br /&gt;
&lt;br /&gt;
[DisallowMultipleComponent]&lt;br /&gt;
&lt;br /&gt;
// the class name as defined here is what you need to refer to in any json&lt;br /&gt;
// config files, NOT the name of this script file. Case sensitive.&lt;br /&gt;
public class Balance : MonoBehaviour&lt;br /&gt;
{&lt;br /&gt;
    // called when the script is loaded&lt;br /&gt;
    private void Awake()&lt;br /&gt;
    {&lt;br /&gt;
        // this registers a function (OnPlayerChat in this case) to be called&lt;br /&gt;
        // whenever a player chat event occurs&lt;br /&gt;
        // for other types of events, check in the modding channel on S2 discord&lt;br /&gt;
        GameChat.instance.OnChat.AddListener(OnPlayerChat);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // called before the script is unloaded, probably when the server closes/restarts&lt;br /&gt;
    private void OnDestroy()&lt;br /&gt;
    {&lt;br /&gt;
        // presumably important to prevent your script from continuing to respond&lt;br /&gt;
        // to events after it gets removed/disabled&lt;br /&gt;
        GameChat.instance.OnChat.RemoveListener(OnPlayerChat);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // user-defined function for handling chat events - the name can be any&lt;br /&gt;
    // (valid) identifier, only the signature is important&lt;br /&gt;
    void OnPlayerChat(Player p, string msg)&lt;br /&gt;
    {&lt;br /&gt;
        // we are only implementing a single command in this example, but if&lt;br /&gt;
        // you want to have multiple commands a switch/case statement is probably&lt;br /&gt;
        // more appropriate&lt;br /&gt;
        if( msg == &amp;quot;!bal&amp;quot; || msg == &amp;quot;!balance&amp;quot; )&lt;br /&gt;
        {&lt;br /&gt;
            // first we grab a list of the players on each team&lt;br /&gt;
            List&amp;lt;Player&amp;gt; t0 = MonoSingleton&amp;lt;Players&amp;gt;.Get.GetPlayersOfTeam(0);&lt;br /&gt;
            List&amp;lt;Player&amp;gt; t1 = MonoSingleton&amp;lt;Players&amp;gt;.Get.GetPlayersOfTeam(1);&lt;br /&gt;
&lt;br /&gt;
            // integer division rounds down, so we will only do something if teams&lt;br /&gt;
            // are unbalanced by more than one player&lt;br /&gt;
            int hdiff = (t0.Count-t1.Count)/2;&lt;br /&gt;
            if( hdiff &amp;gt; 0 )&lt;br /&gt;
            { // more players on team 0, move half the difference to team 1&lt;br /&gt;
                for( int i=0; i&amp;lt;hdiff; i++ ) t0[i].props[&amp;quot;team&amp;quot;] = 1;&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            else if( hdiff &amp;lt; 0 )&lt;br /&gt;
            { // more players on team 1, move half the difference to team 0&lt;br /&gt;
                for( int i=0; i&amp;lt;-hdiff; i++ ) t1[i].props[&amp;quot;team&amp;quot;] = 0;&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting]]&lt;/div&gt;</summary>
		<author><name>AL</name></author>
	</entry>
</feed>