Jump to content

AJUDA MATH.RANDOM


Recommended Posts

total = math.random(5000,10000) --vamos dizer que o total seja entre 5000 a 10000 reais

total1 = total --o total definido agora passa a ser total1
total2 = total1/4 --agora o total1 passa a ser dividido em 4 e passa a ser total2

if dinheiro1 >= 1 then
				setTimer(function()				
				local money = math.random(total2)
				givePlayerMoney(total2)
				outputChatBox("Dinheiro +$"..total2.."", 255, 255, 255, true)
				end, 3000, 1)
end

if dinheiro2 >= 1 then
				setTimer(function()				
				local money = math.random(total2)
				givePlayerMoney(total2)
				outputChatBox("Dinheiro +$"..total2.."", 255, 255, 255, true)
				end, 3000, 1)
end

if dinheiro3 >= 1 then
				setTimer(function()				
				local money = math.random(total2)
				givePlayerMoney(total2)
				outputChatBox("Dinheiro +$"..total2.."", 255, 255, 255, true)
				end, 3000, 1)
end

if dinheiro4 >= 1 then
				setTimer(function()				
				local money = math.random(total2)
				givePlayerMoney(total2)
				outputChatBox("Dinheiro +$"..total2.."", 255, 255, 255, true)
				end, 3000, 1)
end

Estou tentando dividir o valor total entre esses 4 if mais nao estou conseguindo, ele sempre gera um valor aleatorio

 

tambem tentei fazer % mais ele sempre gera um numero diferente entre 5000 a 10000 oque estou fazendo de errado

Edited by LucasMTA
Link to comment

nuss agora que eu vi eu tou colocando o math.random dentro do if gerando ele novamente

Eu quero dividir o valor total entre as 4 tabelas feitas em if

um simples erro pode causar um oceano kkkk

eu fiz o seguinte

dinheirototal = math.random(5000,10000) --total

total = dinheirototal

if 1 then
local money = total/4
givePlayerMoney(money)
end
if 2 then
local money = total/4
givePlayerMoney(money)
end
if 3 then
local money = total/4
givePlayerMoney(money)
end
if 4 then
local money = total/4
givePlayerMoney(money)
end

DNL teria alguma dica pra mim melhorar , como por exemplo %

 

assim ele tem 4 tabelas dividindo o total e cada uma dividi em 4 que sairia na mesma ou estou errado

Link to comment

:/

Mas e aí, conseguiu fazer funcionar agora? Pra dividir é só armazenar a divisão numa variável (já fez) e cada parte distribuir. dinheiro1, dinheiro2 não sei de onde é esses valores, também não sei se com "tabelas feitas em if" você quis dizer as verificações em If.

Sobre o erro, realmente um erro às vezes pode ser o que mais tira tempo quando você está desenvolvendo, por isso é muito importante você saber depurar da melhor forma.

EDIT:

23 minutes ago, LucasMTA said:

DNL teria alguma dica pra mim melhorar , como por exemplo %

 

local vinte = (20 * dinheirototal) / 100 -- 20% do valor total

Seria o cálculo pra obter 20 por cento do valor total. @LucasMTA

Edited by DNL291
Link to comment

obrigado danilin agora vou usar % é bem mais pratico, funcionou sim mais com % é bem melhor sem erros futuros

 

eu tinha feito quase do mesmo jeito

total = math.random(5000,10000)

total1 = total

givePlayerMoney(source,20*total1/100)

mais nao funcionou 

Edited by LucasMTA
  • Haha 1
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...