Cubingo Posted March 31, 2014 Share Posted March 31, 2014 i wanted to loop through all the players online and pickup the wanted's and put them into a gridlist but idk how that works,,, if someone can explain me detailed please, how to loop through the wanted player, and put them into a gridlist i found this at the wiki but idk how to continue local players = getElementsByType ( "player" ) -- get a table of all the players in the server for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player local level = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player if ( level > 0 ) then Link to comment
WhoAmI Posted March 31, 2014 Share Posted March 31, 2014 And add row to gridlist and set this row text. Link to comment
Cubingo Posted March 31, 2014 Author Share Posted March 31, 2014 And add row to gridlist and set this row text. what ? i want an explanation please, the idea is to make a row for each wanted player, not for just 1 Link to comment
WhoAmI Posted March 31, 2014 Share Posted March 31, 2014 So as I am telling. You are looping threw all players, so row would be created for each player. Link to comment
xXMADEXx Posted March 31, 2014 Share Posted March 31, 2014 Note: getPlayerWantedLevel() on the client side returns the client's wanted level, not the defined player. Link to comment
Cubingo Posted April 3, 2014 Author Share Posted April 3, 2014 Sorry for late response, i have made a gridlist which contains all the players online but there is a problem function slapbtn ( thePlayer ,button, state, absoluteX, absoluteY) if ( source == slap_btn ) then local playername = guiGridListGetItemText ( player_namesgrd, guiGridListGetSelectedItem ( player_namesgrd ), column ) if playername then setElementHealth ( playername, 20 ) outputChatBox ( ""..playername.."Done" ) -- Test output end end end addEventHandler( "onClientGUIClick", slap_btn, slapbtn) when i click on the button it outputs the playername but it doesn't set his health bad argument @ 'setElementHealth' and i have a question -- how to make it refresh the list everytime someonejoins ? Link to comment
pa3ck Posted April 3, 2014 Share Posted April 3, 2014 @line 5 setElementHealth ( getPlayerFromName ( playername ), 20 ) Link to comment
.:HyPeX:. Posted April 3, 2014 Share Posted April 3, 2014 Lol guys.. How you wanna set an element health to a "NAME"? Its even obious to read, "NAMES" are not elements, they're usually strings!.. in any case: setElementHealth(player, value) Link to comment
Cubingo Posted April 3, 2014 Author Share Posted April 3, 2014 and i have a question -- how to make it refresh the player list everytime someonejoins ? or when someone leaves ? setTimer ( 'functionname', 5000, 0 ) i know this could work but is there another way of setting a timer ?? Thx for answering, i am still a beginner how could i know if i didn't ask ?? i am sure hypex that you were like me before, but this section which you should ask in, you learnt from it as i do,,, And sorry, another question. how could i loop through a table ?? Link to comment
.:HyPeX:. Posted April 3, 2014 Share Posted April 3, 2014 onPlayerJoin onPlayerQuit setTimer Not sure what else you want Link to comment
Cubingo Posted April 4, 2014 Author Share Posted April 4, 2014 i meant to refresh the gridlist which contains all the players, everytime someone joins, so if someone joined he would be added to the list, i thought of doing it with a timer like refreshing the list every 5 seconds but that will be annoying... function playersin() column = guiGridListAddColumn(player_namesgrd, "Player name", 0.9) if ( column ) then for id, playeritem in ipairs(getElementsByType("player")) do local row = guiGridListAddRow ( player_namesgrd ) guiGridListSetItemText ( player_namesgrd, row, column, getPlayerName ( playeritem ), false, false ) end end end addEventHandler ( "onClientResourceStart", getRootElement(), playersin ) does this will add a player everytime someone joins and will remove him when he leaves or not ? if not then how to make remove him ?? that's my question Link to comment
Anubhav Posted April 4, 2014 Share Posted April 4, 2014 function playersin() column = guiGridListAddColumn(player_namesgrd, "Player name", 0.9) if ( column ) then for id, playeritem in ipairs(getElementsByType("player")) do local row = guiGridListAddRow ( player_namesgrd ) guiGridListSetItemText ( player_namesgrd, row, column, getPlayerName ( playeritem ), false, false ) end end end addEventHandler ( "onClientResourceStart", getRootElement(), playersin ) setTimer(playersin,10000,0) Link to comment
Cubingo Posted April 4, 2014 Author Share Posted April 4, 2014 i said i don't want it to be with a timer, i just want it to refresh everytime someone joins or leaves... Link to comment
cheez3d Posted April 4, 2014 Share Posted April 4, 2014 Instead of setTimer use "onPlayerJoin", "onPlayerLeave" and "onElementDataChange" with setElementData(player,"wanted_level",getPlayerWantedLevel(player)). Link to comment
.:HyPeX:. Posted April 5, 2014 Share Posted April 5, 2014 ......... took me 3 mins.. Server: function onPlayerJQ(state) triggerClientEvent(getRootElement(), "RefreshGrid", source,state) end addEventHandler("onPlayerJoin", getRootElement(), onPlayerJQ, "join") addEventHandler("onPlayerQuit", getRootElement(), onPlayerJQ, "left") Client: function RefreshGridList(state) local Player = source -- Player Who Left / Join local state = state -- Can be "join" or "left" @Source --Do your stuff here for updating. end addEvent("RefreshGrid", true) addEventHandler("RefreshGrid", getRootElement(), RefreshGridList) 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