Jump to content

Grid list problem


TheIceman1

Recommended Posts

When I start resource, then i have players on grid list, but when i do reconnect then I dont have players on grid list.

for id, player in ipairs(getElementsByType("player")) do 
  if (getPlayerWantedLevel(player) > 0) then 
              local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[2], getPlayerWantedLevel( player ), false, false ) 
  end 
end 

Link to comment

try this:

for _,player in ipairs(getElementsByType("player")) do 
  if (getPlayerWantedLevel(player) > 0) then 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, tostring( player [ 1 ] ), getPlayerName( player ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, tostring( player [ 2 ] ), getPlayerWantedLevel( player )) 
  end  
end 

Link to comment
try this:
for _,player in ipairs(getElementsByType("player")) do 
  if (getPlayerWantedLevel(player) > 0) then 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, tostring( player [ 1 ] ), getPlayerName( player ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, tostring( player [ 2 ] ), getPlayerWantedLevel( player )) 
  end  
end 

Dont work.

@Solidsnake14:But how to put wanted level of players on the grid list?

for id, player in ipairs(getElementsByType("player")) do 
  if (getPlayerWantedLevel(player) > 0) then 
              local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[2], getPlayerWantedLevel( player ), false, false ) 
  end 
end 

This code showing me players and their wanted levels,but problem is that when i do /reconnect the i cant see players on grid list and their wanted levels.

Edited by Guest
Link to comment

try this:

for _, player in ipairs ( getElementsByType( "player" ) ) do 
  local wanted = getPlayerWantedLevel ( player ) 
  if wanted > 0 then 
              local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, GUIEditor_Column[2], wanted, false, false ) 
  end 
end 

Link to comment
try this:
for _, player in ipairs ( getElementsByType( "player" ) ) do 
  local wanted = getPlayerWantedLevel ( player ) 
  if wanted > 0 then 
              local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, GUIEditor_Column[2], wanted, false, false ) 
  end 
end 

Dont work.

Link to comment

Please, use events. Doesn't matter if it's simple script or you need to process more action when starting resource. Events are there to be used and onClientResourceStart is one of them. I don't know why gui editor doesn't put all the gui creation in one onClientResourceStart.

