Custom formula if a variable = x

Hello rpg makers,

I have a question regarding custom formulas.

In my game, Elves got a passive skill called Half-Dream which changes the sleeping state to a state allowing only the use of magic.

I'd like the sleep applying skill to apply a different state to characters tagged as Elves.
The tag itself is contained in a variable called "Race", where the number 2 is associated with the Elves.

I can't really use a specific actor tag in the formula as the player is free to define each of his characters' races.

I was thinking about something like :

If var(race)=2 then apply state (Half-Dream)
Else apply (Sleep)

The thing is that I'd want the game to take into consideration the race of the receiver of the attack (which would be B.smthg if i'm correct), but I can't seem to understand how to connect both (target being an elfe).

Would you mind helping me with that ?
Thanks a lot !
Hey,

How exactly are the race variables stored?

If the variable is a property of the actor itself you could probably simply use b.race .

If you are using the Control Variables event command and assign each actor a variable, you can use b.actorId() to get an actors database ID if you know that the target is an actor, and b.isActor() to check if they are:

(b.isActor() ? v[b.actorId() + Offset] : NonActorRaceValue)


If you are using something the actors class for your races, you could also make every elf immune to sleep, everybody else immune to half-sleep, and have your sleep skills apply both states, eliminating the need to explicitely check for the race.
alternative method is every skill that applies sleep actually just applies both states. but every character has state resist for 1 of them.

just noticed fen actually mentions this in the last paragraph
there is an easier way to handle this

have the skill apply both sleep and half-dream to everyone.
and have the elves a trait to be immune to sleep, while the other races are immune to half-dream.

OK, getting the races the appropiate traits is still requiring some work, but there should be plugins for dynamic traits or the like.

EDIT: ninja'd
There are several possible methods.

You say you can change your race, but is that using the class settings?
Let's create two types of sleep (normal) and sleep (for elves), and try to generate both of the above two types for the skill that causes the sleep state.
Then set the trait to disable sleep (normal) or sleep (elves only) on something that represents the race (assuming class here).
This method is the same as the one proposed by Tiamat-86.

Another method is to set a common event call to the skill that causes sleep, and use the common event to switch sleep to elves only.
This method may generate extra messages.
the common event method also doesnt take into account the possibility for state resistance that isnt race dependant. (ie. 50% sleep resistance from an accessory)
Hey,

How exactly are the race variables stored?

If the variable is a property of the actor itself you could probably simply use b.race .

If you are using the Control Variables event command and assign each actor a variable, you can use b.actorId() to get an actors database ID if you know that the target is an actor, and b.isActor() to check if they are:

(b.isActor() ? v[b.actorId() + Offset] : NonActorRaceValue)


If you are using something the actors class for your races, you could also make every elf immune to sleep, everybody else immune to half-sleep, and have your sleep skills apply both states, eliminating the need to explicitely check for the race.

I just have a Race variable that I use upon character creation (1 Human, 2 Elve, 3 Dwarf etc.). So far i'm just using it to check if the race is met when creating/analyzing a character.

A property of the actor ? How do I define a property that is non-existent in the game engine ? I'm much intrigued and would like to learn more !

Also I do understand the "(b.isActor() ? v[b.actorId()" part, but the rest doesn't mean anything to me :x

alternative method is every skill that applies sleep actually just applies both states. but every character has state resist for 1 of them.

just noticed fen actually mentions this in the last paragraph

there is an easier way to handle this

have the skill apply both sleep and half-dream to everyone.
and have the elves a trait to be immune to sleep, while the other races are immune to half-dream.

OK, getting the races the appropiate traits is still requiring some work, but there should be plugins for dynamic traits or the like.

EDIT: ninja'd

Oh my. I haven't figured it out, it's pretty smart !
I might check dynamic traits plugin. I'm always interested in things I can't really put a name on, so it makes the research pretty difficult !

There are several possible methods.

You say you can change your race, but is that using the class settings?
Let's create two types of sleep (normal) and sleep (for elves), and try to generate both of the above two types for the skill that causes the sleep state.
Then set the trait to disable sleep (normal) or sleep (elves only) on something that represents the race (assuming class here).
This method is the same as the one proposed by Tiamat-86.

Another method is to set a common event call to the skill that causes sleep, and use the common event to switch sleep to elves only.
This method may generate extra messages.

Haven't think about the Comment event call in the Skill tab, frankly when I thought about "battle skills" I tried to make things work in "Troops" lol

the common event method also doesnt take into account the possibility for state resistance that isnt race dependant. (ie. 50% sleep resistance from an accessory)

So common event has priority over items I guess ?
So common event has priority over items I guess ?
no, it is the fact that event commands override most game mechanics.

think of it this way: a randomly used skill can be resisted, but if you create a scene where you command something to happen based on the story you want, then checking for resistances or similar is a bad idea.
Thanks a lot for your answers guys !
(I wanted to thank you while editing my message, but my PC hardreset and I had to go to my work.)

no, it is the fact that event commands override most game mechanics.

think of it this way: a randomly used skill can be resisted, but if you create a scene where you command something to happen based on the story you want, then checking for resistances or similar is a bad idea.

Yeah just like being able to inflict a battle -only status on map !
I do understand the "(b.isActor() ? v[b.actorId()" part, but the rest doesn't mean anything to me :x
The rest was supposed to be placeholders here. I still don't exactly know how you store/check a characters race exactly, but if you use, for example, actors 1 to 10, and store their races in variables 21 to 30, and every enemy you meet has race 3, then the complete statement could look like this:

(b.isActor() ? v[b.actorId() + 20] : 3)

A property of the actor ? How do I define a property that is non-existent in the game engine ? I'm much intrigued and would like to learn more !
In theory, you could just assign them.
$gameActors.actor(1).race = 3;
would set the first actors race property to 3, and you could check/modify the value later. You should of course avoid names that are already in use.

One thing to keep in mind with this approach would be the objects life cycle.
In case of actor objects, this should work fine. The game creates each actor once and properly saves/loads them with your savestate (including the properties you added to them).

Other types of objects might be shorter lived. Events for example are discarded when you leave the map and recreated on reentering, so their properties would be lost. Enemies are recreated for every fight, so adding a race to the first enemy of your troop would only last during the current battle. Database objects are loaded at the start of the application and shared across all savestates until the player exits the game, so modifying these should be done carefully as well.

For more complex management you would probably use a plugin then.

Original thread: https://forums.rpgmakerweb.com/threads/custom-formula-if-a-variable-x.150053/