Game engine behind Sea Dogs, Pirates of the Caribbean and Age of Pirates games.

Related articles: Scripting Language Overview, Article 0004. Entities
Here you will find the list of the built-in and some game-level useful functions for the game scripting.
Below are the functions which make part of the compiler API. Each function has its own unique identifier token that’s also listed below.
FUNC_SAVEENGINESTATEsaveName: name of the save.
syntax:
void SaveEngineState(string saveName);
FUNC_LOADENGINESTATEsaveName: name of the save.
syntax:
void LoadEngineState(string saveName);
FUNC_LOAD_SEGMENTfilename: relative path to the file to load
syntax:
bool LoadSegment(string filename);
example:
if (LoadSegment("interface\alchemy.c"))
{
// ...
// do necessary work
// ...
UnloadSegment("interface\alchemy.c");
}
FUNC_UNLOAD_SEGMENTfilename: relative path to the file to unload
syntax:
void UnloadSegment(string fileName); // unload segment (delayed)
example:
if (LoadSegment("interface\alchemy.c"))
{
// ...
// do necessary work
// ...
UnloadSegment("interface\alchemy.c");
}
FUNC_GETDELTATIME
syntax:
int GetDeltaTime(0);
FUNC_GETTARGETPLATFORM syntax:
string GetTargetPlatform();
example:
GetTargetPlatform(); // "pc"
FUNC_SETTIMESCALEvalue: time scale, from 0 to 1.float, so passing both float and int values is allowed. syntax:
void SetTimeScale(int value);
void SetTimeScale(float value);
example:
SetTimeScale(0.0);
system.log file.
FUNC_TRACE
syntax:
void Trace(int message);
void Trace(float message);
void Trace(string message);
example:
int n = LocationInitAntigua(n);
Trace("Antigua locations " + n);
FUNC_BREAKPOINT
syntax:
void Breakpoint();
FUNC_STOP
syntax:
void Stop();
ExitMain function if it’s defined in the loaded segments and exit the game.
FUNC_EXIT_PROGRAM
syntax:
void ExitProgram();
FUNC_SEGMENT_IS_LOADEDfilename: relative path of the file to test
syntax:
bool SegmentIsLoaded(string filename);
ENGINE_SCRIPT_VERSION constant (defined in core.h).
FUNC_GETENGINEVERSION syntax:
int GetEngineVersion();
example:
GetEngineVersion();
FUNC_CHECKFUNCTIONvalue: function name.
syntax:
bool CheckFunction(string value);
example:
if (CheckFunction("ControlsTreeInit"))
{
ControlsTreeInit();
}
FUNC_TEST_REFtarget: a reference or an attribute to test.
syntax:
bool TestRef(ref target);
bool TestRef(aref target);
example:
bool LAi_CheckCharacter(aref chr, string out)
{
if (!TestRef(chr))
{
Trace("LAi_CheckCharacter -> invalid aref, call from " + out);
return false;
}
return true;
}
FUNC_IS_Entity_LOADEDobj: object to test
syntax:
bool IsEntity(object obj);
bool IsEntity(ref obj);
example:
object torn;
if (!isEntity(&torn))
{
CreateEntity(&torn, "Tornado");
}
FUNC_CHECK_ATTRIBUTEobj: address of the target objectattribute: attribute to verify
syntax:
bool CheckAttribute(object &obj, string attribute);
example:
if (!CheckAttribute(&Weather, "Stars.Enable"))
{
Weather.Stars.Enable = false;
};
FUNC_ISDIGIT
source: The string containing the character to verifyposition: Position of the tested character in the string
syntax:
bool IsDigit(string source, int position);
example:
string testString = "1ten20";
bool test1 = IsDigit(testString, 0); // true
bool test2 = IsDigit(testString, 3); // false
bool test1 = IsDigit(testString, 5); // true
FUNC_CREATE_CLASSentityType: Class name, must be predefined by the engine.CreateClass don’t expose their attributes to the engine.
syntax:
object CreateClass(string entityType);
example:
object obj = CreateClass("CustomType"); // "invalid entity name"
object obj = CreateClass("Sky"); // OK
CreateClass, except it allows specific attributes to be used directly by the engine.
objectReference: Address of the object to which the new entity will be bound.entityType: Class name, must be predefined by the engine.
syntax:
bool CreateEntity(object& objectReference, string entityType);
example:
object torn;
if (!isEntity(&torn))
{
CreateEntity(&torn, "Tornado");
}
refs and arefs will now fail.
FUNC_DELETE_Entity (capitalization preserved)
syntax:
void DeleteClass(object obj);
FUNC_DELETEENTITIESBYTYPEtype: type of the entities to delete
syntax:
void DeleteEntitiesByType(string type);
FUNC_DELETE_ENTITIES
syntax:
void DeleteEntities();
example:
DeleteEntities();
FUNC_FINDENTITYentityPointer: Address of the ref to contain the entity reference, if found.name: Name of the entity typefalse if no entities are foundFindEntity.
syntax:
bool GetEntity(ref &entityPointer, string name);
example:
ref location;
if (GetEntity(&location, "Location"))
{
// Do something with the entity
}
FUNC_FINDENTITYentityPointer: Address of the ref to contain the entity reference, if found.name: Name of the entity typefalse if no entities are foundFindEntityNext.
syntax:
bool FindEntity(ref &entityPointer, string name);
example:
ref location;
if (FindEntity(&location, "Location"))
{
// Do something with the found entity
}
FUNC_FINDENTITYNEXTentityPointer: Address of the ref to contain the entity reference, if found.false if no other entities are foundFindEntity must be called to initialize the search first.
syntax:
bool FindEntityNext(ref &entityPointer);
example:
ref location;
if (FindEntity(&location, "Location"))
{
// Do something with the found entity
while (FindEntityNext(&location))
{
// Iterate of the rest
}
}
FUNC_Entity_UPDATEisEnabled: if set to false, entity will not receive attribute updates.
syntax:
void EntityUpdate(bool isEnabled);
example:
EntityUpdate(false);
// ...
// Update the object
// ...
EntityUpdate(true);
FUNC_DELETE_ATTRIBUTEobj: Object to remove attribute fromattribute: attribute to remove."" as attribute, all the attributes of the object are cleared.
syntax:
void DeleteAttribute(object obj, string attribute);
example:
DeleteAttribute(&Sky, ""); // clear the object
DeleteAttribute(pchar, "Items"); // remove all collected items
string sQuest2 = "quest.Deposits." + city + "_Type2";
DeleteAttribute(pchar, sQuest2);
FUNC_GET_ATTRIBUTES_NUMobj/attribute: object to count child attributes of.GetAttributeN for iteration on attributes.
syntax:
int GetAttributesNum(object obj);
int GetAttributesNum(ref obj);
int GetAttributesNum(aref attribute);
example:
int count = GetAttributesNum(arRoot);
for (i = 0; i < count; i++)
{
aref attribute = GetAttributeN(arRoot, i);
// ...
// Do some work on attribute
// ...
}
FUNC_GET_ATTRIBUTE_BYNobj/attribute: object to count child attributes of.index: Sequential number of the attribute inside the object.GetAttributeNum for iteration on attributes.
syntax:
aref GetAttributeN(object obj, int index);
aref GetAttributeN(ref obj, int index);
aref GetAttributeN(aref attribute, int index);
example:
int count = GetAttributesNum(arRoot);
for (i = 0; i < count; i++)
{
aref attribute = GetAttributeN(arRoot, i);
// ...
// Do some work on attribute
// ...
}
FUNC_GET_ATTRIBUTE_NAMEobj/attribute: target object or attribute.
syntax:
string GetAttributeName(object obj);
string GetAttributeName(ref obj);
string GetAttributeName(aref attribute);
example:
object Test;
Test.value = "hello";
string attrName = GetAttributeName(Test.value); // "value"
FUNC_GET_ATTRIBUTE_VALUEobj/attribute: target object or attribute.objects, floats and ints need to be converted accordingly before use.
syntax:
string GetAttributeValue(object obj);
string GetAttributeValue(ref obj);
string GetAttributeValue(aref attribute);
example:
object Test;
Test.value = "hello";
string attrValue = GetAttributeValue(Test.value); // "hello"
FUNC_COPYATTRIBUTESdestination: address of the object to receive attributessource: object to copy
syntax:
void CopyAttributes(object &destination, object source);
example:
object Tmp;
CopyAttributes(&Tmp, CargoOne);
FUNC_DUMP_ATTRIBUTESobj/attribute: target object or attribute.
syntax:
void DumpAttributes(object obj);
void DumpAttributes(ref obj);
void DumpAttributes(aref attribute);
example:
trace("nConditionsNum : " + nConditionsNum);
DumpAttributes(conditions);
FUNC_SEND_MESSAGEobj: address of the recipient (or its reference)stringFormat: the types of the passed arguments arranged in a string:
l: int/boolf: floats: stringa, i: object or arefe: refmsg: the arguments passed to the handlers. syntax:
void SendMessage(ref obj, string stringFormat, msg...);
example:
SendMessage(&Dialog, "lii", 0, Character, &persRef); // pass an int and two objects to "Dialog" object
SendMessage(&AIBalls, "l", MSG_MODEL_RELEASE); // pass a single int to "AIBalls" object
FUNC_EVENT syntax:
void Event(string eventName, [MSG]);
example:
Event("NextDay"); // no message
Event("ControlActivation", "s", "ChrAction"); // pass trigger type
FUNC_POSTEVENTeventName: Name of the event to trigger.delay: Delay, in milliseconds. syntax:
void PostEvent(string eventName, int delay, [MSG]);
example:
PostEvent("My_eventMoveImg", 100); // no message
int charIndex = sti(CharacterRef.index);
PostEvent("eventDialogExit", 1, "l", charIndex); // pass character ID
FUNC_SET_EVENT_HANDLEReventName: name of the event.functionName: name of the function to call when the event triggers.post: true for events to be processed with a delay. syntax:
void SetEventHandler(string eventName, string functionName, bool post);
#event_handler(string eventName, string functionName, bool post);
example:
SetEventHandler("frame", "RefreshTableByFrameEvent", false); // execute when "Event()" is called
SetEventHandler("frame", "ProcessFrame", true); // execute when "PostEvent()" is called
FUNC_DEL_EVENT_HANDLEReventName: name of the event.functionName: name of the function to remove.
syntax:
void DelEventHandler(string eventName, string functionName);
example:
DelEventHandler("frame", "RefreshTableByFrameEvent");
FUNC_GET_EVENTDATA syntax:
[any type] GetEventData();
example:
SetEventHandler("Control Activation", "InfoShow_Control", 0);
Event("Control Activation", "s", "ChrAction");
void InfoShow_Control()
{
string controlName = GetEventData(); // "ChrAction"
// ...
}
FUNC_CLEAR_EVENTS syntax:
void ClearEvents();
FUNC_CLEAR_POST_EVENTS syntax:
void ClearPostEvents();
bEventsBreak is always false coming into the event loop.FUNC_EVENTSBREAK
syntax:
void EventsBreak();
Please note that, unlike the previous versions, the current version of the Storm Engine requires the layers to be entered as IDs (as opposed to strings in the past). You can find the reference table here.
FUNC_LAYER_ADDOBJECTlayerID: id of the desired layer.obj: address of the added object.priority: Lower priority entities will be processed first, can be negative.
syntax:
void LayerAddObject(int layerID, object &obj, int priority);
example:
#define SEA_EXECUTE 2
#define SEA_REALIZE 3
object tornado;
CreateEntity(&tornado, "Tornado");
LayerAddObject(SEA_EXECUTE, &tornado, 65535);
LayerAddObject(SEA_REALIZE, &tornado, 65535);
FUNC_LAYER_SET_EXECUTElayerID: id of the desired layer.
syntax:
void LayerSetExecute(int layerID);
example:
LayerSetExecute(SEA_EXECUTE);
FUNC_LAYER_SET_REALIZElayerID: id of the desired layer.
syntax:
void LayerSetRealize(int layerID);
example:
LayerSetRealize(SEA_REALIZE);
FUNC_LAYER_FREEZElayerID: id of the desired layer.isEnabled: whether or not the layer should be enabled.
syntax:
void LayerFreeze(int layerID, bool isEnabled);
FUNC_LAYER_DELOBJECTlayerID: id of the desired layer.obj: address of the removed object.
syntax:
void LayerDelObject(int layerID, object &obj);
example:
LayerDelObject(EXECUTE, &Sky);
LayerDelObject(REALIZE, &Sky);
Currently disabled/not implemented functions:
FUNC_LAYER_CREATE
syntax:
void LayerCreate(int layerID, bool ordered);
FUNC_LAYER_DELETE
syntax:
void LayerDeleteLayer(int layerID);
FUNC_LAYER_DELETE_CONTENT
syntax:
void LayerDeleteContent(int layerID);
FUNC_LAYER_SET_MESSAGES
syntax:
void LayerSetMessages(int layerID, bool isEnabled);
range.
FUNC_RANDrange: Any positive number.
syntax:
int Rand(int range);
example:
ref ch = GetCharacter(NPC_GenerateCharacter(...));
ch.Nation = rand(4); // random nation
FUNC_FRAND
syntax:
float frnd();
example:
float fChecker = frand();
if (fChecker < 0.8) {...}
FUNC_ABSvalue: can be positive or negative, integer or float
``` C++
syntax:
int abs(int value);
float abs(float value);example: int x = 5; int y = -5;
int absX = abs(x); // 5.0
int absY = abs(y); // 5.0 ```
FUNC_SQRvalue: can be an integer or a float
syntax:
float sqr(int value);
float sqr(float value);
example:
int x = 5 * 5; // 25.0
int y = sqr(5); // 25.0
FUNC_POW
base: number to elevateexponent: desired power
syntax:
float Pow(float base, float exponent);
example:
Log_Info("" + pow(10.0, 3.0)); // 10^3, 1000
Log_Info("" + pow(10.0, -3.0)); // 10^3, 0.001
FUNC_SQRTvalue: can be an integer or a float
syntax:
float sqrt(int value);
float sqrt(float value);
example:
int x = sqrt(25); // 5.0
FUNC_SINvalue: angle in radians.
syntax:
float sin(int value);
float sin(float value);
example:
Particles.winddirection.x = sin(Whr_GetWindAngle());
FUNC_COSvalue: angle in radians.
syntax:
float cos(int value);
float cos(float value);
example:
Particles.winddirection.z = cos(Whr_GetWindAngle());
FUNC_TANvalue: angle in radians.
syntax:
float tan(int value);
float tan(float value);
FUNC_ATANvalue: tangent of the desired angle. syntax:
float atan(int value);
float atan(float value);
FUNC_TAN2x: x-coordinate of the pointy: y-coordinate of the point syntax:
float atan2(int/float x, int/float y); // in any combination
FUNC_ASINvalue: sine of the angle to be inverted, -1 to 1.
syntax:
float asin(int value);
float asin(float value);
FUNC_ACOSvalue: cosine of the angle to be inverted, -1 to 1.
syntax:
float acos(int value);
float acos(float value);
int.
FUNC_MAKE_INTvalue may be a string or an int syntax:
int MakeInt(string value);
int MakeInt(float value);
float.
FUNC_MAKE_FLOATvalue may be a string or an int syntax:
float MakeFloat(string value);
float MakeFloat(int value);
string to int
FUNC_STIvalue can only be a string
syntax:
int sti(string value);
string to a float
FUNC_STFvalue can only be a string
syntax:
float stf(string value);
FUNC_FTS
value: value to be converted.
digits: Number of significant digits stored.
syntax:
string fts(float value, int digits);
example:
float pi = 3.141526535
string pi2 = fts(pi, 3); // 3.14
string pi4 = fts(pi, 5); // 3.1415
FUNC_ARGBa, r, g, b: alpha and color channels from 0 to 255.0xAARRGGBB
syntax:
int argb(int a, int r, int g, int b);
value to n bits to the left
FUNC_SHLvalue: The value containing the bitsn: By how many bits to shiftvalue << n;
syntax:
int shl(int value, int n);
value to n bits to the right
FUNC_SHRvalue: The value containing the bitsn: By how many bits to shiftvalue >> n;
syntax:
int shr(int value, int n);
FUNC_ANDvalue: The value containing the bitsmask: Mask containing the bits to comparevalue & mask;
syntax:
int and(int value, int mask);
FUNC_ORvalue: The value containing the bitsmask: Mask containing the bits to comparevalue | mask;
syntax:
int or(int value, int mask);
FUNC_CREATE_CONTROLcontrolName: Unique identifier for the control. syntax:
int CreateControl(string controlName);
FUNC_DELETE_CONTROL
syntax:
void DeleteControl(string controlName);
FUNC_MAP_CONTROLControlID: ID of the control to set.key: ID of the key to bind.
syntax:
void MapControl(int controlID, int key);
FUNC_SET_CONTROL_TRESHOLD
syntax:
void SetControlTreshold(int controlID, float thresholdValue);
FUNC_SET_CONTROL_FLAGSControlID: ID of the control to set.flags: Set of flags to apply to the controlUSE_AXIS_AS_BUTTON or 1false if incorrect control ID has been provided.
syntax:
bool SetControlFlags(int controlID, int flags);
FUNC_LOCK_CONTROLcontrolName: Unique identifier for the control.isLocked: true to disable the control.
syntax:
void LockControl(string controlName, bool isLocked);
FUNC_CLEAR_Entity_AP
syntax:
void ClearEntityAP(1);
FUNC_VARTYPE
syntax:
string Vartype(ref attribute);
FUNC_CLEARREF
syntax:
void ClearRef(1);
FUNC_GET_ARRAY_SIZE
syntax:
int GetArraySize(1);
FUNC_SET_ARRAY_SIZE
syntax:
void SetArraySize(2);
FUNC_STRCUT
syntax:
string strcut(3);
FUNC_FINDSUBSTR
syntax:
string findSubStr(3)
FUNC_STRLEN
syntax:
int strlen(1);
FUNC_GETSYMBOL
syntax:
string GetSymbol(2);
| Home | Site Map |