Adde Posted October 5, 2013 Share Posted October 5, 2013 Hello, I am trying to create a function that removes the blip for the local player when the distance between the players is more than 300. I can´t find out what i am doing wrong help? client function distance300thendestroy() p1x, p1y, p1z = getElementPosition ( source ) p2x, p2y, p2z = getElementPosition ( localPlayer ) local dist = getDistanceBetweenPoints2D ( p1x, p1y, p2x, p2y ) if ( dist >= 300 ) then local attached = getAttachedElements ( source ) if ( attached ) then for k,element in ipairs(attached) do if getElementType ( element ) == "blip" then setElementVisibleTo(element, localPlayer, false) end end end end end Link to comment
manawydan Posted October 5, 2013 Share Posted October 5, 2013 whats is source? i think you can use one table with all players in the server. Link to comment
qaisjp Posted October 5, 2013 Share Posted October 5, 2013 You said something is wrong, but you haven't told us what is wrong. What is the issue? Is that your entire code? Link to comment
Adde Posted October 5, 2013 Author Share Posted October 5, 2013 Manawydan: but then all blips Will be removed when anyone are more than 300away from someone? Oh forgot that part. It doesn't work at all, it doesn't remove the blip. Nothing in debug. Link to comment
Moderators Citizen Posted October 6, 2013 Moderators Share Posted October 6, 2013 Try this: function blipDistanceChecker() local px, py, _ = getElementPosition ( localPlayer ) for k, blip in ipairs ( getElementsByType( "blip" ) ) local bx, by, _ = getElementPosition( blip ) local dist = getDistanceBetweenPoints2D ( px, py, bx, by ) if dist >= 300 then setElementVisibleTo(blip, localPlayer, false) else setElementVisibleTo(blip, localPlayer, true) end end end setTimer(blipDistanceChecker, 1000, 0) Link to comment
xXMADEXx Posted October 6, 2013 Share Posted October 6, 2013 Try this: function blipDistanceChecker() local px, py, _ = getElementPosition ( localPlayer ) for k, blip in ipairs ( getElementsByType( "blip" ) ) local bx, by, _ = getElementPosition( blip ) local dist = getDistanceBetweenPoints2D ( px, py, bx, by ) if dist >= 300 then setElementVisibleTo(blip, localPlayer, false) else setElementVisibleTo(blip, localPlayer, true) end end end setTimer(blipDistanceChecker, 1000, 0) "setElementVisibleTo" is a server function and localPlayer is a client variable. Here is a code that I have (client-side): function fixBlipRanges ( ) for index, blip in ipairs ( getElementsByType ( 'blip' ) ) do local id = getBlipIcon ( blip ) if ( id > 1 and id ~= 41 ) then setBlipVisibleDistance ( blip, 300 ) end end end Link to comment
myonlake Posted October 6, 2013 Share Posted October 6, 2013 If you necessarily want it, use this. local createBlip_ = createBlip function createBlip(x, y, z, icon, size, r, g, b, a, ordering, visibleDistance, visibleTo) return createBlip_(x, y, z, icon, size, r, g, b, a, ordering, (tonumber(visibleDistance) and tonumber(visibleDistance) or 300), visibleTo) end That's a wrapper function. Another way is to use https://wiki.multitheftauto.com/wiki/Se ... leDistance. Link to comment
Moderators Citizen Posted October 6, 2013 Moderators Share Posted October 6, 2013 ok I should definitely check the functions I use before posting the code, sorry for that. 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