NPC gamble against each other, is it possible?

I watched several gambling tutorials and think they're about player gambling against a npc. Is it possible to have 2 NPC gambling against each other?

If NPC A has 100 gold, NPC B has 100 gold, both do a dice check and the one who lost lose 10 gold to the other, making one 110 and the other at 90.
Yes, just have a variable per NPC to track their "gold", then go ahead with the eventing as usual~
Yes, just have a variable per NPC to track their "gold", then go ahead with the eventing as usual~

Thanks, I think I've got it.

I've to wonder, does the comparsion event have to happen to named common events?

For example, I created 2 common events called orc d20 roll, goblin d20 roll, then 2 variable orc wealth and goblin wealth so the competition between the first 2 common events would change their wealth. That's what worked.

However, if I want orc to gamble against a random npc (could also be goblin) that came to the table, it seems I've to create common events for all possible npcs that came to the table. Can making orc d20 roll vs the random guy who stays at the table at the moment d20 roll be done instead?
Oh I see. Hmm, I think you could reduce it to one common event with a little scripting (or a LOT of branches 😅). Here's an example with some ideas:
Spoiler: Event example
Code:
◆Comment:Variables 41, 42, and 43 are used to store the current gold of the NPCs.
◆Text:None, Window, Bottom
:    :Pick the first player!
◆Show Choices:Orc, Elf, Goblin (Window, Right, #1, -)
:When Orc 
  ◆Control Variables:#0031 Gambler ID 1 = 41
  ◆Control Variables:#0032 Gambler Name 1 = 'Orc'
  ◆
:When Elf 
  ◆Control Variables:#0031 Gambler ID 1 = 42
  ◆Control Variables:#0032 Gambler Name 1 = 'Elf'
  ◆
:When Goblin 
  ◆Control Variables:#0031 Gambler ID 1 = 43
  ◆Control Variables:#0032 Gambler Name 1 = 'Goblin'
  ◆
:When Cancel
  ◆Exit Event Processing
  ◆
:End
◆Text:None, Window, Bottom
:    :Pick the second player!
◆Show Choices:Orc, Elf, Goblin (Window, Right, #1, -)
:When Orc 
  ◆Control Variables:#0035 Gambler ID 2 = 41
  ◆Control Variables:#0036 Gambler Name 2 = 'Orc'
  ◆
:When Elf 
  ◆Control Variables:#0035 Gambler ID 2 = 42
  ◆Control Variables:#0036 Gambler Name 2 = 'Elf'
  ◆
:When Goblin 
  ◆Control Variables:#0035 Gambler ID 2 = 43
  ◆Control Variables:#0036 Gambler Name 2 = 'Goblin'
  ◆
:When Cancel
  ◆Exit Event Processing
  ◆
:End
◆If:#0030 = Gambler ID 1
  ◆Text:None, Window, Bottom
  :    :\v[32] can't play against themselves... >_>
  ◆
:Else
  ◆Control Variables:#0033 Gambler Roll 1 = Random 1..20
  ◆Control Variables:#0037 Gambler Roll 2 = Random 1..20
  ◆Text:None, Window, Bottom
  :    :\v[32] rolled a \v[33]!\!
  :    :\v[36] rolled a \v[37]!
  ◆If:Gambler Roll 1 > Gambler Roll 2
    ◆Text:None, Window, Bottom
    :    :\v[32] wins 10\G from \v[36]!
    ◆Script:var id1 = $gameVariables.value(31);
    :      :var id2 = $gameVariables.value(35);
    :      :var bet = 10;
    :      :$gameVariables.setValue(id1, $gameVariables.value(id1) + bet);
    :      :$gameVariables.setValue(id2, $gameVariables.value(id2) - bet);
    ◆
  :Else
    ◆If:Gambler Roll 1 < Gambler Roll 2
      ◆Text:None, Window, Bottom
      :    :\v[36] wins 10\G from \v[32]!
      ◆Script:var id1 = $gameVariables.value(31);
      :      :var id2 = $gameVariables.value(35);
      :      :var bet = 10;
      :      :$gameVariables.setValue(id1, $gameVariables.value(id1) - bet);
      :      :$gameVariables.setValue(id2, $gameVariables.value(id2) + bet);
      ◆
    :Else
      ◆Text:None, Window, Bottom
      :    :Tie! Nobody wins.
      ◆
    :End
    ◆
  :End
  ◆
:End
◆Control Variables:#0034 Gambler Gold 1 = $gameVariables.value($gameVariables.value(31))
◆Control Variables:#0038 Gambler Gold 2 = $gameVariables.value($gameVariables.value(35))
◆Text:None, Window, Bottom
:    :\v[32] now has \v[34]\G.
:    :\v[36] now has \v[38]\G.
I've used a lot of variables here:
  • Gambler ID: stores the ID of the variable where this guy's gold total is stored.
  • Gambler Name: just for display! You can put text in a variable using Control Variables > Script > 'text'.
  • Gambler Roll: the number rolled by each NPC.
  • Gambler Gold: used for the message at the end, to display the current gold of each NPC.
The script call looks like this:
Code:
var id1 = $gameVariables.value(31);
var id2 = $gameVariables.value(35);
var bet = 10;
$gameVariables.setValue(id1, $gameVariables.value(id1) + bet);
$gameVariables.setValue(id2, $gameVariables.value(id2) - bet);
In English:
  • Get the value of variable 31 (Gambler ID 1) and call it id1
  • Get the value of variable 35 (Gambler ID 2) and call it id2
  • Store the winnings (10 gold) in a var called bet.
  • Set the variable with ID id1 equal to its current value plus the bet value.
  • Set the variable with ID id2 equal to its current value minus the bet value.
The plus & minus are swapped when the other player wins, of course. 😮‍💨

Note that you can press F9 during play-test to show a debug scene where you can check (or change) values of the game switches and variables. 🙂

Hope that helps! 😂

[Edit: fixed a couple of typos (Gambler Roll 1|2).]

Original thread: https://forums.rpgmakerweb.com/threads/npc-gamble-against-each-other-is-it-possible.111355/