kieran Posted August 10, 2017 Share Posted August 10, 2017 (edited) I am messing with progress bars as I plan to make some jobs which require them, the problem is I can't figure out how to check the percentage of the progress bar... I am basically trying to start it as red, if it's 100% it will change to green. Here's what I tried. Progress_Window = {} function clientResourceStart( ) Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) if ( somebar ) then progress = guiProgressBarGetProgress(somebar)--Problem starts here. if (progress) >= (tonumber (100)) then guiSetProperty(Progress_Window, "CaptionColour", "FF00FF00") else --Problem ends here. setTimer ( function() guiProgressBarSetProgress(somebar, progress+10) --See below example. end, 2000, 10 ) else outputChatBox ("Something went wrong!") --See below example. end end end addEventHandler( "onClientResourceStart", resourceRoot, clientResourceStart ) --See below example. And here is my original script that doesn't change color. Progress_Window = {} function clientResourceStart( ) Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) --Creates it in window at bottom, will be more visually pleasing later. if ( somebar ) then setTimer ( function() --Timer will change progress by 10% every 2 seconds. progress = guiProgressBarGetProgress(somebar) guiProgressBarSetProgress(somebar, progress+10) end, 2000, 10 ) else outputChatBox ("Something went wrong!") end end addEventHandler( "onClientResourceStart", resourceRoot, clientResourceStart )--Will be changed later, just getting used to it for now. I also wish to create a small label with the percentage showing, how could I do this? I know I need to do "progress = guiProgressBarGetProgress(somebar)" but what after that? Thanks for all help/suggestions! Edited August 10, 2017 by kieran Link to comment
NeXuS™ Posted August 10, 2017 Share Posted August 10, 2017 Progress_Window = {} function clientResourceStart( ) Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) if ( somebar ) then progress = guiProgressBarGetProgress(somebar) else setProgress = setTimer(function() guiProgressBarSetProgress(somebar, progress+10) if (progress) >= (tonumber (100)) then guiSetProperty(Progress_Window, "CaptionColour", "FF00FF00") killTimer(setProgress) end end, 2000, 10) else outputChatBox ("Something went wrong!") end end addEventHandler( "onClientResourceStart", resourceRoot, clientResourceSt Try this one. Link to comment
kieran Posted August 10, 2017 Author Share Posted August 10, 2017 @NeXuS™Nope, still not working, I know, there was 1 or 2 typos you made, but sorted them and still no result, kills the timer after it goes to 10, the whole idea was to check the progress outside the timer.... Progress_Window = {} function clientResourceStart( ) Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) if ( somebar ) then progress = guiProgressBarGetProgress(somebar) --The else here said it wanted to close line 9 with end setProgress = setTimer(function() guiProgressBarSetProgress(somebar, progress+10) if (progress) >= (tonumber (100)) then guiSetProperty(Progress_Window, "CaptionColour", "FF00FF00") killTimer(setProgress) end end, 2000, 10) else outputChatBox ("Something went wrong!") end end addEventHandler( "onClientResourceStart", resourceRoot, clientResourceStart) --Sorted that Link to comment
NeXuS™ Posted August 10, 2017 Share Posted August 10, 2017 (edited) You can't check the progress outside of the timer. Run your head through the code if you don't understand it totally. Progress_Window = {} function clientResourceStart( ) Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) if ( somebar ) then setProgress = setTimer(function() guiProgressBarSetProgress(somebar, progress+10) progress = guiProgressBarGetProgress(somebar) if (progress) >= (tonumber (100)) then guiSetProperty(Progress_Window, "CaptionColour", "FF00FF00") killTimer(setProgress) end end, 2000, 10) else outputChatBox ("Something went wrong!") end end addEventHandler( "onClientResourceStart", resourceRoot, clientResourceStart) --Sorted that Check this. Edited August 10, 2017 by NeXuS™ 1 Link to comment
kieran Posted August 10, 2017 Author Share Posted August 10, 2017 @NeXuS™ It now works! I switched the code round a bit, thanks a lot bud! Can finally start adding this GUI to markers now. Spoiler Progress_Window = {} function clientResourceStart( ) Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) if ( somebar ) then setProgress = setTimer(function() progress = guiProgressBarGetProgress(somebar) if (progress) >= (tonumber (100)) then guiSetProperty(Progress_Window, "CaptionColour", "FF00FF00") killTimer(setProgress) elseif (progress) <= (tonumber (100)) then guiProgressBarSetProgress(somebar, progress+10) end end, 2000, 0) else outputChatBox ("Something went wrong!") end end addEventHandler( "onClientResourceStart", resourceRoot, clientResourceStart) --Sorted that Oh, and if you don't mind me asking unrelated question, how could I go about giving a player data, such as iron = 10 or tokens = 10 or something? Would it be as simple as exporting to xml? Link to comment
NeXuS™ Posted August 10, 2017 Share Posted August 10, 2017 What do you want to do with the player data? Link to comment
kieran Posted August 10, 2017 Author Share Posted August 10, 2017 (edited) 19 minutes ago, NeXuS™ said: What do you want to do with the player data? Basically my idea was to get progress bar, after it is complete a player would recieve a certain amount of an item and it would be added to an existing amount, like when you give a player money! I also want to get that number and place it in as a label or something, but I am unsure how to save it or even create it, I have found xmCreateChild which I think would work, but would be unsure how to get the data..... (Obviously need more than xmlCreateChild, but is one I thought would best describe my idea.) Edited August 10, 2017 by kieran Link to comment
NeXuS™ Posted August 10, 2017 Share Posted August 10, 2017 It wouldn't be such a good idea, use elementdata or accountdata, or at last, you can use a database. 1 Link to comment
kieran Posted August 10, 2017 Author Share Posted August 10, 2017 Ah, okay, will look into it! Thanks again. Oh and good luck on the DX stuff! 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