flomix77 Posted March 9, 2014 Share Posted March 9, 2014 Hello i have a problem with my script.. i need help to get if a player is near a ped.. or conversely.. someone can help me? Thank you Link to comment
Castillo Posted March 9, 2014 Share Posted March 9, 2014 Calculate the distance. getElementPosition getDistanceBetweenPoints3D Link to comment
Karuzo Posted March 9, 2014 Share Posted March 9, 2014 getDistanceBetweenPoints3D //Edit: aw solid D: Link to comment
flomix77 Posted March 9, 2014 Author Share Posted March 9, 2014 Thanks but now i have another question, i have this code: function check3DDistance(leader) local pX, pZ, pY = getElementPosition( leader ) local bX, bZ, bY = getElementPosition( source ) local distancia = getDistanceBetweenPoints3D ( pX, pZ, pY, bX, bZ, bY ) outputChatBox ( "the distance between "..getPlayerName(leader).." and the zombie is of "..tonumber(distancia)) end addEventHandler("onBotFollow", getRootElement(), check3DDistance) but dont works.. what "callback" i can use to check the distance when the ped is moving..? Link to comment
Moderators Citizen Posted March 9, 2014 Moderators Share Posted March 9, 2014 Well you can create a timer when onBotFollow is triggered and will call check3DDistance function every secs or 2 secs with the argument leader. Link to comment
Saml1er Posted March 9, 2014 Share Posted March 9, 2014 function check3DDistance(leader) local pX, pZ, pY = getElementPosition( leader ) local bX, bZ, bY = getElementPosition( source ) outputChatBox ( "the distance between "..getPlayerName(leader).." and the zombie is of "..getDistanceBetweenPoints3D ( pX, pZ, pY, bX, bZ, bY ) ) end addEventHandler("onBotFollow", getRootElement(), check3DDistance) Link to comment
Moderators Citizen Posted March 9, 2014 Moderators Share Posted March 9, 2014 function check3DDistance(leader) local pX, pZ, pY = getElementPosition( leader ) local bX, bZ, bY = getElementPosition( source ) outputChatBox ( "the distance between "..getPlayerName(leader).." and the zombie is of "..getDistanceBetweenPoints3D ( pX, pZ, pY, bX, bZ, bY ) ) end addEventHandler("onBotFollow", getRootElement(), check3DDistance) What's the point of doing that ? to make this line even longer ? Link to comment
flomix77 Posted March 9, 2014 Author Share Posted March 9, 2014 I need detect the distance between the player and ped if the player is 5.0 meters of distance of the ped, the ped kill be make an action... sorry for my bad english.. but someone knows how to detect the distance everytime? Link to comment
flomix77 Posted March 10, 2014 Author Share Posted March 10, 2014 someone can help me? Link to comment
Moderators Citizen Posted March 10, 2014 Moderators Share Posted March 10, 2014 function onBotTargeting( player ) setElementData( source, "playerTargeted", player) end addEventHandler("onBotFollow", getRootElement(), onBotTargeting) function check3DDistance(leader) for k, bot in ipairs ( getElementsByType("ped") ) do local targetedPlayer = getElementData(bot, "targetedPlayer") if targetedPlayer then local pX, pZ, pY = getElementPosition( targetedPlayer ) local bX, bZ, bY = getElementPosition( bot ) local distance = getDistanceBetweenPoints3D ( pX, pZ, pY, bX, bZ, bY ) if distance < 5 then --do your stuff here outputChatBox ( "the distance between "..getPlayerName(leader).." and a zombie is under 5 ("..distance..")" ) end end end end setTimer(check3DDistance, 1000, 0) 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