SKIPPER's code will add players to the grid list ONLY if YOUR (local player) wanted level higher than 0. If that's what you want you can use his code, otherwise you need to communicate with the server/client ((triggerServerEvent and triggerClientEvent) if you want to get all players' wanted level so that you can use it in grid list.

Link to comment

Whats wrong here?Nothing happens.

Server:

function wantedplayers () 
local wl = getPlayerWantedLevel ( source ) 
if wl > 0 then 
end 
end 
addEvent ( "wantedplayers", true ) 
addEventHandler ( "wantedplayers", root, wantedplayers ) 

Client:

function setplayers () 
for id, player in ipairs(getElementsByType("player")) do 
  if ( triggerServerEvent ( player, "wantedplayers" ) ) then 
              local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
  end 
end 
end 
addEventHandler ( "onClientResourceStart", getThisResource(), setplayers ) 

Link to comment
Whats wrong here?Nothing happens.

Server:

function wantedplayers () 
local wl = getPlayerWantedLevel ( source ) 
if wl > 0 then 
end 
end 
addEvent ( "wantedplayers", true ) 
addEventHandler ( "wantedplayers", root, wantedplayers ) 

Client:

function setplayers () 
for id, player in ipairs(getElementsByType("player")) do 
  if ( triggerServerEvent ( player, "wantedplayers" ) ) then 
              local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
  end 
end 
end 
addEventHandler ( "onClientResourceStart", getThisResource(), setplayers ) 

Make No Sense .

Link to comment
GUIEditor_Window = {} 
         
GUIEditor_Button = {} 
         
GUIEditor_Label = {} 
         
GUIEditor_Grid = {} 
  
   
GUIEditor_Column = {} 
  
       
GUIEditor_Window[1] = guiCreateWindow(303,111,463,438,"SACR Police computer",false) 
  
guiSetVisible ( GUIEditor_Window[1], false ) 
GUIEditor_Grid[1] = guiCreateGridList(10,26,204,375,false,GUIEditor_Window[1]) 
GUIEditor_Column[1] = guiGridListAddColumn(GUIEditor_Grid[1],"Wanted player",0.5) 
GUIEditor_Column[2] = guiGridListAddColumn(GUIEditor_Grid[1],"Wanted player",0.5) 
  
       
GUIEditor_Button[1] = guiCreateButton(9,408,205,21,"Blip player",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[1] = guiCreateLabel(218,27,241,74,"My informations:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[2] = guiCreateLabel(226,46,224,27,"Account name:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[3] = guiCreateLabel(226,65,227,27,"Arrests:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[4] = guiCreateLabel(226,85,233,26,"Hours:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[5] = guiCreateLabel(226,106,231,28,"Group:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[6] = guiCreateLabel(216,122,240,51,"Wanted player information:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[7] = guiCreateLabel(229,143,213,27,"Account name:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[8] = guiCreateLabel(229,166,223,21,"Hours:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[9] = guiCreateLabel(227,188,214,22,"Group:",false,GUIEditor_Window[1]) 
         
GUIEditor_Label[10] = guiCreateLabel(227,207,221,22,"Wanted level:",false,GUIEditor_Window[1]) 
         
GUIEditor_Button[2] = guiCreateButton(225,380,224,49,"Close",false,GUIEditor_Window[1]) 
  
function setplayers () 
for id, player in ipairs(getElementsByType("player")) do 
  if ( triggerServerEvent ( player, "wantedplayers" ) ) then 
              local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
              guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
  end 
end 
end 
addEventHandler ( "onClientResourceStart", getThisResource(), setplayers ) 

Link to comment

Try

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Grid = {} 
GUIEditor_Column = {} 
  
GUIEditor_Window[1] = guiCreateWindow(303,111,463,438,"SACR Police computer",false) 
guiSetVisible ( GUIEditor_Window[1], false ) 
GUIEditor_Grid[1] = guiCreateGridList(10,26,204,375,false,GUIEditor_Window[1]) 
GUIEditor_Column[1] = guiGridListAddColumn(GUIEditor_Grid[1],"Wanted player",0.5) 
GUIEditor_Column[2] = guiGridListAddColumn(GUIEditor_Grid[1],"Wanted player",0.5) 
GUIEditor_Button[1] = guiCreateButton(9,408,205,21,"Blip player",false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel(218,27,241,74,"My informations:",false,GUIEditor_Window[1]) 
GUIEditor_Label[2] = guiCreateLabel(226,46,224,27,"Account name:",false,GUIEditor_Window[1]) 
GUIEditor_Label[3] = guiCreateLabel(226,65,227,27,"Arrests:",false,GUIEditor_Window[1]) 
GUIEditor_Label[4] = guiCreateLabel(226,85,233,26,"Hours:",false,GUIEditor_Window[1]) 
GUIEditor_Label[5] = guiCreateLabel(226,106,231,28,"Group:",false,GUIEditor_Window[1]) 
GUIEditor_Label[6] = guiCreateLabel(216,122,240,51,"Wanted player information:",false,GUIEditor_Window[1]) 
GUIEditor_Label[7] = guiCreateLabel(229,143,213,27,"Account name:",false,GUIEditor_Window[1]) 
GUIEditor_Label[8] = guiCreateLabel(229,166,223,21,"Hours:",false,GUIEditor_Window[1]) 
GUIEditor_Label[9] = guiCreateLabel(227,188,214,22,"Group:",false,GUIEditor_Window[1]) 
GUIEditor_Label[10] = guiCreateLabel(227,207,221,22,"Wanted level:",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(225,380,224,49,"Close",false,GUIEditor_Window[1]) 
  
function setplayers () 
for id, player in ipairs(getElementsByType("player")) do 
    if (getPlayerWantedLevel(player) > 0) then 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", getThisResource(), setplayers ) 

Link to comment
Try
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Grid = {} 
GUIEditor_Column = {} 
  
GUIEditor_Window[1] = guiCreateWindow(303,111,463,438,"SACR Police computer",false) 
guiSetVisible ( GUIEditor_Window[1], false ) 
GUIEditor_Grid[1] = guiCreateGridList(10,26,204,375,false,GUIEditor_Window[1]) 
GUIEditor_Column[1] = guiGridListAddColumn(GUIEditor_Grid[1],"Wanted player",0.5) 
GUIEditor_Column[2] = guiGridListAddColumn(GUIEditor_Grid[1],"Wanted player",0.5) 
GUIEditor_Button[1] = guiCreateButton(9,408,205,21,"Blip player",false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel(218,27,241,74,"My informations:",false,GUIEditor_Window[1]) 
GUIEditor_Label[2] = guiCreateLabel(226,46,224,27,"Account name:",false,GUIEditor_Window[1]) 
GUIEditor_Label[3] = guiCreateLabel(226,65,227,27,"Arrests:",false,GUIEditor_Window[1]) 
GUIEditor_Label[4] = guiCreateLabel(226,85,233,26,"Hours:",false,GUIEditor_Window[1]) 
GUIEditor_Label[5] = guiCreateLabel(226,106,231,28,"Group:",false,GUIEditor_Window[1]) 
GUIEditor_Label[6] = guiCreateLabel(216,122,240,51,"Wanted player information:",false,GUIEditor_Window[1]) 
GUIEditor_Label[7] = guiCreateLabel(229,143,213,27,"Account name:",false,GUIEditor_Window[1]) 
GUIEditor_Label[8] = guiCreateLabel(229,166,223,21,"Hours:",false,GUIEditor_Window[1]) 
GUIEditor_Label[9] = guiCreateLabel(227,188,214,22,"Group:",false,GUIEditor_Window[1]) 
GUIEditor_Label[10] = guiCreateLabel(227,207,221,22,"Wanted level:",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(225,380,224,49,"Close",false,GUIEditor_Window[1]) 
  
function setplayers () 
for id, player in ipairs(getElementsByType("player")) do 
    if (getPlayerWantedLevel(player) > 0) then 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", getThisResource(), setplayers ) 

Nothing

Link to comment

Can't people read? Are they so lazy?

@SKIPPER,

Especially you. Read my previous post. You can't use getPlayerWantedLevel in a client-side script to get remote player's wanted level... Also, read wiki if unsure.

@TheIceman1,

use triggerServerEvent/triggerClientEvent like you did in your last post but you have to remember that triggerServerEvent will not return the results of the event from server-side. Once you trigger server event and process all the data (get all player's wanted level in this case) then you have to send these information back to the client with a table that holds other player's wanted level.

If the wanted level is set by your resource, then you can use this function:

_setPlayerWantedLevel = setPlayerWantedLevel; 
function setPlayerWantedLevel( player, level ) 
    setElementData( player, "wantedLevel", leve ); 
    return _setPlayerWantedLevel( player, level ); 
end 

So whenever you use setPlayerWantedLevel function, it will call this custom function which will change player's data ("wantedLevel") to whatever level you set. This way you can use the data in client-side script like this:

function setplayers () 
    for id, player in ipairs(getElementsByType("player")) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[2], tostring( getElementData( player, "wantedLevel" ) ), false, false ) 
    end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, setplayers ) 

Link to comment

@50p: But this code showing me "false" or "true",not wanted level.

I remade this code but this showing me only name not wanted level.

Client:

function setplayers () 
    for id, player in ipairs(getElementsByType("player")) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[1], getPlayerName( player ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[2], tostring( getElementData( player, "wantedLevel" ) ), false, false ) 
    end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, setplayers ) 
  

Server:

_getPlayerWantedLevel = getPlayerWantedLevel; 
function getPlayerWantedLevel( player, level ) 
    setElementData( player, "wantedLevel", level ); 
    return _getPlayerWantedLevel( player ); 
end 

Link to comment
...

If the wanted level is set by your resource, then you can use this function:

_setPlayerWantedLevel = setPlayerWantedLevel; 
function setPlayerWantedLevel( player, level ) 
    setElementData( player, "wantedLevel", leve ); 
    return _setPlayerWantedLevel( player, level ); 
end 

So whenever you use setPlayerWantedLevel function, it will call this custom function which will change player's data ("wantedLevel") to whatever level you set. This way you can use the data in client-side script like this:

...

You showed getPlayerWantedLevel which is not setPlayerWantedLevel... Why did you change my code? If you don't modify setPlayerWantedLevel the way I did it, you will NOT change player's data, therefore client-side getElementData will return false.

If you want to show 0 instead of false simply change the the 2nd gui line to:

guiGridListSetItemText ( GUIEditor_Grid[1], row, GUIEditor_Column[2], tostring( getElementData( player, "wantedLevel" ) or 0 ), false, false ) 

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