Skip to content

Commit b94c796

Browse files
committed
- added script sources to repo
1 parent 4c04aa8 commit b94c796

File tree

9 files changed

+839
-0
lines changed

9 files changed

+839
-0
lines changed

data/scripts/_old/docs_dump.lua

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
2+
local luaDocs = {}
3+
4+
function LuaDocumentation_Initialise()
5+
print("$luadoc$:init")
6+
luaDocs = {}
7+
end
8+
function LuaDocumentation_Shutdown()
9+
print("$luadoc$:shutdown")
10+
addUserUpdateFunction("LuaDocs", function()
11+
local blacklist = {
12+
["_M"] = true,
13+
["_NAME"] = true,
14+
["_PACKAGE"] = true,
15+
}
16+
17+
print("**** sorting docs")
18+
local docs = {}
19+
for k,v in pairs(luaDocs) do
20+
if k ~= "_G" then
21+
table.insert(docs, k)
22+
end
23+
end
24+
table.sort(docs)
25+
26+
if luaDocs["_G"] ~= nil then
27+
table.insert(docs, 1, "_G")
28+
end
29+
30+
local docfile = io.open("temp:luadocs.txt", "w+")
31+
32+
print("**** writing docs")
33+
for i,libraryName in ipairs(docs) do
34+
local library = rawget(luaDocs, libraryName)
35+
local t = "table"
36+
if library._M and library._NAME and library._PACKAGE then
37+
t = "module"
38+
end
39+
docfile:write(string.format("[%s] : %s\n", libraryName, t))
40+
local sorted = {}
41+
for name,_ in pairs(library) do
42+
if not blacklist[name] then
43+
table.insert(sorted, name)
44+
end
45+
end
46+
table.sort(sorted)
47+
local typeMap = {
48+
"CFunction",
49+
"function",
50+
"property",
51+
"userdata",
52+
"table",
53+
"boolean",
54+
"number",
55+
"string",
56+
"nil",
57+
}
58+
local typeSorted = {}
59+
for _,t in ipairs(typeMap) do
60+
typeSorted[t] = {}
61+
end
62+
for _,name in ipairs(sorted) do
63+
local info = library[name]
64+
local m = ""
65+
local t = type(name)
66+
if t == "string" then
67+
if name:find(" ") ~= nil then
68+
m = string.format("[\"%s\"]", name)
69+
else
70+
m = name
71+
end
72+
else
73+
m = string.format("[%s]", tostring(name))
74+
end
75+
if string.len(info.docs) > 0 then
76+
m = m .." : ".. info.docs
77+
end
78+
table.insert(typeSorted[info.type], m)
79+
end
80+
for _,t in ipairs(typeMap) do
81+
local v = typeSorted[t]
82+
for _,m in ipairs(v) do
83+
local l = string.format("\t%s %s\n", t, m)
84+
docfile:write(l)
85+
end
86+
end
87+
end
88+
docfile:close()
89+
90+
removeUserUpdateFunction("LuaDocs")
91+
end, 0.01 * updates.stepRate, true)
92+
end
93+
function LuaDocumentation_AddLuaLibrary(libraryName)
94+
if luaDocs[libraryName] == nil then
95+
luaDocs[libraryName] = {}
96+
end
97+
end
98+
function LuaDocumentation_AddLuaDocumentation(libraryName, docType, docName, docText)
99+
if luaDocs[libraryName] == nil then
100+
luaDocs[libraryName] = {}
101+
end
102+
if luaDocs[libraryName][docName] == nil then
103+
luaDocs[libraryName][docName] = { type = docType, docs = docText or "" }
104+
end
105+
end
106+
function LuaDocumentation_AddLuaDataDocumentation(libraryName, value, name, docs)
107+
local printTypes = {
108+
["string"] = true,
109+
["number"] = true,
110+
["boolean"] = true,
111+
}
112+
local dataType = type(value)
113+
if printTypes[dataType] then
114+
local v = tostring(value)
115+
if dataType == "string" then
116+
v = '"'..v..'"'
117+
end
118+
if string.len(docs) > 0 then
119+
docs = v .." : ".. docs
120+
else
121+
docs = v
122+
end
123+
end
124+
LuaDocumentation_AddLuaDocumentation(libraryName, dataType, name, docs)
125+
end
126+
function LuaDocumentation_AddLuaFunctionDocumentation(libraryName, functionName, functionDocs)
127+
LuaDocumentation_AddLuaDocumentation(libraryName, "function", functionName, functionDocs)
128+
end
129+
function LuaDocumentation_AddLuaPropertyDocumentation(libraryName, propertyName, propertyDocs)
130+
LuaDocumentation_AddLuaDocumentation(libraryName, "property", propertyName, propertyDocs)
131+
end
132+
function LuaDocumentation_RemoveLuaLibrary(libraryName)
133+
if luaDocs[libraryName] then
134+
table.remove(luaDocs, libraryName)
135+
end
136+
end
137+
function LuaDocumentation_ParseTable(name, values)
138+
local function parseTable(name, key, value)
139+
if key ~= name then
140+
LuaDocumentation_AddLuaDataDocumentation(name, value, key, "")
141+
end
142+
end
143+
local function parseGlobals(name, key, value)
144+
if type(value) == "table" then
145+
if key ~= "_G" then
146+
LuaDocumentation_ParseTable(key, value)
147+
end
148+
else
149+
LuaDocumentation_AddLuaDataDocumentation("_G", value, key, "")
150+
end
151+
end
152+
153+
local parseIt = parseGlobals
154+
if string.len(name) > 0 then
155+
parseIt = parseTable
156+
end
157+
158+
for key, value in next, values do
159+
parseIt(name, key, value)
160+
end
161+
end

