Jump to content

Carpanel problem ...


Miika

Recommended Posts

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
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
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
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

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...