tatusmen Posted December 8, 2014 Share Posted December 8, 2014 Hi all. I have to create a script for police fraction and I don't know why this not working. This show me only one player but not all. I want to create a list of players who are within colShape (next to me). Look at this: -- clientside local okno = guiCreateWindow(0.4, 0.3, 0.2, 0.3, "Panel Policji", true) guiWindowSetSizable(okno, false) local wybor = guiCreateComboBox(0.1, 0.2, 0.8, 0.6, "-wybierz-", true, okno) showCursor(true) function wypisywanieGraczy(message) local x, y = guiGetSize(wybor, false) guiSetSize(wybor, x, y+25, false) guiComboBoxClear(wybor) guiComboBoxAddItem(wybor, message) end addEvent("wypisywanieGraczy", true) addEventHandler("wypisywanieGraczy", getRootElement(), wypisywanieGraczy) --serverside: function pobieranieGraczy(plr) local x, y, z = getElementPosition(plr) local strefa = createColCircle(x, y, 50) local gracze = getElementsWithinColShape(strefa, "player") for i,v in pairs(gracze) do nicki = getPlayerName(v) outputChatBox(nicki, plr) -- example: table is working triggerClientEvent(plr, "wypisywanieGraczy", plr, tostring(nicki)) -- combobox isn't working end destroyElement(strefa) end addCommandHandler("x", pobieranieGraczy) Very sorry for my English... Link to comment
novo Posted December 8, 2014 Share Posted December 8, 2014 (edited) Only one player is shown because you're clearing the combo box (guiComboBoxClear) every time wypisywanieGraczy is triggered. You could store the players' name on an array instead, then send it to the client and finally iterate over the same in order to add its values (names) into the combo box. -- clientside local okno = guiCreateWindow(0.4, 0.3, 0.2, 0.3, "Panel Policji", true) guiWindowSetSizable(okno, false) local wybor = guiCreateComboBox(0.1, 0.2, 0.8, 0.6, "-wybierz-", true, okno) showCursor(true) function wypisywanieGraczy (players) local x, y = guiGetSize(wybor, false) guiSetSize(wybor, x, y+25, false) guiComboBoxClear(wybor) for i,v in ipairs(players) do guiComboBoxAddItem(wybor, v) end end addEvent("wypisywanieGraczy", true) addEventHandler("wypisywanieGraczy", getRootElement(), wypisywanieGraczy) --serverside: function pobieranieGraczy(plr) local x, y, z = getElementPosition(plr) local strefa = createColCircle(x, y, 50) local gracze = getElementsWithinColShape(strefa, "player") local players = {} for i,v in pairs(gracze) do local nicki = getPlayerName(v) outputChatBox(nicki, plr) table.insert(players, nicki) --triggerClientEvent(plr, "wypisywanieGraczy", plr, tostring(nicki)) end triggerClientEvent(plr, "wypisywanieGraczy", plr, players) destroyElement(strefa) end addCommandHandler("x", pobieranieGraczy) -- Fixed few mistakes, as referenced down below Edited December 8, 2014 by Guest Link to comment
tatusmen Posted December 8, 2014 Author Share Posted December 8, 2014 I corrected your version becouse you make some mistakes but it's work: -- clientside local okno = guiCreateWindow(0.4, 0.3, 0.2, 0.3, "Panel Policji", true) guiWindowSetSizable(okno, false) local wybor = guiCreateComboBox(0.1, 0.2, 0.8, 0.6, "-wybierz-", true, okno) guiSetVisible(okno, false) function wypisywanieGraczy (players) local x, y = guiGetSize(wybor, false) guiSetSize(wybor, x, y+25, false) guiComboBoxClear(wybor) for i,v in ipairs(players) do guiComboBoxAddItem(wybor, v) end end addEvent("wypisywanieGraczy", true) addEventHandler("wypisywanieGraczy", getRootElement(), wypisywanieGraczy) function dowy() if isCursorShowing() then showCursor(false) else showCursor(true) end if (guiGetVisible(okno) == true) then guiSetVisible(okno, false) else guiSetVisible(okno, true) end end addCommandHandler("y", dowy) --serverside: function pobieranieGraczy(plr) local x, y, z = getElementPosition(plr) local strefa = createColCircle(x, y, 50) local gracze = getElementsWithinColShape(strefa, "player") local players = {} for i,v in pairs(gracze) do local nicki = getPlayerName(v) outputChatBox(nicki, plr) table.insert(players, nicki) --triggerClientEvent(plr, "wypisywanieGraczy", plr, tostring(nicki)) end triggerClientEvent(plr, "wypisywanieGraczy", plr, players) destroyElement(strefa) end addCommandHandler("x", pobieranieGraczy) I'm so happy, thank you very much . 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