DexoTronic Posted March 31, 2010 Share Posted March 31, 2010 Hi i have a problem. i have this client script: function onClickBtn ( button, state ) if (button == "left" and state == "up") then if (source == TruckArbeitBtn ) then guiSetInputEnabled(false) guiSetVisible ( TruckWindow , false ) showCursor ( false ) triggerServerEvent ( "truckerarbeit", getRootElement()) end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler ) addEventHandler ( "onClientGUIClick", TruckArbeitBtn, onClickBtn, false ) it triggers the server event "truckarbeit" : function truckerarbeit_func ( ) if PlayerJob[client] < 2 or PlayerJob[client] > 2 then outputChatBox( "Du musst erst den Job annehmen!", client, 255, 0, 0 ) end if PlayerJob[client] == 2 then Truck[client] = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824) setVehicleColor ( Truck[client], 3, 3, 3, 3 ) warpPedIntoVehicle ( client, Truck[client] ) end end addEvent ( "truckerarbeit", true ) addEventHandler ( "truckerarbeit", getRootElement(), truckerarbeit_func ) works. perfectly. it creates the vehicle and puts the player in it. now i want to delete the vehicle after the player leaves it: (in the server script) function exitVehicle ( theVehicle, seat, jacked ) if ( theVehicle == Truck[source]) then destroyElement(Truck[source]) end end addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle ) it doesnt work. i tried it with Truck[client] too, doesnt work too. whats wrong? Link to comment
Gamesnert Posted March 31, 2010 Share Posted March 31, 2010 It "doesn't work". In what way? Link to comment
DexoTronic Posted March 31, 2010 Author Share Posted March 31, 2010 all works, only deleting the vehicle doesnt work. i tried it with if ( theVehicle == Truck[source]) then destroyElement(Truck[source]) and if ( theVehicle == Truck[client]) then destroyElement(Truck[client]) doenst work both Link to comment
Gamesnert Posted March 31, 2010 Share Posted March 31, 2010 all works, only deleting the vehicle doesnt work. For which I asked, in what way. Do you get any errors? Or anything else you can add? Link to comment
Remp Posted March 31, 2010 Share Posted March 31, 2010 the variable 'client' only exists in events that were triggered from a clientside script if you look at the wiki page for onVehicleExit, the 'source' variable is actually the vehicle that was exited, not the player that got out. the player is passed as the first argument, so you need to do: function exitVehicle ( thePlayer, seat, jacked ) if ( theVehicle == Truck[thePlayer]) then destroyElement(Truck[thePlayer]) end end addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle ) Link to comment
DexoTronic Posted March 31, 2010 Author Share Posted March 31, 2010 i doenst work too Link to comment
Gamesnert Posted March 31, 2010 Share Posted March 31, 2010 function exitVehicle ( thePlayer, seat, jacked ) if ( source == Truck[thePlayer]) then destroyElement(Truck[thePlayer]) end end addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle ) Corrected a small mistake in line 2: R3mp was still using theVehicle instead of source. Link to comment
Jason_Gregory Posted March 31, 2010 Share Posted March 31, 2010 Hm...you should add some more Parameters to your trigger (Clientside) Command. Try this... function truckerarbeit_func ( client ) if PlayerJob[client] < 2 or PlayerJob[client] > 2 then outputChatBox( "Du musst erst den Job annehmen!", client, 255, 0, 0 ) end if PlayerJob[client] == 2 then Truck[client] = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824) setVehicleColor ( Truck[client], 3, 3, 3, 3 ) warpPedIntoVehicle ( client, Truck[client] ) end end addEvent ( "truckerarbeit", true ) addEventHandler ( "truckerarbeit", getRootElement(), truckerarbeit_func ) triggerServerEvent ( "truckerarbeit", getRootElement(), getLocalPlayer()) What exactly is not working ? Link to comment
DexoTronic Posted March 31, 2010 Author Share Posted March 31, 2010 that works, i dont need that parameter. the only thing thats not working ist "onVehicleExit". The Vehicle should get deleted, but i doesnt get deleted. Link to comment
Antibird Posted March 31, 2010 Share Posted March 31, 2010 function exitVehicle( thePlayer ) outputChatBox( tostring( source ) ) outputChatBox( tostring( Truck[thePlayer] ) ) end addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle ) Do line 2 and line 3 output the same? Link to comment
Jason_Gregory Posted March 31, 2010 Share Posted March 31, 2010 Try it out, cause the Wikipedia says you need to work with 'source' instead of 'client'. But ive you says you tryed them out, and they dont work, try to pass the PlayerElement to a Argument and it should work. (It works for me, why not for ya ) Or something is going wrong with your Truck table. I cant find any Bug in Gamesnerts Code aswell. The 'onVehicleEnter' Handler is not the culprit @Antibird What are you trying to do ? Printing a Element ? Link to comment
Antibird Posted March 31, 2010 Share Posted March 31, 2010 What are you trying to do ? Printing a Element ? Exactly. Should output something like "userdata: [some hexadecimal number]". If one hex is not equal to another one then " if ( source == Truck[thePlayer]) " condition won't ever become true. By the way, why not to have a check: function exitVehicle ( thePlayer, seat, jacked ) if ( source == Truck[thePlayer]) then outputChatBox( "must be correct!" ) local success = destroyElement(Truck[thePlayer]) if sucess then outputChatBox( "vehicle destroyed" ) end else outputChatBox( "Epic fail" ) end end addEventHandler ( "onVehicleExit", getRootElement(), exitVehicle ) or something like that. Come on, fill up your code with debug strings. It always helps. How can you fix the error if you have no idea where it's located? I don't see anything wrong with Gamesnerts code neither. Link to comment
DexoTronic Posted March 31, 2010 Author Share Posted March 31, 2010 output is: Epic Fail € comon pls help me Link to comment
Antibird Posted April 1, 2010 Share Posted April 1, 2010 It's obvious that "source" is not equal to "Truck[thePlayer]" in the "exit" event. But since you say "truckerarbeit_func" does the job just great and there are no any errors/warnings in server console, then I can't tell you what's wrong, I can't see the reason. It's something related to the rest code you have, most likely some mess with "Truck" table. Use debug strings throughout the code, check it line by line. Either post everything here if you like so. 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