Sprache Deutsch Language English

Menu:



Letzte Änderung:
12. Februar 2016


Script Dokumentation LS 2015 - Utils (Patch 1.3)

Script Dokumentation Übersicht
  1. Funktionen
    1. Utils.indexToObject(components, index)
    2. Utils.getFilename(filename, baseDir)
    3. Utils.getNoNil(value, defaultValue)
    4. Utils.getVectorFromString(inputString)
    5. Utils.getVectorNFromString(inputString, num)
    6. Utils.getRadiansFromString(inputString, num)
    7. Utils.cutFruitArea(fruitId, parallelogram)
    8. Utils.loadParticleSystem(xmlFile, particleSystems, baseString, linkNodes, defaultEmittingState, defaultPsFile, baseDir)
    9. Utils.deleteParticleSystem(table particleSystems)
    10. Utils.setEmittingState(table particleSystems, boolean emitting)

Parallelogram

Most foliage regions are defined by a parallelogram. This is a quadrangle with two sets of parallel sides. It is defined by a position and a height and width direction, each is specified by an x and z component. The following picture shows the parallelogram with its height/width directions.
parallelogram

Utils.indexToObject

Description
Returns the object of the object which has the given index

Definition
function Utils.indexToObject(table components, string index)

Arguments
tablecomponentsTable which includes all components
stringindexzero index of the object. Hierarchy is separated by |. Component is selected by componentNr>index (e.g. 2>1|0)


Utils.getFilename

Description
Returns a modified filename. If the filename starts with $, the $ is removed, otherwise baseDir is added.

Definition
function Utils.getFilename(string filename, string baseDir)

Arguments
stringfilenameThe filename to modify
stringbaseDirThe base directory of the current mod (In a vehicle use self.baseDirectory. While a mod lua file is loaded, you may use g_currentModDirectory


Utils.getNoNil

Description
Returns either the value given or if it is nil, the default value.
This is a handy helper to load values from an xml file which should have a default value, if there is no information in the xml available.
local v = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.theValue#v"), 0.0)
The variable v now contains either the value in vehicle.theValue#v or 0.0

Definition
function Utils.getNoNil(any value, any defaultValue)

Arguments
anyvalueThe value to be checked for nil
anydefaultValueThe default value, which is returned if the value is nil


Utils.getVectorFromString

Description
Returns the components from a vector stored in a string separated with spaces. E.g. "3 1 5" returns 3, 1 and 5.
Example:
local x,y,z = Utils.getVectorFromString("3 1 5");
local x,y,z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.theVector"));
If there are not enough components stored in the string, the values are nil.
E.g. local x,y,z = Utils.getVectorFromString("3 1"); assigns x=3, y=1 and z=nil

Definition
function Utils.getVectorFromString(string inputString)

Arguments
stringinputStringSpace separated components of a vector


Utils.getVectorNFromString

Description
Returns the components as a table from a vector stored in a string separated with spaces. E.g. "3 1 5" returns {3, 1, 5}.
Example:
local vec = Utils.getVectorNFromString("3 1 5", 3);
If there are less components stored in the string than specified with the num parameter, the return value is nil.
E.g. local vec = Utils.getVectorFromString("3 1", 3); assigns vec=nil

Definition
function Utils.getVectorNFromString(string inputString, integer num)

Arguments
stringinputStringSpace separated components of a vector
integernumThe number of components expected


Utils.getRadiansFromString

Description
Returns the components as a table from a vector stored in a string separated with spaces and converts them from degree to radian. E.g. "180 0 360" returns {pi, 0, 2*pi}.
Example:
local vec = Utils.getVectorNFromString("180 0 360", 3);
If there are less components stored in the string than specified with the num parameter, the return value is nil.
E.g. local vec = Utils.getVectorFromString("180 0", 3); assigns vec=nil

Definition
function Utils.getRadiansFromString(string inputString, integer num)

Arguments
stringinputStringSpace separated components of a vector
integernumThe number of components expected


Utils.cutFruitArea

Description
Cuts the given fruitType at the given parallelogram. Only areas that have the same fruit type and that have a big enough growth state (> minHarvestingGrowthState) are modified. The function returns the amount of fruit that was cut. See Parallelogram

Definition
function Utils.cutFruitArea(integer fruitId, float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ)

Arguments
integerfruitIdThe id of the fruit type to cut, eg FruitUtil.FRUITTYPE_WHEAT
floatstartWorldXThe x start position of the parallelogram
floatstartWorldZThe z start position of the parallelogram
floatwidthWorldXThe x coordinate of the width vector of the parallelogram
floatwidthWorldZThe z coordinate of the width vector of the parallelogram
floatheightWorldXThe x coordinate of the height vector of the parallelogram
floatheightWorldZThe z coordinate of the height vector of the parallelogram


Utils.loadParticleSystem

Description
Loads a particle system specified in the xmlFile.
A xml node can contain the following attributes:
node: An index-string to a node that the particle system is linked to. Default: "0>" = rootNode. See indexToObject
position: Position of the particle system relative to the node. Format: "x y z"
rotation: Rotation of the particle system relative to the node. Format: "x y z" [degrees]
file: Filename of the i3d file of the particle system. This may contain several particle system nodes.

Example:
XML: <testParticleSystem node="1>9|0" position="0 2 5" rotation="180 0 0" file="$data/vehicles/particleSystems/particleSystem.i3d" />
Lua:
self.testParticleSystems = {}; local psName = "vehicle.testParticleSystem";
local defaultPs = "$data/vehicles/particleSystems/defaultParticleSystem.i3d";
Utils.loadParticleSystem(xmlFile, self.testParticleSystems, psName, self.components, false, defaultPs, self.baseDirectory);

Definition
function Utils.loadParticleSystem(xmlFile, table particleSystems, string baseString, table linkNodes, boolean defaultEmittingState, string defaultPsFile, string baseDir)

Arguments
integerxmlFileThe id of xml file
tableparticleSystemsThis is the table where the information loaded is stored
stringbaseStringThe key of the node of the particle system in the xml file
tablelinkNodesThis list is used to resolve the index string of the node attribute. See indexToObject
booleandefaultEmittingStateIf true, all particle systems are emitting from the beginning, otherwhise they are stopped
stringdefaultPsFileIf the file attribute is missing, this value is used as the i3d filename
stringbaseDirThe base directory to use with the particle system filename. See getFilename


Utils.deleteParticleSystem

Description
Deletes the particle system previously loaded with Utils.loadParticleSystem.

Definition
function Utils.deleteParticleSystem(table particleSystems)

Arguments
tableparticleSystemsThis is the table where the information of the particle system is stored


Utils.setEmittingState

Description
Sets the emtting state of a particle system loaded with Utils.loadParticleSystem.

Definition
function Utils.setEmittingState(table particleSystems, boolean emitting)

Arguments
tableparticleSystemsThis is the table where the information of the particle system is stored
booleanemittingIf true, the particle systems are set to emitting, otherwhise they are stopped
Script Dokumentation Übersicht