Jump to content

loop through wanted players


Cubingo

Recommended Posts

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

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

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

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
  
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

......... 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...