bartje01 Posted March 9, 2011 Share Posted March 9, 2011 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
proracer Posted March 9, 2011 Share Posted March 9, 2011 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 Citizen Posted March 9, 2011 Moderators Share Posted March 9, 2011 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
bartje01 Posted March 9, 2011 Author Share Posted March 9, 2011 Hey thanks for helping. I do understand the code. But I don't understand that the script is all different Can you give a little explain of that? Link to comment
Moderators Citizen Posted March 9, 2011 Moderators Share Posted March 9, 2011 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
bartje01 Posted March 9, 2011 Author Share Posted March 9, 2011 Oh I understand it noW Thankyou very many. LOl many Mercii!!!! Link to comment
Moderators Citizen Posted March 9, 2011 Moderators Share Posted March 9, 2011 (edited) You'r welcome ^^ Mercii!!!! Haha Tu vas devenir un vrai français Edited March 9, 2011 by Guest Link to comment
bartje01 Posted March 9, 2011 Author Share Posted March 9, 2011 Je parles un peu de français. Is that a right sentence? Sorry for offtopic. Just having fun here Link to comment
Moderators Citizen Posted March 9, 2011 Moderators Share Posted March 9, 2011 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... Good night I'm very tired Link to comment
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