threevictor Posted January 10, 2017 Share Posted January 10, 2017 (edited) PROBLEM: The fim function does not execute the commands that are to give money to the player and destroy the vehicle of the player Mk1 = createMarker (-33.35546875, -279.1201171875, 5.625 -1, "cylinder", 1.1, 255 ,255 ,0, 255) Mk2 = createMarker (-92.0009765625, -307.244140625, 1.4296875 -1,"cylinder",7.5 , 255, 0,0) Mk3 = createMarker (1070.2001953125, 1889.2646484375, 10.8203125 -1,"cylinder", 7.5, 255, 0,0) Mk4 = createMarker (-40.4404296875, -225.564453125, 5.4296875 -1,"cylinder",7.5, 255, 0,0) B1 = createBlipAttachedTo (Mk2, 0 ) B2 = createBlipAttachedTo (Mk3, 41) B3 = createBlipAttachedTo (Mk4, 19) setElementVisibleTo ( B1, root, false ) setElementVisibleTo ( B2, root, false ) setElementVisibleTo ( B3, root, false ) setElementVisibleTo ( Mk2, root, false ) setElementVisibleTo ( Mk3, root, false ) setElementVisibleTo ( Mk4, root, false ) veh = {} function incio (source) if isElementWithinMarker(source, Mk1) then if veh[source] and isElement( veh[source] ) then destroyElement ( veh[source] ) veh[source] = nil end x,y,z = getElementPosition(source) Trabalho = true setElementVisibleTo ( B1, source, true ) setElementVisibleTo ( Mk2, source, true ) outputChatBox ("#00ff00Vá carregar o furgão.",source,0,0,0,true ) end end addEventHandler( "onMarkerHit", Mk1, incio ) function carrega (source) if isElementWithinMarker(source, Mk2) then setElementVisibleTo ( B1, source, false ) setElementVisibleTo ( Mk2, source, false ) outputChatBox("#00ff00Leve a carga do furgão até o local marcado no mapa para descarregar.",source,0,0,0,true) setElementVisibleTo ( Mk3, source, true ) setElementVisibleTo ( B2, source, true ) else end end addEventHandler("onMarkerHit",Mk2 ,carrega) function retorna (source) if isElementWithinMarker(source, Mk3) then outputChatBox ("Agora retorne a empresa com o furgão para receber seu pagamento.",source,0,0,0,true) setElementVisibleTo ( Mk3, source, false ) setElementVisibleTo ( B2, source, false ) setElementVisibleTo ( Mk4, source, true ) setElementVisibleTo ( B3, source, true ) else end end addEventHandler("onMarkerHit",Mk3 ,retorna) function fim (source) -------PROBLEM if veh[source] and isElement(veh[source]) then destroyElement (veh[source]) givePlayerMoney(source,1000) setElementVisibleTo ( B3, source, false ) setElementVisibleTo ( B4, source, false ) else end end addEventHandler("onMarkerHit",Mk4 ,fim) function sair (source) if (veh[source]) and isElement(veh[source]) then setElementVisibleTo ( B1, source, false ) destroyElement (veh[source]) outputChatBox("#00ff00Você saiu do veiculo,desobedeceu as ordems do chefe e foi demitido.", source ,0,0,0,true) else end end addEventHandler ( "onVehicleExit", getRootElement(), sair ) Edited January 10, 2017 by #banana Link to comment
myonlake Posted January 11, 2017 Share Posted January 11, 2017 (edited) That happens because there is no veh[ source ] set for the player. I was able to make it work once I defined veh[ source ] with a vehicle, as an example. Here's a cleaned up version: Mk1 = createMarker( -33.35546875, -279.1201171875, 5.625 - 1, "cylinder", 1.1, 255, 255, 0, 255 ) Mk2 = createMarker( -92.0009765625, -307.244140625, 1.4296875 - 1, "cylinder", 7.5, 255, 0, 0 ) Mk3 = createMarker( 1070.2001953125, 1889.2646484375, 10.8203125 - 1, "cylinder", 7.5, 255, 0, 0 ) Mk4 = createMarker( -40.4404296875, -225.564453125, 5.4296875 - 1, "cylinder", 7.5, 255, 0, 0 ) B1 = createBlipAttachedTo( Mk2, 0 ) B2 = createBlipAttachedTo( Mk3, 41 ) B3 = createBlipAttachedTo( Mk4, 19 ) setElementVisibleTo( B1, root, false ) setElementVisibleTo( B2, root, false ) setElementVisibleTo( B3, root, false ) setElementVisibleTo( Mk2, root, false ) setElementVisibleTo( Mk3, root, false ) setElementVisibleTo( Mk4, root, false ) veh = { } function incio( source ) if ( isElementWithinMarker( source, Mk1 ) ) then if ( isElement( veh[ source ] ) ) then destroyElement( veh[ source ] ) end x, y, z = getElementPosition( source ) Trabalho = true setElementVisibleTo( B1, source, true ) setElementVisibleTo( Mk2, source, true ) outputChatBox( "#00ff00Vá carregar o furgão.", source, 0, 0, 0, true ) end end addEventHandler( "onMarkerHit", Mk1, incio ) function carrega( source ) if ( isElementWithinMarker( source, Mk2 ) ) then outputChatBox( "#00ff00Leve a carga do furgão até o local marcado no mapa para descarregar.", source, 0, 0, 0, true ) setElementVisibleTo( B1, source, false ) setElementVisibleTo( Mk2, source, false ) setElementVisibleTo( Mk3, source, true ) setElementVisibleTo( B2, source, true ) end end addEventHandler( "onMarkerHit", Mk2 ,carrega ) function retorna( source ) if ( isElementWithinMarker( source, Mk3 ) ) then outputChatBox( "Agora retorne a empresa com o furgão para receber seu pagamento.", source, 0, 0, 0, true ) setElementVisibleTo( Mk3, source, false ) setElementVisibleTo( B2, source, false ) setElementVisibleTo( Mk4, source, true ) setElementVisibleTo( B3, source, true ) end end addEventHandler( "onMarkerHit", Mk3, retorna ) function fim( source ) -- Never gets triggered, because the player has no vehicle... if ( isElement( veh[ source ] ) ) then destroyElement( veh[ source ] ) givePlayerMoney( source, 1000 ) setElementVisibleTo( B3, source, false ) setElementVisibleTo( B4, source, false ) -- There is no B4 blip in the script? This throws an error. end end addEventHandler( "onMarkerHit", Mk4, fim ) function sair( source ) if ( isElement( veh[ source ] ) ) then setElementVisibleTo( B1, source, false ) destroyElement( veh[ source ] ) outputChatBox( "#00ff00Você saiu do veiculo,desobedeceu as ordems do chefe e foi demitido.", source, 0, 0, 0, true ) end end addEventHandler( "onVehicleExit", root, sair ) Edited January 11, 2017 by myonlake 1 Link to comment
threevictor Posted January 12, 2017 Author Share Posted January 12, 2017 6 hours ago, myonlake said: And what command exactly should I put where you notified the vehicle problem ?? Link to comment
myonlake Posted January 12, 2017 Share Posted January 12, 2017 (edited) Nothing. You just need to make sure you've defined veh[ source ]. What I did was I created a new vehicle when they entered the first marker, which defined veh[ source ] as that. Then the vehicle would stay as veh[ source ] on the 4th marker, and then it deletes the vehicle. I don't know where you want to define veh[ source ]. Is it spawned somewhere else in code, or do you want them to spawn a vehicle once they hit the first marker? If you want it to work even without a vehicle, then move everything else out of the if-statement except for the destroyElement. Edited January 12, 2017 by myonlake 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