ViRuZGamiing Posted December 10, 2013 Share Posted December 10, 2013 As the title says but is it possible, Link to comment
Moderators IIYAMA Posted December 10, 2013 Moderators Share Posted December 10, 2013 https://wiki.multitheftauto.com/wiki/DxDrawRectangle yes. But that one on the picture isn't a dx bar. Link to comment
ViRuZGamiing Posted December 10, 2013 Author Share Posted December 10, 2013 I know its a GUI and the dxDraw is moveable? I want not only money to be given i want xp bar to move too with dxDrawRectangle. Example; local x,y = guiGetScreenSize() local rectangle = dxDrawRectangle(x/3.8, y/3.8, x/2.02, y/2, 0, 0, 255) function checkKill if (killer) and (killer ~= source)thengivePlayerMoney (killer, 1000) addEventHandler("onPlayerWasted", getRootElement(), checkKill) end end Sry if its crap im mobile atm Link to comment
Desaster Posted December 10, 2013 Share Posted December 10, 2013 you can create a DX rectangle and set the lenght to "text" for example then in a functions with a timer wish stars every second you get this "text" and add 1 to it so it will be "text+1" idk if you understand me but I am also on mobile lol ps: "" here isn't a string format it represents the script Link to comment
ViRuZGamiing Posted December 11, 2013 Author Share Posted December 11, 2013 so like you mean would be; local x,y = guiGetScreenSize() local rectangle = dxDrawRectangle(x/3.8, y/3.8, x/2.02, y/2, 0, 0, 255) function text x+1 end function checkKill if (killer) and (killer ~= source)then givePlayerMoney (killer, 1) setTimer(text, 1000, 1) addEventHandler("onPlayerWasted", getRootElement(), checkKill) Could this work? i'm on mobile again Link to comment
Dealman Posted December 11, 2013 Share Posted December 11, 2013 Just increase or decrease the width of the rectangle, and it will look like it's moving left/right. Link to comment
ViRuZGamiing Posted December 11, 2013 Author Share Posted December 11, 2013 Can I set the DxDraw Invisible and show up when I get xp? I think this is a bit hard too try... Link to comment
Dealman Posted December 11, 2013 Share Posted December 11, 2013 Well first of all, you're using it wrongly. You need to use onClientRender to draw DirectX Drawings. Otherwise they will only show up for one frame. You can make it invisible/visible by either changing the alpha to 0 or destroying the element. Or you could use removeEventHandler. Example; local screenW, screenH = guiGetScreenSize() -- Assign a local variable to know if it is currently drawing or not. local isCurrentlyDrawing = false function startDrawing() -- Check if it is currently not drawing the rectangle. if(isCurrentlyDrawing == false) then -- Add the event handler to the function containing the drawings. addEventHandler("onClientRender", getRootElement(), stuffToDraw) -- Change the variable to true since you are now drawing it with every frame. isCurrentlyDrawing = true -- Check if it is currently drawing the rectangle. elseif(isCurrentlyDrawing == true) then -- If it is drawing, then remove the event handler. This will stop drawing the rectangle. removeEventHandler("onClientRender", getRootElement(), stuffToDraw) -- And change the variable back to false, since you're no longer drawing. isCurrentlyDrawing = false end end addCommandHandler("draw", startDrawing, false, false) function stuffToDraw() -- Add the drawings you want in here. Do note that this code will be run with every frame. So 30-60 times PER SECOND. Be careful when using other code attached to onClientRender and onClientPreRender. rectangle = dxDrawRectangle(screenW/3.8, screenH/3.8, screenW/2.02, screenH/2, tocolor(187, 0, 0, 150)) I can give you an example of how to do progress later, I need to make some dinner now. Link to comment
ViRuZGamiing Posted December 11, 2013 Author Share Posted December 11, 2013 local x,y = guiGetScreenSize() local isCurrentlyDrawing = false function startDrawing() if(isCurrentlyDrawing == false) then addEventHandler("onClientRender", getRootElement(), stuffToDraw) isCurrentlyDrawing = true elseif(isCurrentlyDrawing == true) then removeEventHandler("onClientRender", getRootElement(), stuffToDraw) isCurrentlyDrawing = false end end function stuffToDraw() rectangle = dxDrawRectangle(screenW/3.8, screenH/3.8, screenW/2.02, screenH/2, tocolor(187, 0, 0, 150)) end function text x+1 end function checkKill if (killer) and (killer ~= source)then givePlayerMoney (killer, 1) setTimer(text, 1000, 1) addEventHandler("onPlayerWasted", getRootElement(), checkKill) Dealman you forgot to end the last function Link to comment
Dealman Posted December 11, 2013 Share Posted December 11, 2013 Here you have a working DirectX Progress Bar, ran via the use of commands. This was written entirely for testing purposes, so you will still have to modify it to do whatever you want it to do. It should be enough for you to do it yourself Commands: /draw This will start drawing the rectangles. Run command again to hide them. /progress This will start progressing the timer with random values. local screenW, screenH = guiGetScreenSize() -- Assign a local variable to know if it is currently drawing or not. local isCurrentlyDrawing = false -- Variable for telling the script whether the timer is active or not. local progressTimer = false -- The total and current progress, this should always be between 0-100. local totalProgress = 0 -- Math for converting the width. Originally the relative size to the screen was 2.575. So when totalProgress is at 100, renderProgress will be at 2.575. This will display the progress bar as full. local renderProgress = (totalProgress/100)/2.575 function startDrawing() -- Check if it is currently not drawing the rectangle. if(isCurrentlyDrawing == false) then -- Add the event handler to the function containing the drawings. addEventHandler("onClientRender", getRootElement(), stuffToDraw) -- Change the variable to true since you are now drawing it with every frame. isCurrentlyDrawing = true -- Check if it is currently drawing the rectangle. elseif(isCurrentlyDrawing == true) then -- If it is drawing, then remove the event handler. This will stop drawing the rectangle. removeEventHandler("onClientRender", getRootElement(), stuffToDraw) -- And change the variable back to false, since you're no longer drawing. isCurrentlyDrawing = false end end addCommandHandler("draw", startDrawing, false, false) function startTheProgress() -- Check so the timer isn't already running. if(progressTimer == false) then -- Change the variable, you know the drill about those from now on. progressTimer = true -- Start the timer, and assign it a variable so it can be killed later. theTimer = setTimer(function() -- Increase the totalProgress with a random value between 0 to 10. local randomProgress = math.random(0, 10) -- Increase the totalProgress with the returned integer from above. totalProgress = totalProgress+randomProgress -- For debugging, will out put the random number and total progress in the format of randomNumber(totalProgress). outputChatBox(tostring(randomProgress).."("..tostring(totalProgress)..")") -- Update the renderProgress variable. renderProgress = (totalProgress/100)/2.575 -- Check if the totalProgress becomes equal to or greater than 100. if(totalProgress >= 100) then -- Set the total progress to 100, in case it became greater than 100. This is to prevent the actual progress bar from becoming wider than the background. totalProgress = 100 -- Update the renderProgress variable, since you change totalProgress above. renderProgress = (totalProgress/100)/2.575 -- Update the timer variable. progressTimer = false -- Message to tell you that the progress became greater than or equal to 100. outputChatBox("Progress greater than or equal to 100, killed timer.") -- Kill the timer so it doesn't keep running. killTimer(theTimer) end end, 1000, 0) else outputChatBox("Already progressing!") end end addCommandHandler("progress", startTheProgress, false, false) function stuffToDraw() -- Add the drawings you want in here. Do note that this code will be run with every frame. So 30-60 times PER SECOND. Be careful when using other code attached to onClientRender and onClientPreRender. backgroundRectangle = dxDrawRectangle(screenW/3.0, screenH/1.4, screenW/2.5, screenH/15.0, tocolor(0, 0, 0, 200)) progressRectangle = dxDrawRectangle(screenW/2.95, screenH/1.38, screenW*renderProgress, screenH/22, tocolor(187, 0, 0, 255)) progressText = dxDrawText("Progress: ("..totalProgress.."%)", screenW/2.15, screenH/1.37, screenW/2.575, screenH/22, tocolor(255, 255, 255, 255), 1, "pricedown") end Edit: If you want the progress bar to extend all across the screen from left to right, you will have to do some small changes, I'm sure you can figure it out! Link to comment
Moderators IIYAMA Posted December 11, 2013 Moderators Share Posted December 11, 2013 jesus..... I thought it was just a xp bar. Not tested. Probably a typo/bug. But you can try it and give a call when it doesn't work. Client local x,y = guiGetScreenSize() local playerXP = 0 local maxPlayerXP = 100000 local colour = tocolor(187, 0, 0, 150) local colourBlack = tocolor(0, 0, 0,255) local startX,startY = x*0.80,y*0.30 -- 0.80 = 80% Left , 0.30 = 30% Down local endX,endY = x*0.90,y*0.33 -- 0.90 = 90% Left , 0.33 = 33% Down local dxW,dxH = endX-startX,endY-startY -- different between the start and the end addEventHandler("onClientRender",root, function() local factor = playerXP/maxPlayerXP -- create a factor. Sample 80 / 100 = 0.8 (80%) dxDrawRectangle(startX,startY, dxW,dxH, colourBlack) -- colour the frame with the colour black. dxDrawRectangle(startX,startY, dxW*factor,dxH, colour) -- overflow the frame with another colour. end) addEvent("newXP",true) addEventHandler("newXP",root, function() playerXP = playerXP+100 if playerXP > maxPlayerXP then -- to prevent a bugged bar, you never know….. maxPlayerXP = playerXP *100 end end) Server --- server --- addEventHandler("onPlayerWasted",root, function (ammo,attacker) if attacker and getElementType(attacker) == "player" then triggerClientEvent(attacker,"newXP",attacker) end end) Good luck. 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