manve1 Posted September 17, 2012 Share Posted September 17, 2012 I need double help, on same script but for 2 different things. ___________________________________________________________ 1. I tried making grid list with player names, but when i try making that it refreshes every 50miliseconds, i fail, so i only see other player names after restart. function playerList() local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) if ( Column ) then for id, player in ipairs(getElementsByType("player")) do local Row = guiGridListAddRow ( Grid ) setTimer( function ( ) guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) end ,50, 0 ) end end end addEventHandler("onClientResourceStart", root, playerList) _______________________________________________________________ 2. I'm making on same script label's which tells player name once selected on grid List the name. player_name = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ", true, Wnd ) player_name2 = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ".. getPlayerName ( localPlayer ):gsub ( "#%x%x%x%x%x%x", "" ), true, Wnd ) function change_name() local row = guiGridListGetSelectedItem ( Grid ) if ( row ~= -1 ) then guiSetText( player_name, guiGetText(player_name2) ) end end addEventHandler ( "onClientGUIClick", Grid, change_name, false ) ____________________________________________________ Link to comment
TwiX! Posted September 17, 2012 Share Posted September 17, 2012 Try function playerList() local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) if ( Column ) then for id, player in ipairs(getElementsByType("player")) do local Row = guiGridListAddRow ( Grid ) guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), playerList) addEventHandler ( "onClientPlayerJoin", root, playerList ) player_name = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ", true, Wnd ) player_name2 = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ".. getPlayerName ( localPlayer ):gsub ( "#%x%x%x%x%x%x", "" ), true, Wnd ) function change_name() local row = guiGridListGetSelectedItem ( Grid ) if ( row ~= -1 ) then outputChatBox("* Please select a player!",255,255,255,true) return end guiSetText( player_name, guiGetText(player_name2) ) end addEventHandler ( "onClientGUIClick", Grid, change_name, false ) Link to comment
Anderl Posted September 17, 2012 Share Posted September 17, 2012 (edited) First code: local pColumn = guiGridListAddColumn(Grid, 'Player', 0.85) addEventHandler('onClientResourceStart', resourceRoot, function() if (pColumn) then for k,v in next, getElementsByType 'player' do guiGridListSetItemText(Grid, guiGridListAddRow(Grid), pColumn, getPlayerName(v):gsub('#%x%x%x%x%x%x', ''), false, false) pTimer = setTimer(updateList, 2000, 0) end end end ) function updateList() for i = 1, #guiGridListGetRowCount(Grid) do guiGridListRemoveRow(Grid, i) end for k,v in next, getElementsByType 'player' do guiGridListSetItemText(Grid, guiGridListAddRow(Grid), pColumn, getPlayerName(v):gsub('#%x%x%x%x%x%x', ''), false, false) end end Second code: local pNameLabel = guiCreateLabel(0.325, 0.1, 0.5, 0.2, 'Player Name: ', true, Wnd) addEventHandler('onClientGUIClick', Grid, function() if (pNameLabel) then local pRow = guiGridListGetSelectedItem(source) if (pRow and pRow ~= -1) then guiSetText(pNameLabel, 'Player Name: ' .. guiGridListGetItemText(source, pRow, 1)) end end end, false ) Edited September 17, 2012 by Guest Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 I've got a problem with the grid list. it adds the name over and over again.. never stops. Link to comment
Anderl Posted September 17, 2012 Share Posted September 17, 2012 I've got a problem with the grid list. it adds the name over and over again.. never stops. Ops, my bad; I forgot to remove rows before update, copy my code again. Link to comment
TAPL Posted September 17, 2012 Share Posted September 17, 2012 You shouldn't use timer, if you use timer and clear the grid list and then re add the rows, you will not be able to select anything in the grid list. You should update the grid list with events onClientPlayerJoin and onClientPlayerQuit and onClientPlayerChangeNick. Link to comment
Anderl Posted September 17, 2012 Share Posted September 17, 2012 You shouldn't use timer, if you use timer and clear the grid list and then re add the rows, you will not be able to select anything in the grid list.You should update the grid list with events onClientPlayerJoin and onClientPlayerQuit and onClientPlayerChangeNick. It's updated every 2 seconds, there's nothing stopping from select anything. Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 He could update it when someone: joins/leaves/changes nick with the following events: onClientPlayerJoin onClientPlayerQuit onClientPlayerChangeNick Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 (edited) I am sorry, but Anderl, the grid list player names isn't being updated EDIT: everything i tried to change, isn't updating .. Edited September 17, 2012 by Guest Link to comment
TAPL Posted September 17, 2012 Share Posted September 17, 2012 You shouldn't use timer, if you use timer and clear the grid list and then re add the rows, you will not be able to select anything in the grid list.You should update the grid list with events onClientPlayerJoin and onClientPlayerQuit and onClientPlayerChangeNick. It's updated every 2 seconds, there's nothing stopping from select anything. Try to select anything and after 2 second, you will lose what you select and the scroll bar will back to top again. Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 local Column = guiGridListAddColumn ( Grid, "Player", 0.85 ) function playerList ( ) guiGridListClear ( Grid ) if ( Column ) then for _, player in ipairs ( getElementsByType ( "player" ) ) do local Row = guiGridListAddRow ( Grid ) guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) end end end addEventHandler ( "onClientResourceStart", resourceRoot, playerList ) addEventHandler ( "onClientPlayerJoin", root, playerList ) addEventHandler ( "onClientPlayerQuit", root, playerList ) addEventHandler ( "onClientPlayerChangeNick", root, playerList ) @Anderl: You could have used: guiGridListClear instead of: for i = 1, #guiGridListGetRowCount(Grid) do guiGridListRemoveRow(Grid, i) end Also, you placed the timer inside the for-loop. Link to comment
Anderl Posted September 17, 2012 Share Posted September 17, 2012 function playerList ( ) local Column = guiGridListAddColumn ( Grid, "Player", 0.85 ) if ( Column ) then for _, player in ipairs ( getElementsByType ( "player" ) ) do local Row = guiGridListAddRow ( Grid ) guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) end end end addEventHandler ( "onClientResourceStart", resourceRoot, playerList ) addEventHandler ( "onClientPlayerJoin", root, playerList ) addEventHandler ( "onClientPlayerQuit", root, playerList ) addEventHandler ( "onClientPlayerChangeNick", root, playerList ) @Anderl: You could have used: guiGridListClear instead of: for i = 1, #guiGridListGetRowCount(Grid) do guiGridListRemoveRow(Grid, i) end Also, you placed the timer inside the for-loop. Heh, my bad, didn't even see ._. Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 I've got same problem as with anderl Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 Yeah, I forgot to clear it first, copy my code again. Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 it stay's on, player left game and it still was on the grid Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 Must be because it was creating column every time, I moved it outside the update function, copy it again. Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 Still the same, it stay's on Link to comment
Jaysds1 Posted September 17, 2012 Share Posted September 17, 2012 it should work, Did you try restarting the resource and asking you friends to reconnect? Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 yes .. thats what i always do to test my scripts, use my friends, and tell them to reconnect Link to comment
TAPL Posted September 17, 2012 Share Posted September 17, 2012 (edited) Try function playerList() Column = guiGridListAddColumn(Grid, "Player", 0.85) if (Column) then for _, player in ipairs (getElementsByType("player")) do local Row = guiGridListAddRow(Grid) guiGridListSetItemText (Grid, Row, Column, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) end end end addEventHandler("onClientResourceStart", resourceRoot, playerList) function updateList(old, new) if eventName == "onClientPlayerJoin" then local i = guiGridListAddRow(Grid) guiGridListSetItemText(Grid, i, Column, getPlayerName(source):gsub("#%x%x%x%x%x%x", ""), false, false) elseif eventName == "onClientPlayerQuit" then for i=0, guiGridListGetRowCount(Grid) do if guiGridListGetItemText(Grid, i, Column) == getPlayerName(source):gsub("#%x%x%x%x%x%x", "") then guiGridListRemoveRow(Grid, i) end end elseif eventName == "onClientPlayerChangeNick" then for i=0, guiGridListGetRowCount(Grid) do if guiGridListGetItemText(Grid, i, Column) == old then guiGridListSetItemText(Grid, i, Column, new, false, false) end end end end addEventHandler("onClientPlayerJoin", root, updateList) addEventHandler("onClientPlayerQuit", root, updateList) addEventHandler("onClientPlayerChangeNick", root, updateList) Edited September 17, 2012 by Guest Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 @TAPL: if eventName == "onClientPlayerJoin" then guiGridListSetItemText(Grid, i, Column, getPlayerName(source):gsub("#%x%x%x%x%x%x", ""), false, false) "i" is not defined anywhere. @manve1: My script should work just fine. Link to comment
Jaysds1 Posted September 17, 2012 Share Posted September 17, 2012 (edited) Try this: local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) function playerList() if not isElement(Grid) then outputDebugString("Column/Grid not created!") return end for _, player in ipairs(getElementsByType("player")) do guiGridListSetItemText ( Grid, guiGridListAddRow ( Grid ), Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) end end addEventHandler("onClientResourceStart",resourceRoot, playerList) addEventHandler("onClientPlayerJoin", root, playerList) addEventHandler("onClientPlayerQuit", root, playerList) addEventHandler("onClientPlayerChangeNick", root, playerList) player_name = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ", true, Wnd ) --label is created first player_name2 = "PlayerName: "..getPlayerName ( localPlayer ):gsub ( "#%x%x%x%x%x%x", "" ) function change_name() local row = guiGridListGetSelectedItem ( Grid ) if row == -1 then guiSetText(player_name,player_name2) else guiSetText( player_name,guiGridListGetItemText(Grid,row,1)) end end addEventHandler ( "onClientGUIClick", Grid, change_name, false ) Edited September 17, 2012 by Guest Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 after reconnect didn't add my friend, but when left, he got removed. EDIT: Jay, ur's didn't even add player's .. Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 Try this:function playerList() if not isElement(Column) then local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) end if not(isElement(Column) or isElement(Grid)) then outputDebugString("Column/Grid not created!") return end for _, player in ipairs(getElementsByType("player")) do guiGridListSetItemText ( Grid, guiGridListAddRow ( Grid ), Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) end end addEventHandler("onClientResourceStart",resourceRoot, playerList) addEventHandler("onClientPlayerJoin", root, playerList) addEventHandler("onClientPlayerQuit", root, playerList) addEventHandler("onClientPlayerChangeNick", root, playerList) Columns aren't elements. Link to comment
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