Michcio Posted February 24, 2011 Share Posted February 24, 2011 Hi! I have a problem with my gridlist. Gridlist is good, but there aren't any players in it. Please help me! local x,y = getElementPosition(getLocalPlayer()) colshape = createColCircle ( x, y, 20.0 ) playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) guiSetVisible(playerList,false) function createPlayerList () -- Create the grid list -- Create a players column in the list local column = guiGridListAddColumn( playerList, "Player", 0.85 ) if ( column ) then -- If the column has been created, fill it with players for id, playeritem in ipairs(getElementsWithinColShape ( colshape, "player" )) do local row = guiGridListAddRow ( playerList ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) end addEventHandler ( "onClientGUIClick", row, click ) end end addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) function click ( button, state, sx, sy, x, y, z, elem, gui ) -- if state is down ( not to trigger the function twice on mouse button up/down), clicked gui and the element is our player list if ( source == playerList ) then -- get the player name from the selected row, first column local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) outputChatBox ( playerName ) -- output it to chat box end end function visible () guiSetVisible(playerList,true) showCursor(true) end addCommandHandler("pokaz",visible) Link to comment
12p Posted February 24, 2011 Share Posted February 24, 2011 Nice wiki-taken script. Why don't you try to UNDERSTAND it before asking...? Link to comment
Martyz Posted February 24, 2011 Share Posted February 24, 2011 for i, v in ipairs(getElementsByType ("player")) do local row = guiGridListAddRow ( playerList ) guiGridListSetItemText (playerList, row, column, getPlayerName(v), false, false) end Link to comment
#Paper Posted February 24, 2011 Share Posted February 24, 2011 for i, v in ipairs(getElementsByType ("player")) do local row = guiGridListAddRow ( playerList ) guiGridListSetItemText (playerList, row, column, getPlayerName(v), false, false) end martyz i think that he wants to take the player whitin a colshape Link to comment
proracer Posted February 24, 2011 Share Posted February 24, 2011 Line 15 is wrong. 2nd argument 'row' is not a gui element, you should use gridlist .. so try this. local x,y = getElementPosition(getLocalPlayer()) colshape = createColCircle ( x, y, 20.0 ) playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) guiSetVisible(playerList,false) function createPlayerList () -- Create the grid list -- Create a players column in the list local column = guiGridListAddColumn( playerList, "Player", 0.85 ) if ( column ) then -- If the column has been created, fill it with players for id, playeritem in ipairs(getElementsWithinColShape ( colshape, "player" )) do local row = guiGridListAddRow ( playerList ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) end addEventHandler ( "onClientGUIClick", playerList, click ) end end addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) function click ( button) if button == "left" and source == playerList then local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) outputChatBox ( playerName ) function visible () guiSetVisible(playerList,true) showCursor(true) end addCommandHandler("pokaz",visible) Link to comment
Michcio Posted February 24, 2011 Author Share Posted February 24, 2011 It doesnt work Link to comment
proracer Posted February 24, 2011 Share Posted February 24, 2011 Dont just say that... Type: " /debugscript 3 " at least to see any errors. Link to comment
Castillo Posted February 24, 2011 Share Posted February 24, 2011 Line 15 is wrong.2nd argument 'row' is not a gui element, you should use gridlist .. so try this. local x,y = getElementPosition(getLocalPlayer()) colshape = createColCircle ( x, y, 20.0 ) playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) guiSetVisible(playerList,false) function createPlayerList () -- Create the grid list -- Create a players column in the list local column = guiGridListAddColumn( playerList, "Player", 0.85 ) if ( column ) then -- If the column has been created, fill it with players for id, playeritem in ipairs(getElementsWithinColShape ( colshape, "player" )) do local row = guiGridListAddRow ( playerList ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) end addEventHandler ( "onClientGUIClick", playerList, click ) end end addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) function click ( button) if button == "left" and source == playerList then local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) outputChatBox ( playerName ) function visible () guiSetVisible(playerList,true) showCursor(true) end addCommandHandler("pokaz",visible) This makes no sense... he wants to put the player's at the gridlist if i'm not wrong. local x,y = getElementPosition(getLocalPlayer()) colshape = createColCircle ( x, y, 20.0 ) playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) guiSetVisible(playerList,false) function createPlayerList () -- Create the grid list -- Create a players column in the list local column = guiGridListAddColumn( playerList, "Player", 0.85 ) if ( column ) then -- If the column has been created, fill it with players for id, playeritem in ipairs(getElementsByType("player")) do if isElementWithinColShape(playeritem,colshape) then local row = guiGridListAddRow ( playerList ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) end end addEventHandler ( "onClientGUIClick", playerList, click ) end end addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) function click ( button) if button == "left" and source == playerList then local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) outputChatBox ( playerName ) function visible () guiSetVisible(playerList,true) showCursor(true) end addCommandHandler("pokaz",visible) Try that. Link to comment
Michcio Posted February 25, 2011 Author Share Posted February 25, 2011 It hasn't got errors but i don't show me players in colshape. Link to comment
Wojak Posted February 25, 2011 Share Posted February 25, 2011 he did not explain whot this sctipt should do: "I want to create list with nearby players every time i enter the command source: viewtopic.php?f=124&t=32039 Link to comment
Moderators Citizen Posted February 25, 2011 Moderators Share Posted February 25, 2011 Hi Michcio, You have to make 2 parts: - One in Server-Side ( to detect players in colCircle and send the players to the Client-Side ) - One in Client-Side ( to create the Gridlist, to receive the players and show it in the gridlist I have tested it and he works very well: Server-Side: function createTheColCircle( thePlayer, commandName ) if ( colshape ) then -- If another colshape was created before with the command /createCol destroyElement( colshape ) killTimer( timerShape ) end local x,y,z = getElementPosition( thePlayer ) colshape = createColCircle ( x, y, 20.0 ) -- Create the ColCircle timerShape = setTimer( refreshPlayersInColShape, 2000, 0 ) -- Execute the refresh every 2 sec outputChatBox("col created" ) end addCommandHandler( "createCol", createTheColCircle, false, false ) function refreshPlayersInColShape() local nearbyPlayers = getElementsWithinColShape( colshape, "player" ) -- Found all Players in the ColShape for k, i in ipairs ( getElementsByType( "player" ) )do triggerClientEvent(i, "updatePlayerList", getRootElement(), nearbyPlayers ) -- send nearbyPlayers for all clients end end Client-Side: playerList = guiCreateGridList ( 0.70, 0.10, 0.30, 0.60, true ) columnplayerList = guiGridListAddColumn( playerList, "Player", 0.85 ) guiSetVisible(playerList,false) function click ( button ) if button == "left" and source == playerList then local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) outputChatBox ( playerName ) end end function togglePlayerList() local show = guiGetVisible(playerList) guiSetVisible(playerList, not show) showCursor( not show ) end addCommandHandler("pokaz",togglePlayerList) addEvent("updatePlayerList", true) function updatePlayerList( nearbyPlayers ) guiGridListClear(playerList) -- Destroy all rows from the gridlist for k,i in ipairs( nearbyPlayers )do if (getPlayerName(i) ~= getPlayerName( getLocalPlayer() ) )then -- Don't show his name row = guiGridListAddRow(playerList) guiGridListSetItemText(playerList, row, columnplayerList, ""..getPlayerName(i), false, false) addEventHandler( "onClientGUIClick", playerList, click, false) end end end addEventHandler("updatePlayerList", getLocalPlayer(), updatePlayerList) If you don't understand a thing with this script, ask me Link to comment
Castillo Posted February 25, 2011 Share Posted February 25, 2011 Why server side? colshape function is also client side. Link to comment
Moderators Citizen Posted February 25, 2011 Moderators Share Posted February 25, 2011 I'm not sure but I think that the Client side can't detect any other players in the Colshape ( I have to verify it ) And most of all, with the Server-Side, we can send the players who are in the colshape to all clients. Like that every players can see the gridlist with the name of players who are inside the Colshape Do you understand what I mean ? (sorry if I'm not speak very well 'cause I'm French ) And it's work so why not ? 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