Jump to content

[HELP] math.percent


1LoL1

Recommended Posts

Posted

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) 

Posted
10% chance will get bonus
what? this is random so luck.. i want to percent :D

Decide what you want, random chance, or percentage of some value to be a bonus.

Posted
10% chance will get bonus
what? this is random so luck.. i want to percent :D

Decide what you want, random chance, or percentage of some value to be a bonus.

10% i find or get bonus. Now its 100%

Posted

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 

Posted
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

Posted
function math.percent(procent, value) 
    if (tonumber(procent) and tonumber(value)) then 
        local p = (procent/100)*value; 
    end 
    return p; 
end 

Percent calculation.

Posted

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) 

Posted
Maybe because chance never equaled 2 in any of the 4 kills? It's random, you know.

Yes i know but how i can when i killed 2 zombies of 4 i will give bonus?.

Posted
Because your logic is a bit foggy, 2 zombies out of 4? So just after 2 zombie kills bonus should be given?

Yes. or when i killed 50 zombies i give bonus.

Posted

You need to specify a table for each milestone. On each kill, check the number of kills and give the bonus if the milestone exist in the table.

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...