Skip to content

Commit e4b73cb

Browse files
committed
sirenEdit: Fix errors
Fixed errors when opening the GUI and added message about cpicker needing to be installed and running.
1 parent 0ec4e9d commit e4b73cb

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

[gameplay]/sirenEdit/script.lua

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,21 @@ function InitUI ( )
112112
if ( not veh ) then
113113
return
114114
end
115-
local selectedItem = guiComboBoxGetSelected ( sirens ) + 1
116115
local sirensTable = getVehicleSirens(veh)
116+
local selectedItem = guiComboBoxGetSelected ( sirens ) + 1
117+
-- If sirensTable[selectedItem] doesn't exist lets lets some defaults
118+
if ( not sirensTable[selectedItem] ) then
119+
sirensTable[selectedItem] = {}
120+
sirensTable[selectedItem].x = 0
121+
sirensTable[selectedItem].y = 0
122+
sirensTable[selectedItem].z = 0
123+
sirensTable[selectedItem].Red = 255
124+
sirensTable[selectedItem].Green = 0
125+
sirensTable[selectedItem].Blue = 0
126+
sirensTable[selectedItem].Alpha = 255
127+
sirensTable[selectedItem].Min_Alpha = 100
128+
setVehicleSirens(veh, selectedItem, 0, 0, 0, 255, 0, 0, 255, 100)
129+
end
117130
guiScrollBarSetScrollPosition ( sirensX, 50 + ( sirensTable[selectedItem].x * 10 ) )
118131
guiScrollBarSetScrollPosition ( sirensY, 50 + ( sirensTable[selectedItem].y * 10 ) )
119132
guiScrollBarSetScrollPosition ( sirensZ, 50 + ( sirensTable[selectedItem].z * 10 ) )
@@ -142,40 +155,30 @@ function scrollFunc(scrolled)
142155
local veh = getPedOccupiedVehicle ( localPlayer )
143156
local selectedItem = guiComboBoxGetSelected ( sirens ) + 1
144157
if ( selectedItem ~= nil and selectedItem ~= false and selectedItem > 0 and veh ~= false ) then
158+
local sirensTable = getVehicleSirens(veh)
159+
if ( not sirensTable[selectedItem] ) then
160+
return
161+
end
145162
if ( scrolled == sirensX ) then
146-
local sirensTable = getVehicleSirens(veh)
147163
sirensTable[selectedItem].x = ( guiScrollBarGetScrollPosition ( scrolled ) / 10 ) - 5
148164
guiSetText( posLabelX, "Position X: " .. string.format( "%.3f", sirensTable[selectedItem].x ) )
149165
applySirenTable ( veh, sirensTable, false )
150-
return
151-
end
152-
if ( scrolled == sirensY ) then
153-
local sirensTable = getVehicleSirens(veh)
166+
elseif ( scrolled == sirensY ) then
154167
sirensTable[selectedItem].y = ( guiScrollBarGetScrollPosition ( scrolled ) / 10 ) - 5
155168
guiSetText( posLabelY, "Position Y: " .. string.format( "%.3f", sirensTable[selectedItem].y ) )
156169
applySirenTable ( veh, sirensTable, false )
157-
return
158-
end
159-
if ( scrolled == sirensZ ) then
160-
local sirensTable = getVehicleSirens(veh)
170+
elseif ( scrolled == sirensZ ) then
161171
sirensTable[selectedItem].z = ( guiScrollBarGetScrollPosition ( scrolled ) / 10 ) - 5
162172
guiSetText( posLabelZ, "Position Z: " .. string.format( "%.3f", sirensTable[selectedItem].z ) )
163173
applySirenTable ( veh, sirensTable, false )
164-
return
165-
end
166-
if ( scrolled == sirensAlpha ) then
167-
local sirensTable = getVehicleSirens(veh)
174+
elseif ( scrolled == sirensAlpha ) then
168175
sirensTable[selectedItem].Alpha = math.ceil ( (guiScrollBarGetScrollPosition ( scrolled ) * 2.55 ) - 0.05 )
169176
guiSetText( alphaLabel, "Alpha: " .. sirensTable[selectedItem].Alpha )
170177
applySirenTable ( veh, sirensTable, false )
171-
return
172-
end
173-
if ( scrolled == sirensMinAlpha ) then
174-
local sirensTable = getVehicleSirens(veh)
178+
elseif ( scrolled == sirensMinAlpha ) then
175179
sirensTable[selectedItem].Min_Alpha = math.ceil ( ( guiScrollBarGetScrollPosition ( scrolled ) * 2.55 ) - 0.05 )
176180
guiSetText( minAlphaLabel, "Minimum Alpha: " .. sirensTable[selectedItem].Min_Alpha )
177181
applySirenTable ( veh, sirensTable, false )
178-
return
179182
end
180183
end
181184
end
@@ -189,6 +192,14 @@ function btnFunc ( button, state )
189192
end
190193
if ( source == sirensBtnRGB ) then
191194
if ( state == "up" ) then
195+
if ( not getResourceFromName("cpicker") ) then
196+
outputChatBox("cpicker isn't installed, get it from: https://community.multitheftauto.com/index.php?p=resources&s=details&id=3247", 255, 0, 0)
197+
return
198+
end
199+
if ( getResourceState( getResourceFromName("cpicker") ) ~= "running" ) then
200+
outputChatBox("cpicker isn't running. If you're an admin, do: /start cpicker", 255, 0, 0)
201+
return
202+
end
192203
exports.cpicker:openPicker(source, "#FFAA00", "Pick a Beacon Colour")
193204
end
194205
end

0 commit comments

Comments
 (0)