Dynamic Features

I just tried it, it doesn't seem to be working still. The only reaction I get from the script at all is if I put:

e = $game_variables[27].to_fe = e * 5 / $game_variables[14]e = e / 100add_feature🙂actor, 0, :xparam, 1, e)instead of

e = $game_variables[27].to_fe = e * 5 / $game_variables[14]e = e / 100add_feature🙂actor, 1, :xparam, 1, e)but that's because I put a 0, it says

undefined method 'add_feature' for nil:NilClass

I assume it's supposed to be a 1, not a 0 for the ID.

EDIT: ...and got it. It was interference from another script. Yanfly's Extra Stat Formulas, I had set the Formula for evasion to be 0. In case you were wondering. Thank you for the help though.
Hi.

I'm having trouble getting the add_feature to work with state_rate. I've tried it with other things like state_resist, xparam, skill_add, and so forth, and those are working as expected. However, state_rate doesn't have any effect.

Here is an example of the code I am trying.
add_feature🙂actor, 1, :state_rate, 1, 1.00)

The state used is 1, which is death and the rate is 1.00, which guarantees success. Unfortunately, nothing happens.

That single line of code is in a common event, which is called when a specific skill is used.
*Note* The actual state I intend to use once I figure out this problem is going to be evade, but I figured death would give me immediate results to ensure the code was working before I swapped states.

Any help would be appreciated. Thanks.
try it with another state than death. death has hardcoded effects that chain it to HP values.

Testing with something else might require you more checks during tests, but there won't be any hardcoded effects to disturbe the test.
I tried states for poison, stun, paralysis, counterattack, mp cost down, and immortal, and still none of those have their expected effect.
Are you sure you're setting the correct value? When I wrote the script, I noticed some values were fractional (1 = 100%) and some were not (100 = 100%).


Maybe try passing 100 as the value and see if that makes a difference?


You could also try manually adding the 100% rate to an actor, then in an event, do the following:

Code:
Script: p $game_actors[id].get_feature(...)
with the correct settings for state_rate, then play with the console on and activate that event. See what value it provides for state_rate.
Ok, so I did some testing and here is what I found.

-case 1- set the evade state to 95% on the actor through the database and then change state rate in the event

print out current state_rate: this shows 0.95 as expected
change state_rate to .80 on actor for evade through the event
print out current state_rate: Expected .80, but shows 0.95

-case 2- don't set the evade state on actor in the database but change state rate in the event
print out current state_rate: this shows empty as expected
change state_rate to 1.0 on actor through event
print out current state_rate: shows 1.0 as expected

Despite the expected state_rate being there, the evade state itself is never set because the actor still takes damage and never evades.
 

-case 3- don't set evade state on actor but use add state in event
print out current state_rate: this shows empty as expected
add_state on actor through event
print out current state_rate: this shows nothing

I was surprised by the above result. I expected that to be 1.0 since it succeeds all the time, but it was empty.

To me, the above results suggest that what happens on the front end (setting the state and rate percentage in the db) is not passed to the backend in the same regard as a pair (which seems more true given the RPG Maker's add_state method accepts one, not two parms). I will admit I don't know much about ruby scripting, I'm more of a java guy, so I could be missing something. I'm also fairly green on RPG Maker.

That all being said, what I'll probably end up doing (if no solution is possible) is do a workaround involving add_state where I use probability to determine whether or not to call the function. After all, that is what I'm going for - a progressive skill (involving evade) where the higher the level a player gets, the more likely they succeed at pulling it off.
Can you show a screenshot of your event(s) where you modify the setting?
I've attached a screenshot of my event to this post.

dynamic-feature-call.png

And the second screenshot is of the print from the console

dynamic-feature-call2.png
If you add a new script call AFTER all the ones you have there, that looks like this:

p ''p $game_actors[1].featurescan you show me what prints in the console? I'm wondering if the same feature might be there twice with different values, in which case only the first one would be retrieved.You may need to do a remove_feature before the add_feature command to ensure there is only one setting for that value.
Initially I added the code as you posted it and it gave me an error:

Script 'Game Interprete' line 1411:ArgumentError occurred.
wrong number of arguments (0 for 1)

So next I assumed you meant for the feature code to be in there, so I added :state_rate

p ''
p $game_actors[1].features🙂state_rate)

And here's the screenshot of the console output from that, which shows empty brackets

dynamic-feature.png
no, that's not what I'm after. I want a list of ALL the features on the actor.


Try this instead:

Code:
p $game_actors[1].feature_objects.to_s
Here is a snapshot of the console:

all-features.png

Also, here's the copied text from that console, which might be easier for you to look through.

