Sprache Deutsch Language English

Script Dokumentation LS 2015 - HandTool (Patch 1.3)

Script Dokumentation Übersicht

scripts/handTools/HandTool.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
2
3HandTool = {}
4HandTool_mt = Class(HandTool, Object);
5
6InitStaticObjectClass(HandTool, "HandTool", ObjectIds.OBJECT_HANDTOOL);
7
8HandTool.handToolTypes = {};
9
10function registerHandTool(typeName, classObject)
11 if not getIsValidClassName(typeName) then
12 print("Error: invalid handtool typeName: "..typeName);
13 return
14 end
15 HandTool.handToolTypes[typeName] = classObject;
16end;
17
18function HandTool:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = HandTool_mt;
22 end;
23
24 local self = Object:new(isServer, isClient, mt);
25 self.static = true;
26 self.owner = nil;
27 return self;
28end;
29
30function HandTool:load(xmlFilename, player)
31 self.xmlFilename = xmlFilename;
32
33 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename);
34
35 local xmlFile = loadXMLFile("TempXML", xmlFilename);
36 if xmlFile == 0 then
37 return false;
38 end;
39 local i3dFilename = getXMLString(xmlFile, "handTool.filename");
40 self.position = Utils.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.position#value"), "0 0 0"), 3);
41 self.rotation = Utils.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.rotation#value"), "0 0 0"), 3);
42
43 if i3dFilename == nil then
44 delete(xmlFile);
45 return false;
46 end;
47 self.i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory);
48
49 local node = Utils.loadSharedI3DFile(self.i3dFilename);
50 self.rootNode = getChildAt(node, 0);
51 self.player = player;
52
53 self.targets = {};
54 HandTool.loadTargets(xmlFile, "handTool", self.rootNode, self.targets);
55
56 link(player.toolsRootNode, self.rootNode);
57 setTranslation(self.rootNode, self.position[1], self.position[2], self.position[3]);
58 setRotation(self.rootNode, self.rotation[1], self.rotation[2], self.rotation[3]);
59
60 delete(node);
61 delete(xmlFile);
62 setVisibility(self.rootNode, false);
63
64 if player == g_currentMission.player then
65 g_currentMission:addHandTool(self);
66 end;
67
68 return true;
69end;
70
71function HandTool:setHandNode(handNode)
72end;
73
74function HandTool:readStream(streamId, connection, player)
75 local filename = Utils.convertFromNetworkFilename(streamReadString(streamId));
76 player:loadHandTool(filename);
77end;
78
79function HandTool:writeStream(streamId, connection)
80 streamWriteString(streamId, Utils.convertToNetworkFilename(self.xmlFilename));
81end;
82
83function HandTool:delete()
84 if self.player == g_currentMission.player then
85 g_currentMission:removeHandTool(self);
86 end;
87 if self.rootNode ~= nil and self.rootNode ~= 0 then
88 Utils.releaseSharedI3DFile(self.i3dFilename, nil, true);
89 delete(self.rootNode);
90 end;
91end;
92
93function HandTool:update(dt, allowInput)
94end;
95
96function HandTool:updateTick(dt, allowInput)
97end;
98
99function HandTool:draw(dt)
100end;
101
102function HandTool:onActivate(allowInput)
103 setVisibility(self.rootNode, true);
104end;
105
106function HandTool:onDeactivate(allowInput)
107 setVisibility(self.rootNode, false);
108end;
109
110function HandTool:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
111 return true;
112end;
113
114function HandTool:getSaveAttributesAndNodes(nodeIdent)
115 local attributes = "";
116 local nodes = "";
117 return attributes, nodes;
118end;
119
120function HandTool.loadTargets(xmlFile, baseName, rootNode, targets)
121 local i = 0;
122 while true do
123 local key = string.format(baseName.. ".targets.target(%d)", i);
124 if not hasXMLProperty(xmlFile, key) then
125 break;
126 end;
127 local ikName = getXMLString(xmlFile, key .. "#ikChainName");
128 local target = Utils.indexToObject(rootNode, getXMLString(xmlFile, key.."#target"));
129 local x,y,z = Utils.getVectorFromString(Utils.getNoNil(getXMLString(xmlFile, key .. "#targetOffset"), "0 0 0"));
130
131 local rotationNodes = {};
132 local j = 0;
133 while true do
134 local nodeKey = key..string.format(".rotationNode(%d)", j);
135 if not hasXMLProperty(xmlFile, nodeKey) then
136 break;
137 end;
138 local id = getXMLInt(xmlFile, nodeKey .. "#id");
139 if id ~= nil then
140 local rotation = Utils.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, nodeKey .. "#rotation"), "0 0 0"), 3);
141 table.insert(rotationNodes, {id=id, rotation=rotation});
142 end;
143 j = j + 1;
144 end;
145
146
147 targets[ikName] = {targetNode=target, targetOffset={x,y,z}, rotationNodes=rotationNodes};
148 i = i + 1;
149 end;
150end;
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht