qbcore-framework / qb-adminmenu

Admin Menu Using MenuV
GNU General Public License v3.0
43 stars 247 forks source link

[BUG]ShowNames always show other's name in my head #166

Closed SuperMan-Sam closed 8 months ago

SuperMan-Sam commented 2 years ago

ShowNames always show other's name in my head...

PaddyS commented 2 years ago

We're also facing that issue at the moment.

I'm not sure yet, but I guess this code is faulty: qb-adminmenu/server/server.lua

CreateThread(function()
    while true do
        local tempPlayers = {}
        for _, v in pairs(QBCore.Functions.GetPlayers()) do
            local targetped = GetPlayerPed(v)
            local ped = QBCore.Functions.GetPlayer(v)
            tempPlayers[#tempPlayers + 1] = {
                name = (ped.PlayerData.charinfo.firstname or '') .. ' ' .. (ped.PlayerData.charinfo.lastname or '') .. ' | (' .. (GetPlayerName(v) or '') .. ')',
                id = v,
                coords = GetEntityCoords(targetped),
                cid = ped.PlayerData.charinfo.firstname .. ' ' .. ped.PlayerData.charinfo.lastname,
                citizenid = ped.PlayerData.citizenid,
                sources = GetPlayerPed(ped.PlayerData.source),
                sourceplayer = ped.PlayerData.source

            }
        end
        -- Sort players list by source ID (1,2,3,4,5, etc) --
        table.sort(tempPlayers, function(a, b)
            return a.id < b.id
        end)
        players = tempPlayers
        Wait(1500)
    end
end)

Will do some further research in the upcoming days.

daveayee commented 1 year ago

We are also getting this problem. Hopefully there will be a fix

redacid95 commented 1 year ago

I'm too lazy to create a pull request. So if someone else would like to, feel free. This is an easy fix.

Client/blipnames.lua below line 40 you need to add an if statement.

"If playeridx ~= -1 then"

If the player is too far away to get the server id it returns -1. If you use -1 on getplayerped then it returns your ped, hence changes your name and ID to show someone else's.

niterfjord commented 1 year ago

"If playeridx ~= -1 then"

And where is the end of the if-loop?

redacid95 commented 1 year ago

"If playeridx ~= -1 then"

And where is the end of the if-loop?

If statements are conditional statements not loops. This if statement is inside of the loop, yes. It would go right before the end of the loop. Nothing in that loop should run if that condition is not met.