Code:
[#<RPG::Actor:0x6d85fa8 @name=\"Eric\", @face_index=2, @character_index=2, @initial_level=1, @face_name=\"People1\", @class_id=11, @character_name=\"People1\", @id=1, @features=[], @note=\"\", @equips=[0, 0, 0, 0, 0], @nickname=\"\", @description=\"A veteran warrior who fought on many battlefields.\\r\\nHe becomes uncontrollable in battle when berserk.\", @max_level=30, @tp_cost_rate=1.0, @hp_cost_rate=1.0, @gold_cost_rate=1.0>, #<RPG::Class:0x6d8132c @name=\"Shadowman\", @learnings=[#<RPG::Class::Learning:0x6d812f0 @level=1, @skill_id=134, @note=\"\">, #<RPG::Class::Learning:0x6d812b4 @level=3, @skill_id=135, @note=\"\">, #<RPG::Class::Learning:0x6d8128c @level=1, @skill_id=136, @note=\"\">, #<RPG::Class::Learning:0x6d81264 @level=9, @skill_id=137, @note=\"\">, #<RPG::Class::Learning:0x6d8123c @level=7, @skill_id=153, @note=\"\">], @id=13, @features=[#<RPG::BaseItem::Feature:0x6d81200 @code=51, @data_id=7, @value=0.0>, #<RPG::BaseItem::Feature:0x6d811c4 @code=31, @data_id=1, @value=1.0>, #<RPG::BaseItem::Feature:0x6d81188@code=22, @data_id=0, @value=0.75>, #<RPG::BaseItem::Feature:0x6d8114c @code=22, @data_id=1, @value=0.1>, #<RPG::BaseItem::Feature:0x6d81110 @code=41, @data_id=3, @value=0.0>, #<RPG::BaseItem::Feature:0x6d810d4 @code=41, @data_id=1, @value=0.0>, #<RPG::BaseItem::Feature:0x6d81098 @code=52, @data_id=3, @value=0.0>, #<RPG::BaseItem::Feature:0x6d8105c @code=52, @data_id=1, @value=0>, #<RPG::BaseItem::Feature:0x6d81048 @code=51, @data_id=1, @value=0.0>], @note=\"\", @params=#<Table:0x6d80fe4>, @exp_params=[35, 25, 35, 35], @icon_index=0, @description=\"\", @tp_cost_rate=1.0, @hp_cost_rate=1.0, @gold_cost_rate=1.0>, #<RPG::Weapon:0x6d3f210 @description=\"A dagger with a large blade made for combat.\", @name=\"Dagger\", @icon_index=150, @price=500, @animation_id=7, @note=\"\", @id=38, @features=[#<RPG::BaseItem::Feature:0x6d3f1ac @code=31, @data_id=1, @value=0>, #<RPG::BaseItem::Feature:0x6d3f198 @code=22, @data_id=0, @value=0.0>, #<RPG::BaseItem::Feature:0x6d3f15c @code=22, @data_id=2, @value=0.03>, #<RPG::BaseItem::Feature:0x6d3f120 @code=33, @data_id=0, @value=5.0>], @params=[0, 0, 5, 0, 0, 0, 0, 0], @etype_id=0, @wtype_id=7, @tp_cost_rate=1.0, @hp_cost_rate=1.0, @gold_cost_rate=1.0>, #<RPG::Armor:0x6d3d5dc @description=\"Very lightweight clothes.\", @name=\"Casual Clothes\", @icon_index=168, @price=100, @note=\"\", @id=1, @features=[#<RPG::BaseItem::Feature:0x6d3d4c4 @code=22, @data_id=1, @value=0>], @params=[0, 0, 0,2, 0, 0, 0, 0], @etype_id=3, @atype_id=1, @tp_cost_rate=1.0, @hp_cost_rate=1.0,@gold_cost_rate=1.0>]"
mmm ... it's not showing me what I expect to see.


I can have a tinker with it to see if I can reproduce your issue, but honestly, I'm not sure when I'll have time.
Shaz, I really appreciate your help thus far . . I've learned a bit more scripting because of it.  So, no worries if you can't get to it anytime soon.
I need to reduce an actor's params, but I can't seem to get the remove_feature to work for params, only xparams.


For example, I need to reduce ATK.  I can't use numeric because I cannot be sure exactly what it will be (the player could have over/under leveled) so I use percentage.  My script call (copy/pasted) is:


remove_feature🙂actor, 1, 😛aram, 2, 0.5)


I cannot see my error.  As a test I ran


add_feature🙂actor, 1, :xparam, 3, 0.03)


This successfully increased CEV by 3%.  I then reduced it back down to zero using


remove_feature🙂actor, 1, :xparam, 3)


Can you please explain what I should be doing.  Thanks.
If you send through a value as the last parameter, it needs to be exactly what it will contain (can't send through a % if it's going to contain a number).


You could either use get_feature to get the value, and then pass that through, or easier - if an actor will only have that param 2 once - just leave out the last value altogether.
I used the script call


remove_feature🙂actor, 1, 😛aram, 2)


I thought this would reduce ATK to zero, but it leaves it unchanged, so I think I must have misunderstood what you were saying.
Can you please send me your save file?  It's been a while since I created this, and those params were always a bit confusing.
Great.  I'm on the train at the moment, so uploading anything will take a while.  I'll pm you when it's done.


Thanks.
Just doing some testing ... 


remove_feature🙂actor, 1, 😛aram, 2) 


works for me.


Also, the value is a float (but the value is only necessary if you have multiples of the same feature and you want to be very explicit about which one you remove).


I'll take a look at your save file when it comes through and see if I can figure out why it's not working for you.

Original thread: https://forums.rpgmakerweb.com/threads/dynamic-features.19645/