User:AL

From Soldat2 Wiki
Revision as of 08:49, 22 January 2023 by AL (talk | contribs)
Jump to navigation Jump to search

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. Note that this list is by no means exhaustive.

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

Player

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

public Type type;
public string nick;
public ushort id;
public bool rcon;
public int ping;
public bool levelLoaded;
public bool waitingForSpawn;
public SyncedProperties props;
public object userData;
protected float timeOnJoin;
protected float timeOnPing;
public float timeOnDeath;
public float timeOnSpawn;
public Dictionary<string, List<string>> votes = new Dictionary<string, List<string>>();
public bool muted;
public bool IsLocal();
public bool IsBot();
public bool IsRemote();
public float GetPlayTime();
public float GetTimeSinceLastPing();
public float GetTimeSinceDeath();
public float GetTimeSinceRespawn();
public bool IsDead();
public int GetTeam();
public bool IsSpectator();
  • 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 player.props.Create(string key, object value)

Players

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();

Controls

The Teal.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
  • controls.GetComponent<StandardObject>().Master_Death() kill the player
  • controls.GetComponent<StandardObject>().Master_SetHealth(float hp, Player p = null, NetworkObject unknown = null) set player health, only works if executed on the server

Can potentially set up a listener for whenever a specific player's health changes: controls.GetComponent<StandardObject>().HealthChanged.AddListener(cb), where the callback function cb takes a single float as its argument

Math

The Teal.Math class contains some potentially useful functions:

public static bool IsNearlyEqual(float value1, float value2, float epsilon = 0.0001f);
public static Vector2 CloserPosition(Vector2 point, Vector2 a, Vector2 b);
public static bool IsWithin(this int value, int minimum, int maximum);
public static bool IsWithin(this float value, float minimum, float maximum);
public static bool IsValid(this float value);
public static float Normalize(ref Vector2 v);
public static float Normalize(ref Vector3 v);
public static float Angle(Vector2 p_vector2);
public static float SignedAngle(Vector2 p_vector2);
public static float SignedAngle(Vector2 p1, Vector2 p2);
public static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles);
public static Vector3 RotateVector(Vector3 vector, float angle);
public static void InitRandom(int seed);
public static int Random(int max);
public static float Random(float max);
public static int RandomRange(int min, int max);
public static float RandomRange(float min, float max);
public static Vector3 GetRandomVector(Vector3 v);
public static Vector2 GetRandomVector(Vector2 v);
public static bool CirclesCollide(Vector3 pos1, Vector3 pos2, float radius1, float radius2);
public static bool LineSegmentsIntersecting(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4);
public static Vector2 LineIntersectionPoint(Vector2 l1s, Vector2 l1e, Vector2 l2s, Vector2 l2e);
public static bool IsPointBetweenLine(Vector2 a, Vector2 b, Vector2 c);
public static bool AreLinesIntersecting(Vector2 l1_p1, Vector2 l1_p2, Vector2 l2_p1, Vector2 l2_p2, bool shouldIncludeEndPoints);
public static bool AreLinesParallel(Vector2 l1_p1, Vector2 l1_p2, Vector2 l2_p1, Vector2 l2_p2);
public static bool AreLinesSame(Vector2 l1_p1, Vector2 l1_p2, Vector2 l2_p1, Vector2 l2_p2);
public static float ClampRotation(float rotation);
public static Quaternion MirrorRotation(Quaternion q);
public static bool IsStraight(Vector2 p1, Vector2 p2, Vector2 p3, float factor = 0.9f);
public static float GetStraightness(Vector2 p1, Vector2 p2, Vector2 p3);
public static bool IsTurningLeft(Vector2 a, Vector2 b, Vector2 c);
public static Vector2 NearestPointOnLineSegment(Vector2 origin, Vector2 end, Vector2 point);
public static bool IsCountourInteresecting(Vector3[] v);

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
  • UnityEngine.Time.timeScale can be used to change the speed at which the game runs, 1=normal, 2=double speed, 0.5=half speed, etc
  • RespawningCommon.KillAllRespawnAll() kill all players