SCRIPTING FUNCTIONS

Sort alphabetically | Sort by category

All | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | R | S | T | U | V | Z


AddCommoditiesCount

Add commodities to the player inventory.

int commodityId = 15 ;[->commodities.wdt]
int amount = 105 ;
player AddCommoditiesCount commodityId amount ;


AddContraband

Add a commodity to a list of illegal commodities in a region.

int region = 1 ; [->regions.wdt]
int commodity = 4 ; [->commodities.wdt]
game AddContraband region commodity ;


AddCredits

Add credits to player.

int credits = 250 ;
player AddCredits credits ;


AddExp

Add Experience to player.

int experience = 110 ;
player AddExp experience ;


AddQuestItemCount

Add item to player inventory.

int itemId = 1 ; [->items.wdt]
int amount = 3 ;
player AddQuestItemCount itemId amount ;


AddReputation

Change player reputation.

int repChange = 100 ;
player AddReputation repChange ;


anomalyAdd

Create a temporary anomaly.

int id = 0 ; [->EditorAnomalies.wdt]
float3 position = 0.0 0.0 0.0 ;
float duration = 5.0 ;
anomalyAdd ANO_151 id position duration ;


Assembly spawn

Spawn an assembly (*.asb that contains model mesh and particles)

float delay = 0.0 ;
float3 position = 0.0 0.0 0.0 ;
int asbId = 0 ; [->FreeModel.wds]
float lifetime = 3.0 ;
assembly delay position asbId lifetime ;


AttackPlayer

Force an AI ship to attack player.

ship GetByKeyName ship0 AttackPlayer ;


CampaignChoice

Special command used only in the main campaign to give the player the option to either continue the campaign or start free-roam.

campaignchoice 0 ;


CheckContraband

Check if player has any contraband in inventory.
Contraband status depends on current region, random events and scripted events.
Function returns either 0(false) or 1(true).

int smuggle = 0 ;
player CheckContraband smuggle ;


ClearAllContraband

Clear contraband list of a region.

int regionId = 1 ; [->regions.wdt]
game ClearAllContraband regionId ;


Create (assemblyex)

Create an assembly entity to be accessed in a script. Assembly is accessed via ID in FreeModel.wds. The special assemblyex object is created locally on the parent object.

int retId = 0 ; [unique entity ID used in the current script only]
float delay = 0.0 ;
float3 position = 0.0 0.0 0.0 ;
int asbId = 46 ; [->FreeModel.wds]
float lifetime = 3.0 ;
assemblyex Create retId delay position asbId lifetime ;


CreateEx (global assembly)

Create an assembly entity to be access in a script. Assembly is accessed via ID in FreeModel.wds. The special assemblyex object created with CreateEx is created in global space, detached from any parent object.

int retId = 0 ; [unique entity ID used in the current script only]
float delay = 0.0 ;
float3 position = 0.0 0.0 0.0 ; [Position where the assembly will be created]
int asbId = 15 ; [->FreeModelswds]
float lifetime = 5.0 ; [duration of the created entity]
assemblyex CreateEx retId delay position asbId lifetime ;


Debris

Create a debris explosion.

float delay = 0.0 ;
int debrisId = 0 ; [->Debris.wds]
int number = 15 ; [number of debris elements]
float shotTime = 2.5 ; [random time offset of each element]
float3 position = 0.0 0.0 0.0 ;
float3 norm = 0.0 0.0 0.0 ; [leave 0.0 0.0 0.0 for spherical scatter]
arc = 1.57 ; [arc of scatter, if norm NOT spherical]
float velocityMin = 3.0 ;
float velocityMax = 5.0 ;
float size = 1.0 ;
float lifetimeMin = 2.0 ;
float lifetimeMax = 5.0 ;
int fadeSort = 0 ; [0=noFade; 1=fadeToBlack; 2=rotateOverTime; 3=RotateAndFade]
debris delay debrisId number shotTime position norm arc velocityMin velocityMax size lifetimeMin lifetimeMax fadeSort ;


Delete (ship)

Disables and deletes an object.
Use for ships ONLY! For other objects use SetEnabled!

float delay = 0.5 ;
ship GetByKeyName shipKeyName Delete delay ;
ship GetParent Delete delay ;


derelictAdd

Create a derelict on the specified position with the specified rotation.

Alternatively, use the second method to create a derelict based on the parent ship object where the spawned derelict is specified in the parent ship file (*.shp) and the position and rotation parameters are taken over from the parent object.

This function MUST be used BEFORE deleting the parent object!

int derelictId = 0 ;
float3 position = 0.0 0.0 0.0 ;
float3 rotation = 0.0 0.0 0.0 ;
derelictAdd keynameDER derelictId position rotation ;

derelictAdd keynameDER -1 ;


Dialogue

Start dialogue.
Dialogues are saved as *.dia files in Dialogues sub-folder.

dialogue Spg2\Dialogues\M01\D01.dia ;


