#RooTs Posted April 27, 2015 Share Posted April 27, 2015 Hello friends, i have a doubt. I wanted to know how many porcents(%) has this function, 100% or 1000% I want to make a DX in (nitro state in 1000%) getVehicleUpgradeOnSlot Exemple local id = 8 local nitro = getVehicleUpgradeOnSlot(vehicle, id ) dxDrawText("nitro state in" ..nitro.."%", x*200, y*500, 100, 100, ........................... Link to comment
Banex Posted April 28, 2015 Share Posted April 28, 2015 "nitro state in" ..math.ceil(getVehicleNitroLevel(vehicle)/1*100).."%" Link to comment
Walid Posted April 28, 2015 Share Posted April 28, 2015 You must you use getVehicleNitroLevel() local nitro = getVehicleNitroLevel(vehicle) like this : local id = 8 local slot = getVehicleUpgradeOnSlot(vehicle, tonumber(id)) if slot then if nitro ~= false and nitro ~= nil and nitro > 0 then -- Your Dx code using this one ("Nitro: "..math.floor(nitro/1*100).." %" ) end end Link to comment
#RooTs Posted May 27, 2015 Author Share Posted May 27, 2015 what is wrong?, I put for account of 5 on 5 in dxDrawImage local nitro = getVehicleNitroLevel(getPedOccupiedVehicle(getLocalPlayer())) local id = 8 local slot = getVehicleUpgradeOnSlot(vehicle, tonumber(id)) if slot then if nitro ~= false and nitro ~= nil and nitro > 0 then dxDrawImage(x*960+x2, y*470+y2, 306, 232, "files/nitro/"..(math.ceil(nitro/5)*5)..".png", 0,0,0, tocolor(255, 255, 255 , 255)) end end Link to comment
Mega9 Posted May 27, 2015 Share Posted May 27, 2015 "files/nitro/"..(math.ceil(nitro/5)*5)..".png" I suppose you have thousands of images in that folder? Link to comment
Dealman Posted May 27, 2015 Share Posted May 27, 2015 what is wrong?, I put for account of 5 on 5 in dxDrawImage local nitro = getVehicleNitroLevel(getPedOccupiedVehicle(getLocalPlayer())) local id = 8 local slot = getVehicleUpgradeOnSlot(vehicle, tonumber(id)) if slot then if nitro ~= false and nitro ~= nil and nitro > 0 then dxDrawImage(x*960+x2, y*470+y2, 306, 232, "files/nitro/"..(math.ceil(nitro/5)*5)..".png", 0,0,0, tocolor(255, 255, 255 , 255)) end end You'll want to make sure you understand the function before you try to use math like this. getVehicleNitroLevel returns a float value between 0.0001 and 1.0. And with your math, this will always output as 5, whether the Nitro Level is 0.1, 0.5 or even 1.0 - your calculation will always return 5. I suggest you use a website such as http://repl.it/languages/Lua to make quick mathematical tests, that way you won't have to do it with your resource - it's actually a really convenient website and I use for everything between testing mathematic calculations and generating meta.xml files. I don't know how many images you have, so I can't really help you get the results you seek. Link to comment
#RooTs Posted May 27, 2015 Author Share Posted May 27, 2015 "files/nitro/"..(math.ceil(nitro/5)*5)..".png" I suppose you have thousands of images in that folder? Yes, 0.png, 5.png, 10.png, 15.png, 20.png, 25.png, 30.png........ Link to comment
#RooTs Posted May 27, 2015 Author Share Posted May 27, 2015 I don't know how many images you have, so I can't really help you get the results you seek. 0.png, 5.png, 10.png, 15.png, 20.png, 25.png, 30.png........ (100.png) Link to comment
Dealman Posted May 27, 2015 Share Posted May 27, 2015 I don't know how many images you have, so I can't really help you get the results you seek. 0.png, 5.png, 10.png, 15.png, 20.png, 25.png, 30.png........ (100.png) What kind of design are you going for? Could you post one or two of the images? Because generally it's a better idea to just make something you can just alter the width and/or height of depending on the value. Rather than having 20 different images. Link to comment
Walid Posted May 27, 2015 Share Posted May 27, 2015 I don't know how many images you have, so I can't really help you get the results you seek. 0.png, 5.png, 10.png, 15.png, 20.png, 25.png, 30.png........ (100.png) add 100 pictures , i think it's a lot anyways local nitro = getVehicleNitroLevel(getPedOccupiedVehicle(getLocalPlayer())) local id = 8 local slot = getVehicleUpgradeOnSlot(vehicle, tonumber(id)) if slot then if nitro ~= false and nitro ~= nil and nitro > 0 then dxDrawImage(x*960+x2, y*470+y2, 306, 232, "files/nitro/"..(math.floor(nitro/1*100))..".png", 0,0,0, tocolor(255, 255, 255 , 255)) end end Link to comment
#RooTs Posted May 27, 2015 Author Share Posted May 27, 2015 @Walid, no other way to do this count? the idea would be to score 5 out of 5 because it would weigh less on my server. Link to comment
Walid Posted May 28, 2015 Share Posted May 28, 2015 @Walid, no other way to do this count? the idea would be to score 5 out of 5 because it would weigh less on my server. try this it should work table = {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100} function getNearestValue(table, number) local index, value for i, y in ipairs(table) do if not index or (math.abs(number-y) < index) then index = math.abs(number - y) value = i end end return table[value] end -- Your code local nitro = getVehicleNitroLevel(getPedOccupiedVehicle(getLocalPlayer())) local id = 8 local slot = getVehicleUpgradeOnSlot(vehicle, tonumber(id)) if slot then if nitro ~= false and nitro ~= nil and nitro > 0 then dxDrawImage(x*960+x2, y*470+y2, 306, 232, "files/nitro/"..getNearestValue(table,(math.floor(nitro/1*100)))..".png", 0,0,0, tocolor(255, 255, 255 , 255)) end end 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