AlexMiller Posted September 22, 2009 Share Posted September 22, 2009 As title, I made a GUI, a vehicle panel GUI, that tells to driver the state of engine, lights and doors. The problem is that if I enter a vehicle, i see the panel, but eveyone sees my panel too and I everyone's ones. And i've another problem, the status is realoaded each time I enter the vehicle, not everytime i press the engine, lights or lockcar button... Here's the entire GUI code: addEventHandler("onClientVehicleEnter", getRootElement(), function(thePlayer, seat) Panel_Window = guiCreateWindow(751,159,174,123,"VEHICLE PANEL",false) guiWindowSetMovable(Panel_Window,false) guiWindowSetSizable(Panel_Window,false) Engine_Label = guiCreateLabel(0.0747,0.252,0.8046,0.2195,"Engine status: Off ",true,Panel_Window) guiLabelSetColor(Engine_Label,255,255,255) guiLabelSetVerticalAlign(Engine_Label,"top") guiLabelSetHorizontalAlign(Engine_Label,"left",false) Doors_Label = guiCreateLabel(0.069,0.6829,0.8621,0.1951,"Door Status: Locked ",true,Panel_Window) guiLabelSetColor(Doors_Label,255,255,255) guiLabelSetVerticalAlign(Doors_Label,"top") guiLabelSetHorizontalAlign(Doors_Label,"left",false) Lights_Label = guiCreateLabel(0.069,0.4715,0.8046,0.2114,"Lights Status: On ",true,Panel_Window) guiLabelSetColor(Lights_Label,255,255,255) guiLabelSetVerticalAlign(Lights_Label,"top") guiLabelSetHorizontalAlign(Lights_Label,"left",false) playervehicle = getPedOccupiedVehicle ( thePlayer ) if getVehicleOverrideLights ( playervehicle ) == 2 then guiSetText ( Lights_Label, "Lights status: On " ) else guiSetText ( Lights_Label, "Lights status: Off " ) end playervehicle = getPedOccupiedVehicle ( thePlayer ) if isVehicleLocked ( playervehicle ) then guiSetText ( Doors_Label, "Door status: Locked " ) else guiSetText ( Doors_Label, "Door status: Unlocked " ) end playervehicle = getPedOccupiedVehicle ( thePlayer ) local engine1 = getVehicleEngineState ( playervehicle ) if ( engine1 == false ) then guiSetText ( Engine_Label, "Engine status: Off " ) else guiSetText ( Engine_Label, "Engine status: On " ) end end ) function enginefunc( key , state ) if ( keyState == "down" ) then local player = getLocalPlayer outputChatBox("PRESSED 1") playervehicle = getPedOccupiedVehicle ( plr ) if isPedInVehicle ( plr ) then local engine1 = getVehicleEngineState ( playervehicle ) if ( engine1 == false ) then guiSetText ( Engine_Label, "Engine status: Off " ) else guiSetText ( Engine_Label, "Engine status: On " ) end end end end function lightsfunc( key , state ) if ( keyState == "down" ) then local player = getLocalPlayer outputChatBox("PRESSED 2") playervehicle = getPedOccupiedVehicle ( plr ) if isPedInVehicle ( plr ) then if isVehicleLocked ( playervehicle ) then guiSetText ( Doors_Label, "Door status: Locked " ) else guiSetText ( Doors_Label, "Door status: Unlocked " ) end end end end function doorsfunc( key , state ) if ( keyState == "down" ) then local player = getLocalPlayer outputChatBox("PRESSED 3") playervehicle = getPedOccupiedVehicle ( plr ) if isPedInVehicle ( plr ) then if isVehicleLocked ( playervehicle ) then guiSetText ( Doors_Label, "Door status: Locked " ) else guiSetText ( Doors_Label, "Door status: Unlocked " ) end end end end function chiavi2 () local bind1 = bindKey( "1", "down", "enginefunc" ) local bind2 = bindKey( "2", "down", "lightsfunc" ) local bind3 = bindKey( "3", "down", "doorsfunc" ) if bind1 and bind2 and bind3 then outputChatBox( "Keys bound") end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), chiavi2) addEventHandler("onClientVehicleExit", getRootElement(), function(thePlayer, seat) destroyElement(Panel_Window) end ) I hope someone can help me. I wrote the same question in another section, it was ignored, so i thought it was the wrong one... Thank you. Link to comment
subenji99 Posted September 22, 2009 Share Posted September 22, 2009 (And I ended up replying to the post in the wrong section too - moved post here.) Telling you exactly how to fix this would mean one of us basically rewrites your code for you and you would learn nothing. Instead, here are a couple of pointers to help you in the right direction: You're creating a new GUI Window everytime you enter the car. Obviously, this is not the best method. Have a seperate function that creates the GUI window and sub-elements on client resource start instead, and use guiSetVisible on the GUI Window element in onClientPlayerVehicleEnter/onClientPlayerVehicleExit. function createGUI() Panel_Window = guiCreateWindow(751,159,174,123,"VEHICLE PANEL",false) guiWindowSetMovable(Panel_Window,false) guiWindowSetSizable(Panel_Window,false) ... end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),createGUI) Speaking of which, my 2nd point is to use onClientPlayerVehicleEnter instead of onClientVehicleEnter, as it will fix your 1st bug: addEventHandler("onClientPlayerVehicleEnter", getLocalPlayer(), --bind to just yourself entering a vehicle function(theVehicle, seat) --this event passes the player as "source", not the vehicle guiSetVisible(Panel_Window,true) ... end ,false) --propagated false as you only want the event to trigger for yourself addEventHandler("onClientPlayerVehicleExit", getLocalPlayer(), function(theVehicle, seat) guiSetVisible(Panel_Window,false) end ,false) Try implementing those for now, see if you can get it to behave better. Once that's done, if the labels still don't update properly then it can be looked into when we know the GUI window is behaving. Link to comment
AlexMiller Posted September 22, 2009 Author Share Posted September 22, 2009 (edited) Thank you for answering my proble. I really didn't see that Events, however i don't think there's a lot to learn by changing an event. Maybe, you was talking about the label's behavoir. I have to test the new changes with someone that joins the server. But the labels still doesn't change when i0m on the vehicle. I made some changes and this is the new code: EDIT: I changed again the code, because I fixed the problem. Now I have a new problem ( ), forget the previous: When I press 1,2,3 in the chatbox the text PRESSED 1,2,3 is outputted, but nothing changes, so the debugger says that: Bad argument @'isPedInVehicle' line etc. What's the problem here? function enginefunc( key , state ) if ( state == "down" ) then local player = getLocalPlayer outputChatBox("PRESSED 1") local playervehicle = getPedOccupiedVehicle ( player ) if isPedInVehicle ( player ) then local engine1 = getVehicleEngineState ( theVehicle ) if ( engine1 == false ) then guiSetText ( Engine_Label, "Engine status: Off " ) else guiSetText ( Engine_Label, "Engine status: On " ) end end end end function lightsfunc( key , state ) if ( state == "down" ) then local player = getLocalPlayer outputChatBox("PRESSED 2") local playervehicle = getPedOccupiedVehicle ( player ) if isPedInVehicle ( player ) then if isVehicleLocked ( theVehicle ) then guiSetText ( Doors_Label, "Door status: Locked " ) else guiSetText ( Doors_Label, "Door status: Unlocked " ) end end end end function doorsfunc( key , state ) if ( state == "down" ) then local player = getLocalPlayer outputChatBox("PRESSED 3") local playervehicle = getPedOccupiedVehicle ( player ) if isPedInVehicle ( player ) then if isVehicleLocked ( theVehicle ) then guiSetText ( Doors_Label, "Door status: Locked " ) else guiSetText ( Doors_Label, "Door status: Unlocked " ) end end end end That will be the part where i'll learn nothing, i think, any suggestion? Thank you. Edited September 22, 2009 by Guest Link to comment
subenji99 Posted September 22, 2009 Share Posted September 22, 2009 Sorry, don't have timne atm for a full look at your code, but did spot this in all 3 bindKey-linked functions: function enginefunc( key , state ) if ( keyState == "down" ) then local player = getLocalPlayer ... You missed the brakets on calling the function: getLocalPlayer() Link to comment
Remp Posted September 23, 2009 Share Posted September 23, 2009 You are also using a variable theVehicle which does not exist local player = getLocalPlayer outputChatBox("PRESSED 1") local playervehicle = getPedOccupiedVehicle ( player ) if isPedInVehicle ( player ) then local engine1 = getVehicleEngineState ( theVehicle ) ... you should be using playervehicle instead Link to comment
AlexMiller Posted September 23, 2009 Author Share Posted September 23, 2009 Thank you both R3mp and subenji99, now everything its ok. My panel properly works now. If anyone wants me to post here my Vehicle panel working, just ask me. 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