Jump to content

Help me with this small problem please


Dentos

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...