I can pretty safely say I wasn't expecting this. This is vastly appreciated, Fen.
State Add/Remove Commands
RGSS3 Scripts (RMVX Ace)I can pretty safely say I wasn't expecting this. This is vastly appreciated, Fen.
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
Edit: I accidentally posted in the wrong thread.
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?
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?
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 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
# * 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
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.
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.
So I've been getting a game breaking "stack level too deep" SystemStackError from this script. Here's the thread I made about it in the Script Support forum. https://forums.rpgmakerweb.com/inde...-script-and-im-not-sure-how-to-fix-it.110507/
@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?
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.
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.
That script doesn't have an add_param command or method. Are you sure it shouldn't be add_cparam?
@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.
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.
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.
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)
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.
Try changing add_param to this.add_param
You mean, self.add_param?
Original thread: https://forums.rpgmakerweb.com/threads/state-add-remove-commands.18593/