Basic math support.

So here's what I'm trying to do"

have some integer variables :

common
uncommon
rare
Ultra


then call a common event (or script ) that does the following:

var loot_rng_total = (common + uncommon + rare + Ultra)
var loot_rng = random number between 1 and loot_rng_total

if

loot_rng < common

call plugin command A

else if

loot_rng < (common + Uncommon)

call plugin command B

else if

loot_rng < (common + Uncommon + rare)

call plugin command C

else

call plugin command D


I'm basically trying to have this loot tables plugin call a plugin command instead of giving an item
https://forums.rpgmakerweb.com/index.php?threads/random-loot.71822/

I tried doing this with common events but failed to sum multiple variables without making dozens of lines.
I also failed to randomize a number based on a variable.

Any help appreciated
Why do you need to call plugin commands instead of functions?
because there's a plugin that creates item tables and you can call a command to add a random item of the desired table. I'm creating a gacha which probabilities can be manipulated by variables in game.
I see.
To answer your questions...
This is how you randomize value based on variable:
var loot_rng = Math.RandInt (1, loot_rng_total) - maybe rand doesn't have capital r, but I think it has - only one way to find out.

Here you can find out how to call a plugin command through script (note: some functions in there may be false or incorrect)
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/

I will not build the exact function for you, because A. I don't use this script call and B. I don't use that plugin.
Not to mention my plugin doesn't use plugin commands at all, you have to use a script call.
I've updated the plugin to make it easier for you.

If you want it via event, it's quite easy: you can add each table's probability yourself easily beforehand, and then it just becomes this:

Var 1 = Random between 1 and 100
Condition var 1 <= 75:
script call for loot table common
Condition var 1 <= 95:
script call for loot table rare
Condition var 2 <= 100:
script call for loot table legendary
Thanks for your help, the plugin creator helped me integrate the function, but now I know how to do rng via scripting, 👍👍👍

solved.
Thanks a lot AStfgl66

I was actually trying to do this via https://rpgmakermv.co/threads/mv-random-loot-awarder.1357/ at first, but it became much more convenient with your help.

Original thread: https://forums.rpgmakerweb.com/threads/basic-math-support.85368/