Dentos Posted September 22, 2014 Share Posted September 22, 2014 I have this other little problem when i reconnect it wont show you on map anymore I tried adding addEventHandler ( "onPlayerJoin", root, addTeamBlip ) but didnt work I have to restart script everytime i reconnect for it to work heres what i added local pBlips = { } addEventHandler("onResourceStart", resourceRoot, function() for index, player in ipairs(getElementsByType("player")) do addTeamBlip(player) end end ) function addTeamBlip(player) if ( pBlips[player] ) then return false end -- Adding a prevention of duplicate blips local theGang = getElementData ( player, "gang" ) if ( theGang and theGang ~= "None" ) then local r, g, b = getPlayerNametagColor( player ) local theBlip = createBlipAttachedTo( player, 0, 2, 0, 255, 0 ) -- Change visibility to only the team members setElementVisibleTo( theBlip, root, false ) for index, value in ipairs ( getPlayersByGang ( theGang ) ) do -- THIS setElementVisibleTo( theBlip, value, true ) end pBlips[player] = theBlip end end function destroyBlip(element) local theElement = source or element if ( theElement ) then destroyElement(pBlips[theElement]) pBlips[theElement] = nil -- Just in-case... end end -- Events addEventHandler ( "onPlayerJoin", root, addTeamBlip ) --ADDED THIS! addEventHandler ( "onPlayerSpawn", root, addTeamBlip ) -- onPlayerSpawn will now add a teamBlip addEventHandler ( "onPlayerQuit", root, destroyBlip ) addEventHandler ( "onPlayerWasted", root, destroyBlip ) function getPlayersByGang ( gang ) local players = { } for _, player in ipairs ( getElementsByType ( "player" ) ) do if ( getElementData ( player, "gang" ) == gang ) then table.insert ( players, player ) end end return players end or maybe a command to to make resource restart every 5 seconds automatically or something but i think it be more efficient if reousrce restarted when player connected Link to comment
Saml1er Posted September 22, 2014 Share Posted September 22, 2014 local BlipAdd = function () addTeamBlip (source) end addEventHandler ( "onPlayerJoin", root, BlipAdd ) addEventHandler ( "onPlayerSpawn", root, BlipAdd ) Link to comment
Dentos Posted September 22, 2014 Author Share Posted September 22, 2014 I tried and only thing it did is show my playerblip when i reconnect and not all gang members had restart manually for it to show i think i need use a eventhandler restart the resource everytime someone logs in Link to comment
Mr_Moose Posted September 22, 2014 Share Posted September 22, 2014 The problem is most likely a missing element data on "gang", check your mtaserver.conf file and see which order your resources are loaded, where are "gang" set to a player, if the resource who gives a player a value on their element data "gang" starts after this one, it won't add your blip when you join or spawn. I suggest you change the order of how your resources are loaded so the gangsystem (or whatever resource that sets "gang" is) loads before the player blips resource you are working on. The reason why it works when you restart your resource is because it's loaded after the client got his "gang" data applied. Try that and see if it helps. Link to comment
Saml1er Posted September 23, 2014 Share Posted September 23, 2014 Actually when a player joins then you must get all player and check their gang and elements attached to the player, so if it is a blip then make it visible for the player that joined your server. 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