data/scripts/_old/user.lua

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
function spawnVehicleEx(modelID, vehicleParams, characters)
2+
local function spawn()
3+
vehicleParams = vehicleParams or {}
4+
5+
local params = {
6+
heading = 0,
7+
modelID = modelID or 0,
8+
snapToTerrain = vehicleParams.snapToTerrain or true,
9+
panelSet = mods.panelSetOverride or vehicleParams.panelSet or nil,
10+
shader = {
11+
[0] = vehicleParams.chosenShader or framework.random(0,8)
12+
},
13+
}
14+
local mt = {__index = vehicleParams, __newindex = function(t, k, v) rawset(vehicleParams, k, v) end}
15+
setmetatable(params, mt)
16+
if localPlayer.currentVehicle then
17+
params.position = localPlayer.position + -localPlayer.currentVehicle.matrix[0] * 5
18+
params.heading = localPlayer.heading
19+
else
20+
params.position = player.position + vec.vector(5, 0, 0, 1)
21+
end
22+
local vehicle = vehicleManager.spawnVehicle(params)
23+
vehicle.owner = "Script"
24+
if characters then
25+
for i = 1, #characters do
26+
GameVehicleResource.setCharacterSpoolingEntityIndex(vehicle.gameVehicle, i - 1, characters[i])
27+
end
28+
else
29+
-- clear passengers
30+
for i = 1, 3 do
31+
GameVehicleResource.setCharacterSpoolingEntityIndex(vehicle.gameVehicle, i, "-1")
32+
end
33+
end
34+
35+
local rigID = 285
36+
local bigRigID = 286
37+
local trailerID = 123
38+
39+
local trailerIDs = {
40+
123,
41+
131,
42+
289,
43+
}
44+
45+
if modelID == bigRigID or modelID == rigID then
46+
local selTrailerId = trailerIDs[framework.random(1, 3)]
47+
48+
-- make sure special trailers are spooled in
49+
if selTrailerId ~= trailerID then
50+
local trailerLoaded = TrafficSpooler.IsMissionVehicleLoaded(selTrailerId)
51+
local tries = 1
52+
53+
while not trailerLoaded do
54+
if tries > 3 then
55+
print("**** COULD NOT SPAWN TRAILER WITH ID ".. selTrailerId .." - USING DEFAULT! ****")
56+
selTrailerId = trailerID
57+
break
58+
end
59+
60+
TrafficSpooler.RequestMissionVehicle(selTrailerId)
61+
trailerLoaded = TrafficSpooler.IsMissionVehicleLoaded(selTrailerId)
62+
tries = tries + 1
63+
end
64+
end
65+
66+
GameVehicleResource.createTrailerAndHookup({
67+
gameVehicle = vehicle.gameVehicle,
68+
trailerId = selTrailerId,
69+
panelSet = framework.random(0,8)
70+
})
71+
end
72+
73+
return vehicle
74+
end
75+
local function waitForSpooling(modelID)
76+
TrafficSpooler.SetAsPlayerVehicle(modelID)
77+
return function()
78+
if TrafficSpooler.IsPlayerVehicleLoaded() then
79+
removeUserUpdateFunction("spawnVehicleEx")
80+
spawn()
81+
end
82+
end
83+
end
84+
if TrafficSpooler.IsMissionVehicleLoaded(modelID) then
85+
return spawn()
86+
elseif not spooling.requestToSpoolVehicle(modelID, spawn) then
87+
addUserUpdateFunction("spawnVehicleEx", waitForSpooling(modelID), 1)
88+
end
89+
end
90+
91+
local function safeRun()
92+
if localPlayer.currentVehicle then
93+
local status = controlHandler:getStatus("Zap_ActiveVehicle_Two")
94+
if status == "JustPressed" then
95+
local vehicle = localPlayer.currentVehicle
96+
97+
local newVehicle = spawnVehicleEx(vehicle.model_id)
98+
99+
OneShotSound.PlayMenuSound("HUD_Garage_Vehicle_Repair")
100+
101+
localPlayer:setPreviousVehicle()
102+
localPlayer:zapToAgent(newVehicle, {playerInstigated = true, disableZapFlash = true})
103+
end
104+
local status = controlHandler:getStatus("Zap_ActiveVehicle_One")
105+
if status == "JustPressed" then
106+
spawnVehicleEx(269)
107+
end
108+
end
109+
end
110+
111+
local function waitForSimulation()
112+
-- wait for the pause menu to go away
113+
if simulation.getSpeed() ~= 0 then
114+
removeUserUpdateFunction("safeRunWait")
115+
addUserUpdateFunction("safeRunDelay", safeRun, 1)
116+
end
117+
end
118+
119+
addUserUpdateFunction("safeRunWait", waitForSimulation, 0.1 * updates.stepRate)

