Jump to content

Problem with selfmade Playerlist ( Tried :) )


Maurize

Recommended Posts

Posted

Hey everybody,

I tried to create a playerlist.

I got 1 Problem: If I join server as first & alone all is shown correctly.

But if a second player joins, my name is shown twice and his, too.

So is there a way to debug this ?

And maybe ideas how to make it better?

Thanks & Greetings,

Brasco

local x, y = guiGetScreenSize() 
local pList = guiCreateGridList( x / 4, y / 4, 400, 400, false ) 
local pcol1 = guiGridListAddColumn( pList, "Name", 0.2 ) 
local pcol2 = guiGridListAddColumn( pList, "Gang", 0.2 ) 
local pcol3 = guiGridListAddColumn( pList, "Ping", 0.2 ) 
guiWindowSetMovable( pList, false ) 
guiWindowSetSizable( pList, false ) 
guiSetVisible( pList, false ) 
  
function PlayerList() 
if ( guiGetVisible( pList ) == false ) then 
    for i = 0, guiGridListGetRowCount( pList ) do 
    guiGridListRemoveRow( pList, i ) 
end 
    guiSetVisible( pList, true ) 
    for id, player in ipairs( getElementsByType( "player" ) ) do 
    prow1 = guiGridListAddRow( pList ) 
    guiGridListSetItemText( pList, prow1, pcol1, getPlayerName( player ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol2, getTeamName( getPlayerTeam( player ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol3, getPlayerPing( player ), false, false ) 
end 
else 
    guiSetVisible( pList, false ) 
    end 
end 
bindKey( "tab", "both", PlayerList ) 

Posted
local x, y = guiGetScreenSize() 
local pList = guiCreateGridList( x / 4, y / 4, 400, 400, false ) 
local pcol1 = guiGridListAddColumn( pList, "Name", 0.2 ) 
local pcol2 = guiGridListAddColumn( pList, "Gang", 0.2 ) 
local pcol3 = guiGridListAddColumn( pList, "Ping", 0.2 ) 
guiWindowSetMovable( pList, false ) 
guiWindowSetSizable( pList, false ) 
guiSetVisible( pList, false ) 
  
function PlayerList() 
if ( guiGetVisible( pList ) == false ) then 
    guiGridListClear(pList) 
    guiSetVisible( pList, true ) 
    for id, player in ipairs( getElementsByType( "player" ) ) do 
    prow1 = guiGridListAddRow( pList ) 
    guiGridListSetItemText( pList, prow1, pcol1, getPlayerName( player ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol2, getTeamName( getPlayerTeam( player ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol3, getPlayerPing( player ), false, false ) 
end 
else 
    guiSetVisible( pList, false ) 
    end 
end 
bindKey( "tab", "both", PlayerList ) 

It should clear the gridlist when you open it, then add the rows.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

No problem :D.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Maybe you can help me a second time.

I´ve created a Timer which sets the players accountdata every minute +1 .

But to show it in the playerlist I need to setElementData().

I do all this, but my Playtime isn´t shown. Here my code:

SERVER:

function SpielerZeit() 
gTime = tonumber( getAccountData( getPlayerAccount( source ), "time" ) ) 
if ( gTime ) then 
    gTimer = setTimer( setAccountData, 60000, 0, getPlayerAccount( source ), "time", gTime + 1 ) 
else 
    nTime = 0 
    gTimer = setTimer( setAccountData, 60000, 0, getPlayerAccount( source ), "time", nTime + 1 ) 
end 
    addEventHandler( "onPlayerQuit", Spieler, function() killTimer( gTimer ) 
    end ) 
end 
addEventHandler( "onPlayerLogin", Spieler, SpielerZeit ) 
  
function SpielerUpdate() 
    local update = tonumber( getAccountData( getPlayerAccount( source ), "time" ) ) 
    setElementData( source, "time_v", update ) 
end 
addEvent( "update", true ) 
addEventHandler( "update", Spieler, SpielerUpdate ) 

CLIENT:

local sx, sy = guiGetScreenSize() 
local pList = guiCreateGridList( 300, 300, sx - 600, sy - 600, false ) 
local pcol1 = guiGridListAddColumn( pList, "Name", 0.3 ) 
local pcol2 = guiGridListAddColumn( pList, "Gang", 0.3 ) 
local pcol3 = guiGridListAddColumn( pList, "Spielzeit", 0.175 ) 
local pcol4 = guiGridListAddColumn( pList, "Ping", 0.175 ) 
guiWindowSetMovable( pList, false ) 
guiWindowSetSizable( pList, false ) 
guiSetVisible( pList, false ) 
     
function PlayerList() 
if ( guiGetVisible( pList ) == false ) then 
    guiGridListClear(pList) 
    guiSetVisible( pList, true ) 
for id, player in ipairs( getElementsByType( "player" ) ) do 
    triggerServerEvent( "update", player ) 
    prow1 = guiGridListAddRow( pList ) 
    guiGridListSetItemText( pList, prow1, pcol1, getPlayerName( player ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol2, getTeamName( getPlayerTeam( player ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol3, tonumber( getElementData( player, "time" ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol4, getPlayerPing( player ), false, false ) 
end 
else 
    guiSetVisible( pList, false ) 
    end 
end 
bindKey( "tab", "both", PlayerList ) 

Posted

Gridlist texts must be a string, it can't be a number.

local sx, sy = guiGetScreenSize() 
local pList = guiCreateGridList( 300, 300, sx - 600, sy - 600, false ) 
local pcol1 = guiGridListAddColumn( pList, "Name", 0.3 ) 
local pcol2 = guiGridListAddColumn( pList, "Gang", 0.3 ) 
local pcol3 = guiGridListAddColumn( pList, "Spielzeit", 0.175 ) 
local pcol4 = guiGridListAddColumn( pList, "Ping", 0.175 ) 
guiWindowSetMovable( pList, false ) 
guiWindowSetSizable( pList, false ) 
guiSetVisible( pList, false ) 
    
function PlayerList() 
if ( guiGetVisible( pList ) == false ) then 
    guiGridListClear(pList) 
    guiSetVisible( pList, true ) 
for id, player in ipairs( getElementsByType( "player" ) ) do 
    triggerServerEvent( "update", player ) 
    prow1 = guiGridListAddRow( pList ) 
    guiGridListSetItemText( pList, prow1, pcol1, getPlayerName( player ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol2, getTeamName( getPlayerTeam( player ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol3, tostring( getElementData( player, "time" ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol4, getPlayerPing( player ), false, false ) 
end 
else 
    guiSetVisible( pList, false ) 
    end 
end 
bindKey( "tab", "both", PlayerList ) 

Try that.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That's because you are using getElementData in the value "time" but the value in the server side is "time_v".

local sx, sy = guiGetScreenSize() 
local pList = guiCreateGridList( 300, 300, sx - 600, sy - 600, false ) 
local pcol1 = guiGridListAddColumn( pList, "Name", 0.3 ) 
local pcol2 = guiGridListAddColumn( pList, "Gang", 0.3 ) 
local pcol3 = guiGridListAddColumn( pList, "Spielzeit", 0.175 ) 
local pcol4 = guiGridListAddColumn( pList, "Ping", 0.175 ) 
guiWindowSetMovable( pList, false ) 
guiWindowSetSizable( pList, false ) 
guiSetVisible( pList, false ) 
    
function PlayerList() 
if ( guiGetVisible( pList ) == false ) then 
    guiGridListClear(pList) 
    guiSetVisible( pList, true ) 
for id, player in ipairs( getElementsByType( "player" ) ) do 
    triggerServerEvent( "update", player ) 
    prow1 = guiGridListAddRow( pList ) 
    guiGridListSetItemText( pList, prow1, pcol1, getPlayerName( player ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol2, getTeamName( getPlayerTeam( player ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol3, tostring( getElementData( player, "time_v" ) ), false, false ) 
    guiGridListSetItemText( pList, prow1, pcol4, getPlayerPing( player ), false, false ) 
end 
else 
    guiSetVisible( pList, false ) 
    end 
end 
bindKey( "tab", "both", PlayerList ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Of course it works :) So last thing here. Is it possible to create a function to let the time in the scoreboard be shown like: 12:00 and not only one number like: 12.

And how can I maximaze the minute duration so it counts 1 to the hours? :D

I think you know what I mean :)

Anyway much thanks!

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