Jump to content

[HELP] math.percent


1LoL1

Recommended Posts

Hello how i can fix this when i want to 10% = give 1 bonus please can anyone help me?

function math.percent(percent,maxvalue) 
    if tonumber(percent) and tonumber(maxvalue) then 
        local x = (maxvalue*percent)/100 
        return x 
    end 
    return false 
end 
  
addEvent("onZombieGetsKilled",true) 
addEventHandler("onZombieGetsKilled",getRootElement(), 
function (killer) 
if math.percent(10,100) then 
setElementData(killer, "F", getElementData(killer, "F") + 1) 
local killer = getPlayerName(killer) 
outputChatBox("+1 F", getRootElement(), 255, 0, 0, true) 
end 
end) 

Link to comment
If you do it to only occur if 1 is picked out of 10 possibilities, it is basically 1/10 chance, which is also known as 10%.
if math.random(1,10) == 1 then 
--give bonus 
end 

this work but i have given always bonus.

And when i want this:

(10) == 5 then

give bonus

10 = zombies

5 = give bonus

Link to comment

so this? but this not work i killed 4 zombies and i dont have bonus

addEvent("onZombieGetsKilled",true) 
addEventHandler("onZombieGetsKilled",getRootElement(), 
function (killer) 
chance = math.random(0,4) 
if (chance == 2) then 
setElementData(killer, "F", getElementData(killer, "F") + 1) 
local killer = getPlayerName(killer) 
outputChatBox("F", getRootElement(), 255, 0, 0, true) 
end 
end) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...