Miika Posted August 7, 2014 Share Posted August 7, 2014 Hi! I am making a car panel. But I have problem. TriggerServerEvent not working. My code is: [server side] function changeLightsState(source) if not isPedInVehicle(source) then return end local sourceVehicle = getPedOccupiedVehicle( source ) if getVehicleOverrideLights ( sourceVehicle ) ~= 2 then setVehicleOverrideLights( sourceVehicle, 2 ) else setVehicleOverrideLights( sourceVehicle, 1 ) end end addEvent ( "lightsState", true ) addEventHandler ( "lightsState", root, changeLightsState ) [Client side] function createCarPanel() carPanel = guiCreateWindow(250,100,445,445,"carPanel panel (TESTI)",false) guiSetVisible(carPanel, false) guiWindowSetSizable(carPanel, false) carPanelButton = guiCreateButton(14, 283, 136, 58, "asd", false, carPanel) addEventHandler ( "onClientGUIClick", carPanelButton, changeLights, false ) end addEventHandler ("onClientResourceStart", getResourceRootElement(getThisResource()), createCarPanel ) function changeLights() triggerServerEvent("lightsState", localPlayer ) end function windowcloseopen () if (guiGetVisible (carPanel) == true) then guiSetVisible (carPanel, false) guiSetInputEnabled (false) showCursor (false) elseif (guiGetVisible (carPanel) == false) then guiSetVisible (carPanel, true) showCursor (true) end end bindKey ("f2", "down", windowcloseopen) What is the problem? Link to comment
Et-win Posted August 7, 2014 Share Posted August 7, 2014 The function changeLights couldn't be found. Move the function ALWAYS (If starting with resource start) above the addEventHandler, so above function createCarPanel. Link to comment
TAPL Posted August 7, 2014 Share Posted August 7, 2014 The function changeLights couldn't be found. Move the function ALWAYS (If starting with resource start) above the addEventHandler, so above function createCarPanel. Nope it's found because the event onClientGUIClick added inside the event onClientResourceStart which mean the whole resource loaded therefore function changeLights exists. The problem from the server side. function changeLightsState() local sourceVehicle = getPedOccupiedVehicle(source) if sourceVehicle then if getVehicleOverrideLights ( sourceVehicle ) ~= 2 then setVehicleOverrideLights( sourceVehicle, 2 ) else setVehicleOverrideLights( sourceVehicle, 1 ) end end end addEvent ( "lightsState", true ) addEventHandler ( "lightsState", root, changeLightsState ) Link to comment
Miika Posted August 7, 2014 Author Share Posted August 7, 2014 The function changeLights couldn't be found. Move the function ALWAYS (If starting with resource start) above the addEventHandler, so above function createCarPanel. Nope it's found because the event onClientGUIClick added inside the event onClientResourceStart which mean the whole resource loaded therefore function changeLights exists. The problem from the server side. function changeLightsState() local sourceVehicle = getPedOccupiedVehicle(source) if sourceVehicle then if getVehicleOverrideLights ( sourceVehicle ) ~= 2 then setVehicleOverrideLights( sourceVehicle, 2 ) else setVehicleOverrideLights( sourceVehicle, 1 ) end end end addEvent ( "lightsState", true ) addEventHandler ( "lightsState", root, changeLightsState ) IT WORKING! Thx tapl! Link to comment
Et-win Posted August 7, 2014 Share Posted August 7, 2014 Nope it's found because the event onClientGUIClick added inside the event onClientResourceStart which mean the whole resource loaded therefore function changeLights exists. So first the resource get's loaded + scripts, and then all event's get started? And if so, what about replacing event 'onResourceStart' to functionname() ? Link to comment
TAPL Posted August 7, 2014 Share Posted August 7, 2014 Nope it's found because the event onClientGUIClick added inside the event onClientResourceStart which mean the whole resource loaded therefore function changeLights exists. So first the resource get's loaded + scripts, and then all event's get started? And if so, what about replacing event 'onResourceStart' to functionname() ? The script file start load from the first line until the last line, when it reach the end of the file the event onClientResourceStart get triggered. IT WORKING! Thx tapl! You're welcome. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now