Cubingo Posted March 31, 2014 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
Cubingo Posted March 31, 2014 Author 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
WhoAmI Posted March 31, 2014 Posted March 31, 2014 So as I am telling. You are looping threw all players, so row would be created for each player.
xXMADEXx Posted March 31, 2014 Posted March 31, 2014 Note: getPlayerWantedLevel() on the client side returns the client's wanted level, not the defined player.
Cubingo Posted April 3, 2014 Author 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 ?
pa3ck Posted April 3, 2014 Posted April 3, 2014 @line 5 setElementHealth ( getPlayerFromName ( playername ), 20 )
.:HyPeX:. Posted April 3, 2014 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)
Cubingo Posted April 3, 2014 Author 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 ??
.:HyPeX:. Posted April 3, 2014 Posted April 3, 2014 onPlayerJoin onPlayerQuit setTimer Not sure what else you want
Cubingo Posted April 4, 2014 Author 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
Anubhav Posted April 4, 2014 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)
Cubingo Posted April 4, 2014 Author 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...
cheez3d Posted April 4, 2014 Posted April 4, 2014 Instead of setTimer use "onPlayerJoin", "onPlayerLeave" and "onElementDataChange" with setElementData(player,"wanted_level",getPlayerWantedLevel(player)).
.:HyPeX:. Posted April 5, 2014 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)
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