Script Dokumentation LS 2015 - Utils (Patch 1.3)
- Funktionen
- Utils.indexToObject(components, index)
- Utils.getFilename(filename, baseDir)
- Utils.getNoNil(value, defaultValue)
- Utils.getVectorFromString(inputString)
- Utils.getVectorNFromString(inputString, num)
- Utils.getRadiansFromString(inputString, num)
- Utils.cutFruitArea(fruitId, parallelogram)
- Utils.loadParticleSystem(xmlFile, particleSystems, baseString, linkNodes, defaultEmittingState, defaultPsFile, baseDir)
- Utils.deleteParticleSystem(table particleSystems)
- 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.Utils.indexToObject
DescriptionReturns the object of the object which has the given index
Definition
function Utils.indexToObject(table components, string index)
Arguments
table components Table which includes all components string index zero index of the object. Hierarchy is separated by |. Component is selected by componentNr>index (e.g. 2>1|0)
Utils.getFilename
DescriptionReturns a modified filename. If the filename starts with $, the $ is removed, otherwise baseDir is added.
Definition
function Utils.getFilename(string filename, string baseDir)
Arguments
string filename The filename to modify string baseDir The 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
DescriptionReturns 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
any value The value to be checked for nil any defaultValue The default value, which is returned if the value is nil
Utils.getVectorFromString
DescriptionReturns 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
string inputString Space separated components of a vector
Utils.getVectorNFromString
DescriptionReturns 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
string inputString Space separated components of a vector integer num The number of components expected
Utils.getRadiansFromString
DescriptionReturns 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
string inputString Space separated components of a vector integer num The number of components expected
Utils.cutFruitArea
DescriptionCuts 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
integer fruitId The id of the fruit type to cut, eg FruitUtil.FRUITTYPE_WHEAT float startWorldX The x start position of the parallelogram float startWorldZ The z start position of the parallelogram float widthWorldX The x coordinate of the width vector of the parallelogram float widthWorldZ The z coordinate of the width vector of the parallelogram float heightWorldX The x coordinate of the height vector of the parallelogram float heightWorldZ The z coordinate of the height vector of the parallelogram
Utils.loadParticleSystem
DescriptionLoads 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
integer xmlFile The id of xml file table particleSystems This is the table where the information loaded is stored string baseString The key of the node of the particle system in the xml file table linkNodes This list is used to resolve the index string of the node attribute. See indexToObject boolean defaultEmittingState If true, all particle systems are emitting from the beginning, otherwhise they are stopped string defaultPsFile If the file attribute is missing, this value is used as the i3d filename string baseDir The base directory to use with the particle system filename. See getFilename
Utils.deleteParticleSystem
DescriptionDeletes the particle system previously loaded with Utils.loadParticleSystem.
Definition
function Utils.deleteParticleSystem(table particleSystems)
Arguments
table particleSystems This is the table where the information of the particle system is stored
Utils.setEmittingState
DescriptionSets the emtting state of a particle system loaded with Utils.loadParticleSystem.
Definition
function Utils.setEmittingState(table particleSystems, boolean emitting)
Arguments
table particleSystems This is the table where the information of the particle system is stored boolean emitting If true, the particle systems are set to emitting, otherwhise they are stopped