Skip to content

Commit 97121bc

Browse files
author
Mingming Cui
authored
Code cleanup
1 parent 9d6b67c commit 97121bc

File tree

1 file changed

+47
-134
lines changed

1 file changed

+47
-134
lines changed

open_sesame/init.lua

Lines changed: 47 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
registerForEvent("onInit", function()
22
HotKey = 0x45 -- Change Hotkey Here. You can find Key Codes at https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
3-
drawFakeDoor = false
4-
drawDoor = false
5-
drawVehicle = false
6-
drawNPC = false
3+
drawPopup = false
74
getTime = 0
85
print("******************************************************")
96
print("* Open Semame Mod Loaded... Press E to open any door *")
@@ -12,20 +9,29 @@ end)
129

1310
registerForEvent("onUpdate", function()
1411
if (not ImGui.IsKeyDown(0x10) and ImGui.IsKeyPressed(HotKey, false)) then
15-
drawFakeDoor = false
16-
drawDoor = false
17-
drawVehicle = false
18-
drawNPC = false
12+
drawPopup = false
1913
player = Game.GetPlayer()
2014
objLook = Game.GetTargetingSystem():GetLookAtObject(player,false,false)
2115
objType = objLook:ToString()
16+
17+
-- Real door --
2218
if (objType == "Door") then
23-
objLook:OpenDoor() -- Real Door
19+
objName = objType
20+
detailInfo = "Open Sesame..."
21+
breachInfo = "The door has been opened."
22+
objLook:OpenDoor()
2423
getTime = os:clock()
25-
drawDoor = true
24+
drawPopup = true
25+
26+
-- Fake door --
2627
elseif (objType == "FakeDoor") then
28+
objName = objType
29+
detailInfo = "This is a fake door..."
30+
breachInfo = "Failed to breach the door."
2731
getTime = os:clock()
28-
drawFakeDoor = true -- Fake Door
32+
drawPopup = true
33+
34+
-- Vehicle door --
2935
elseif (objLook:IsVehicle()) then
3036
vehDestoryed = objLook:IsDestroyed()
3137
if (not vehDestoryed) then
@@ -34,7 +40,9 @@ registerForEvent("onUpdate", function()
3440
vehComp = objLook:GetVehicleComponent()
3541
vehOcc = not is_empty(vehPS:GetNpcOccupiedSlots())
3642
vehMass = objLook:GetTotalMass()
37-
vehBreachInfo = "Vehicle doors has been unlocked."
43+
objName = vehName
44+
detailInfo = vehName.." weighs "..vehMass.."KG"
45+
breachInfo = "Vehicle doors has been unlocked."
3846
if (vehOcc) then -- Vehicle is occupied by npc
3947
vehComp:DestroyVehicle() -- Eject NPCs
4048
vehComp:RepairVehicle()
@@ -43,35 +51,41 @@ registerForEvent("onUpdate", function()
4351
vehPS:UnlockAllVehDoors() -- Open Vehicle Doors
4452
vehComp:HonkAndFlash()
4553
getTime = os:clock()
46-
drawVehicle = true
54+
drawPopup = true
4755
end
4856
end
4957
elseif (ImGui.IsKeyDown(0x10) and ImGui.IsKeyPressed(HotKey, false)) then
50-
drawFakeDoor = false
51-
drawDoor = false
52-
drawVehicle = false
53-
drawNPC = false
58+
drawPopup = false
5459
player = Game.GetPlayer()
5560
objLook = Game.GetTargetingSystem():GetLookAtObject(player,false,false)
5661
objType = objLook:ToString()
62+
63+
-- Kill NPC --
5764
if (objType == "NPCPuppet") then
5865
if (not objLook:IsDead()) then
5966
npcName = objLook:GetDisplayName()
67+
objName = npcName
68+
detailInfo = npcName.." is a NPC."
69+
breachInfo = npcName.." has been killed."
6070
objLook:Kill(player, false, false) -- Kill NPC by player
6171
getTime = os:clock()
62-
drawNPC = true
72+
drawPopup = true
6373
end
74+
75+
-- Explode Vehicle --
6476
elseif (objLook:IsVehicle()) then
6577
vehName = objLook:GetDisplayName()
6678
vehComp = objLook:GetVehicleComponent()
6779
vehMass = objLook:GetTotalMass()
6880
vehDestoryed = objLook:IsDestroyed()
6981
vehComp:ExplodeVehicle(player)
7082
vehComp:DestroyVehicle()
71-
vehBreachInfo = "Vehicle has been blown up."
83+
objName = vehName
84+
detailInfo = vehName.." weighs "..vehMass.."KG"
85+
breachInfo = "Vehicle has been blown up."
7286
if (not vehDestoryed) then
7387
getTime = os:clock()
74-
drawVehicle = true
88+
drawPopup = true
7589
end
7690
end
7791
-- Dump object
@@ -82,142 +96,41 @@ registerForEvent("onUpdate", function()
8296
end)
8397

8498
registerForEvent("onDraw", function()
85-
ImGui.PushStyleColor(ImGuiCol.PopupBg, 0.21, 0.08, 0.08, 1)
99+
ImGui.PushStyleColor(ImGuiCol.PopupBg, 0.21, 0.08, 0.08, 0.85)
86100
ImGui.PushStyleColor(ImGuiCol.Border, 0.4, 0.17, 0.12, 1)
87-
if (drawFakeDoor) then
101+
ImGui.PushStyleColor(ImGuiCol.Separator, 0.4, 0.17, 0.12, 1)
102+
if (drawPopup) then
88103
ImGui.BeginTooltip()
89104
ImGui.SetWindowFontScale(1.6)
90-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
91-
ImGui.Text("DATA")
92105
ImGui.Spacing()
93-
ImGui.PopStyleColor(1)
94-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
95-
ImGui.Text("SCAN RESULTS")
96-
ImGui.PopStyleColor(1)
97-
ImGui.PushStyleColor(ImGuiCol.Text, 0.98, 0.85, 0.25, 1)
98-
ImGui.Text(objType)
99-
ImGui.PopStyleColor(1)
106+
ImGui.TextColored(0.2, 1, 1, 1, "DATA")
100107
ImGui.Spacing()
101-
ImGui.Separator()
102108
ImGui.Spacing()
103-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
104-
ImGui.Text("DETAILS")
105-
ImGui.PopStyleColor(1)
106-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
107-
ImGui.Text("This is a fake door...")
108-
ImGui.PopStyleColor(1)
109-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
110109
ImGui.Spacing()
111-
ImGui.Text("BREACH RESULT")
112-
ImGui.PopStyleColor(1)
113-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
114-
ImGui.Text("Breaching Failed")
115-
ImGui.PopStyleColor(1)
116-
ImGui.EndTooltip()
117-
if (os:clock() > getTime + 2) then
118-
drawFakeDoor = false
119-
end
120-
elseif (drawDoor) then
121-
ImGui.BeginTooltip()
122-
ImGui.SetWindowFontScale(1.6)
123-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
124-
ImGui.Text("DATA")
110+
ImGui.TextColored(1, 0.36, 0.35, 1, "SCAN RESULTS")
125111
ImGui.Spacing()
126-
ImGui.PopStyleColor(1)
127-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
128-
ImGui.Text("SCAN RESULTS")
129-
ImGui.PopStyleColor(1)
130-
ImGui.PushStyleColor(ImGuiCol.Text, 0.98, 0.85, 0.25, 1)
131-
ImGui.Text(objType)
132-
ImGui.PopStyleColor(1)
112+
ImGui.TextColored(0.98, 0.85, 0.25, 1, objName)
133113
ImGui.Spacing()
134-
ImGui.Separator()
135-
ImGui.Spacing()
136-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
137-
ImGui.Text("DETAILS")
138-
ImGui.PopStyleColor(1)
139-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
140-
ImGui.Text("Open Sesame...")
141-
ImGui.PopStyleColor(1)
142-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
143114
ImGui.Spacing()
144-
ImGui.Text("BREACH RESULT")
145-
ImGui.PopStyleColor(1)
146-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
147-
ImGui.Text("The door has been opened.")
148-
ImGui.PopStyleColor(1)
149-
ImGui.EndTooltip()
150-
if (os:clock() > getTime + 2) then
151-
drawDoor = false
152-
end
153-
elseif (drawVehicle) then
154-
ImGui.BeginTooltip()
155-
ImGui.SetWindowFontScale(1.6)
156-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
157-
ImGui.Text("DATA")
115+
ImGui.Separator()
158116
ImGui.Spacing()
159-
ImGui.PopStyleColor(1)
160-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
161-
ImGui.Text("SCAN RESULTS")
162-
ImGui.PopStyleColor(1)
163-
ImGui.PushStyleColor(ImGuiCol.Text, 0.98, 0.85, 0.25, 1)
164-
ImGui.Text(vehName)
165-
ImGui.PopStyleColor(1)
166117
ImGui.Spacing()
167-
ImGui.Separator()
118+
ImGui.TextColored(1, 0.36, 0.35, 1, "DETAILS")
168119
ImGui.Spacing()
169-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
170-
ImGui.Text("DETAILS")
171-
ImGui.PopStyleColor(1)
172-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
173-
ImGui.Text(vehName.." weighs "..vehMass.."Kg.")
174-
ImGui.PopStyleColor(1)
175-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
120+
ImGui.TextColored(0.2, 1, 1, 1, detailInfo)
176121
ImGui.Spacing()
177-
ImGui.Text("BREACH RESULT")
178-
ImGui.PopStyleColor(1)
179-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
180-
ImGui.Text(vehBreachInfo)
181-
ImGui.PopStyleColor(1)
182-
ImGui.EndTooltip()
183-
if (os:clock() > getTime + 2) then
184-
drawVehicle = false
185-
end
186-
elseif (drawNPC) then
187-
ImGui.BeginTooltip()
188-
ImGui.SetWindowFontScale(1.6)
189-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
190-
ImGui.Text("DATA")
191122
ImGui.Spacing()
192-
ImGui.PopStyleColor(1)
193-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
194-
ImGui.Text("SCAN RESULTS")
195-
ImGui.PopStyleColor(1)
196-
ImGui.PushStyleColor(ImGuiCol.Text, 0.98, 0.85, 0.25, 1)
197-
ImGui.Text(npcName)
198-
ImGui.PopStyleColor(1)
199123
ImGui.Spacing()
200-
ImGui.Separator()
124+
ImGui.TextColored(1, 0.36, 0.35, 1, "BREACH RESULT")
201125
ImGui.Spacing()
202-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
203-
ImGui.Text("DETAILS")
204-
ImGui.PopStyleColor(1)
205-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
206-
ImGui.Text(npcName.." is a NPC.")
207-
ImGui.PopStyleColor(1)
208-
ImGui.PushStyleColor(ImGuiCol.Text, 1, 0.36, 0.35, 1)
126+
ImGui.TextColored(0.2, 1, 1, 1, breachInfo)
209127
ImGui.Spacing()
210-
ImGui.Text("BREACH RESULT")
211-
ImGui.PopStyleColor(1)
212-
ImGui.PushStyleColor(ImGuiCol.Text, 0.2, 1, 1, 1)
213-
ImGui.Text(npcName.." has been killed.")
214-
ImGui.PopStyleColor(1)
215128
ImGui.EndTooltip()
216129
if (os:clock() > getTime + 2) then
217-
drawNPC = false
130+
drawPopup = false
218131
end
219132
end
220-
ImGui.PopStyleColor(2)
133+
ImGui.PopStyleColor(3)
221134
end)
222135

223136
function is_empty(t)

0 commit comments

Comments
 (0)