Stylez Posted October 24, 2012 Share Posted October 24, 2012 Good Evening everybody i have this small script. You should understand what i am trying to do.. i know where i have problem. But i cant solve it the problem is in local vehicle = getPedOccupiedVehicle(source) - source argument.. but as i said, i cant solve this problem Here is the code function bind() local vehicle = getPedOccupiedVehicle(source) if vehicle then local driver = getVehicleOccupant(vehicle) if driver then bindKey(source, "m", "down", bind) triggerClientEvent(source, "bindKey", getRootElement(), "trigger") end else outputChatBox("u need to be in a car",source) end end addEventHandler("onPlayerVehicleEnter", getRootElement(), bind) Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 This doesn't really make much sense, why are you binding the key to the same function that binds it? it makes no sense. Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 (edited) i tried to trigger bindKey function to client side. Maybe, u can fix my code so it triggers bindKey function to clientside? Edited October 24, 2012 by Guest Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 So, what you want to do is bind a key to trigger that event? function bind ( ) bindKey ( source, "m", "down", trigger ) end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), bind ) function trigger ( thePlayer ) if ( isPedInVehicle ( thePlayer ) ) then triggerClientEvent ( thePlayer, "bindKey", getRootElement(), "trigger" ) else outputChatBox ( "u need to be in a car", thePlayer ) end end Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 Nonono. i want to trigger bindKey function to client side. i tried to bind M key with "onClientPlayerVehicleEnter" but it didint worked for me, so i tried another way. Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 Why didn't work? post what you tried. Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 i deleted it 1 hour ago -.- so u say it should have worked? im gonna retry it with client side then. Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 addEventHandler ( "onClientVehicleEnter", root, function ( thePlayer, seat ) if ( thePlayer == localPlayer ) then bindKey ( "M", "down", bind ) end end ) That would work. Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 Here. i tried to bind m key when player enters vehicle, so i could show and hide mouse. function cursor(button, state) if showCursor == false then showCursor(true) else showCursor(false) end end function bind () bindKey("m", "down", cursor) end addEventHandler("onClientPlayerVehicleEnter", getRootElement(), bind) Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 if showCursor == false then That is wrong, you should use: if ( not isCursorShowing ( ) ) then Or just: showCursor ( not isCursorShowing ( ) ) Would show the cursor if is not already showing, else hide it. Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 oh didint knew that isCursorShowing funcion existed is the rest of my code ok? Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 You should check if the player that entered the vehicle is the localPlayer. if ( source == localPlayer ) then -- Bind key end Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 cant figure out, why? i mean it should bind m key when player(source) enters the car. so why it needs checking? Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 Because that will be triggered by remote players as well. Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 ok. i understand now. Thanks for your help. Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 Hey, solidsnake. i have new problem with same script. Everything works, just when i click on vehicle it opens 99999999+ window. function masiniukui() mainWin = guiCreateWindow(0.80, 0.15, 0.20, 0.60,"WINDOW!!!!!!!!!", true) local car = getPedOccupiedVehicle(getLocalPlayer()) if car then local driver = getVehicleOccupant(car) if driver then if isPedInVehicle(driver) then local carClick = getPedOccupiedVehicle(driver) if carClick then guiSetVisible(mainWin, true) end end end end end addEventHandler("onClientClick", getRootElement(), masiniukui) function cursor( ) if not isCursorShowing() then showCursor(true) else showCursor(false) guiSetVisible(mainWin, false) end end function bind (thePlayer, seat) if source == localPlayer then bindKey( "m", "down", cursor) end end addEventHandler("onClientPlayerVehicleEnter", getRootElement(), bind) Link to comment
Castillo Posted October 24, 2012 Share Posted October 24, 2012 mainWin = guiCreateWindow(0.80, 0.15, 0.20, 0.60,"WINDOW!!!!!!!!!", true) guiSetVisible ( mianWin, false ) function masiniukui() local car = getPedOccupiedVehicle(getLocalPlayer()) if car then local driver = getVehicleOccupant(car) if driver then if isPedInVehicle(driver) then local carClick = getPedOccupiedVehicle(driver) if carClick then guiSetVisible(mainWin, true) end end end end end addEventHandler("onClientClick", getRootElement(), masiniukui) function cursor( ) if not isCursorShowing() then showCursor(true) else showCursor(false) guiSetVisible(mainWin, false) end end function bind (thePlayer, seat) if source == localPlayer then bindKey( "m", "down", cursor) end end addEventHandler("onClientPlayerVehicleEnter", getRootElement(), bind) You was creating the window every time. Link to comment
Stylez Posted October 24, 2012 Author Share Posted October 24, 2012 oh. Stupid mistake Thankyou 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