Jump to content

GuiLabel with members's ID


Artisz

Recommended Posts

Hi!

I want to create a member list with guiLabel or dxDrawText(nevermind, just working). But I can't make that the created Label has an own ID what is the player ID, that when I click the player name, I got hes informations.

I don't know what I did... Here is the code:

  
local memberlist = {} 
local player_cache = {} 
  
function Test() 
  
    player_cache = getElementsByType("player") 
    for k,v in ipairs(player_cache) do 
        local slot = nil 
        for k = 1, 200 do 
            if (memberlist[k]==nil) then 
                local name = getPlayerName(v) 
                local slot = k - 1                 
                                         
                memberlist[slot] = guiCreateLabel(400,60 + slot * (30) ,700,50,name,false) 
                addEventHandler("onClientGUIClick",memberlist[slot],handleButtonClick) 
                break 
            end 
        end                       
    end 
end 
  
function handleButtonClick(button,state) 
    if (button == "left" and state == "up") then 
           outputChatBox(tostring(slot)) 
    end 
end 

When I click my name label, I got: "nil", and I think when there is more the 1 online player, then I can click just the latest player's label(I don't know, I can't try this at the moment, just a long time ago)

Link to comment

First of all, you don't have to declare this

  
local player_cache = {} 
  

since 'getElementsByType' already created a table.

Second, you just declared memberlist = {} empty, and 'k' returns you the index of the player, so this part:

  
for k = 1, 200 do 
     if (memberlist [k] == nil) then 
          ... 
     end 
end 
  

is kind of useless.

And to make a button, you should as well use gridlists to get the clicked item since the way with only a button works not.

You can write this to display all the names of online players (since getElementsByType "player") returns online players;

  
local x, y = guiGetScreenSize () 
  
addEventHandler ("onClientRender", getRootElement(), 
    function () 
        for playerPosition, playerName in ipairs (getElementsByType ("player")) do 
            dxDrawText (playerName, 0, 50 + (playerPosition * 20), x, y, tocolor (255, 255, 255, 200), 1, "default-bold", "center") 
        end 
    end 
) 
  

MTA Wiki provides a very similar example to getting player's name:

https://wiki.multitheftauto.com/wiki/Gu ... etItemText

Link to comment

What you wrote, I don't understand, sorry, but I am bad in English.

But you linked this gridlist, and I saw that the gridlist a gui. So what if I set the grid list alpha 0, and create label above it. It can be working, isn't it?

I ask this because now I can't try it.

If it is working, than how can I solve the scrolling? Sorry for the problems..

Link to comment

Let me first explain the stuff I did above:

so this:

local x, y = guiGetScreenSize () 

gets your screen's size so you fit it for every screen (I didn't fit mine there)

then on Client Render keeps the frames going so you can actually 'draw' the text. Then for playerPosition, playerName are usually found as (for k, v) or for (i, v), I did it so you can understand it easier; they loop through the table of all online players and you use the dxDrawText finally.

dxDrawText (0 (because I did "center" at last argument I wrote up), then 20 + (playerPosition * 20). playerPosition * 20 is going to keep growing every time you loop through the table, so if there are 5 players, you'll have these coordinates:

50, 70, 90, 110, 130

as for your second question, you can do that but it would be messy af. I highly recommend a full GUI interface or just try to create a dx one (might be hard for a beginner)

Link to comment

This part of the resource I understand. Thanks for the guide. But when I clicked one of the generated draw text, how can I choose the correct one, what I clicked on?

I don't want to use the basic gui, because it is ugly in a custom dxdraw inteface.

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