mateplays Posted December 24, 2020 Share Posted December 24, 2020 Hi guys. I have some trouble. I want to get rid of any blips attached to a player, here is the code: addEventHandler("onPlayerQuit",getRootElement(), function() local blip = getBlipAttachedTo(source) if blip then destroyElement(blip) end end ) function getBlipAttachedTo( thePlayer ) local blips = getElementsByType( "blip" ) for k, theBlip in ipairs( blips ) do if getElementAttachedTo( theBlip ) == thePlayer then return theBlip end end return false end What causes the problem? Please help me. Link to comment
Tekken Posted December 25, 2020 Share Posted December 25, 2020 for i,v in ipairs(getElementChildren(source, "blip")) do destroyElement(v) end Link to comment
mateplays Posted December 25, 2020 Author Share Posted December 25, 2020 is this for client or for server or both? i tried it on the server side and it did not work, but it didn't give any errors... strange Link to comment
justn Posted December 25, 2020 Share Posted December 25, 2020 Your getBlipAttachedTo function only returns the first blip that it finds attached to the player. (Also I wouldn't loop through every blip in the server as this can have an impact on performance depending on how many blips there are) What I would advise is looping through the attached elements of the player , adding all the blips to a table then returning the table(instead of only returning the first found attached blip). Then in your onPlayerQuit event, you loop through that table destroying everything. Pretty much the code I have below, hope this helps you! addEventHandler("onPlayerQuit",getRootElement(), function() local blips = getBlipsAttachedTo(source) if blips then for i,theBlip in ipairs(blips) do destroyElement(theBlip) end end end ) function getBlipsAttachedTo( thePlayer ) local attached = {} local blips = getAttachedElements(thePlayer) for k, theBlip in ipairs( blips ) do if isElement(theBlip) and getElementType(theBlip) == 'blip' then table.insert(attached,theBlip) end end return attached end Link to comment
mateplays Posted December 25, 2020 Author Share Posted December 25, 2020 Thanks for the code, but... somehow it still does not work... i tried putting this into a different resource but it still does not get rid of any blips, and it does not output any errors to debugscript Link to comment
justn Posted December 25, 2020 Share Posted December 25, 2020 9 minutes ago, mateplays said: Thanks for the code, but... somehow it still does not work... i tried putting this into a different resource but it still does not get rid of any blips, and it does not output any errors to debugscript Just tested it, works perfectly for me when I attached a blip to myself via command. Could you show your current code ? Link to comment
mateplays Posted December 25, 2020 Author Share Posted December 25, 2020 (edited) So... Here is the code. I call this function once a new player joins into the party. This is client side: function getBlipAttachedTo( thePlayer ) local blips = getElementsByType( "blip" ) for k, theBlip in ipairs( blips ) do if getElementAttachedTo( theBlip ) == thePlayer then return theBlip end end return false end function belepveAGecibe() for k,v in pairs(getElementsByType("player")) do if (getElementData(v, "inPartyOf") == getElementData(localPlayer, "inPartyOf")) then if v ~= localPlayer then if not getBlipAttachedTo(v) then x, y, z = getElementPosition(v) blipToPartyMembers = createBlipAttachedTo(v, 35) setElementData(blipToPartyMembers, 'tooltipText', getPlayerName(v)) end end end end end addEvent("belepveNagyon",true) addEventHandler("belepveNagyon",getRootElement(), belepveAGecibe) And i use this on server side: addEventHandler("onPlayerQuit",getRootElement(), function() local blips = getBlipsAttachedTo(source) if blips then for i,theBlip in ipairs(blips) do destroyElement(theBlip) end end end ) function getBlipsAttachedTo( thePlayer ) local attached = {} local blips = getAttachedElements(thePlayer) for k, theBlip in ipairs( blips ) do if isElement(theBlip) and getElementType(theBlip) == 'blip' then table.insert(attached,theBlip) end end return attached end Edit: Got it to work using this solution: addEventHandler("onClientPlayerQuit",getRootElement(), function() if getBlipAttachedTo(source) then destroyElement(blipToPartyMembers) end end ) Edited December 25, 2020 by mateplays - Link to comment
justn Posted December 25, 2020 Share Posted December 25, 2020 Ah , a client sided blip, that explains why my code didn't work for you. Nice to hear you got it working though. topic can be locked now then 1 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