Distance

Calculate distance between two points.

float3 pointA = 0.0 0.0 0.0 ;
float3 pointB = 100.0 0.0 0.0 ;
math distance = Distance pointA pointB ;


DropResource

Used for dropping loot when destroying derelicts. DropLoot function can be used instead.
LootDrop file used by the function is linked through the derelict parent parameters.

derelict GetParent DropResource 1 ;


Exist

Check if a ship exists or not.
This function is used specifically for checking ships. For other objects, use GetEnabled.
Function returns either 0(false) or 1(true) and saves to status.

int status = 0 ;
ship GetByKeyName ship0 Exist status ;


Explosion

Creates an explosion.

float delay = 0.0 ;
float3 position = 0.0 0.0 0.0 ;
float3 dPosition = 0.0 0.0 0.0 ; [diagonal offset]
float3 color = 1.0 1.0 1.0 ; [additive colorizing]
float transparency = 1.0 ;
int explosionId = 1 ; [->explosions.wds]
float sizeStart = 30.0 ;
float sizeEnd = 75.0 ;
int sizeSort = 0 ; [set 0 for no size offset]
float lifetime = 0.6 ;
float rndOffset = 0.0 ; [random position offset]
int blendType = 0 ;
explosion delay position dPosition color transparency explosionId sizeStart sizeEnd sizeSort lifetime rndOffset blendType ;


factdialogue (generate dialog)

Generate a simple one-liner dialog through script.

