GerardWay Posted July 13, 2014 Share Posted July 13, 2014 Hey, I was wondering how I can create a progressbar at the top of the screen of every player, showing how much health this bot has left. It should start at 100 and end on 0 depending on the health. It would also need "Nemesis Health - (Amount of Health)" wrote above it function boss ( ) Nemesis = exports [ "slothBot" ]:spawnBot ( -1935.5480957031, 665.44055175781, 47.0, 90, 312, 0, 0, Nemesis, 0, "chasing", true ) exports.extra_health:setElementExtraHealth ( Nemesis, 2500 ) outputChatBox ("Nemesis has spawned! Go and defeat him!",localPlayer,255,0,0,true) myBlip = (createBlipAttachedTo ( Nemesis, 23 )) setElementData ( Nemesis, "nemesis", true ) triggerClientEvent(root, "nemesishp", root, Nemesis) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), boss ) Any help is appreciated! Link to comment
ADCX Posted July 13, 2014 Share Posted July 13, 2014 How about guiCreateProgressBar ? https://wiki.multitheftauto.com/wiki/Gu ... rogressBar Link to comment
#DRAGON!FIRE Posted July 13, 2014 Share Posted July 13, 2014 user .. at Client Side Event : onClientRender guiCreateProgressBar math.floor getElementHealth guiProgressBarSetProgress and use removeEventHandler + destroyElement when close panel or if u want remove the progress Link to comment
GerardWay Posted July 14, 2014 Author Share Posted July 14, 2014 possible example please? Link to comment
Dealman Posted July 14, 2014 Share Posted July 14, 2014 Here's a bit overly complicated way of doing it, so I'll just quote myself. There are some easier ways of doing it, of course. But this might be able to help you get on your feet, and make it yourself - there's no better way of learning than that. 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
GerardWay Posted September 2, 2014 Author Share Posted September 2, 2014 I know I really shouldn't bump a topic, but it's kind of important So I tried to create it myself, but it failed a lot of times and I was wondering if someone could possibly add it in for me. I know it's not normally a thing for you guys to do it for the guy that needs help, but I keep fucking up hahah Link to comment
Ab-47 Posted September 2, 2014 Share Posted September 2, 2014 How about post the code you've made and we'll try fix it up or notify where you went wrong? Link to comment
GerardWay Posted September 2, 2014 Author Share Posted September 2, 2014 I erased it ^ I'm now back with the code that is at the start of this topic Link to comment
GerardWay Posted September 3, 2014 Author Share Posted September 3, 2014 Sorry for the Double-Post, but can anyone help out please? Link to comment
Saml1er Posted September 3, 2014 Share Posted September 3, 2014 This isn't your code, you simply took it from slothbot resource. Nice try. Link to comment
GerardWay Posted September 6, 2014 Author Share Posted September 6, 2014 Excuse me, could you point out when I actually said this was my resource? If you look closely, I didn't. Link to comment
LabiVila Posted September 6, 2014 Share Posted September 6, 2014 Hey, a progress bar isn't the best solution, this is a script which shows Health bar and Nitro Bar. It has an ugly appearance but the script is very simple and easy to understand. It's not a guiProgressBar tho, it's dx... just copy and paste it client-side and it'll work... local x,y = guiGetScreenSize () addEventHandler ("onClientRender", root, function (source) local pVehicle = getPedOccupiedVehicle (localPlayer) if pVehicle then local vHealth = (getElementHealth (pVehicle)-250)/10 if vHealth < 0 then vHealth = 0 end dxDrawLine (x/1.05, y/2.1, x/1.05, y/2.40, tocolor (255, 255, 255)) -- VER (HP) dxDrawLine (x/1.25, y/2.1, x/1.25, y/2.40, tocolor (255, 255, 255)) -- VER (HP) dxDrawLine (x/1.05, y/2.1, x/1.25, y/2.1, tocolor (255, 255, 255)) -- HOR (HP) dxDrawLine (x/1.05, y/2.4, x/1.25, y/2.4, tocolor (255, 255, 255)) -- HOR (HP) dxDrawRectangle (x/1.249, y/2.39,x/4.95*vHealth/100, y/17.25, tocolor (0, 255, 0, 175)) -- ARENA (HP) dxDrawText ("HP", x/1.163, y/2.35, x, y, tocolor (255, 255, 255, 200), 1.5, "clear") -- TEXT (HP) end end ) function drawNitroCopertine (source) dxDrawLine (x/1.05, y/1.7, x/1.05, y/1.9, tocolor (255, 255, 255)) -- VER (NOS) dxDrawLine (x/1.25, y/1.7, x/1.25, y/1.9, tocolor (255, 255, 255)) -- VER (NOS) dxDrawLine (x/1.05, y/1.7, x/1.25, y/1.7, tocolor (255, 255, 255)) -- HOR (NOS) dxDrawLine (x/1.05, y/1.9, x/1.25, y/1.9, tocolor (255, 255, 255)) -- HOR (NOS) dxDrawText ("NOS", x/1.173, y/1.86, x, y, tocolor (255, 255, 255, 200), 1.5, "clear") -- TEXT (NOS) end addEventHandler ("onClientRender", root, function (source) local pVehicle = getPedOccupiedVehicle (localPlayer) if pVehicle then drawNitroCopertine () local vNitro = getVehicleNitroLevel (pVehicle) if vNitro ~= nil and vNitro ~= false and vNitro > 0 then dxDrawRectangle (x/1.24902, y/1.8902, x/6.6/10*10*vNitro, y/16.75, tocolor (0, 175, 255, 175)) end end end ) Link to comment
GerardWay Posted September 7, 2014 Author Share Posted September 7, 2014 Thanks, that seems a lot better:) Could you possibly make it work with Nemesis for me please? Link to comment
LabiVila Posted September 7, 2014 Share Posted September 7, 2014 Not sure what you mean with Nemesis, I don't know what that word word means at all if you explain better, maybe I can help you out Link to comment
GerardWay Posted September 7, 2014 Author Share Posted September 7, 2014 Could you possibly make it display the extra health (getElementExtraHealth) of the bot called Nemesis in my script please? Link to comment
Saml1er Posted September 7, 2014 Share Posted September 7, 2014 Could you possibly make it display the extra health (getElementExtraHealth) of the bot called Nemesis in my script please? Let me give you the answer: "/No" Link to comment
GerardWay Posted September 7, 2014 Author Share Posted September 7, 2014 Let me give you the answer: "/No" Well, so far, you've contributed two useless pathetic answers to this thread. I can't really see anyone wanting scripting services from an asshole like you. Now, if you're going to be a little /beta/ kid, and spam - take yourself elsewhere. I'm pretty sure nobody wants prematures like you here anyway. Link to comment
LabiVila Posted September 7, 2014 Share Posted September 7, 2014 Could you possibly make it display the extra health (getElementExtraHealth) of the bot called Nemesis in my script please? I sadly can't, I'm not an advanced scripter, just a beginner, srry. 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