LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

AnimatedMapObject

Description
Class for animated map objects
Parent
AnimatedObject
Functions

load

Description
Load animated object attributes from object
Definition
load(integer nodeId)
Arguments
integernodeIdid of object to load from
Return Values
booleansuccesssuccess
Code
54function AnimatedMapObject:load(nodeId)
55 local xmlFilename = getUserAttribute(nodeId, "xmlFilename")
56 if xmlFilename == nil then
57 Logging.error("Missing 'xmlFilename' user attribute for AnimatedMapObject node '%s'!", getName(nodeId))
58 return false
59 end
60
61 local baseDir = g_currentMission.loadingMapBaseDirectory
62 if baseDir == "" then
63 baseDir = Utils.getNoNil(self.baseDirectory, baseDir)
64 end
65 xmlFilename = Utils.getFilename(xmlFilename, baseDir)
66
67 local index = getUserAttribute(nodeId, "index")
68 if index == nil then
69 Logging.error("Missing 'index' user attribute for AnimatedMapObject node '%s'!", getName(nodeId))
70 return false
71 end
72
73 local xmlFile = XMLFile.load("AnimatedObject", xmlFilename, AnimatedMapObject.xmlSchema)
74 if xmlFile == nil then
75 return false
76 end
77
78 -- Find the index in the XML
79 local key
80 xmlFile:iterate("animatedObjects.animatedObject", function(_, objectKey)
81 local configIndex = xmlFile:getString(objectKey.."#index")
82 if configIndex == index then
83 key = objectKey
84 return true
85 end
86 end)
87
88 if key == nil then
89 Logging.error("index '%s' not found in AnimatedObject xml '%s'!", index, xmlFilename)
90 return false
91 end
92
93 local result = AnimatedMapObject:superClass().load(self, nodeId, xmlFile, key, xmlFilename)
94
95 xmlFile:delete()
96
97 return result
98end

new

Description
Creating new instance of animated object class
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableselfnew instance of object
Code
40function AnimatedMapObject.new(isServer, isClient, customMt)
41 return AnimatedObject.new(isServer, isClient, customMt or AnimatedMapObject_mt)
42end

onCreate

Description
Creating animated object
Definition
onCreate(integer id)
Arguments
integeridnode id
Code
24function AnimatedMapObject:onCreate(id)
25 local object = AnimatedMapObject.new(g_server ~= nil, g_client ~= nil)
26 if object:load(id) then
27 g_currentMission.onCreateObjectSystem:add(object, true)
28 object:register(true)
29 else
30 object:delete()
31 end
32end