flomix77 Posted March 9, 2014 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
Castillo Posted March 9, 2014 Posted March 9, 2014 Calculate the distance. getElementPosition getDistanceBetweenPoints3D
flomix77 Posted March 9, 2014 Author 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..?
Moderators Citizen Posted March 9, 2014 Moderators 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.
Saml1er Posted March 9, 2014 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)
Moderators Citizen Posted March 9, 2014 Moderators 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 ?
flomix77 Posted March 9, 2014 Author 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?
Moderators Citizen Posted March 10, 2014 Moderators 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)
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