[Solved] How to read and write from Specific Actor Inventory Gold.

I'm running a dev game after having borrowed the basics from Actor Inventory (Roninator2), an addon to Hines Actor Inventory Script. The basic idea of that is to separate inventory gold by specific actors.

However, I've run into a small snag. I need to initiate a script call inside an event system, which causes both active actors (all party members) to lose half of their current gold. This means the lose_gold also needs to call on an in-game variable with predetermined values.

I have added some bits and pieces to the script, and made a specific call, but I don't have a means to test this readily. All I'm asking is, does it even look right?

class Game_Interpreter
def gain_gold(amount, actor_id)
$game_actors[actor_id].gain_gold(amount)
end
def lose_gold(amount, actor_id)
$game_actors[actor_id].lose_gold(amount)
end
def p1_lose_gold($game_variables[4941], actor_id)
$game_actors[actor_id].lose_gold($game_variables[4941])
end
def p2_lose_gold($game_variables[4942], actor_id)
$game_actors[actor_id].lose_gold($game_variables[4942])
end

end


>Control Variables: [4944:Isothermic Player1 Gold] = $game_actors[015].inventory_gold
>Control Variables: [4945:Isothermic Player2 Gold] = $game_actors[014].inventory_gold
>Control Variables: [4941:IsoPlayer1 Lose Gold] = Variable [4944:Isothermic Player1 Gold]
>Control Variables: [4942:IsoPlayer2 Lose Gold] = Variable [4945:Isothermic Player2 Gold]
>Control Variables: [4941:IsoPlayer1 Lose Gold] =/ 2
>Control Variables: [4942:IsoPlayer2 Lose Gold] =/ 2
>Script: p1_lose_gold($game_variables[4941], 015)
p2_lose_gold($game_variables[4942], 014)



The first 2 definitions are what already existed. I added the next 2 following this to the whole script within the same class. The idea is to define the function in which the specified actor loses gold based on a specific in-game variable, rather than "amount." However, I am unsure if this creates any issue with the arguments expected.

The second segment is the code execution, presently stored in a common event system to keep it organized and prevent it from running automatically if incorrectly made. Variable 4944 refers to the specific amount of gold of the 15th actor (which is the default in the project, as well as party leader). With the Hines script running natively, the build-in game function for determining actor gold doesn't seem to work correctly anymore, but even if it did, it only applies to the primary actor and doesn't account for other actors. So, the initial objective is to set 4944 and 4945 to interpret the specific gold of each actor in their respective inventories.

The next 2 control variables will actually become the "amount" of gold that is removed from the actor based on the functions added into the script. Since it is supposed to be based on [inventory gold / 2], the variable must first check and match the data of actor gold before dividing it by 2. Once done, the previous script is called, as shown above.

I predict I might not have it quite right, but cannot test it for a while with other scripts I am currently editing. It's also a unique idea for those learning along side me. This goal can be particularly useful if actor gold is an important factor of any game.
Thoughts?

Oh, and here is a copy of the original script I was working off of. Everything in green is what I tried to add.
Inventory Script
Here I'm assuming you have some code that lets you get the total amount of gold or gain or lose gold per actor.
It would be easier to lose gold if you use a loop like this one:

Ruby:
$game_party.members.each do |a|
  gold = $game_variables[1000] * a.gold / 100
  a.lose_gold(gold)
end

...where gold stands for a specific integer, namely a positive number.

Now the question is if you want to lose a specific percentage of gold only like I did it above.
Here I'm assuming you have some code that lets you get the total amount of gold or gain or lose gold per actor.
It would be easier to lose gold if you use a loop like this one:

Ruby:
$game_party.members.each do |a|
  gold = $game_variables[1000] * a.gold / 100
  a.lose_gold(gold)
end

...where gold stands for a specific integer, namely a positive number.

Now the question is if you want to lose a specific percentage of gold only like I did it above.

Yes. {The percentage would just be 50%} The first two functions enable as Script: lose_gold(amount, actor_id)
But the issue is that the amount is designed to be a specific number without reading a variable.

The goal is to replace "amount" with a specific variable (though without deleting the original function as this is used too). If I understand your suggestion right, it looks like you call on the game to prepare a change to all party members, and set all of their gold to a specific variable before dividing. However, if my assumption here is correct, this defeats the purpose, as we have suddenly set all actors to have the same exact amount of gold before dividing. Each actor will have a different amount of gold through various game progression, and it should not exactly match another actor via any scripting. Is there a way to process this division based on actor ID?

The two game variables I am working with are designed to match the exact amount of gold each actor has, using common event section above, but this only exists because I am trying to call two different actor inventory golds and assign each a variable.
*Update: Finally solved the problem!*

Initially, I was trying to run custom scripts from the script editor. Bad idea there.
I learned that the in-game script handler can pick up and set variable data, making at least half of the code I threw up above useless.

losing or adding gold by a variable instead of a number was as simple as running
>Script: lose_gold($game_variables[4944], 15)

As for the additional problem this created, the main issue surrounding this was in setting 4941 (a variable representation of actor 15's Inventory Gold) to match specific inventory gold. After driving myself insane, I came up with this:
> $game_variables[4942] = $game_actors[14]inventory_gold

This assigns a specific variable the exact current value of a specific actor's inventory, which is useful to run branches of "if Player Gold is lower than #value," as the default engine version of this doesn't work with the Hines script in place, nor would it account for multiple players.

If anyone is wondering why this is useful in other ways, this can apply especially to a virtual board game system. Separating actor inventory and actor money is important for a lot of possible projects, and it helps to specify specific variables for math.
I'm sure there is direct scripts that can do math outside of running in-game variables, but I don't have a good teacher yet.

Summary of useful scripts = Hines Actor Inventory Script & Gold Inventory Add-on Script

Original thread: https://forums.rpgmakerweb.com/threads/solved-how-to-read-and-write-from-specific-actor-inventory-gold.178866/