User:AL: Difference between revisions

From Soldat2 Wiki
Jump to navigation Jump to search
(Created page with "== Scripting Notes == The exact limits of what scripting in Soldat 2 can do is not yet known, but it already looks to far exceed what was possible in Soldat 1. The following is a somewhat random assortment of different ways to affect or read the game state from scripting. === Messaging === * <code>GameChat.ChatOrLog(string message)</code> print a chat message * <code>HUD.Get.Notify(string message, UnityEngine.Color c)</code> text printout similar to flag grabbed/returne...")
 
No edit summary
Line 3: Line 3:


=== Messaging ===
=== Messaging ===
* <code>Debug.Log()</code> print to debug console, accepts any number of printable arguments
* <code>GameChat.ChatOrLog(string message)</code> print a chat message
* <code>GameChat.ChatOrLog(string message)</code> print a chat message
* <code>HUD.Get.Notify(string message, UnityEngine.Color c)</code> text printout similar to flag grabbed/returned text
* <code>HUD.Get.Notify(string message, UnityEngine.Color c)</code> text printout similar to flag grabbed/returned text
Line 8: Line 9:
=== Players ===
=== Players ===
The <code>Teal.Player</code> object is what we manipulate to read or change data related to players.
The <code>Teal.Player</code> object is what we manipulate to read or change data related to players.
* The <code>props</code> member is a dictionary that is both readable and writable. Some potentially useful keys are:
** Id
** type
** team
** score
** kills
** deaths
** weapon
** weapon2
It is also possible to add new properties if you want to associate some custom data to players using <code>Create(string key, object value)</code>


The singleton class <code>Teal.Players</code> provides many different ways to retrieve relevant player objects:
The singleton class <code>Teal.Players</code> provides many different ways to retrieve relevant player objects:
Line 35: Line 46:
</pre>
</pre>


The <code>Controls</code> class allows querying some properties like whether the player is dead, is human/bot, and some (limited?) input events
The <code>Controls</code> class allows querying some properties like whether the player is dead, is human/bot, and some (limited?) input events. It also allows access to some other classes that affect different aspects of the player.
* <code>controls.GetComponent<GostekJets>().jetsAllowed</code> boolean value, read/writable
* <code>controls.transform.position</code> returns a Vector3 of the current position of the player


=== Misc ===
=== Misc ===
Line 42: Line 55:
** <code>public static float timeSinceLevelLoad;</code>
** <code>public static float timeSinceLevelLoad;</code>
** <code>public static double SecsSinceStart;</code>
** <code>public static double SecsSinceStart;</code>
* <code>GameCursor.GetWorldPosition()</code> gets the current position of the local player's cursor, unknown how it will work on a server

Revision as of 14:29, 17 January 2023

Scripting Notes

The exact limits of what scripting in Soldat 2 can do is not yet known, but it already looks to far exceed what was possible in Soldat 1. The following is a somewhat random assortment of different ways to affect or read the game state from scripting.

Messaging

  • Debug.Log() print to debug console, accepts any number of printable arguments
  • GameChat.ChatOrLog(string message) print a chat message
  • HUD.Get.Notify(string message, UnityEngine.Color c) text printout similar to flag grabbed/returned text

Players

The Teal.Player object is what we manipulate to read or change data related to players.

  • The props member is a dictionary that is both readable and writable. Some potentially useful keys are:
    • Id
    • type
    • team
    • score
    • kills
    • deaths
    • weapon
    • weapon2

It is also possible to add new properties if you want to associate some custom data to players using Create(string key, object value)

The singleton class Teal.Players provides many different ways to retrieve relevant player objects:

public List<Player> players;
public int PlayersCount;
public Player GetLocalPlayer();
public ushort GetLocalPlayerId();
public Controls GetLocalPlayerControlled();
public Player GetPlayerByID(ushort ID);
public Player GetPlayerByNick(string nick);
public Player GetPlayerByPropertyId(ushort id);
public Controls GetPlayerControlledByID(ushort ID);
public List<Player> GetPlayersOfTeam(int team);
public List<Player> GetPlayersOfTeamExcept(int team, Player player);
public List<Player> GetBots();
public List<Player> GetAlive();
public List<Player> GetAliveBots();
public List<Player> GetAliveHumans();
public List<Player> GetHumans();
public List<Player> GetHumansNonSpectator();
public List<Player> GetHumansOnClient();
public List<Player> GetTeam(int team);
public List<Player> GetAliveTeam(int team);
public List<Player> GetSpecators();
public List<Player> GetPlayersNonSpecators();

The Controls class allows querying some properties like whether the player is dead, is human/bot, and some (limited?) input events. It also allows access to some other classes that affect different aspects of the player.

  • controls.GetComponent<GostekJets>().jetsAllowed boolean value, read/writable
  • controls.transform.position returns a Vector3 of the current position of the player

Misc

  • The Teal.RealTime class offers a number of different time measures:
    • public static float realtimeSinceStartup;
    • public static float timeSinceLevelLoad;
    • public static double SecsSinceStart;
  • GameCursor.GetWorldPosition() gets the current position of the local player's cursor, unknown how it will work on a server