LucasMTA Posted May 22, 2019 Share Posted May 22, 2019 (edited) 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 May 22, 2019 by LucasMTA Link to comment
DNL291 Posted May 22, 2019 Share Posted May 22, 2019 Não entendi, explique melhor por favor. Explique qual a ideia por trás do código. Link to comment
LucasMTA Posted May 22, 2019 Author Share Posted May 22, 2019 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
DNL291 Posted May 22, 2019 Share Posted May 22, 2019 (edited) 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 May 22, 2019 by DNL291 Link to comment
LucasMTA Posted May 22, 2019 Author Share Posted May 22, 2019 (edited) 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 May 22, 2019 by LucasMTA 1 Link to comment
Other Languages Moderators Lord Henry Posted May 22, 2019 Other Languages Moderators Share Posted May 22, 2019 10 hours ago, LucasMTA said: obrigado danilin Ele não é o Danilin, hauahauah Pra obter 20% de um valor, é só multiplicar ele por 0.2 Link to comment
LucasMTA Posted May 22, 2019 Author Share Posted May 22, 2019 1 hour ago, Lord Henry said: Ele não é o Danilin, hauahauah Pra obter 20% de um valor, é só multiplicar ele por 0.2 kkkk é porque tem DNL pensei que foce , mais mesmo assim eu agradeço meu broder 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