Jump to content

guiShowWindow troubleeesss


bartje01

Recommended Posts

Hey guys. I made a gui window with stats myself. It works by the way. Just one problem

I want that it shows up with /stats. That works But I also want that it closes with /stats once it is visable

  
function playerStats (  ) 
    triggerServerEvent ( "onShowStats", getLocalPlayer()) 
end 
addCommandHandler ( "stats", playerStats ) 
addEvent( "SendAccountData", true ) 
addEventHandler( "SendAccountData", getRootElement(), function(cash,deaths,adminlevel) 
    outputChatBox ( "Money: ".. tostring( cash ) ) 
     outputChatBox ( "Deaths: ".. tostring( deaths)  ) 
     outputChatBox ( "Adminlevel: ".. tostring( adminlevel ) ) 
     local statWindow = guiCreateWindow ( 0.3367,0.0391,0.3352,0.3018, "Stats", true ) 
     guiCreateLabel(0.0676,0.1327,0.0956,0.0550, "Money:", true, statWindow) 
     guiCreateLabel(0.1702,0.1359,0.2153,0.0518, tostring( cash ) , true, statWindow) 
     guiCreateLabel(0.0676,0.2104,0.0956,0.0583, "Deaths:", true, statWindow) 
     guiCreateLabel(0.1725,0.2104,0.1538,0.0550, tostring( deaths ) , true, statWindow) 
     if ( guiGetVisible ( statWindow ) == false ) then 
     guiSetVisible(statWindow, true) 
     else 
     guiSetVisible(statWindow, false) 
     end 
     
end) 
  

I addedthis part

  
if ( guiGetVisible ( statWindow ) == false ) then 
     guiSetVisible(statWindow, true) 
     else 
     guiSetVisible(statWindow, false) 
     end 
  

But then it doesn't show at all :(

Please help

Link to comment

Give it a try... (not tested)

function playerStats() 
    showCursor(true) 
    -- GUI Elements 
    local statWindow = guiCreateWindow ( 0.3367,0.0391,0.3352,0.3018, "Stats", true ) 
    local label1 = guiCreateLabel(0.0676,0.1327,0.0956,0.0550, "Money:", true, statWindow) 
    local label2 = guiCreateLabel(0.1702,0.1359,0.2153,0.0518, "" , true, statWindow) 
    local label3 = guiCreateLabel(0.0676,0.2104,0.0956,0.0583, "Deaths:", true, statWindow) 
    local label4 = guiCreateLabel(0.1725,0.2104,0.1538,0.0550, "" , true, statWindow) 
    -- Element Data 
    local playerMoney = getElementData (getLocalPlayer(), "data.cash") 
    local playerDeaths = getElementData (getLocalPlayer(), "data.deaths") 
    -- Set text for player to show element data 
    guiSetText(label2, playerMoney) 
    guiSetText(label4, playerDeaths) 
    -- Visibility tweaking for stats 
    if guiGetVisible(statWindow) == false then 
        guiSetVisible(statWindow,true) 
    else 
        guiSetVisible(statWindow,false) 
    end 
end 
  
addCommandHandler("stats", playerStats) 

You don't need to trigger any server event for this because you can use element data.

Link to comment
  • Moderators

When you type /stats, it creates the Window so it's visible so when you change his visibilty, the client hides him and when you type again /stats, the client creates another window so it's again visible and the client hides it again ...

Try this and I want that you understand my code:

function playerStats (  ) 
    triggerServerEvent ( "onShowStats", getLocalPlayer()) 
end 
addCommandHandler ( "stats", playerStats ) 
  
addEvent( "SendAccountData", true ) 
addEventHandler( "SendAccountData", getRootElement(), function(cash,deaths,adminlevel) 
    outputChatBox ( "Money: ".. tostring( cash ) ) 
    outputChatBox ( "Deaths: ".. tostring( deaths )  ) 
    outputChatBox ( "Adminlevel: ".. tostring( adminlevel ) ) 
    guiSetText( statWindow_Label1, ""..cash ) -- we change the text in the label 
    guiSetText( statWindow_Label2, ""..deaths )-- we change the text in the label too 
    local visible = guiGetVisible( statWindow ) -- we get if the window is visible (= true ) or if it's not visible (= false ) 
    guiSetVisible( statWindow, not visible ) -- not false = true and not true = false so if is visble(= true ), we hide the window and conversely 
end) 
  
function createStatsWindow() 
    statWindow = guiCreateWindow ( 0.3367,0.0391,0.3352,0.3018, "Stats", true ) 
    guiCreateLabel(0.0676,0.1327,0.0956,0.0550, "Money:", true, statWindow) 
    statWindow_Label1 = guiCreateLabel(0.1702,0.1359,0.2153,0.0518, "" , true, statWindow) 
    guiCreateLabel(0.0676,0.2104,0.0956,0.0583, "Deaths:", true, statWindow) 
    statWindow_Label2 = guiCreateLabel(0.1725,0.2104,0.1538,0.0550, "" , true, statWindow) 
    guiSetVisible( statWindow, false ) 
end 
addEventHandler( "onClientResourceStart", getLocalPlayer(), createStatsWindow ) 

This:

if guiGetVisible(statWindow) == false then 
    guiSetVisible(statWindow,true) 
else 
    guiSetVisible(statWindow,false) 
end 

is the same as:

local visible = guiGetVisible( statWindow )  
guiSetVisible( statWindow, not visible ) 

Tell me if you don't understand something.

Link to comment
  • Moderators

Of course, so...

We create your GUI for the stats and keep the labels empty when the player join the server ( onClientResourceStart ) and we hide it ( guiSetVisible( statWindow, false ) ).

Then when a player tape /stats, the client-side ask, to the server-side, the stats of this player and the Server-Side send the datas to the client-side in the function of the SendAccountData.

Then we write the stats in the 2 empty labels with guiSetText( theLabel, theStat ) and if the window is hidden, we show this window, but if it's already visible, we hide the window.

And why your code doesn't works ? I said it in my latest post:

When you type /stats, it creates the Window so it's visible so when you change his visibilty, the client hides him and when you type again /stats, the client creates another window so it's again visible and the client hides it again ...

But I can explain again why your code doesn't works if you want.

Link to comment
  • Moderators

Yeah it's a correct sentence and you can say too:

Je parles un peu le français.

It's the same.

Now stop the "freeposts" ^^

You can add me on msn if you want to write in french or if you need more help... :mrgreen:

Good night I'm very tired :|

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