DexoTronic Posted March 29, 2010 Share Posted March 29, 2010 Hi, i create a vehicle with truck = createvehicle (..). now in OnPlayerEnterVehicle i want to check if player enters the "truck". is it possible in mta? in the wiki it can only make a diffenrence between the vehicle ids. i didnt find a example in the net. please help me Link to comment
DakiLLa Posted March 29, 2010 Share Posted March 29, 2010 simple enough: truck = createVehicle( ... ) addEventHandler( 'onPlayerVehicleEnter', getRootElement(), function( theVehicle, seat ) if theVehicle == truck then --if variable 'truck' is the vehicle, that somebody has got in outputChatBox( 'You have got into the truck :D', source, 0, 255, 0 ) end end ) Link to comment
karlis Posted March 29, 2010 Share Posted March 29, 2010 Im lil bit confused w/this, so soz if i say smtn wrong, but isnt attaching truck to onvehicleenter more efficent? Ps:soz for shorting words, just im writing on phone Link to comment
DakiLLa Posted March 29, 2010 Share Posted March 29, 2010 Well, he asked about 'onPlayerVehicleEnter' event, so i gave him an example with it Link to comment
DexoTronic Posted March 29, 2010 Author Share Posted March 29, 2010 i use the ID 455 as a truck it hasnt a trailer next question: if i enter the maker TruckerStartMarker it should make an chat output: function starttruckmission_func () TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.342208862305, "cylinder", 6, 255, 0, 0, 150 ) TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.092173576355, "cylinder", 6, 255, 0, 0, 150 ) end addEvent ( "starttruckmission", true ) addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func ) function MarkerHit( hitElement, matchingDimension ) if hitElement==getLocalPlayer() then outputChatBox( "in the marker TruckerStartMarker" ) end end addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit ) function starttruckmission_func () works, it creates the marker after the server calls that function. but it doesnt react if i enter this marker Link to comment
Dark Dragon Posted March 29, 2010 Share Posted March 29, 2010 the element which hits the marker is probably the truck, not the player function starttruckmission_func () TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.342208862305, "cylinder", 6, 255, 0, 0, 150 ) TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.092173576355, "cylinder", 6, 255, 0, 0, 150 ) end addEvent ( "starttruckmission", true ) addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func ) function MarkerHit( hitElement, matchingDimension ) if hitElement==getPedOccupiedVehicle(getLocalPlayer()) then -- the vehicle of the local player outputChatBox( "in the marker TruckerStartMarker" ) end end addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit ) Link to comment
DexoTronic Posted March 29, 2010 Author Share Posted March 29, 2010 nope didnt work i tested my version onfoot too, but it didnt work too Link to comment
Dark Dragon Posted March 29, 2010 Share Posted March 29, 2010 but your script is client side isn't it? if not just use onMarkerHit instead Link to comment
DexoTronic Posted March 29, 2010 Author Share Posted March 29, 2010 yes its clientside. here i call the starttruckmission_func: Server script: function enterVehicle ( theVehicle, seat, jacked ) if ( theVehicle == truck) then if ( PlayerJob[source] == 2 ) then triggerClientEvent( source, "starttruckmission", getRootElement()) else removePedFromVehicle ( source ) outputChatBox( "Trucker: Nur unsere Angestellten können dieses Fahrzeug benutzen!", source, 255, 0, 0 ) end end end and its works... the markers are created after entering "truck". but if i enter the marker nothing happens addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) Link to comment
Dark Dragon Posted March 29, 2010 Share Posted March 29, 2010 really strange, both your and my script work fine for me, at least the client-side stuff Link to comment
DexoTronic Posted March 29, 2010 Author Share Posted March 29, 2010 you know TeamViewer? you can control my PC with it, maybe you can help me that way € please help me Link to comment
Castillo Posted March 29, 2010 Share Posted March 29, 2010 I got a question what is this line? what it checks, i mean where is the truck called "truck"? if ( theVehicle == truck) then Link to comment
DexoTronic Posted March 29, 2010 Author Share Posted March 29, 2010 truck = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824) i dont get what you mean^^ Link to comment
Castillo Posted March 29, 2010 Share Posted March 29, 2010 truck = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824)i dont get what you mean^^ i mean that line wasnt in code, im wrong? Link to comment
DexoTronic Posted March 29, 2010 Author Share Posted March 29, 2010 it doesnt matter if the player is in the truck or not. for example this code works: function MarkerHit( hitElement, matchingDimension ) if hitElement==getLocalPlayer() then guiSetVisible ( TruckWindow , true ) guiBringToFront ( TruckWindow ) showCursor ( true ) end end addEventHandler( "onClientMarkerHit", TruckMarker, MarkerHit ) this doesnt work: function MarkerHit( hitElement, matchingDimension ) if hitElement== getLocalPlayer() then outputChatBox( "in the marker TruckerStartMarker" ) end end addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit ) and i dont get why Link to comment
Castillo Posted March 29, 2010 Share Posted March 29, 2010 ok, i fixed your code now it works i ve tested it 10 times, here is code: client-side function starttruckmission_func () TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.342208862305, "cylinder", 6, 255, 0, 0, 150 ) TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.092173576355, "cylinder", 6, 255, 0, 0, 150 ) end addEvent ( "starttruckmission", true ) addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func ) function MarkerHit( hitElement, matchingDimension ) if hitElement== getLocalPlayer() then outputChatBox( "in the marker TruckerStartMarker" ) end end addEventHandler( "onClientMarkerHit", getRootElement(), MarkerHit ) server-side truck = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824) addEventHandler( 'onPlayerVehicleEnter', getRootElement(), function ( theVehicle, seat, jacked ) if ( theVehicle == truck) then if ( PlayerJob[source] == 2 ) then triggerClientEvent( source, "starttruckmission", getRootElement()) else removePedFromVehicle ( source ) outputChatBox( "Trucker: Nur unsere Angestellten können dieses Fahrzeug benutzen!", source, 255, 0, 0 ) end end end) Link to comment
DexoTronic Posted March 29, 2010 Author Share Posted March 29, 2010 yes it works.... but it should only react if im in "TruckerStartMarker". your version reacts in all markers Link to comment
Castillo Posted March 29, 2010 Share Posted March 29, 2010 yes it works.... but it should only react if im in "TruckerStartMarker". your version reacts in all markers well i think this event is only server-side: addEventHandler( "onMarkerHit", TruckerStartMarker, MarkerHit ) Link to comment
DexoTronic Posted March 30, 2010 Author Share Posted March 30, 2010 ok.. i have now: function MarkerHit( hitElement, matchingDimension ) if hitElement== source then outputChatBox( "in the marker TruckerStartMarker" ) end end addEventHandler( "onMarkerHit", TruckerStartMarker, MarkerHit ) in the server script. but it reacts at all markes again EDIT: Here whole client script...: TruckWindow = guiCreateWindow(389,354,497,222,"",false) guiSetAlpha(TruckWindow ,1) TruckMann = guiCreateStaticImage(11,24,112,136,"images/truck.jpg",false,TruckWindow ) guiSetAlpha(TruckMann ,1) TruckText = guiCreateLabel(130,28,346,130,"Willkommen bei unserer Spedition.\nDu verdienst ihr Geld,\nindem du Waren von A nach B transportierst.\nWenn du willst kannst du gleich loslegen,\nwir suchen noch Leute.\nAlles was du brauchst ist ein Fuehrerschein.",false,TruckWindow ) guiSetAlpha(TruckText ,1) guiLabelSetColor(TruckText ,255,120,0) guiLabelSetVerticalAlign(TruckText ,"top") guiLabelSetHorizontalAlign(TruckText ,"left",false) TruckAnnehmenBtn = guiCreateButton(9,171,243,42,"Job annehmen",false,TruckWindow ) guiSetAlpha(TruckAnnehmenBtn ,1) TruckAblehnenBtn = guiCreateButton(255,171,233,42,"Job ablehnen/kuendigen",false,TruckWindow ) guiSetAlpha(TruckAblehnenBtn ,1) guiSetVisible ( TruckWindow , false ) local TruckMarker = createMarker( -144.73950195313, 1078.8743896484, 19.492191314697, 'cylinder', 1.0, 255, 0, 0, 150 ) function TruckMarkerHit( hitElement, matchingDimension ) if hitElement==getLocalPlayer() and matchingDimension==true then if source==TruckerStartMarker then guiSetVisible ( TruckWindow , true ) guiBringToFront ( TruckWindow ) showCursor ( true ) end end end addEventHandler( "onClientMarkerHit", TruckMarker, TruckMarkerHit ) local localPlayer = getLocalPlayer ( ) --function windowHandler( ) -- guiSetVisible ( TruckWindow , true ) -- guiBringToFront ( TruckWindow ) -- showCursor ( true ) --end function onClickBtn ( button, state ) if (button == "left" and state == "up") then if (source == TruckAnnehmenBtn ) then guiSetInputEnabled(false) guiSetVisible ( TruckWindow , false ) showCursor ( false ) triggerServerEvent ( "truckerannehmen", getRootElement()) end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler ) addEventHandler ( "onClientGUIClick", TruckAnnehmenBtn, onClickBtn, false ) function onClickBtn ( button, state ) if (button == "left" and state == "up") then if (source == TruckAblehnenBtn ) then guiSetInputEnabled(false) guiSetVisible ( TruckWindow , false ) showCursor ( false ) triggerServerEvent ( "truckerablehnen", getRootElement()) end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler ) addEventHandler ( "onClientGUIClick", TruckAblehnenBtn, onClickBtn, false ) function starttruckmission_func () TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.742208862305, "cylinder", 6, 255, 0, 0, 150 ) TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.492173576355, "cylinder", 6, 255, 0, 0, 150 ) end addEvent ( "starttruckmission", true ) addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func ) function MarkerHit( hitElement, matchingDimension ) if hitElement== getLocalPlayer() and matchingDimension==true then if source==TruckerStartMarker then outputChatBox( "in the marker TruckerStartMarker" ) elseif source==TruckerEndeMarker then outputChatBox( "in the marker TruckerEndeMarker" ) removeEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit ) removeEventHandler( "onClientMarkerHit", TruckerEndeMarker, MarkerHit ) destroyElement(TruckerStartMarker) destroyElement(TruckerEndeMarker) TruckerStartMarker, TruckerEndeMarker = nil end end end addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit ) addEventHandler( "onClientMarkerHit", TruckerEndeMarker, MarkerHit ) 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