Calculate value based on encountered actors' parameters

Grognard

Villager
Member
Joined
Apr 3, 2019
Messages
26
Reaction score
7
First Language
English
Primarily Uses
RMMV
Hi all, I have a specialized request that I need some help with.

I want a mechanic where the player encounters individuals (either Actors or Enemies, it doesn't matter to me), and when the player encounters an individual she is added to a list (or activated in the enemy book - just kept track of). In the background, there is a loop running, and on each completion of the loop I want a calculation to be made based on the parameters of the individuals met. Sometime like ATK - DEF * LUK. So the calculation would be Actor1(ATK - DEF * LUK) + Actor2(ATK - DEF * LUK) + Actor3(ATK...

And I need to be able to remove individuals from the list of encountered individuals, so that, for example Actor 2 can be eliminated through an event, and only Actor1 and Actor3's parameter calculations will be added together to get the final value.

If anyone could help me out with this - I would be so grateful. I'd be happy to contribute financially if anyone wants to work on this as a plugin.
Thanks!
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
This doesn't really need to be a plugin.
Just make a variable into an array at the start of the game using control variables: script: []
Each time you want to add to the list use the push method to add to it, and use splice to remove from it as needed.
The rest is simple array manipulation that googling will solve easily.

I can't go further than that because your request is super vague.
When do you want people added? Automatically? Manually?

Same for removed.

What is the exact calculation you want to do? When exactly do you want it to run? What do you plan to use it for ?
 

Grognard

Villager
Member
Joined
Apr 3, 2019
Messages
26
Reaction score
7
First Language
English
Primarily Uses
RMMV
I appreciate the help! I didn't want to get too much into the weeds in the first post.

I want the player to be able to manually press an event that will add a person to the list. The event will also deduct 1 from the variable Money. (The play can press this event, and add more people as long as varMoney >= 1).

Then I have a common event where a loop that adds one day every 30 frames. Each time a day is added, there is a 50% chance of an event firing (determined through random variables). If the event does fire, the player encounters a person from the list, and is given a box to click (an "ok" box). When the box is clicked, the picture of the person is shown. At this point the player can decide to keep the person on the list, or delete the person (sending her back into the pool of non-added people).

Every time the 30 frame loop completes, I need the calculation to be done.
I don't know what the exact formula will be yet, but I'm thinking of it being: DEF - MDE * (1 + (MAT * (0.01 * Day number))).
So if a person has DEF of 10, MDE of 2, MAT of 2, and it's day 50, the forumla would result in 6 for this person. That would be added to all the other results for the other people on the list, and the total result would be added to varMoney.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,434
Reaction score
7,713
First Language
German
Primarily Uses
RMMV
as said before - no need for a plugin.

in fact all you need is the control variable command and the conditional branch - and a lot of time to write the event.
The control variable command allows you to load all actor data into variables (through the game data option), then you use the mathematical options to combine the data into any formula you want.
and you'll use the conditional branches to check which actors should be added to the values and which not.
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
Okay, then I guess you could do it purely with events. It wouldn't really be that scalable, and a hassle to maintain with the huge numbers of conditionals. It's better to automate things like this with a script call or two.

To be able to give you a solution, I need to know: what will your "persons" be, actors? enemies ? both? something else?
 

Grognard

Villager
Member
Joined
Apr 3, 2019
Messages
26
Reaction score
7
First Language
English
Primarily Uses
RMMV
I've decided to make them all actors.
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
Okay, so we're going to do this with a loop and an array.

First you set up the array:
Set a variable to an empty array with control script : []
This variable will act as your list.

Each time you want to add a person to the list you push its id into the list with the following script call:
Code:
$gameVariables.value(arrayVarId).push(personId)
Change arrayVarId to the variable number that will contain your list.

Each time you want to remove someone from the list you run the following script code:
Code:
var ar =$gameVariables.value(arrayVarId)
var index =ar.indexOf(personId)
ar.splice(index,1)
Using these two script call and the array your variable array will look like this [1,2,3,5,7,9]. Push to add to it, splice to remove from it using the two above script bits.


What you do now is in your calculation event you make a loop.
Set a variable that will be used to tell how many time the loop will run we'll call it i, set it to 0 just before the loop, not inside.
Then you set a variable that gets the length of the array with control:script
Code:
$gameVariables.value(arrayVarId).length
, again do it just outside the loop.

Inside the loop then you set a conditional that will exit the loop if variable i exceeds the length of the list, use the condition if variable i >= variable (list length)
With that done you now have a loop that will run the same amount of time as the amount of person, in order from the list.
Then you use a variable to get the actor id from the list with control variables: script
Code:
$gameVariables.value(arrayVarId)[$gameVariables.value(i)]
Now you have the variable with the actor id. Do whatever calculation to your money variable you want with it.
Then as the last command, you increment i (control variable i = i + 1).

The loop will run its course once for each person of the list, each time adding to the money variable with the new id, until i reaches the list length, which means there is no more actor to look at.

I've ran you through it so you understand how it works. It might sound like a lot, but it's really not complicated to do in editor: have a screenshot.


In this screenshot the list will be [1,2,4,7].
You should not initialize the list with the first command every time, for obvious reasons, as that will reset the list, just add to it, or remove from it with the script calls above. Initialize it at the game start and you're set.
What needs to be in your common event that runs the calculations is everything down from the first control variable command, except the money variable reset to 0 probably.
 

Grognard

Villager
Member
Joined
Apr 3, 2019
Messages
26
Reaction score
7
First Language
English
Primarily Uses
RMMV
That's amazingly helpful, thanks Astfgl!

I have a command set up to push a random actor into the array (variable 21) after a random id number is selected by variable 22:
$gameVariables.value(21).push($gameActors.actor($gameVariables.value(22)))

If I have this run 5 times, so my array contains 5 actors, and I want an autorun event to pull a random actor from the array so I can interact with him, should I use a script sort of like this:
Var0023 = $gameVariables.value(21)[Math.randomInt]
I tested this and Variable 23 didn't change :(
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
You shouldn't blindly try script calls. That's the quickest way to crash your game.

Set a variable between 1 and list length using control variable script.
Set another variable as the actor id just like in the loop and you'll be able to do what you want.

Look at the thread stickyied in the mv forums for the script call equivalent of event commands.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top