State Add/Remove Commands

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
252
Reaction score
65
Primarily Uses
(Since ZServ didn't create another topic yet I hope it's okay to post this here)


Edit: Aaaaand I didn't look at the posting date... Sorry


"adding another stack won't cause the onadd's to go off"


I think it's save to recommend to remove the
if !state?(state_id)
part from the code section you posted above. The method is alredy written in a way that it shouldn't be called unless there really is a new state to add anyway, so removing the second check should not break it.

"Removing any stack removes all of em"


That's how the "Stacking States" script is written, it has nothing to do with the "Add/Remove Commands" script. I once wrote a quick "fix" for this for another user of a german forum, but since it wouldn't work with this script you could try this adapted version: link
I can pretty safely say I wasn't expecting this. This is vastly appreciated, Fen.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
536
Reaction score
249
First Language
German
Primarily Uses
No, I'm pretty sure that line has to be there.


The line makes sense for  erase_state , but calling add_new_state multiple times would just add multiple instances of the same state to the battler:

Code:
#--------------------------------------------------------------------------
# * Add New State
#--------------------------------------------------------------------------
def add_new_state(state_id)
  die if state_id == death_state_id
  @states.push(state_id)
  on_restrict if restriction > 0
  sort_states
  refresh
end
 
Last edited by a moderator:

Robin Hoot

Veteran
Veteran
Joined
Feb 14, 2016
Messages
83
Reaction score
22
Primarily Uses
Edit: I accidentally posted in the wrong thread.
 

Taladro-Senpai

Villager
Member
Joined
May 7, 2018
Messages
12
Reaction score
1
First Language
Spanish
Primarily Uses
RMVXA
Heya Shaz, thanks for the script. It's been really useful!
I hope you can help me with this scenario:

When an enemy gets a 'Intimidated' state, I call a common event which give a random value to a variable, and plays a sound depending on the value (if it's 1, plays sound1; if it's 2, plays sound2, etc).

The thing is, I have different common events for different types of enemies (for example: Human_Intimidated, Orc_Intimidated, Animal_Intimidated, etc), so I would like to get the enemy ID from the database, and call a common event depending on the ID.

So, if the enemy is a human (a hunter, a soldier, an archer, etc), it will call Human_Intimidated, if it's an orc, it will call Orc_Intimidated,etc.

Any tips?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,315
Reaction score
11,917
First Language
English
Primarily Uses
RMMV
you could call $game_temp.reserve_common_event(id) but do a calculation to determine the common event id to be called. This will be easiest if you keep them in the same sequence as your enemies tab, with gaps where necessary. So if your enemies start at 1 and end at 20, and 13 and 14 are blank, you'd use common events 1-20, with 13 and 14 blank, for the easiest translation. If you started adding the common events at 35, then you'd have to do the calculation as (enemy id + 34) and make sure 47 and 48 are blank.

I don't have my laptop with me, and I don't remember the variable for the enemy id - not sure whether it's this.id or this.enemy_id - try them both and see what works. Or take a look at Game_Troop and see what it uses to refer to the enemy id.

Note that common events are called using the event id, not the name.
 

Taladro-Senpai

Villager
Member
Joined
May 7, 2018
Messages
12
Reaction score
1
First Language
Spanish
Primarily Uses
RMVXA
you could call $game_temp.reserve_common_event(id) but do a calculation to determine the common event id to be called. This will be easiest if you keep them in the same sequence as your enemies tab, with gaps where necessary. So if your enemies start at 1 and end at 20, and 13 and 14 are blank, you'd use common events 1-20, with 13 and 14 blank, for the easiest translation. If you started adding the common events at 35, then you'd have to do the calculation as (enemy id + 34) and make sure 47 and 48 are blank.

I don't have my laptop with me, and I don't remember the variable for the enemy id - not sure whether it's this.id or this.enemy_id - try them both and see what works. Or take a look at Game_Troop and see what it uses to refer to the enemy id.

Note that common events are called using the event id, not the name.
I got all that so far, the problem is getting the enemy ID to call the corresponding common event.
I think I can get the enemy ID from this snippet of Game_Troop, but I'm not sure what do I need to do:
#--------------------------------------------------------------------------
# * Setup
#--------------------------------------------------------------------------
def setup(troop_id)
clear
@troop_id = troop_id
@enemies = []
troop.members.each do |member|
next unless $data_enemies[member.enemy_id]
enemy = Game_Enemy.new(@enemies.size, member.enemy_id)
enemy.hide if member.hidden
enemy.screen_x = member.x
enemy.screen_y = member.y
@enemies.push(enemy)
end
init_screen_tone
make_unique_names
end
Thanks for your help.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,315
Reaction score
11,917
First Language
English
Primarily Uses
RMMV
So the code is all in the Game_Battler class, which is shared by enemies and actors, and unfortunately there's no id variable, but an @actor_id variable for actors, and an @enemy_id variable for enemies.

So you can use $game_temp.reserve_common_event(@enemy_id) if the enemy id is exactly the same as the common event id, or, for example, $game_temp.reserve_common_event(14 + @enemy_id) if your common event 15 corresponds to enemy 1.

But you will have to be sure that that state can ONLY be applied to enemies, because if you try to apply it to actors it will likely crash as actors don't have an @enemy_id variable.
 

Taladro-Senpai

Villager
Member
Joined
May 7, 2018
Messages
12
Reaction score
1
First Language
Spanish
Primarily Uses
RMVXA
So the code is all in the Game_Battler class, which is shared by enemies and actors, and unfortunately there's no id variable, but an @actor_id variable for actors, and an @enemy_id variable for enemies.

So you can use $game_temp.reserve_common_event(@enemy_id) if the enemy id is exactly the same as the common event id, or, for example, $game_temp.reserve_common_event(14 + @enemy_id) if your common event 15 corresponds to enemy 1.

