-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclient.lua
128 lines (113 loc) · 4.78 KB
/
client.lua
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
local txd = CreateRuntimeTxd("scaleformui")
local banner = CreateDui("", 270, 151)
CreateRuntimeTextureFromDuiHandle(txd, "menuBanner", GetDuiHandle(banner))
local handlingMenu = UIMenu.New("Handling Editor", "Handling Editor Menu", 25, 25, true, "scaleformui", "menuBanner", 1.0)
handlingMenu:MouseControlsEnabled(false)
handlingMenu:MaxItemsOnScreen(10)
local handlingData = {}
local function toNumber(value)
return math.floor(tonumber(value) * 1000 + 0.5) / 1000
end
local function constructMenu(handlingData)
handlingMenu.Items = {}
for _, v in ipairs(handlingData) do
if tonumber(v.value) then
v.value = toNumber(v.value)
elseif type(v.value) == "vector3" then
local x, y, z = table.unpack(v.value)
v.value = string.format("%s, %s, %s", toNumber(x), toNumber(y), toNumber(z))
end
local description = "Type: ~b~" .. v.type
for _, param in pairs(handlingVariables) do
if param.name == v.name then
description = description .. "\n~w~Description: ~b~" .. param.desc
break
end
end
local button = UIMenuItem.New(v.name, description)
button:RightLabel(v.value)
handlingMenu:AddItem(button)
end
end
local function split(input, sep)
local table = {}
local index = 1
sep = sep or "%s"
for str in string.gmatch(input, "([^"..sep.."]+)") do
table[index] = str
index = index + 1
end
return table
end
local function SetVehicleHandlingData(vehicle, data, value)
if DoesEntityExist(vehicle) then
for _, v in pairs(handlingVariables) do
if v.name == data then
local int = string.find(data, "n")
local float = string.find(data, "f")
local vector3 = string.find(data, "vec")
if int and int == 1 then
SetVehicleHandlingInt(vehicle, "CHandlingData", data, tonumber(value))
elseif float and float == 1 then
SetVehicleHandlingFloat(vehicle, "CHandlingData", data, tonumber(value)+.0)
elseif vector3 and vector3 == 1 then
SetVehicleHandlingVector(vehicle, "CHandlingData", data, value)
else
SetVehicleHandlingField(vehicle, "CHandlingData", data, value)
end
end
end
end
end
local function GetVehicleHandlingData(vehicle)
local data = {}
if DoesEntityExist(vehicle) then
for _, v in pairs(handlingVariables) do
local int = string.find(v.name, "^n")
local float = string.find(v.name, "^f")
local vector3 = string.find(v.name, "^vec")
if int and int == 1 and GetVehicleHandlingInt(vehicle, "CHandlingData", v.name) then
table.insert(data, {name = v.name, value = GetVehicleHandlingInt(vehicle, "CHandlingData", v.name), type = "int"})
elseif float and float == 1 and GetVehicleHandlingFloat(vehicle, "CHandlingData", v.name) then
table.insert(data, {name = v.name, value = GetVehicleHandlingFloat(vehicle, "CHandlingData", v.name), type = "float"})
elseif vector3 and vector3 == 1 and GetVehicleHandlingVector(vehicle, "CHandlingData", v.name) then
table.insert(data, {name = v.name, value = GetVehicleHandlingVector(vehicle, "CHandlingData", v.name), type = "vector3"})
end
end
return data
end
end
handlingMenu.OnItemSelect = function(_, item, index)
local selected = handlingData[index]
if not selected then return end
AddTextEntry("FMMC_KEY_TIP8", "Enter new ~b~"..selected.name.."~w~ value:")
DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP8", "", selected.value, "", "", "", 128)
while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do
Wait(0)
end
local result = GetOnscreenKeyboardResult()
if result then
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if selected.type == "vector3" then
local x, y, z = table.unpack(split(result, ", "))
if x and y and z then
SetVehicleHandlingData(vehicle, selected.name, vector3(tonumber(x), tonumber(y), tonumber(z)))
end
else
SetVehicleHandlingData(vehicle, selected.name, result)
end
selected.value = result
item:RightLabel(result)
end
end
RegisterCommand("handling", function()
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle then
handlingData = GetVehicleHandlingData(vehicle)
constructMenu(handlingData)
handlingMenu:Visible(not handlingMenu:Visible())
else
handlingMenu:Visible(false)
end
end)
RegisterKeyMapping("handling", "Handling Editor Menu", "keyboard", "")