diff --git a/docs/source/native/functions.rst b/docs/source/native/functions.rst index 67f4a36a..52b455f5 100644 --- a/docs/source/native/functions.rst +++ b/docs/source/native/functions.rst @@ -32,9 +32,17 @@ Conditional operators can also be used to make comparisons, such as ``==`` (equa .. code-block:: javascript if(RandomInt(6)+1 == 5) - + Like other languages, if statements can be connected to ``else if`` and ``else`` statements. ``else if`` statements must be used immediately after an ``if`` or ``else if`` and will only check their condition if the preceding statements failed. ``else`` statements behave similarly, but always run if the preceding statements failed and must be last. +Squirrel supports ternary operations like most languages. The value of the expression depends if a condition is truthy or not. However, if not used carefully this can worsen readability. +The Syntax is ``condition ? if_condition_true : if_condition_false``. This is especially useful when declaring variables or passing parameters. + +.. code-block:: javascript + + // shortenedUsername is "longus..."" if username is "longusername" or "short" if username is "short" + string shortenedUsername = username.len() > 9 ? username.slice(0,6) + "..." : username; + Loops ------ There are three primary loops: ``while``, ``for``, and ``foreach``. ``while`` loops are similar to ``if`` statements, but repeat endlessly so long as the test remains true: @@ -48,10 +56,10 @@ This script will repeat endlessly until ``ReturnTrueOrFalse`` returns false. ``for`` loops are similar to ``while`` loops, but also run code once at the start and after every loop. These are primarily used to loop a specific number of times, such as over the length of a list: .. code-block:: javascript - + array somelist = [0, 5, 6, 4, 11] for(int i = 0; i < somelist.len(); i++) - + ``int i = 0`` runs immediately; ``i < somelist.len()`` is the test for the loop, only executing the loop if it is true; ``i++`` runs after every loop iteration. ``foreach`` loops only loop over a set of data, such as a list or table, and will execute for each entry. They don't loop in any order and data should not be added or removed from the set during the loop: @@ -65,14 +73,14 @@ Implicit conditional behavior Conditional statements, such as while loops and if statements, also implictly cast non-boolean inputs to booleans. For numbers, this means 0 is considered false and anything else is considered true. For instance variables like arrays and entities, ``null`` is considered false and anything else is considered true. For example, these inputs are considered true by the if statements: .. code-block:: javascript - + if(2) - + .. code-block:: javascript - + array somelist = [0, 1] if(somelist) - + Be aware that empty arrays and strings, ``[]`` and ``""``, are considered true by this logic. Formatting of actions diff --git a/docs/source/native/intro.rst b/docs/source/native/intro.rst index 46167bf1..65b9e23b 100644 --- a/docs/source/native/intro.rst +++ b/docs/source/native/intro.rst @@ -42,10 +42,11 @@ Variable types * ``void``: can be used to define functions that do not return a value, but still do things. most of your functions will be void * ``integer``: a whole number * ``float``: any floating-point number. -* ``string``: text +* ``string``: text. Squirrel does not have native chars, so calling an index of a string will return a number in standart ascii format. e.g. "a"[0] = 97 * ``entity``: an entity and all its associated information -* ``bool``: ``true`` or ``false`` (Squirrel does not treat 1 as true or 0 as false) +* ``bool``: ``true`` or ``false`` (Squirrel treats ``null`` and ``0`` as false and every other number or object that's ``!= null`` as true) * ``array``: an ordered list of items indexed from 0, increasing with the number of items such as: 0:"hello",1:1000,2:entity player -* ``table``: a list of items with indexes defined on object entry such as: ``"word":"hello"``, ``"kilo":1000"``, ``"pilot":entity player`` +* | ``table``: a list of items with indexes defined on object entry such as: ``"word":"hello"``, ``"kilo":1000"``, ``"pilot":entity player``. + | You have to create new slots with the ``<-`` operator and overwrite values in slots with ``=``. Tables are explained in more detail in the `squirrel documentation `_ * ``struct``: a series of attributes assigned to a structure and accessed through with ``structname.variablename`` * ``var``: Var typically refers to variables that lack any stated type, this will cause issues with many functions unless you use the ``untyped`` identifier at the start of your file, or if you use ``expect type(variable)`` when passing the variable to that function diff --git a/docs/source/reference/respawn/player.rst b/docs/source/reference/respawn/player.rst index d1f23787..7e368e59 100644 --- a/docs/source/reference/respawn/player.rst +++ b/docs/source/reference/respawn/player.rst @@ -3,6 +3,10 @@ Player Functions for getting player, and methods of the player object +.. cpp:function:: bool IsAlive( entity ent ) + +.. cpp:function:: bool IsValid( entity ent ) + .. cpp:function:: entity GetLocalViewPlayer() player you're watching (can be replay) @@ -11,10 +15,18 @@ Functions for getting player, and methods of the player object .. cpp:function:: array GetPlayerArray() +.. cpp:function:: array GetPlayerArrayEx( string class, int team, vector origin, float radius ) + + returns a list of every player of the specified class in radius relative to origin. The parameter ``class`` must be one of these strings: ``titan``, ``pilot`` or ``any``. + .. cpp:function:: array GetPlayerArrayOfTeam( int team ) + array of players from team index + .. cpp:function:: array GetPlayerArrayOfTeam_Alive( int team ) + every player alive in team + .. cpp:function:: array GetPlayerArrayOfEnemies_Alive( int team ) .. cpp:function:: array GetSortedPlayers( IntFromEntityCompare compareFunc, int team) @@ -33,9 +45,13 @@ Functions for getting player, and methods of the player object return 0 }, 0) +.. cpp:function:: entity GetTitanFromPlayer( entity player) + + if the player is a titan, returns the player. If not, returns the player's pet titan + .. cpp:class:: player : public entity - .. cpp:function:: int GetActivePilotLoadoutIndex( player ) + .. cpp:function:: int GetActivePilotLoadoutIndex( entity player ) .. cpp:function:: entity GetActiveWeapon() @@ -43,6 +59,8 @@ Functions for getting player, and methods of the player object .. cpp:function:: vector GetAngles() + direction the entity is facing + .. cpp:function:: entity GetAntiTitanWeapon() .. cpp:function:: vector GetAttachmentAngles() @@ -63,9 +81,9 @@ Functions for getting player, and methods of the player object .. cpp:function:: int GetGen() - .. cpp:function:: float GetHealthFrac(player) + .. cpp:function:: float GetHealthFrac( entity player ) - .. cpp:function:: unknown GetLastPingTime() + .. cpp:function:: float GetLastPingTime() .. cpp:function:: int GetLevel() @@ -83,53 +101,59 @@ Functions for getting player, and methods of the player object .. cpp:function:: float GetNextTitanRespawnAvailable() - .. cpp:function:: unknown GetNumPingsAvailable() + .. cpp:function:: int GetNumPingsAvailable() - .. cpp:function:: unknown GetObjectiveEndTime() + .. cpp:function:: float GetObjectiveEndTime() .. cpp:function:: unknown GetObjectiveEntity() - .. cpp:function:: unknown GetObjectiveIndex() + .. cpp:function:: int GetObjectiveIndex() + + returns the index of the player objective. ObjIndex 0 means no objective .. cpp:function:: int GetObserverMode() - .. cpp:function:: entity GetOffhandWeapon(slot) + returns either ``OBS_MODE_IN_EYE`` (first person) or ``OBS_MODE_CHASE`` (third person) + + .. cpp:function:: entity GetOffhandWeapon( int slot ) .. cpp:function:: array GetOffhandWeapons() .. cpp:function:: vector GetOrigin() - (x, y, z) + entity position .. cpp:function:: entity GetParent() - .. cpp:function:: int GetPersistentSpawnLoadoutIndex( player, "pilot" ) + .. cpp:function:: int GetPersistentSpawnLoadoutIndex( entity player, string playerClass ) - .. cpp:function:: entity GetPetTitan() + playerClasses: ``"pilot"`` ``"titan"``. This returns null for every other string. - .. cpp:function:: PilotLoadoutDef GetPilotLoadoutFromPersistentData( player, loadoutIndex ) + .. cpp:function:: entity GetPetTitan() - .. cpp:function:: unknown GetPingGroupAccumulator() + auto titan of player - .. cpp:function:: unknown GetPingGroupStartTime() + .. cpp:function:: PilotLoadoutDef GetPilotLoadoutFromPersistentData( entity player, int loadoutIndex ) - .. cpp:function:: array GetPlayerArray() + stored loadout data of player - .. cpp:function:: array GetPlayerArrayOfEnemies_Alive( int team ) + .. cpp:function:: int GetPingGroupAccumulator() - .. cpp:function:: array GetPlayerArrayOfTeam( int team ) + .. cpp:function:: float GetPingGroupStartTime() .. cpp:function:: string GetPlayerClass() + "titan", "spectator" or "pilot" + .. cpp:function:: PGS_ELIMINATED GetPlayerGameStat() .. cpp:function:: string GetPlayerName() - .. cpp:function:: string GetPlayerNameWithClanTag() + player (origin) username - networks are disabled in northstar + .. cpp:function:: string GetPlayerNameWithClanTag() - .. cpp:function:: bool GetPlayerNetBool( net_bool_name ) + .. cpp:function:: bool GetPlayerNetBool( string net_bool_name ) example @@ -139,7 +163,9 @@ Functions for getting player, and methods of the player object .. cpp:function:: string GetPlayerSettings() - .. cpp:function:: unknown GetPlayerSettingsField( "weaponClass" ) + .. cpp:function:: string GetPlayerSettingsField( string ) + + some settings: ``"weaponClass"`` ``"gravityscale"`` ``"airSpeed"`` ``"airAcceleration"`` .. cpp:function:: int GetShieldHealth() @@ -167,59 +193,58 @@ Functions for getting player, and methods of the player object .. cpp:function:: vector GetViewVector() - vector representation of your look direction. <0, 0, 1> -> looking straight up - .. cpp:function:: int GetWeaponAmmoStockpile() - .. cpp:function:: unknown GetXP() + .. cpp:function:: int GetXP() .. cpp:function:: float GetZoomFrac() 0.0 (no zoom) - 1.0 (full zoom) - .. cpp:function:: void GiveArmor( player, int amount ) - - .. cpp:function:: void GiveOffhandWeapon( name, slot ) + .. cpp:function:: void GiveArmor( entity player, int amount ) - .. cpp:function:: void GivePilotLoadout( player, loadout ) + .. cpp:function:: void GiveOffhandWeapon( string name, int slot ) - .. cpp:function:: void GiveWeapon() + .. cpp:function:: void GivePilotLoadout( entity player, int loadout ) - .. cpp:function:: void GiveWeaponPowerUp( player, string newWeapon ) + .. cpp:function:: void GiveWeapon( string weapon ) - .. cpp:function:: void TakeOffhandWeapon() + .. cpp:function:: void GiveWeaponPowerUp( entity player, string newWeapon ) - .. cpp:function:: void TakeWeaponNow() + .. cpp:function:: void TakeOffhandWeapon( int offhandIndex ) - .. cpp:function:: void SetActiveWeaponByName() + can be used for titans as well. + some constants are: ``OFFHAND_ORDNANCE`` ``OFFHAND_SPECIAL`` ``OFFHAND_LEFT`` ``OFFHAND_INVENTORY`` ``OFFHAND_MELEE`` ``OFFHAND_EQUIPMENT`` ``OFFHAND_ANTIRODEO`` - .. cpp:function:: void SetBodygroup() + .. cpp:function:: void TakeWeaponNow( string weaponToSwitch) - .. cpp:function:: void SetDodgePowerDelayScale() + .. cpp:function:: void SetActiveWeaponByName( string newWeapon ) - .. cpp:function:: void SetHealth() + .. cpp:function:: void SetBodygroup( int bodyGroupIndex, int stateIndex ) - .. cpp:function:: void SetLastPingTime() + .. cpp:function:: void SetDodgePowerDelayScale( float delay ) - .. cpp:function:: void SetMaxHealth() + .. cpp:function:: void SetHealth(int health) - .. cpp:function:: void SetNumPingsAvailable() + .. cpp:function:: void SetLastPingTime( float time) - .. cpp:function:: void SetNumPingsUsed() + .. cpp:function:: void SetMaxHealth( int health ) - .. cpp:function:: void SetOrigin() + .. cpp:function:: void SetNumPingsAvailable( int num ) - .. cpp:function:: void SetPowerRegenRateScale() + .. cpp:function:: void SetNumPingsUsed( int num ) - .. cpp:function:: void SetShieldHealth() + .. cpp:function:: void SetOrigin( vector origin ) - .. cpp:function:: void SetShieldHealthMax() + .. cpp:function:: void SetPowerRegenRateScale( float scale ) - .. cpp:function:: void SetTitanDisembarkEnabled( bool ) + .. cpp:function:: void SetShieldHealth( float health) + .. cpp:function:: void SetShieldHealthMax( float health ) + .. cpp:function:: void SetTitanDisembarkEnabled( bool enabled ) - .. cpp:function:: void AddThreatScopeColorStatusEffect(weaponOwner) + .. cpp:function:: void AddThreatScopeColorStatusEffect( entity weaponOwner ) .. cpp:function:: vector CameraPosition() @@ -233,15 +258,15 @@ Functions for getting player, and methods of the player object .. cpp:function:: vector EyePosition() - .. cpp:function:: int FindBodyGroup() + .. cpp:function:: int FindBodyGroup( string bodyGroup ) - .. cpp:function:: int LookupAttachment() + .. cpp:function:: int LookupAttachment( string attachment = "" ) .. cpp:function:: void Lunge_ClearTarget() .. cpp:function:: int Minimap_GetZOrder() - .. cpp:function:: int RemoveThreatScopeColorStatusEffect(weaponOwner) + .. cpp:function:: int RemoveThreatScopeColorStatusEffect( entity player ) .. cpp:function:: bool HasBadReputation() @@ -249,15 +274,13 @@ Functions for getting player, and methods of the player object .. cpp:function:: bool InPartyChat() - .. cpp:function:: bool IsAlive(player) - .. cpp:function:: bool IsEjecting() .. cpp:function:: bool IsHologram() .. cpp:function:: bool IsHuman() - .. cpp:function:: bool IsInScoreboard( player ) + .. cpp:function:: bool IsInScoreboard( entity player ) .. cpp:function:: bool IsInThirdPersonReplay() @@ -265,17 +288,17 @@ Functions for getting player, and methods of the player object .. cpp:function:: bool IsPartyLeader() - .. cpp:function:: bool IsPartyMember( player ) + .. cpp:function:: bool IsPartyMember( entity player ) .. cpp:function:: bool IsPhaseShifted() .. cpp:function:: bool IsPlayer() - .. cpp:function:: bool IsPlayerEliminated( player ) + .. cpp:function:: bool IsPlayerEliminated( entity player ) - .. cpp:function:: bool IsPlayerFemale( player ) + .. cpp:function:: bool IsPlayerFemale( entity player ) - .. cpp:function:: bool IsRespawnAvailable( player ) + .. cpp:function:: bool IsRespawnAvailable( entity player ) .. cpp:function:: bool IsScriptMenuOn() @@ -283,12 +306,10 @@ Functions for getting player, and methods of the player object .. cpp:function:: bool IsTitan() - .. cpp:function:: bool IsTitanAvailable( player ) + .. cpp:function:: bool IsTitanAvailable( entity player ) .. cpp:function:: bool IsUsingOffhandWeapon() - .. cpp:function:: bool IsValid( player ) - .. cpp:function:: bool IsWatchingKillReplay() .. cpp:function:: bool IsWatchingReplay()