manve1 Posted September 17, 2012 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 ) ____________________________________________________ Looking for tutorials or information? check out: www.simpleask.co.uk
TwiX! Posted September 17, 2012 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 ) - Working on [php/HTML/Mysql/Lua/Java Scripts/Web Design/3D Modeling]
Anderl Posted September 17, 2012 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 "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
manve1 Posted September 17, 2012 Author Posted September 17, 2012 I've got a problem with the grid list. it adds the name over and over again.. never stops. Looking for tutorials or information? check out: www.simpleask.co.uk
Anderl Posted September 17, 2012 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. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
TAPL Posted September 17, 2012 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.
manve1 Posted September 17, 2012 Author Posted September 17, 2012 ty anderl Looking for tutorials or information? check out: www.simpleask.co.uk
Anderl Posted September 17, 2012 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. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
Castillo Posted September 17, 2012 Posted September 17, 2012 He could update it when someone: joins/leaves/changes nick with the following events: onClientPlayerJoin onClientPlayerQuit onClientPlayerChangeNick San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
manve1 Posted September 17, 2012 Author 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 Looking for tutorials or information? check out: www.simpleask.co.uk
TAPL Posted September 17, 2012 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.
Castillo Posted September 17, 2012 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. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Anderl Posted September 17, 2012 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 ._. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
manve1 Posted September 17, 2012 Author Posted September 17, 2012 I've got same problem as with anderl Looking for tutorials or information? check out: www.simpleask.co.uk
Castillo Posted September 17, 2012 Posted September 17, 2012 Yeah, I forgot to clear it first, copy my code again. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
manve1 Posted September 17, 2012 Author Posted September 17, 2012 it stay's on, player left game and it still was on the grid Looking for tutorials or information? check out: www.simpleask.co.uk
Castillo Posted September 17, 2012 Posted September 17, 2012 Must be because it was creating column every time, I moved it outside the update function, copy it again. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
manve1 Posted September 17, 2012 Author Posted September 17, 2012 Still the same, it stay's on Looking for tutorials or information? check out: www.simpleask.co.uk
Jaysds1 Posted September 17, 2012 Posted September 17, 2012 it should work, Did you try restarting the resource and asking you friends to reconnect? My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
manve1 Posted September 17, 2012 Author Posted September 17, 2012 yes .. thats what i always do to test my scripts, use my friends, and tell them to reconnect Looking for tutorials or information? check out: www.simpleask.co.uk
TAPL Posted September 17, 2012 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
Castillo Posted September 17, 2012 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. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Jaysds1 Posted September 17, 2012 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 My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
manve1 Posted September 17, 2012 Author 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 .. Looking for tutorials or information? check out: www.simpleask.co.uk
Castillo Posted September 17, 2012 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. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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