But you will have to be sure that that state can ONLY be applied to enemies, because if you try to apply it to actors it will likely crash as actors don't have an @enemy_id variable.
I guess I'll do it this way then, haven't found any other way to make it work. Thanks again for the help Shaz.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,315
Reaction score
11,917
First Language
English
Primarily Uses
RMMV
@Ninjakillzu can you please check that you don't have the script installed in multiple slots, or twice in the same slot? Could you please insert a new line before the eval($1), and put the following there:
p $1

Then play with the debug window open and see what it shows there immediately before the crash.

Also, when does it happen? ANY time a state is removed, or only a specific state? If it's only a specific state, please show a screenshot of the state in the database so we can see how it's set up. If it references other states (when removing this state, either add or remove that state, for example), then please show a screenshot of those states as well. Any chance you have some kind of looping going on, where state A adds/removes state B, and state B adds/removes state A (with or without another state or more in between)?

Did you go through this thread looking at the other issues that had been reported previously and the fixes for them?
 

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
128
Reaction score
40
First Language
English
Primarily Uses
RMVXA
@Ninjakillzu can you please check that you don't have the script installed in multiple slots, or twice in the same slot? Could you please insert a new line before the eval($1), and put the following there:
p $1

Then play with the debug window open and see what it shows there immediately before the crash.

Also, when does it happen? ANY time a state is removed, or only a specific state? If it's only a specific state, please show a screenshot of the state in the database so we can see how it's set up. If it references other states (when removing this state, either add or remove that state, for example), then please show a screenshot of those states as well. Any chance you have some kind of looping going on, where state A adds/removes state B, and state B adds/removes state A (with or without another state or more in between)?

Did you go through this thread looking at the other issues that had been reported previously and the fixes for them?
I think I've narrowed it down to states that change parameters, and have things like this in the notebox:

onadd: add_param(6, 6)
onremove: add_param(6, -6)

It looks like their removal is what causes the crash.

An example of a troublesome state.

I'll post more later, cause I have to go to work now.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,315
Reaction score
11,917
First Language
English
Primarily Uses
RMMV
What is add_param? What script does that?
 

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
128
Reaction score
40
First Language
English
Primarily Uses
RMVXA
What is add_param? What script does that?
That's from a custom parameters script by Sixth. https://forums.rpgmakerweb.com/index.php?threads/custom-parameters-v1-5-22-04-2018.60832/

In the script, add_param makes it possible to increase and decrease parameters by integers, through states. For instance the first number in (6,6) refers to the 6th parameter "Agility", and the second number is by how much it is increased. If the second number is negative, that shows how much it is decreased.

I also did look through earlier posts for relevant information, but didn't really come across any.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,315
Reaction score
11,917
First Language
English
Primarily Uses
RMMV
That script doesn't have an add_param command or method. Are you sure it shouldn't be add_cparam?
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
805
First Language
Hungarian
Primarily Uses
RMVXA
@Ninjakillzu
Like Shaz wrote, my script only has an add_cparam method, not add_param.
So if you want to change the value of a custom parameter, use add_cparam instead.
 

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
128
Reaction score
40
First Language
English
Primarily Uses
RMVXA
@Ninjakillzu
Like Shaz wrote, my script only has an add_cparam method, not add_param.
So if you want to change the value of a custom parameter, use add_cparam instead.
Sorry, I probably wasn't clear enough. I'm just increasing and decreasing the default parameters, not custom ones. I did the change, and I got an immediate crash.

As for how I came across add_param, I'm not completely sure. I think I was trying to figure out a way to increase parameters, and stumbled across that. It works fine with the adding part, but subtracting seems to cause issues. As for why, I'm still not sure.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,315
Reaction score
11,917
First Language
English
Primarily Uses
RMMV
And we go back to this:

What is add_param? What script does that?
We need to know where you got that command, before we can figure out why it's not working. If you run those two commands in just a plain Script call from an event, does it work, or does it still crash? If it still crashes, then the issue is not with my script, and you should start a new thread.
 

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
128
Reaction score
40
First Language
English
Primarily Uses
RMVXA
And we go back to this:



We need to know where you got that command, before we can figure out why it's not working. If you run those two commands in just a plain Script call from an event, does it work, or does it still crash? If it still crashes, then the issue is not with my script, and you should start a new thread.
When I search for "add_param" in all my scripts with the "find" function, it only comes up with these:
  • Game_BattlerBase (455): def add_param(param id, value)
  • Game_Battler (688): add_param(effect.data_id, effect.value1.to_i)
  • Game_Interpreter (1225): actor.add_param(@params[2], value)
I'm certain I didn't get it from a script I installed. I must have come across it in the scripts that normally come with the program. As for running the two commands, I'm not sure what that would look like in the script call. If I put add_param(3, 2) in the script call, then I get a NoMethod error.

If I just use the item with the states outside of combat, it works like it should with no errors. It also works fine in combat if they player uses it. It only crashes if used by enemies in combat.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,315
Reaction score
11,917
First Language
English
Primarily Uses
RMMV
Try changing add_param to this.add_param
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Well, the Danganronpa games are the biggest disappointment I've had playing mystery games. I've never had so much BS shoveled down my throat. They're an insult to intelligence.
OMG! There's a rat themed Steam profile wallpaper for 5k lunar tokens. I want it so badly!
Huh, lots has changed since I've been away...
It's almost new year, again!
Succesfully finished a quest of saving my kitty who fell from a wall!

+25XP

MrKiwi leveled up!
MrKiwi learned how to save his kitty!

Forum statistics

Threads
93,574
Messages
913,598
Members
123,106
Latest member
RezaMaulana98
Top