Albinix Posted May 9, 2010 Share Posted May 9, 2010 (edited) how to make when you hit the blue marker your gravity will be normal (0.008) and when you hit the red marker your gravity will be half as normal (0.004) createMarker ( 4000, -460, 25, "corona", 3, 0, 0, 255, 255 ) createMarker ( 4040, -460, 25, "corona", 3, 255, 0, 0, 255 ) function MarkerHit( thePed ) setPedGravity ( thePed, 0.008 ) end addEventHandler( "onMarkerHit", getRootElement(), MarkerHit ) function MarkerHit( thePed ) setPedGravity ( thePed, 0.004 ) end addEventHandler( "onMarkerHit", getRootElement(), MarkerHit ) Edited May 10, 2010 by Guest Link to comment
dzek (varez) Posted May 9, 2010 Share Posted May 9, 2010 use [lua] tags not you have 2 functions with same name!! Link to comment
Callum Posted May 10, 2010 Share Posted May 10, 2010 local blueMarker = createMarker ( 4000, -460, 25, "corona", 3, 0, 0, 255, 255 ) local redMarker = createMarker ( 4040, -460, 25, "corona", 3, 255, 0, 0, 255 ) function onHit(hitElement) if (source == blueMarker) then setPedGravity(hitElement,0.008) end if (source == redMarker) then setPedGravity(hitElement,0.004) end end addEventHandler("onMarkerHit",getRootElement(),onHit) Link to comment
dzek (varez) Posted May 10, 2010 Share Posted May 10, 2010 The best way (less cpu consume): bluemarker = createMarker ( 4000, -460, 25, "corona", 3, 0, 0, 255, 255 ) -- blue redmarker = createMarker ( 4040, -460, 25, "corona", 3, 255, 0, 0, 255 ) -- red function MarkerHit(theElement) if (getElementType(theElement)=='ped') then if (source==bluemarker) then setPedGravity ( theElement, 0.008 ) elseif (source==redmarker) then setPedGravity ( theElement, 0.004 ) end end end addEventHandler( "onMarkerHit", bluemarker, MarkerHit ) addEventHandler( "onMarkerHit", redmarker, MarkerHit ) this will add handler only for that two markers, will help with errors/warnings in console when car or any other element than ped hit the marker.. you can also check if the element type is vehicle, and then get vehicle driver and others occupants,and set gravity for each of them Link to comment
eAi Posted May 10, 2010 Share Posted May 10, 2010 I'd make redmarker and bluemarker have their own functions - it's simpler. bluemarker = createMarker ( 4000, -460, 25, "corona", 3, 0, 0, 255, 255 ) -- blue redmarker = createMarker ( 4040, -460, 25, "corona", 3, 255, 0, 0, 255 ) -- red function setElementGravity(theElement, gravity) if (getElementType(theElement)=='ped') then setPedGravity ( theElement, gravity ) end end function BlueMarkerHit(theElement) setElementGravity ( theElement, 0.008 ) end function RedMarkerHit(theElement) setElementGravity ( theElement, 0.004 ) end addEventHandler( "onMarkerHit", bluemarker, BlueMarkerHit ) addEventHandler( "onMarkerHit", redmarker, RedMarkerHit ) 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