Maurize Posted July 4, 2011 Posted July 4, 2011 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 )
Castillo Posted July 4, 2011 Posted July 4, 2011 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.
Maurize Posted July 4, 2011 Author Posted July 4, 2011 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 )
Castillo Posted July 4, 2011 Posted July 4, 2011 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.
Maurize Posted July 4, 2011 Author Posted July 4, 2011 works. but shows me only "false" instead of the time. ^^
Castillo Posted July 5, 2011 Posted July 5, 2011 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 )
Maurize Posted July 5, 2011 Author Posted July 5, 2011 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? I think you know what I mean Anyway much thanks!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now