Jump to content

GUI refreshing for one client


DarkLink

Recommended Posts

Okay guys, I made a gui to count players alive on each team.

But it just refresh for the player that dies :S

I cant get what is wrong :S

Here is my code:

server-side:

  
setTimer(triggerClientEvent, 1000, 1, "colocarNrJogadores", root, team_immigrantsSP, team_policeSP) -- that optional arguments are variables with teams. players are already set on them, before this timer. 
  

client-side:

  
            X = 0.65 
        Y = 0.055 
        Width = 0.1 
        Height = 0.1 
        numbersOfPlayersTeam = guiCreateWindow(X, Y, Width, Height, "EMI vs POL", true) 
        guiWindowSetMovable( numbersOfPlayersTeam, false) 
        guiWindowSetSizable( numbersOfPlayersTeam, false) 
        guiSetVisible(numbersOfPlayersTeam, false) 
        nrAliveEMI = guiCreateLabel ( 0.23, 0.34, 0.5, 1, "0", true, numbersOfPlayersTeam ) 
        nrAlivePOL = guiCreateLabel ( 0.64, 0.34, 0.5, 1, "0", true, numbersOfPlayersTeam ) 
        guiSetFont ( nrAliveEMI, "sa-header" ) 
        guiSetFont ( nrAlivePOL,"sa-header" ) 
        guiLabelSetColor ( nrAliveEMI, 205, 133, 63 ) 
        guiLabelSetColor ( nrAlivePOL, 0, 0, 255 ) 
  
  
  
  
addEvent("colocarNrJogadores",true) 
    function colocarJogadoresNoGUI(team_immigrantsSP, team_policeSP) 
         
        setTimer(function(team_immigrantsSP, team_policeSP) local nr1, nr2 = getPlayersInTeam(team_immigrantsSP), getPlayersInTeam(team_policeSP) colocarNrAliveNoGUI(nr1,nr2) end, 1000,0, team_immigrantsSP, team_policeSP) 
         
    end 
addEventHandler("colocarNrJogadores", getRootElement(), colocarJogadoresNoGUI) 
  
    function colocarNrAliveNoGUI(nr1, nr2) 
        local qtd = 0 
        for i, v in ipairs (nr1) do 
             
            if(not isPlayerDead(v)) then 
                qtd = qtd + 1 
            end 
             
        end 
        guiSetText ( nrAliveEMI, tostring(qtd) ) 
        qtd = 0 
        for i, k in ipairs (nr2) do 
             
            if(not isPlayerDead(k)) then 
                qtd = qtd +1 
            end 
        end 
     
        guiSetText ( nrAlivePOL, tostring(qtd) ) 
         
    end 
  

Thanks in advance, I hope someone finds the problem :S

EDIT: if u guys dont understand, the problem is, on start there are 1 - 1 on gui (one player on each team)

when a player dies his GUI changes to 0 - 1, but on the other client it stays 1 - 1, cant understand why?

thanks!!

Link to comment

Use this custom function:

addEvent("colocarNrJogadores",true) 
    function colocarJogadoresNoGUI(team_immigrantsSP, team_policeSP) 
        setTimer(function(team_immigrantsSP, team_policeSP) colocarNrAliveNoGUI(team_immigrantsSP,team_policeSP) end, 1000,0, team_immigrantsSP, team_policeSP) 
    end 
addEventHandler("colocarNrJogadores", getRootElement(), colocarJogadoresNoGUI) 
  
function colocarNrAliveNoGUI(team1, team2) 
        local qtd = #getAlivePlayersInTeam(team1) or 0 
        guiSetText ( nrAliveEMI, tostring(qtd) ) 
        local qtd2 = #getAlivePlayersInTeam(team2) or 0 
        guiSetText ( nrAlivePOL, tostring(qtd2) ) 
end 
     