int faction = 1 ; [Id as seen in Faction.wdt]
int textLine = 100 ; [Text line number from dialogs.txt. Counting starts from 0!
float duration = 4.0 ; [Dialog duration in seconds]
factdialogue faction textLine duration ;


FadeFromColor

Fades back to screen from color over time.

float3 color = 0.0 0.0 0.0 ;
float time = 1.0 ;
camera FadeFromColor color time ;


FadeToColor

Fades screen to color over time.

float3 color = 0.0 0.0 0.0 ;
float time = 1.0 ;
camera FadeToColor color time ;


GetAcquire

Check status of quest acquired flag.
Function returns either 0(false) or 1(true).

int questCond = 0 ;
GetById -> QuestMain.wdt | QuestSide.wdt
mainquest GetById 1 GetAcquire questCond ;
sidequest GetById 1 GetAcquire questCond ;


GetAvailable

Check status of quest available flag.
Function returns either 0(false) or 1(true).

int questCond = 0 ;
GetById -> QuestMain.wdt | QuestSide.wdt
mainquest GetById 1 GetAvailable questCond ;
sidequest GetById 1 GetAvailable questCond ;


GetBoardable

Get ship's boardable flag. (0 == false, 1 == true).
Ships with flag set to 0 CANNOT be boarded!

int boardFlag = 0 ;
ship GetByKeyName ship0 GetBoardable boardFlag ;


GetByKeyName

Get object by it's unique keyname.
Function is used ONLY as a part of other functions!

GetByKeyName keyname;


GetCharacterClass

Get player character class (as integer).

charClass = 0 ; [->SkillClasses.wdt]
player GetCharacterClass charClass ;


GetClass

Get ship class (as integer).

int shipClass = 0 ; [->ShipClass.wdt]
ship GetByKeyName ship0 GetClass shipClass ;


GetCloak

Check whether ship has cloak set to ON(1) or OFF(0).

int cloakState ;
ship GetbyKeyName ship0 GetCloaked cloakState ;


GetCommoditiesCount

Check quantity of a commodity in player inventory.

int commodityId = 15 ; [->commodities.wdt]
int howMuch = 0 ;
player GetCommoditiesCount commodityId howMuch ;


GetCondition

Get condition of an object.
0 = indestructible
1 = destructible

int condition = 0 ;
ship GetByKeyName ship0 GetCondition condition ;


GetCredits

Get player credit count.

int credits = 0 ;
player GetCredits credits ;


GetDefault

Saves current player camera setup for later use. Used in conjunction with cutscene cameras. Can only be used after(!) SetCSCamera is activated

camera GetDefault ;


GetEnabled

Check if an object is activated.

int shipCond = 0 ;
ship GetByKeyName ship0 GetEnabled shipCond ;


GetExp

Get player experience.

int exp = 0 ;
player GetExp exp ;


GetFaction

Get faction of object.

int facId = 0 ;
structure GetByKeyName keynameSTR GetFaction facId ;


GetFloat

Get value of the float modding variable in the save file.

int stackVarId = 0 ;
float floatVal = 0.0 ;
modingvar GetFloat stackVarId floatVal ;
modingvar GetFloat 0 floatVal ;


GetFriendFoe

Check status of Friend-Foe mechanism.
Function returns either 0(false) or 1(true).

int status = 0 ;
game GetFriendFoe status ;


GetGameStatus

Check status of player controls.
Function returns either 0(on) or 1(off).

int status = 0 ;
game GetGameStatus status ;


GetHP

Get objects hitpoints.

float shipHP = 0.0 ;
ship GetByKeyName ship0 GetHP shipHP ;


GetHPRel

Get relative Hull value of object. Return value is percentage integer [0,100].

int HullPercentage;
ship GetByKeyname ship0 GetHPRel HullPercentage ;


GetInt

Get the value of int modding variable in the save file.

int stackVarId = 0 ;
int intVal = 0 ;
modingvar GetInt stackVarId intVal ;
modingvar GetInt 0 intVal ;


GetInvulnerable

Get invulnerable flag of a ship.

int state = 0 ;
ship GetByKeyName ship0 GetInvulnerable state ;


GetLevel

Get player experience level.

int level = 0 ;
player GetLevel level ;


GetPosition

Get position of an object.

float3 position ;
ship GetByKeyName ship0 GetPosition position ;
ship GetPlayer GetPosition position ;


GetPTE

Check whether ship has Power to Engines set to ON(1) or OFF(0).

int pteState ;
ship GetbyKeyName ship0 GetPTE pteState ;


GetQuestItemCount

Check quantity of a quest item in player inventory.

int itemId = 3 ; [->QuestItems.wdt]
int howMuch = 0 ;
player GetQuestItemCount itemId howMuch ;


GetRadius

Get radius of object frustum sphere.
Frustum sphere encompasses an entire object.

float radius = 0.0 ;
ship GetByKeyName ship0 GetRadius radius ;


GetRandomEffectPosition

Get one of the ShipEffectPositions positions from the *.shp file. The position will NOT be remain linked to the parent ship, but remain in global space.
Used specifically for linking various particle effects like critical hits.

float3 position = 0.0 0.0 0.0 ;
ship GetByKeyName GetRandomEffectPosition position ;


GetRandomEffectPositionLocal

Get one of the ShipEffectPositions positions from the *.shp file. The position will remain linked to the parent ship in local space.
Used specifically for linking various particle effects like critical hits.

float3 position = 0.0 0.0 0.0 ;
ship GetByKeyName GetRandomEffectPositionLocal position ;


GetRank

Get player rank (as integer).

int rank = 0 ; [->Ranks.wdt]
player GetRank rank ;


GetReputation

Get player reputation.

int rep = 0 ;
player GetReputation rep ;


GetRndPosition

Get a random position intersecting a ship shield mesh. Used for explosions.

float3 position = 0.0 0.0 0.0 ;
ship GetByKeyName ship0 GetRndPosition position ;


GetRndPositionLoc

Get random position intersecting a ship shield mesh. The position remains linked to the parent object.

Can be used for spawning particle effects, but GetRandomEffectPositionLoc could be more suitable.

float3 position = 0.0 0.0 0.0 ;
ship GetByKeyName ship0 GetRndPositionLoc position ;


GetRotation

Get object rotation.

float3 rotation = 0.0 0.0 0.0 ;
ship GetByKeyName ship0 GetRotation rotation ;


GetSolve

Check status of quest solved flag.
Function returns either 0(false) or 1(true).

int questCond = 0 ;
mainquest GetById 1 GetSolve questCond ;
sidequest GetById 1 GetSolve questCond ;


GetSort (structure)

Get type of structure (as seen in BaseStructureSort.wdt)

int structureSort = 0 ;
structure GetByKeyName GetSort structureSort ;


GetSpeed

Function returns ship speed.

float speed ;
ship GetByKeyName ship0 GetSpeed speed ;
ship GetPlayer GetSpeed speed ;


GetTroopersNo

Get the number of current Troopers on a ship.

int trooperCount = 0 ;
ship GetByKeyName ship0 GetTroopersNo trooperCount ;


Global event: Alien incursion

Global event: Alien incursion

int eventId = 19 ; //eventId == Alien incursion
int placeType = 1 ; //placeType == REGION (affects alien encounters in the selected region
int regionId = 16 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Anomaly activity decreased

Global event: Anomaly activity decreased

int eventId = 17 ; //eventId == Anomaly activity decreased
int placeType = 1 ; //placeType == REGION (affects anomaly encounters in the selected region
int regionId = 16 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Anomaly activity increased

Global event: Anomaly activity increased

int eventId = 17 ; //eventId == Anomaly activity increased
int placeType = 1 ; //placeType == REGION (affects anomaly encounters in the selected region
int regionId = 16 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Cease fire signed

Global event: Cease fire signed

int eventId = 5 ; //eventId == Peace treaty signed
int placeType = 1 ; //placeType == REGION (affects battle encounters in the selected region, depending on attackerFaction
int regionId = 14 ; //regionId
float eventDur = 60.0 ; //event duration in seconds
int attackerFaction = 0 ; //factionId of the attacker [->BaseFactions.wdt]
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur attackerFaction modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur attackerFaction modVal titleLine textLine ;


Global event: Company lowers prices

Global event: Company lowers prices

int eventId = 13 ; //eventId == Decreased prices of all services and products
int placeType = 7 ; //place type == faction(affects all stations/planets belonging to factionId
int factionId = 6 ; //[->BaseFactions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 0.2 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType factionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType factionId eventDur modObj modifier titleLine textLine ;


Global event: Company raises prices

Global event: Company raises prices

int eventId = 12 ; //eventId == Increased prices of all services and products
int placeType = 7 ; //place type == faction(affects all stations/planets belonging to factionId
int factionId = 6 ; //[->BaseFactions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 0.2 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType factionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType factionId eventDur modObj modifier titleLine textLine ;


Global event: Embargo

Global event: Embargo

int eventId = 14 ; //eventId == Commodity becomes illegal
int placeType = 1 ; //placeType == REGION (affects entire region and security contraband checks
int regionId = 20 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int commId = 46 ; //[->BaseCommodities.wdt]
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur commId modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur commId modVal titleLine textLine ;


Global event: Embargo lifted

Global event: Embargo lifted

int eventId = 15 ; //eventId == Commodity becomes legal
int placeType = 1 ; //placeType == REGION (affects entire region and security contraband checks
int regionId = 20 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int commId = 46 ; //[->BaseCommodities.wdt]
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur commId modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur commId modVal titleLine textLine ;


Global event: Miner activity decreased

Global event: Miner activity decreased

int eventId = 21 ; //eventId == Miner activity decreased
int placeType = 1 ; //placeType == REGION (affects miner encounters in the selected region
int regionId = 27 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Miner activity increased

Global event: Miner activity increased

int eventId = 20 ; //eventId == Miner activity increased
int placeType = 1 ; //placeType == REGION (affects miner encounters in the selected region
int regionId = 27 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Pirate activity decreased

Global event: Pirate activity decreased

int eventId = 9 ; //eventId == Pirate activity increased
int placeType = 1 ; //placeType == REGION (affects pirate encounters in the region
int regionId = 27 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Pirate activity increased

Global event: Pirate activity increased

int eventId = 8 ; //eventId == Pirate activity increased
int placeType = 1 ; //placeType == REGION (affects pirate encounters in the region
int regionId = 27 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Planetary quarantine

Global event: Planetary quarantine

int eventId = 7 ; //eventId == Planet under lockdown
int placeType = 3 ; //placeType == PLANET (affects planet by keyname)
int placeId = -1 ; //unused in this type of event
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType placeId baeldorPLA eventDur modObj modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType placeId baeldorPLA eventDur modObj modVal titleLine textLine ;


Global event: Resource price increase

Global event: Resource price increase

int eventId = 0 ; //eventId == resource price increase
int placeType = 7 ; //place type == faction(affects all stations/planets belonging to factionId
int factionId = 6 ; //[->BaseFactions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int commId = 14 ; //[->BaseCommodities.wdt]
float modifier = 0.2 ; //price modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType factionId eventDur commId modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType factionId eventDur commId modifier titleLine textLine ;


Global event: Resource price reduction

Global event: Resource price reduction

int eventId = 1 ; //eventId == resource price decreased
int placeType = 7 ; //place type == faction(affects all stations/planets belonging to factionId
int factionId = 6 ; //[->BaseFactions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int commId = 14 ; //[->BaseCommodities.wdt]
float modifier = 0.2 ; //price modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType factionId eventDur commId modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType factionId eventDur commId modifier titleLine textLine ;


Global event: Station under lockdown

Global event: Station under lockdown

int eventId = 3 ; //eventId == Station under lockdown
int placeType = 4 ; //placeType == STATION (affects the selected station by keyname
int placeId = -1 ; //unused in this type of event
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType placeId vigoSTA eventDur modObj modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType placeId vigoSTA eventDur modObj modVal titleLine textLine ;


Global event: System price decreased

Global event: System price decreased

int eventId = 11 ; //eventId == ShipSystem price decreased
int placeType = 7 ; //place type == faction(affects all stations/planets belonging to factionId
int factionId = 6 ; //[->BaseFactions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 0.2 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType factionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType factionId eventDur modObj modifier titleLine textLine ;


Global event: System price increased

Global event: System price increased

int eventId = 10 ; //eventId == ShipSystem price increased
int placeType = 7 ; //place type == faction(affects all stations/planets belonging to factionId
int factionId = 6 ; //[->BaseFactions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 0.2 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType factionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType factionId eventDur modObj modifier titleLine textLine ;


Global event: Tgate shutdown

Global event: Tgate shutdown

Global event: Tgate shutdown //Shutdown all TGates in a region
int eventId = 2 ; //eventId == TGate shutdown
int placeType = 1 ; //placeType == region (affects all TGates in the region)
int regionId = 16 ; //[->Base egions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modVal titleLine textLine ;

//Shutdown a single TGate by keyname
int eventId = 2 ; //eventId == TGate shutdown
int placeType = 5 ; //placeType == TGate (affects the selected TGate by keyname
int placeId = -1 ; //unused in this type of event
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType placeId nirithGate eventDur modObj modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType placeId nirithGate eventDur modObj modVal titleLine textLine ;


Global event: Trader activity decreased

Global event: Trader activity decreased

int eventId = 23 ; //eventId == Trader activity decreased
int placeType = 1 ; //placeType == REGION (affects trader encounters in the selected region
int regionId = 27 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: Trader activity increased

Global event: Trader activity increased

int eventId = 22 ; //eventId == Trader activity increased
int placeType = 1 ; //placeType == REGION (affects trader encounters in the selected region
int regionId = 27 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int modObj = 0 ; //unused in this type of event
float modifier = 2.0 ; //modifier
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur modObj modifier titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur modObj modifier titleLine textLine ;


Global event: War breaks out

Global event: War breaks out

int eventId = 6 ; //eventId == War breaks out
int placeType = 1 ; //placeType == REGION (affects battle encounters in the selected region, depending on attackerFaction
int regionId = 14 ; //regionId [->BaseRegions.wdt]
float eventDur = 60.0 ; //event duration in seconds
int attackerFaction = 0 ; //factionId of the attacker [->BaseFactions.wdt]
float modVal = 0.0 ; //unused in this type of event
int titleLine = 0 ; Line Id from TextsLogs.txt (counting starts from 0!)
int textLine = 1 ; Line Id from TextsLogs.txt (counting starts from 0!)
globalevent Set eventId placeType regionId eventDur attackerFaction modVal titleLine textLine ;

//add captain's log and news on stations and planets
globalevent AddLog eventId placeType regionId eventDur attackerFaction modVal titleLine textLine ;


GoTo

Instruct a ship to go to a position. The ship can be distracted in which case it will lose its target position and act according to its AI.

float3 targetPos = 0.0 0.0 0.0 ;
ship GetByKeyName ship0 GoTo targetPos ;


GoToScript

Instruct a ship to go to a position and once there, fire off another script. The ship can be distracted in which case it will lose its target position and script and act according to its AI.

float3 targetPos = 0.0 0.0 0.0 ;
ship GetByKeyName ship0 GoToScript targetPos Spg2\Scripts\TargetScript.sal ;


HideStarchart

Close Starchart panel. Used on accepting missions on the Starchart.

game HideStarchart 1 ;


Log

Add entry into the captains log.
You can add main and side quest logs as well as event news.

int logId = 5 ; [->Logs.wdt]
log logId ;


LootDrop (create loot)

Create and populate loot drop wherever needed.

int lootId = 0 ; [->LootDrop.wdt]
float3 lootPosition = 0.0 0.0 0.0 ;
loot LootDrop lootId lootPos ;


Mathematical functions

Standard mathematical functions.
Pay attention to variable types(!).

int a = 1 ;
int b = 1 ;
int c = 0 ;
math c = a + b ; add
math c = a - b ; subtract
math c = a * b ; multiply
math c = a / b ; division where result can be a float(!)
math a++ ; increment math c = a mod b ; modulus
math c = a div b ; division where result is automatically cast as integer(!)


MoveTo (whole assembly)

Unlike SetPosition function that works on an individual mesh in an assembly, MoveTo changes position of the entire assembly.

int retId = 0 ; [unique entity ID used in the current script only]
float3 moveToPosition = 0.0 0.0 0.0 ;
float duration = 4.0 ; [position interpolation time]
assemblyex MoveTo retId moveToPosition duration ;


Pause

Pause script in mid-execution.

pause 4.0 ;


PrintMessage

Print message to log.txt (root directory).
Used for script debug.
Do NOT use empty spaces. Use _ instead!

PrintMessage This_will_be_printed ;


PrintMessageVar

Print a variable into log.txt (root directory).
Used for script debug.
Do NOT use empty spaces. Use _ instead!
INT, FLOAT and FLOAT3 must(!) be used instead of regular int, float and float3 in the function itself.

float distance = 500.0 ;
PrintMessageVar DistanceToObject: FLOAT distance ;


RandomNumber

Returns a random value from the designated range.

math number = Rnd 0 100 ;


RandomNumberPrefix

Returns the same number with a random prefix (+/-).
Works with integers and floats.

int number = 2 ;
math number = RndSign ;


RegionId

Get Id of current region (Region.wdt).

int regionId ;
region GetId regionId ;


RemoveContraband

Remove a commodity from the illegal commodities list of a region.

int regionId = 1 ; [->regions.wdt]
int commodityId = 2 ; [->commodities.wdt]
game RemoveContraband regionId commodityId ;


ResetShipEnemyList

Resets (or recalculates) enemy list for every active ship. Use this function (in the same script) after using SetAIQuestStatus or SetFriendFoe functions!

game ResetShipEnemyList 1 ; The [ 1 ] is a standardized parameter and must NEVER change


Script

Start another script from withing an executing script. Used mostly for cutscenes.

script Spg2\Scripts\scriptName.sal ;


SectorId

Get Id of current sector (hex).

int sectorID ;
sector GetId sectorID ;


SetAcquire

Set quest acquired flag.
It can be either 0(false) or 1(true).

mainquest GetById 1 SetAcquire 1 ;
sidequest GetById 1 SetAcquire 1 ;


SetAIQuestStatus

Flag that sets desired behavior to a ship. Use this function on quest-related ships ONLY! Set appropriate flag for desired behavior.

int aiState_0 = 0 ; [ship is no longer viewed as quest ship]
int aiState_1 = 1 ; [ship's AI is disabled. Ship becomes passive]
int aiState_2 = 2 ; [ship's AI is partially disabled. Ship will ONLY attack other QUEST ships that are his enemies in regards to SetFriendFoe flag]
int aiState_3 = 3 ; [ship's AI is partially disabled. Ship can accept ONLY special script comamnds like GoTo, but will NOT defend itself]
int aiState_4 = 4 ; [ship's AI is partially disabled. Ship can accept ONLY special script commands like GoTo, but WILL fire back on attackers. Defending will NOT break assigned script command.]
ship GetbyKeyName ship0 SetAIQuestStatus aiState_1 ;


SetAIStatus

Can be set either to 0(active) or 1(passive). Passive ships will not act on their own default AI behavior.

ship GetByKeyName ship0 SetAIStatus 0 ;


SetAngularVelocity

Set angular velocity of a mesh in an assembly.

float3 angVel = 0.0 4.5 0.0 ;
float interpolation = 1.0 ;
float delay = 1.5 ;
tgate GetByKeyName korkyraGate GetMesh 1 SetAngularVel angVel interpolation delay ;


SetAvailable

Set quest available flag.
It can be either 0(false) or 1(true).

mainquest GetById 1 SetAvailable 1 ;
sidequest GetById 1 SetAvailable 1 ;


SetBoardable

Set a ship's boardable flag. (o == false, 1 == true)
Ships with flag set to 0 CANNOT be boarded!

int boardFlag = 0 ;
ship GetByKeyName ship0 SetBoardable boardFlag ;


SetCanRepair

Set repairable flag for structures. Repair action can only be done on structures that have this flag set to 1.
Flag can be set either to 0(false) or 1(true).

structure GetByKeyName structure01 SetCanRepair 0 ;


SetCloak

Set ship cloak state to true(1) or false(0).

int cloakState = 1 ;
ship GetbyKeyName ship0 SetCloaked cloakState ;


SetCommoditiesCount

Set an exact quantity of commodities in the player inventory.

int amount = 101 ;
int commodityId = 5 ; [->commodities.wdt]
player SetCommoditiesCount commodityId amount ;


SetCondition

Set specific AI condition of an object.
State can be set to either o(indestructible) or 1(destructible).

ship GetByKeyName ship0 SetCondition 0 ;


SetControlEnabled

Switch player controls OFF (0) or ON (1).

game SetControlEnabled 1 ;


SetCredits

Set player credit count.

int credits = 1500 ;
player SetCredits credits ;


SetCSCamera

Initializes the cutscene camera controls.

camera SetCSCamera 1 ; turn on
camera SetCSCamera 0 ; turn off


SetDefault

Reverts camera setup to the saved parameters (GetDefault).
NEVER activate this function before(!) using GetDefault.

camera SetDefault ;


SetEnabled

Activate or deactivate an object. Ship is used only as example.
Can be set either to 0(disabled) or 1(enabled).

ship GetByKeyName ship0 SetEnabled 1 ;
ship GetByKeyName ship0 SetEnabled 0 ;


SetExp

Set player experience.

int exp = 1000 ;
player SetExp exp ;


SetFloat

Sets the float modding variable in the save file to the wanted value.

int stackVarId = 0 ;
float floatVal = 0.0 ;
modingvar SetFloat stackVarId floatVal ;
modingvar SetFloat 0 floatVal ;


SetFriendFoe

Friend-Foe mechanism. Used during missions to prevent randomly generated AI ships from interfering.
status = 0 [neutral objects will not interfere
status = 1 [friendly objects will assist player by default]
status = 2 [hostile objects will attack player by default]
Specific behaviour must be scripted.

int status = 0 ;

ship GetByKeyName ship0 SetFriendFoe status ;


SetHP

Sets hull of object to a fixed value.

float shipHP = 500.0 ;
ship GetByKeyName ship0 SetHP shipHP ;


SetHPRel

Sets hull of object to its relative percentage, taking into account the object's base Hull value.

int HullPercentage = 100 ; ship hull will be set to its 100%
ship GetByKeyName ship0 SetHPRel HullPercentage ;


SetInt

Sets the integer modding variable in the save file to the wanted value.

int stackVarId = 0 ;
int intVal = 0 ;
modingvar SetInt stackVarId intVal ;
modingvar SetInt 0 intVal ;


SetInvulnerable

Set whether ship is invulnerable (1) or not (0).

ship GetByKeyName ship0 SetInvulnerable 1 ;


SetMark

Mark an object as important. Used for marking quest objects.
0 = clear marker
1 = main mission
2 = side mission
3 = freelance mission

ship GetByKeyName ship0 SetMark 1 ;


SetMeshPosition

Set mesh position in an assembly (offset).

float3 position = 0.0 30.0 0.0 ;
float interpolation = 1.0 ;
float delay = 1.5 ;
tgate GetByKeyName korkyraGate GetMesh 1 SetPosition position interpolation delay ;


SetMeshRotation

Set rotation of a mesh in an assembly.

float3 rotation = 0.0 1.57 0.0 ;
float interpolation = 1.0 ;
float delay = 1.5 ;
tgate GetByKeyName korkyraGate GetMesh 1 SetRotation rotation interpolation delay ;


SetMeshVisibility

Toggle rendering of an object mesh.
State can be set to either 0(invisible) or 1(visible).
Mesh shader MUST support fading!

int state = 1 ;
float delay = 1.5 ;
tgate GetByKeyName korkyraGate GetMesh 1 SetVisible state delay ;


SetParticleVisibility

Toggle rendering of an object particle.
Type can be set to either 1(interpolation) or 2(instant).

int state = 1 ;
int interpolation = 1 ;
float delay = 1.5 ; [deprecated]
tgate GetByKeyName korkyraGate GetParticle 1 SetVisible state interpolation delay ;


SetPTE

Set ship Power to Engines to ON(1) or OFF(0).

int pteState = 1 ;
ship GetbyKeyName ship0 SetPTE pteState ;


SetQuestItemCount

Set an exact quantity of a quest item in the player inventory.

int amount = 4 ;
int itemId = 2 ; [->QuesItems.wdt]
player SetQuestItemCount itemId amount ;


SetQuestMode

Switch Quest mode to OFF (0) or ON (1). QuestMode MUST be set to ON before SetAIQuestStatus is used on ships!

game SetQuestMode 1 ;


SetReputation

Set player's reputation.

int rep = 1200 ;
player SetReputation rep ;


SetRotation

Set object rotation.

float3 rotation = 1.0 0.0 0.0 ;
ship GetByKeyName ship0 SetRotation rotation ;


SetScale

Set scale of a mesh in an assembly. assemblyex object is used only as an example.

int retId = 0 ;
int meshId = 1 ;
float3 scale = 12.0 12.0 12.0 ;
float interpolation = 1.0 ;
float delay = 0.0 ;
assemblyex GetMesh retId meshId SetScale scale interpolation delay ;


SetSolve

Set quest solved flag. It can be set either to 0(false) or 1(true).

mainquest GetById 1 SetSolve 1 ;
sidequest GetById 1 SetSolve 1 ;


SetSpeed

Sets ship speed. Used primarily for the player. AI ships eventually resume their default AI behavior.

float speed = 5.0 ;
ship GetPlayer SetSpeed speed ;


SetTransparent

Set transparency of a mesh in an assembly. assemblyex object is used only as an example.

int retId = 0 ;
int meshId = 1 ;
float transparency = 0.5 ;
float interpolation = 1.0 ;
float delay = 0.0 ;
assemblyex GetMesh retId meshId SetTransparent transparency interpolation delay ;


SetTroopersNo

Set the number of Troopers on a ship.

int trooperCount = 10 ;
ship GetByKeyName ship0 SetTroopersNo trooperCount ;


SetType (camera)

Defines the camera type and its parameters. This function requires the SetCSCamera function to be turned ON before using.

OBJECT TYPES (hard-coded)
player == 0
ship == 1
tgate == 2
wormhole == 3
rift == 4
station == 5
structure == 6
planet == 7
asteroid field == 8
nebula == 9
waypoint == 10
derelict == 11
anomaly == 12
trigger == 13
junkyard == 14
scenery == 15
single asteroid == 16
platform == 17
path == 18

ROTATION CAMERA
int objectType = 1 ; if objectType is 0 (player) this parameter is followed by NONE as keyname
float rotationStart = 2.4 ; camera starting angle in radians (planar)
float rotationSpeed = 0.08 ; camera speed of rotation
float verticalStart = 2.4 ; camera vertical start position
float verticalOffset = 12.0 ; camera vertical offset
float verticalSpeed = 0.06 ; speed at which camera moves on the vertical axis (within allowed offset)
float cameraDistance = 60.0 ; camera distance from focus
camera SetType 5 objectType SHIP_0 rotationStart rotationSpeed verticalStart verticalOffset verticalSpeed cameraDistance ;

camera SetType 5 0 NONE rotationStart rotationSpeed verticalStart verticalOffset verticalSpeed cameraDistance ; if player is camera target

LOCK-ON CAMERA
int objectType = 1 ; if objectType is 0 (player) this parameter is followed by NONE as keyname
float verticalStartA = 5.0 ; camera vertical start position
int focusObjType = 7 ; if objectType is 0 (player) this parameter is NOT followed by a keyname(!)
float verticalStartB = 0.0 ; focus vertical position
float cameraDistance = 2700.0 ; camera distance from focus
camera SetType 6 objectType SHIP_0 verticalStartA focusObjType trinityPLA verticalStartB cameraDistance ;

camera SetType 6 0 NONE verticalStartA focusObjType trinityPLA verticalStartB cameraDistance ; if camera uses player as starting point


SetZoom

Set camera zoom. Needs SetCSCamera to be first set to ON.

float time = 1.0 ;
float zoomAmount = 190.0 ;
camera SetZoom 0 time zoomAmount ; the 0 is a temporary parameter that will be changed at a later date


Shake (screen)

Screen-shake effect.

LOCAL
int sort = 1 ; [1=local]
int shakeType = 0 ;
float power = 0.5 ;
float duration = 0.6 ;
float delay = 0.0 ;
float3 position = 0 0 0 ;
float radius = 400.0 ;
camera Shake sort shakeType power duration delay position radius ;

GLOBAL
int sort = 0 ; [0=local]
int shakeType = 0 ;
float power = 0.5 ;
float duration = 0.6 ;
float delay = 0.0 ;
camera Shake sort shakeType power duration delay ;


Shockwave

Generate a shockwave.

float delay = 0.0 ;
float3 position = 0.0 0.0 0.0 ;
float3 color = 1.0 1.0 1.0 ;
int shapeId = 0 ; [0,1,2,3]
int textureId = 0 ; [->shockwave.wds]
float radiusStart = 0.0 ;
float radiusEnd = 50.0 ;
float lifetime = 2.0 ;
float distortion = 0.2 ;
float refraction = 0.2 ;
float yScale = 1.0 ; [vertical scale; only works if shapeId is NOT 0]
int fadeType = 1 ; [0=linear, 1=graph]
shockwave delay position color shapeId textureId radiusStart radiusEnd lifetime distortion refraction yScale fadeType ;


ShowAllPanels

Turns HUD panels ON(1) or OFF(0).
NEVER turn panels ON if you haven't already shut them down first!

game ShowAllPanels 0 ;


ShowLine

Show horizontal black lines. Used in cutscenes. Can be set to either true(1) or false(0).

screen ShowLine 1 ;


ShowText

Show text on the bottom of the screen.

int miscLine = 0 ; [->Spg2\Texts\misc.txt | line count starts from 0]
float duration = 10.0 ;
screen ShowText miscLine duration ;


ShowWarnings

Show special notification panel with needed title and text.

int titleLine = 1 ;
int textLine1 = 2 ;
int textLine2 = -1 ;[if no text, set as -1]
screen ShowWarnings titleLine textLine1 textLine2 ;


ShowWarningsEx (pass through wormhole)

Show special notification panel. Title and text lines are hard-coded, but parameters can be sent through. If a parameter is set to 0, it is NOT shown on the notification panel.

int troopers = 5 ; //number of Troopers lost
int hull = 100 ; //amount of Hull lost
int wrongLoc = 0 ; //whether or not you've exited the wormhole in the right location (0 == false, 1 == true)
screen ShowWarningsEx 16 troopers hull wrongLoc ; //16 is the special hard-coded ID of the notification panel


Sound

Play global sound.

sound soundName ; [sound.wdt]


Sound3D

Play local sound with distance falloff.

float3 position = 0.0 0.0 0.0 ;
sound3d soundName position ; [sound.wdt]


Spawn ship (shipAdd)

Spawn a ship based on current region parameters(!).
For keyname use either custom literal value OR keyword "GENERIC" which means the game will assign a generic keyname.
Using GENERIC prevents you from manipulating the spawned ship later on via its keyname.
Keyname MUST be used directly in the function as literal value.

int type = 0 ; //0 = region based
float3 position = 0.0 0.0 0.0 ;
int faction = 0 ; //region based(!) where 0 is the first faction in the region file
int shipId = 0 ; //region based(!) where 0 is the first ship in the faction ship list
shipAdd ship0/GENERIC type position faction shipId ;


Storypanel

Force open a special panel. Used specifically for important VO logs during main campaign. The only parameter is the hard-coded ID.

storypanel 0 ;


Tutorial (panel)

Script function regarding tutorial panels and their automatic opening.

int tutState = 1 ;
tutorial Enable tutState ;[enable(1)/disable(0) automatic opening of tutorial panels]

int tutId = 1 ;
tutorial tutId ; [opens up a specific tutorial panel, by hard-coded ID]