Jump to content

No players in gridlist


Michcio

Recommended Posts

Hi! I have a problem with my gridlist. Gridlist is good, but there aren't any players in it. Please help me!

local x,y = getElementPosition(getLocalPlayer()) 
colshape = createColCircle ( x, y, 20.0 ) 
playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
guiSetVisible(playerList,false) 
  
function createPlayerList () 
        -- Create the grid list 
        -- Create a players column in the list 
        local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
        if ( column ) then         -- If the column has been created, fill it with players 
                for id, playeritem in ipairs(getElementsWithinColShape ( colshape, "player" )) do 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) 
                end 
                addEventHandler ( "onClientGUIClick", row, click ) 
        end 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) 
  
function click ( button, state, sx, sy, x, y, z, elem, gui ) 
        -- if state is down ( not to trigger the function twice on mouse button up/down), clicked gui and the element is our player list 
        if ( source == playerList ) then 
                -- get the player name from the selected row, first column 
                local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) 
                outputChatBox ( playerName )     -- output it to chat box 
        end 
end 
  
function visible () 
    guiSetVisible(playerList,true) 
    showCursor(true) 
end 
addCommandHandler("pokaz",visible) 

Link to comment

Line 15 is wrong.

2nd argument 'row' is not a gui element, you should use gridlist .. so try this.

local x,y = getElementPosition(getLocalPlayer()) 
colshape = createColCircle ( x, y, 20.0 ) 
playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
guiSetVisible(playerList,false) 
  
function createPlayerList () 
        -- Create the grid list 
        -- Create a players column in the list 
        local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
        if ( column ) then         -- If the column has been created, fill it with players 
                for id, playeritem in ipairs(getElementsWithinColShape ( colshape, "player" )) do 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) 
                end 
                addEventHandler ( "onClientGUIClick", playerList, click ) 
        end 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) 
  
function click ( button) 
    if button == "left" and source == playerList then 
        local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) 
        outputChatBox ( playerName ) 
         
  
function visible () 
    guiSetVisible(playerList,true) 
    showCursor(true) 
end 
addCommandHandler("pokaz",visible) 

Link to comment
Line 15 is wrong.

2nd argument 'row' is not a gui element, you should use gridlist .. so try this.

local x,y = getElementPosition(getLocalPlayer()) 
colshape = createColCircle ( x, y, 20.0 ) 
playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
guiSetVisible(playerList,false) 
  
function createPlayerList () 
        -- Create the grid list 
        -- Create a players column in the list 
        local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
        if ( column ) then         -- If the column has been created, fill it with players 
                for id, playeritem in ipairs(getElementsWithinColShape ( colshape, "player" )) do 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) 
                end 
                addEventHandler ( "onClientGUIClick", playerList, click ) 
        end 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) 
  
function click ( button) 
    if button == "left" and source == playerList then 
        local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) 
        outputChatBox ( playerName ) 
         
  
function visible () 
    guiSetVisible(playerList,true) 
    showCursor(true) 
end 
addCommandHandler("pokaz",visible) 

This makes no sense... he wants to put the player's at the gridlist if i'm not wrong.

local x,y = getElementPosition(getLocalPlayer()) 
colshape = createColCircle ( x, y, 20.0 ) 
playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
guiSetVisible(playerList,false) 
  
function createPlayerList () 
        -- Create the grid list 
        -- Create a players column in the list 
        local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
        if ( column ) then         -- If the column has been created, fill it with players 
                for id, playeritem in ipairs(getElementsByType("player")) do 
                if isElementWithinColShape(playeritem,colshape) then 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) 
                      end 
                end 
                addEventHandler ( "onClientGUIClick", playerList, click ) 
        end 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) 
  
function click ( button) 
    if button == "left" and source == playerList then 
        local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) 
        outputChatBox ( playerName ) 
        
  
function visible () 
    guiSetVisible(playerList,true) 
    showCursor(true) 
end 
addCommandHandler("pokaz",visible) 
  

Try that.

Link to comment
  • Moderators

Hi Michcio,

You have to make 2 parts:

- One in Server-Side ( to detect players in colCircle and send the players to the Client-Side )

- One in Client-Side ( to create the Gridlist, to receive the players and show it in the gridlist

I have tested it and he works very well:

Server-Side:

function createTheColCircle( thePlayer, commandName ) 
    if ( colshape ) then -- If another colshape was created before with the command /createCol 
        destroyElement( colshape ) 
        killTimer( timerShape ) 
    end 
    local x,y,z = getElementPosition( thePlayer ) 
    colshape = createColCircle ( x, y, 20.0 ) -- Create the ColCircle 
    timerShape = setTimer( refreshPlayersInColShape, 2000, 0 ) -- Execute the refresh every 2 sec 
    outputChatBox("col created" ) 
end 
addCommandHandler( "createCol", createTheColCircle, false, false ) 
  
function refreshPlayersInColShape() 
    local nearbyPlayers = getElementsWithinColShape( colshape, "player" ) -- Found all Players in the ColShape 
    for k, i in ipairs ( getElementsByType( "player" ) )do 
        triggerClientEvent(i, "updatePlayerList", getRootElement(), nearbyPlayers ) -- send nearbyPlayers for all clients  
    end 
end 
  

Client-Side:

 playerList = guiCreateGridList ( 0.70, 0.10, 0.30, 0.60, true ) 
columnplayerList = guiGridListAddColumn( playerList, "Player", 0.85 ) 
guiSetVisible(playerList,false) 
  
function click ( button ) 
    if button == "left" and source == playerList then 
        local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) 
        outputChatBox ( playerName ) 
    end 
end   
  
function togglePlayerList() 
    local show = guiGetVisible(playerList) 
    guiSetVisible(playerList, not show) 
    showCursor( not show ) 
end 
addCommandHandler("pokaz",togglePlayerList) 
  
addEvent("updatePlayerList", true) 
function updatePlayerList( nearbyPlayers ) 
    guiGridListClear(playerList) -- Destroy all rows from the gridlist 
    for k,i in ipairs( nearbyPlayers )do 
        if (getPlayerName(i) ~= getPlayerName( getLocalPlayer() ) )then -- Don't show his name 
            row = guiGridListAddRow(playerList) 
            guiGridListSetItemText(playerList, row, columnplayerList, ""..getPlayerName(i), false, false) 
            addEventHandler( "onClientGUIClick", playerList, click, false) 
        end 
    end 
end 
addEventHandler("updatePlayerList", getLocalPlayer(), updatePlayerList) 

If you don't understand a thing with this script, ask me :wink:

Link to comment
  • Moderators

I'm not sure but I think that the Client side can't detect any other players in the Colshape ( I have to verify it )

And most of all, with the Server-Side, we can send the players who are in the colshape to all clients.

Like that every players can see the gridlist with the name of players who are inside the Colshape

Do you understand what I mean ? (sorry if I'm not speak very well 'cause I'm French :lol: )

And it's work so why not ?

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...