This repository has been archived by the owner on Mar 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
resource_handlingloader
executable file
·107 lines (88 loc) · 3.47 KB
/
resource_handlingloader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--[[
This script has been created by the "Save to Resource" function of the Handling Editor.
]]
addEventHandler ( "onResourceStart", resourceRoot, function ( )
local handlingXML = xmlLoadFile ( "handling.xml" )
for _,node in ipairs ( xmlNodeGetChildren ( handlingXML ) ) do
local model = tonumber ( xmlNodeGetName ( node ) )
for property,value in pairs ( xmlNodeGetAttributes ( node ) ) do
setHandling ( model, property, value )
end
end
return true
end )
local handlingProperties = {
"identifier", "mass", "turnMass", "dragCoeff", "centerOfMassX", "centerOfMassY",
"centerOfMassZ", "percentSubmerged", "tractionMultiplier", "tractionLoss", "tractionBias", "numberOfGears",
"maxVelocity", "engineAcceleration", "engineInertia", "driveType", "engineType", "brakeDeceleration",
"brakeBias", "ABS", "steeringLock", "suspensionForceLevel", "suspensionDamping", "suspensionHighSpeedDamping",
"suspensionUpperLimit", "suspensionLowerLimit", "suspensionFrontRearBias", "suspensionAntiDiveMultiplier", "seatOffsetDistance", "collisionDamageMultiplier",
"monetary", "modelFlags", "handlingFlags", "headLight", "tailLight", "animGroup"
}
local function setHandling ( model, property, value )
if not isHandlingPropertySupported ( property ) then
return false
end
if isHandlingPropertyCorrectable ( property ) then
value = getCorrectedHandlingValue ( value )
elseif isHandlingPropertyHexadecimal ( property ) then
value = tonumber ( "0x" .. value )
else
value = tonumber ( value )
if isHandlingPropertyCenterOfMass ( property ) then
local com = getModelHandling ( model )["centerOfMass"]
local axis = property
property = "centerOfMass"
if axis == "centerOfMassX" then
value = { value, com[2], com[3] }
elseif axis == "centerOfMassY" then
value = { com[1], value, com[3] }
elseif axis == "centerOfMassZ" then
value = { com[1], com[2], value }
end
end
end
if not setModelHandling ( model, property, value ) then
outputDebugString ( tostring(property) )
end
return true
end
local function isHandlingPropertySupported ( property )
local unsupported = {
["ABS"]=true, ["monetary"]=true,
["headLight"]=true, ["tailLight"]=true,
["animGroup"]=true
}
if unsupported[property] then
return false
end
return true
end
local function isHandlingPropertyCorrectable ( property )
local props ={
["driveType"]=true, ["engineType"]=true,
["headLight"]=true, ["tailLight"]=true
}
return props[property] or false
end
local function isHandlingPropertyCenterOfMass ( property )
local props = {
["centerOfMassX"]=true, ["centerOfMassY"]=true,
["centerOfMassZ"]=true
}
return props[property] or false
end
local function isHandlingPropertyHexadecimal ( property )
if property == "modelFlags" or property == "handlingFlags" then
return true
end
return false
end
local correctedValues = {
["f"] = "fwd", ["r"] = "rwd", ["4"] = "awd",
["p"] = "petrol", ["d"] = "diesel", ["e"] = "electric",
["0"] = "long", ["1"] = "small", ["3"] = "big",
}
local function getCorrectedHandlingValue ( value )
return correctedValues[string.lower(value)] or "big" -- as 3 cant be converted to 'tall', we use 'big'
end