Help w/ Java Script

Hi so I’m making a playlist script but having trouble with the java script displaying words above the player list. I have it done in HTML but is buggy. So how would I get a second table that works.

$(function()
{
    window.addEventListener('message', function(event)
    {
        var item = event.data;
        var buf = $('#wrap');
        buf.find('table').append("<tr class=\"heading\"><th>SERVER</th><th> Name</th></tr>");
        buf.find('table').append("<tr class=\"heading\"><th>ID</th><th>   Name</th></tr>");
        if (item.meta && item.meta == 'close')
        {
            document.getElementById("ptbl").innerHTML = "";
            $('#wrap').hide();
            return;
        }
        buf.find('table').append(item.text);
        $('#wrap').show();
    }, false);
});

I’m guessing I broke it by doing 2 buf.find tables. Any help would be great.

And if your wondering why not just keep it HTML, It pops up when you first join the server in its box with the Headings in the player list box making you press ^ (arrow) to remove it / reset it.

Screenshot your issue so i can see what exactly its doing.

It does not display at all

Lua code?
(20 chars)

I’m out ATM but that’s all vanilla I’m not if it’s because of 2 bud.find lines in the java. Because If I take the top one away it works fine.

You could probably use a different JS framework that will make that so much easier.

I have no clue when it comes to JS. I’ll send you my Lua when home…

If you use Vue or Angular it could make your life alot easier.

1 Like

Heres the lua.

local listOn = false

Citizen.CreateThread(function()
    listOn = false
    while true do
        Wait(0)

        if IsControlPressed(0, 27)--[[ INPUT_PHONE ]] then
            if not listOn then
                local players = {}
                ptable = GetPlayers()
                for _, i in ipairs(ptable) do
                    table.insert(players,
                    '<tr style="color: rgb(255, 255, 255); font-weight: 500;"><td>' .. GetPlayerServerId(i) .. '</td><td>' ..GetPlayerName(i)..'</td></tr>' -- The "color: rgb" sets the color of the list
                    )
                end

                SendNUIMessage({ text = table.concat(players) })

                listOn = true
                while listOn do
                    Wait(0)
                    if(IsControlPressed(0, 27) == false) then
                        listOn = false
                        SendNUIMessage({
                            meta = 'close'
                        })
                        break
                    end
                end
            end
        end
    end
end)

function GetPlayers()
    local players = {}

    for i = 0, 31 do
        if NetworkIsPlayerActive(i) then
            table.insert(players, i)
        end
    end

    return players
end

I’m gonna take this to PM’s so this topic doesn’t get crazy.

1 Like