redacid95 commented 1 year ago
for _, player in pairs(players) do
    local playeridx = GetPlayerFromServerId(player.id)
 if playeridx ~= -1 then
    local ped = GetPlayerPed(playeridx)
    local blip = GetBlipFromEntity(ped)
    local name = 'ID: '..player.id..' | '..player.name

    local Tag = CreateFakeMpGamerTag(ped, name, false, false, "", false)
    SetMpGamerTagAlpha(Tag, 0, 255) -- Sets "MP_TAG_GAMER_NAME" bar alpha to 100% (not needed just as a fail safe)
    SetMpGamerTagAlpha(Tag, 2, 255) -- Sets "MP_TAG_HEALTH_ARMOUR" bar alpha to 100%
    SetMpGamerTagAlpha(Tag, 4, 255) -- Sets "MP_TAG_AUDIO_ICON" bar alpha to 100%
    SetMpGamerTagAlpha(Tag, 6, 255) -- Sets "MP_TAG_PASSIVE_MODE" bar alpha to 100%
    SetMpGamerTagHealthBarColour(Tag, 25)  --https://wiki.rage.mp/index.php?title=Fonts_and_Colors

    if ShowNames then
        SetMpGamerTagVisibility(Tag, 0, true) -- Activates the player ID Char name and FiveM name
        SetMpGamerTagVisibility(Tag, 2, true) -- Activates the health (and armor if they have it on) bar below the player names
        if NetworkIsPlayerTalking(playeridx) then
            SetMpGamerTagVisibility(Tag, 4, true) -- If player is talking a voice icon will show up on the left side of the name
        else
            SetMpGamerTagVisibility(Tag, 4, false)
        end
        if GetPlayerInvincible(playeridx) then
            SetMpGamerTagVisibility(Tag, 6, true) -- If player is in godmode a circle with a line through it will show up
        else
            SetMpGamerTagVisibility(Tag, 6, false)
        end
    else
        SetMpGamerTagVisibility(Tag, 0, false)
        SetMpGamerTagVisibility(Tag, 2, false)
        SetMpGamerTagVisibility(Tag, 4, false)
        SetMpGamerTagVisibility(Tag, 6, false)
        RemoveMpGamerTag(Tag) -- Unloads the tags till you activate it again
        NetCheck2 = false
    end

    -- Blips Logic
    if ShowBlips then
        if not DoesBlipExist(blip) then
            blip = AddBlipForEntity(ped)
            SetBlipSprite(blip, 1)
            ShowHeadingIndicatorOnBlip(blip, true)
        else
            local veh = GetVehiclePedIsIn(ped, false)
            local blipSprite = GetBlipSprite(blip)
            --Payer Death
            if not GetEntityHealth(ped) then
                if blipSprite ~= 274 then
                    SetBlipSprite(blip, 274)            --Dead icon
                    ShowHeadingIndicatorOnBlip(blip, false)
                end
            --Player in Vehicle
            elseif veh ~= 0 then
                local classveh = GetVehicleClass(veh)
                local modelveh = GetEntityModel(veh)
                --MotorCycles (8) or Cycles (13)
                if classveh == 8  or classveh == 13 then
                    if blipSprite ~= 226 then
                        SetBlipSprite(blip, 226)        --Motorcycle icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --OffRoad (9)
                elseif classveh == 9 then
                    if blipSprite ~= 757 then
                        SetBlipSprite(blip, 757)        --OffRoad icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Industrial (10)
                elseif classveh == 10 then
                    if blipSprite ~= 477 then
                        SetBlipSprite(blip, 477)        --Truck icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Utility (11)
                elseif classveh == 11 then
                    if blipSprite ~= 477 then
                        SetBlipSprite(blip, 477)        --Truck icon despite finding better one
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Vans (12)
                elseif classveh == 12 then
                    if blipSprite ~= 67 then
                        SetBlipSprite(blip, 67)         --Van icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Boats (14)
                elseif classveh == 14 then
                    if blipSprite ~= 427 then
                        SetBlipSprite(blip, 427)        --Boat icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Helicopters (15)
                elseif classveh == 15 then
                    if blipSprite ~= 422 then
                        SetBlipSprite(blip, 422)        --Moving helicopter icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Planes (16)
                elseif classveh == 16 then
                    if modelveh == 'besra' or modelveh == 'hydra' or modelveh == 'lazer' then
                        if blipSprite ~= 424 then
                            SetBlipSprite(blip, 424)    --Jet icon
                            ShowHeadingIndicatorOnBlip(blip, false)
                        end
                    elseif blipSprite ~= 423 then
                        SetBlipSprite(blip, 423)        --Plane icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Service (17)
                elseif classveh == 17 then
                    if blipSprite ~= 198 then
                        SetBlipSprite(blip, 198)        --Taxi icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Emergency (18)
                elseif classveh == 18 then
                    if blipSprite ~= 56 then
                        SetBlipSprite(blip, 56)        --Cop icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Military (19)
                elseif classveh == 19 then
                    if modelveh == 'rhino' then
                        if blipSprite ~= 421 then
                            SetBlipSprite(blip, 421)    --Tank icon
                            ShowHeadingIndicatorOnBlip(blip, false)
                        end
                    elseif blipSprite ~= 750 then
                        SetBlipSprite(blip, 750)        --Military truck icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Commercial (20)
                elseif classveh == 20 then
                    if blipSprite ~= 477 then
                        SetBlipSprite(blip, 477)        --Truck icon
                        ShowHeadingIndicatorOnBlip(blip, false)
                    end
                --Every car (0, 1, 2, 3, 4, 5, 6, 7)
                else
                    if modelveh == 'insurgent' or modelveh == 'insurgent2' or modelveh == 'limo2' then
                        if blipSprite ~= 426 then
                            SetBlipSprite(blip, 426)    --Armed car icon
                            ShowHeadingIndicatorOnBlip(blip, false)
                        end
                    elseif blipSprite ~= 225 then
                        SetBlipSprite(blip, 225)        --Car icon
                        ShowHeadingIndicatorOnBlip(blip, true)
                    end
                end
                -- Show number in case of passangers
                local passengers = GetVehicleNumberOfPassengers(veh)
                if passengers then
                    if not IsVehicleSeatFree(veh, -1) then
                        passengers = passengers + 1
                    end
                    ShowNumberOnBlip(blip, passengers)
                else
                    HideNumberOnBlip(blip)
                end
            --Player on Foot
            else
                HideNumberOnBlip(blip)
                if blipSprite ~= 1 then
                    SetBlipSprite(blip, 1)
                    ShowHeadingIndicatorOnBlip(blip, true)
                end
            end

            SetBlipRotation(blip, math.ceil(GetEntityHeading(veh)))
            SetBlipNameToPlayerName(blip, playeridx)
            SetBlipScale(blip, 0.85)

            if IsPauseMenuActive() then
                SetBlipAlpha(blip, 255)
            else
                local x1, y1 = table.unpack(GetEntityCoords(PlayerPedId(), true))
                local x2, y2 = table.unpack(GetEntityCoords(GetPlayerPed(playeridx), true))
                local distance = (math.floor(math.abs(math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))) / -1)) + 900
                if distance < 0 then
                    distance = 0
                elseif distance > 255 then
                    distance = 255
                end
                SetBlipAlpha(blip, distance)
            end
        end
    else
        RemoveBlip(blip)
        NetCheck1 = false
    end
 end
end
github-actions[bot] commented 1 year ago

This issue has had 60 days of inactivity & will close within 7 days

redacid95 commented 1 year ago

This does not appear to be updated on the master branch. Fix is posted above @GhzGarage

github-actions[bot] commented 11 months ago

This issue has had 60 days of inactivity & will close within 7 days

redacid95 commented 11 months ago

Or don't update it?

github-actions[bot] commented 9 months ago

This issue has had 60 days of inactivity & will close within 7 days

msyyn commented 4 months ago

Bump, this is still an issue.