data/scripts/autoexec.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--------------------------------------------
2+
-- DriverNG Hook layer
3+
--------------------------------------------
4+
5+
setAllowDeveloperConsole(true)
6+
allowCustomGameScripts(false)
7+
8+
Development = {
9+
enableDevText = false,
10+
list2DText = {}
11+
}
12+
13+
function Development:useDevText(use)
14+
self.enableDevText = use
15+
end
16+
17+
function Development:add2DText(id, text)
18+
table.insert(self.list2DText, {id = id, text = text})
19+
end
20+
21+
function Development:clearScreen(what)
22+
self.list2DText = {}
23+
end
24+
25+
--[[
26+
registerForEvent("onInit", function()
27+
print("Initialized")
28+
end)
29+
30+
registerForEvent("onUpdate", function()
31+
if Development.enableDevText == false then
32+
return
33+
end
34+
35+
-- draw development view from the game
36+
if ImGui.Begin("Development view") then
37+
ImGui.SetWindowFontScale(1)
38+
39+
for i,val in ipairs(Development.list2DText) do
40+
ImGui.Text(v)
41+
end
42+
43+
end
44+
ImGui.End()
45+
46+
end)]]

data/scripts/driverNGConsole.lua

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
dofile(DNGHookScriptPath.. "driverNGUtil.lua")
2+
dofile(DNGHookScriptPath.. "driverNGDocsUtil.lua")
3+
4+
driverNGHook = {
5+
gamePaused = false,
6+
gameLaunched = false
7+
}
8+
9+
-- this is called from the hook via CallLuaFunction
10+
function driverNGHook_EvalHelper(luaExprStr)
11+
12+
print("> " .. luaExprStr)
13+
14+
if luaExprStr:sub(1, 1) == "=" then
15+
luaExprStr = "util.printObject(" .. luaExprStr:sub(2) .. ")"
16+
end
17+
18+
local f, err = loadstring(luaExprStr)
19+
if not f then
20+
print("ERROR: `" .. err .. "`")
21+
else
22+
local ran, errorMsg = pcall( f )
23+
24+
if not ran then
25+
print("ERROR: " .. errorMsg)
26+
print(debug.traceback())
27+
end
28+
end
29+
end
30+
31+
-- called from hook
32+
function driverNGHook_SwitchPause(enable)
33+
34+
if driverNGHook.gameLaunched == false then
35+
return
36+
end
37+
38+
if driverNGHook.gamePaused == enable then
39+
return
40+
end
41+
42+
driverNGHook.gamePaused = enable
43+
44+
-- game is not going to be paused in Online
45+
if Network.getConnection() == "Offline" then
46+
if enable then
47+
simulation.pause()
48+
else
49+
simulation.start()
50+
end
51+
end
52+
end
53+
54+
-- called from hook
55+
function driverNGHook_QuitGame()
56+
framework.quit()
57+
end

0 commit comments

Comments
 (0)