DRW Posted September 3, 2015 Share Posted September 3, 2015 Hello, I'm making a script that creates a blip per every ped at a maximum range of 50 units, so I use a table to get all the peds and exclude the ones which don't accomplish the distance that I ask for. So I made this along with onClientRender. for i,peds in ipairs (getElementsByType("ped")) do local x,y,z = getElementPosition(peds) local wx,wy,wz = getElementPosition (localPlayer) if getDistanceBetweenPoints3D (wx,wy,wz,x,y,z)<50 then bl = createBlipAttachedTo (peds,0,1) end end Obviously this is the worst way to do it since onClientRender will create a blip per frame no matter if the ped has a blip attached to it or not. Also, if I define the blip with a name, when I destroy it, all of em get destroyed, I'm still not familiarized with tables and all those things, also I want to do this with players, but since I don't even have someone to test with, I'm doing it with peds. What can I do? PD: Please, don't give me examples of setBlipVisibleDistance because I don't want players to see the attached blips around the F11 map. Link to comment
JR10 Posted September 3, 2015 Share Posted September 3, 2015 How about onClientElementStreamIn? It might not be the same distance you want, I'm honestly not sure but it might work for you. Link to comment
DRW Posted September 3, 2015 Author Share Posted September 3, 2015 How about onClientElementStreamIn? It might not be the same distance you want, I'm honestly not sure but it might work for you. Thank you for trying to help me, but I solved it another way: local x,y,z = getElementPosition(localPlayer) el = createColSphere (x,y,z,100) attachElements (el,localPlayer) addEventHandler ("onClientElementColShapeHit",getRootElement(),function(shape) if shape==el then if getElementType (source)=="player" then blep = createBlipAttachedTo (source,1,1) setElementData(blep,"distblip",true) end end end) addEventHandler ("onClientRender",getRootElement(),function() for i,blips in ipairs (getElementsByType("blip"))do local ix,iy,iz = getElementPosition (blips) local xe,ye,ze = getElementPosition(localPlayer) local dist= getDistanceBetweenPoints3D (xe,ye,ze,ix,iy,iz) if dist>100 then if getElementData (blips,"distblip") then destroyElement (blips) end end end end) Link to comment
JR10 Posted September 3, 2015 Share Posted September 3, 2015 Using getDistanceBetweenPoints3D on render is pretty bad. Just use onClientColShapeLeave. 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