Jacobob14 Posted April 12, 2015 Share Posted April 12, 2015 how I can make a progress bar with some dxrectangles? something like this Link to comment
Ryancit2 Posted April 12, 2015 Share Posted April 12, 2015 Yes, you'll need a good knowledge of basic mathematics to get client's resolution, then get center, then divide center with number of rectangles and then draw the rectanles. or, i don't know if its better way but you can create a guiLable in bottom-center of client's screen, then draw rectangle images inside it using images, then set image color one by one on regular intervals. Link to comment
Jacobob14 Posted April 12, 2015 Author Share Posted April 12, 2015 please you give me one example? Link to comment
ALw7sH Posted April 12, 2015 Share Posted April 12, 2015 Just a simple progress that you can start from local sX,sY = guiGetScreenSize() local progX = 200 local progY = 25 local moveSpeed = 3 -- per frame local prog = 0 function render() if prog >= progX then removeEventHandler("onClientRender",root,render) triggerEvent("onClientProgressFinish",localPlayer) end dxDrawRectangle((sX/2)-(progX/2)-1,(sY/2)-(progY/2)-1,progX+2,progY+2,tocolor(255,255,255,170)) -- background prog = math.min(prog+moveSpeed,progX) -- move the progress dxDrawRectangle((sX/2)-(progX/2),(sY/2)-(progY/2),prog,progY,tocolor(50,50,50,255)) -- progress end addEventHandler("onClientRender",root,render) Link to comment
Jacobob14 Posted April 18, 2015 Author Share Posted April 18, 2015 but what I want is making a dxprogress but whit several rectangles something like this Link to comment
#RooTs Posted April 19, 2015 Share Posted April 19, 2015 Just a simple progress that you can start from local sX,sY = guiGetScreenSize() local progX = 200 local progY = 25 local moveSpeed = 3 -- per frame local prog = 0 function render() if prog >= progX then removeEventHandler("onClientRender",root,render) triggerEvent("onClientProgressFinish",localPlayer) end dxDrawRectangle((sX/2)-(progX/2)-1,(sY/2)-(progY/2)-1,progX+2,progY+2,tocolor(255,255,255,170)) -- background prog = math.min(prog+moveSpeed,progX) -- move the progress dxDrawRectangle((sX/2)-(progX/2),(sY/2)-(progY/2),prog,progY,tocolor(50,50,50,255)) -- progress end addEventHandler("onClientRender",root,render) not work client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) Link to comment
SpecT Posted April 19, 2015 Share Posted April 19, 2015 Just a simple progress that you can start from local sX,sY = guiGetScreenSize() local progX = 200 local progY = 25 local moveSpeed = 3 -- per frame local prog = 0 function render() if prog >= progX then removeEventHandler("onClientRender",root,render) triggerEvent("onClientProgressFinish",localPlayer) end dxDrawRectangle((sX/2)-(progX/2)-1,(sY/2)-(progY/2)-1,progX+2,progY+2,tocolor(255,255,255,170)) -- background prog = math.min(prog+moveSpeed,progX) -- move the progress dxDrawRectangle((sX/2)-(progX/2),(sY/2)-(progY/2),prog,progY,tocolor(50,50,50,255)) -- progress end addEventHandler("onClientRender",root,render) not work client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) This is client-sided, not server-side ... Link to comment
#RooTs Posted April 19, 2015 Share Posted April 19, 2015 @toni012899, you not know read, my friend ? client.lua client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) Link to comment
Walid Posted April 19, 2015 Share Posted April 19, 2015 You must add type = "client" in your meta file Link to comment
#RooTs Posted April 19, 2015 Share Posted April 19, 2015 ^^The meta is wrong. more is already added type = "client" Link to comment
Walid Posted April 19, 2015 Share Posted April 19, 2015 more is already added type = "client" Are you sure post you meta here. Link to comment
SpecT Posted April 20, 2015 Share Posted April 20, 2015 @toni012899, you not know read, my friend ? client.lua client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) client.lua: 1: attempt to call global 'guiGetScreenSize' ( a nil value ) Yes, I know. Lel, as the guy above said "post your meta here". I saw that it's named client.lua. If it can't call the "guiGetScreenSize" then you has set it as server-side script in the meta. Also the name of the file doesn't mean anything. Link to comment
WhoAmI Posted April 20, 2015 Share Posted April 20, 2015 progressBars = { }; function dxCreateProgressBar ( x, y, width, height, n ) local id = #progressBars + 1; progressBars[id] = { }; progressBars[id]["x"] = x; -- x position progressBars[id]["y"] = y; -- y position progressBars[id]["w"] = width; -- width progressBars[id]["h"] = height; -- height progressBars[id]["n"] = n; -- number of bars progressBars[id]["p"] = 0; -- progress local element = createElement ( "dxProgressBar", tostring ( id ) ); return element; end function dxProgressBarSetProgress ( element, progress ) if ( progress >= 0 and progress <= 1 ) then if ( isElement ( element ) ) then progressBars [ tonumber ( getElementID ( element ) ) ]["p"] = progress; return true; end end return false; end function drawProgressBars ( ) for _, p in pairs ( getElementsByType ( "dxProgressBar" ) ) do local id = tonumber ( getElementID ( p ) ); if ( id ) then local x, y, w, h, n, p = progressBars[id]["x"], progressBars[id]["y"], progressBars[id]["w"], progressBars[id]["h"], progressBars[id]["n"], progressBars[id]["p"]; local widthOfOne = ( w / n ) - 5; local widthOfOneWithBreaks = widthOfOne + 5; for i=0,n do dxDrawRectangle ( x + ( i * widthOfOneWithBreaks ), y, widthOfOne, h, tocolor ( 0, 0, 0, 255 ) ); end local np = math.floor ( ( n * p ) + 0.5 ); local wp = ( ( w + ( n * 5 ) ) * p ) / n for i=0,np do if ( i == np and p ~= 1 ) then widthOfOne = wp end dxDrawRectangle ( x + ( i * widthOfOneWithBreaks ) + 2, y + 2, widthOfOne - 4, h - 4, tocolor ( 255, 255, 255, 255 ) ); end end end end addEventHandler ( "onClientRender", root, drawProgressBars ); Done sth like this, didn't test it properly, but should work. element dxCreateProgressBar ( int x, int y, int width, int height, int n ) bool dxProgressBarSetProgress ( element ProgressBar, int n ) -- 0 to 1 local p = dxCreateProgressBar ( 0, 0, 500, 50, 4 ); dxProgressBarSetProgress ( p, 0.5 ); 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