function getAlivePlayersInTeam(theTeam) 
local theTable = { } 
local players = getPlayersInTeam(theTeam) 
for i,v in pairs(players) do 
if not isPlayerDead(v) then 
    theTable[#theTable+1]=v 
    end 
end 
return theTable 
end 

I tested it and works fine.

Link to comment

Thanks for ur help, but still not working here.

The gui just change the numbers on client that die, I cant understand this baah :x

In my mind there is no problem here.. but might be, its not working perfect ..

Thanks guys

EDIT: Found these errors on clientscript:

[2011-07-12 23:11:30] WARNING: borderpatrol\client_logingui.lua:194: Bad argument @ 'getPlayersInTeam'

[2011-07-12 23:11:30] ERROR: borderpatrol\client_logingui.lua:195: bad argument #1 to 'pairs' (table expected, got boolean)

its the lines on the function getAlivePlayersInTeam :

local players = getPlayersInTeam(theTeam)

for i,v in pairs(players) do

Link to comment

Maybe try this:

addEvent("colocarNrJogadores",true) 
    function colocarJogadoresNoGUI(team_immigrantsSP, team_policeSP) 
        setTimer(function() colocarNrAliveNoGUI(team_immigrantsSP,team_policeSP) end, 1000,0) 
    end 
addEventHandler("colocarNrJogadores", getRootElement(), colocarJogadoresNoGUI) 
  
function colocarNrAliveNoGUI(team1, team2) 
        local qtd = #getAlivePlayersInTeam(team1) or 0 
        guiSetText ( nrAliveEMI, tostring(qtd) ) 
        local qtd2 = #getAlivePlayersInTeam(team2) or 0 
        guiSetText ( nrAlivePOL, tostring(qtd2) ) 
end 
    
function getAlivePlayersInTeam(theTeam) 
local theTable = { } 
local players = getPlayersInTeam(theTeam) 
for i,v in pairs(players) do 
if not isPlayerDead(v) then 
    table.insert(theTable, v) 
    end 
end 
return theTable 
end 

Link to comment
Maybe try this:
addEvent("colocarNrJogadores",true) 
    function colocarJogadoresNoGUI(team_immigrantsSP, team_policeSP) 
        setTimer(function() colocarNrAliveNoGUI(team_immigrantsSP,team_policeSP) end, 1000,0) 
    end 
addEventHandler("colocarNrJogadores", getRootElement(), colocarJogadoresNoGUI) 
  
function colocarNrAliveNoGUI(team1, team2) 
        local qtd = #getAlivePlayersInTeam(team1) or 0 
        guiSetText ( nrAliveEMI, tostring(qtd) ) 
        local qtd2 = #getAlivePlayersInTeam(team2) or 0 
        guiSetText ( nrAlivePOL, tostring(qtd2) ) 
end 
    
function getAlivePlayersInTeam(theTeam) 
local theTable = { } 
local players = getPlayersInTeam(theTeam) 
for i,v in pairs(players) do 
if not isPlayerDead(v) then 
    table.insert(theTable, v) 
    end 
end 
return theTable 
end 

Didnt worked too..

On client that die its all fine, but now I notice that on other client it go 0 - 1, but right on next second it goes back to 1 - 1, and other client is still dead.. this is very strange :S

Thanks in advance guys!

Link to comment

Guys found the problem, changed from

  
if not isPlayerDead(v) then 
    table.insert(theTable, v) 
    end 
  
  

to

  
if getElementHealth(v) ~= 0 then 
        table.insert(theTable, v) 
        end 
     
  

Guys its not the first time I found a function not working like the wiki says..

We need more testeres reporting this, I dont know how to report bugs, but look if someone knows, just report this bug to the mta team!!

isPlayerDead was not working on client properly!

THANKS alot castillo and jacob ;)

Link to comment
I was going to suggest you to use that, but I never used isPlayerDead before so I didn't know about that function.

P.S: No problem :).

Hm okay thanks bro, since u are MLM can u report bugs to mta team?

This is important to all scripters, I guess :S

Dont wanna more scripters losing their time like me, when they dont know where the problem comes from :S

Thanks castillo

Link to comment
Maybe that function is designed to check if the client is alive?

P.S: Everyone can report bugs, just head to the bug tracker and report it.

And a client alive is different of a player alive right? might be the problem.. dont know much too about it.

Just there is some kinda of problem with it, or wiki tells bad information, might do another thing.. not what is on wiki!

I will report it on that bug tracker, thanks ;)

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