Jump to content

Double clicking windows crashes game


Recommended Posts

Hi. I have a problem with the resources that I make that include GUIs. The GUIs themselves work as intended, however, if I doubleclick something that doesn't trigger anything (most prominent being empty space in a window), my game will crash. I noticed this happens on almost all GUI related things I made, except for a few. I haven't changed the way I make GUIs and there are no errors in my code (well, none that debugscript 3 puts at least). I am running MTA 1.0 nightly r1457 if that helps any. Any help in this matter is appreciated.

Link to comment

There are no onClientGUIDoubleClicks in anything that I make. nothing really calls for a use of double clicking. Heres the code you requested.

addEvent("onClientPayNSprayEnter",true)
 
function payNSprayGUI(vehicle)
c1,c2,c3,c4 = getVehicleColor(vehicle)
paynsprayWindow = guiCreateWindow(0.25208333,0.30222,0.507638889,0.375556,"Pay 'n' Spray",true)
guiWindowSetSizable(paynsprayWindow,false)
colorChart = guiCreateStaticImage(0.0123,0.0651,0.9754,0.7426,"images/chart.png",true,paynsprayWindow)
colorOneSelect = guiCreateEdit(0.015,0.8817,0.0602,0.0917,tostring(c1),true,paynsprayWindow)
guiEditSetMaxLength(colorOneSelect,3)
colorTwoSelect = guiCreateEdit(0.0821,0.8817,0.0602,0.0917,tostring(c2),true,paynsprayWindow)
guiEditSetMaxLength(colorTwoSelect,3)
colorThreeSelect = guiCreateEdit(0.1491,0.8817,0.0629,0.0917,tostring(c3),true,paynsprayWindow)
guiEditSetMaxLength(colorThreeSelect,3)
colorFourSelect = guiCreateEdit(0.2189,0.8817,0.0643,0.0917,tostring(c4),true,paynsprayWindow)
guiEditSetMaxLength(colorFourSelect,3)
colorOneLabel = guiCreateLabel(0.0205,0.8195,0.052,0.0503,"Color 1",true,paynsprayWindow)
guiLabelSetColor(colorOneLabel,255,255,255)
guiLabelSetVerticalAlign(colorOneLabel,"top")
guiLabelSetHorizontalAlign(colorOneLabel,"left",false)
colorTwoLabel = guiCreateLabel(0.0848,0.8195,0.0616,0.0444,"Color 2",true,paynsprayWindow)
guiLabelSetColor(colorTwoLabel,255,255,255)
guiLabelSetVerticalAlign(colorTwoLabel,"top")
guiLabelSetHorizontalAlign(colorTwoLabel,"left",false)
colorThreeLabel = guiCreateLabel(0.1546,0.8225,0.0575,0.0533,"Color 3",true,paynsprayWindow)
guiLabelSetColor(colorThreeLabel,255,255,255)
guiLabelSetVerticalAlign(colorThreeLabel,"top")
guiLabelSetHorizontalAlign(colorThreeLabel,"left",false)
colorFourLabel = guiCreateLabel(0.2244,0.8225,0.0534,0.0414,"Color 4",true,paynsprayWindow)
guiLabelSetColor(colorFourLabel,255,255,255)
guiLabelSetVerticalAlign(colorFourLabel,"top")
guiLabelSetHorizontalAlign(colorFourLabel,"left",false)
paintButton = guiCreateButton(0.3105,0.8373,0.1382,0.1331,"Paint Vehicle: $1500",true,paynsprayWindow)
randomButton = guiCreateButton(0.4624,0.8373,0.1395,0.1361,"Random Colors: $500",true,paynsprayWindow)
repairButton = guiCreateButton(0.617,0.8373,0.1409,0.1361,"Repair Vehicle: $5000",true,paynsprayWindow)
exitButton = guiCreateButton(0.7784,0.8373,0.145,0.1361,"Exit",true,paynsprayWindow)
setVehicleFrozen(getPedOccupiedVehicle(getLocalPlayer()),true)
showCursor(true,true)
local dim = math.random(1,65535)
setElementDimension(vehicle,dim)
setElementDimension(getLocalPlayer(),dim)
addEventHandler("onClientGUIClick",paintButton,paintVehicle)
addEventHandler("onClientGUIClick",randomButton,randomColors)
addEventHandler("onClientGUIClick",repairButton,repairCar)
addEventHandler("onClientGUIClick",exitButton,exitPayNSpray)
end
 
function paintVehicle(button,state,abX,abY)
local c1 = guiGetText(colorOneSelect)
local c2 = guiGetText(colorTwoSelect)
local c3 = guiGetText(colorThreeSelect)
local c4 = guiGetText(colorFourSelect)
local c1 = tonumber(c1)
local c2 = tonumber(c2)
local c3 = tonumber(c3)
local c4 = tonumber(c4)
if (c1 == nil or c2 == nil or c3 == nil or c4 == nil) then
outputChatBox("Only numbers are accepted in the color field.",255,0,0)
elseif ((c1 >= 0 and c1 <= 126) and (c2 >= 0 and c2 <= 126) and (c3 >= 0 and c3 <= 126) and (c4 >= 0 and c4 <= 126)) then
local c1 = math.floor(c1)
local c2 = math.floor(c2)
local c3 = math.floor(c3)
local c4 = math.floor(c4)
local cost = 1500
triggerServerEvent("onVehicleSpray",getPedOccupiedVehicle(getLocalPlayer()),c1,c2,c3,c4,cost)
else
outputChatBox("Valid numbers are 0 through 126.",255,0,0)
end
end
 
function randomColors(button,state,abX,abY)
guiSetText(colorOneSelect,math.random(0,126))
guiSetText(colorTwoSelect,math.random(0,126))
guiSetText(colorThreeSelect,math.random(0,126))
guiSetText(colorFourSelect,math.random(0,126))
local c1 = guiGetText(colorOneSelect)
local c2 = guiGetText(colorTwoSelect)
local c3 = guiGetText(colorThreeSelect)
local c4 = guiGetText(colorFourSelect)
local cost = 500
triggerServerEvent("onVehicleSpray",getPedOccupiedVehicle(getLocalPlayer()),c1,c2,c3,c4,cost)
end
 
function repairCar(button,state,abX,abY)
local cost = 5000
triggerServerEvent("onVehicleRepair",getPedOccupiedVehicle(getLocalPlayer()),cost)
end
 
function exitPayNSpray(button,state,abX,abY)
removeEventHandler("onClientGUIClick",paintButton,paintVehicle)
removeEventHandler("onClientGUIClick",randomButton,randomColors)
removeEventHandler("onClientGUIClick",repairButton,repairCar)
removeEventHandler("onClientGUIClick",exitButton,exitPayNSpray)
destroyElement(paynsprayWindow)
showCursor(false,false)
setVehicleFrozen(getPedOccupiedVehicle(getLocalPlayer()),false)
setElementDimension(getPedOccupiedVehicle(getLocalPlayer()),0)
setElementDimension(getLocalPlayer(),0)
end
 
addEventHandler("onClientPayNSprayEnter",getRootElement(),payNSprayGUI)

Link to comment

Add false to each:

addEventHandler( "onClientGUIClick", ...... , false );

This should prevent from crashing. If it still crashes then try to create GUI in onClientResourceStart and show/hide it whenever you need it. Besides, you don't have to removeEventHandler if you destroyElement because they are removed when elements are destroyed.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...