State Add/Remove Commands

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Shaz, Sep 30, 2013.

  1. ZServ

    ZServ Veteran Veteran

    Messages:
    247
    Likes Received:
    64
    I can pretty safely say I wasn't expecting this. This is vastly appreciated, Fen.
     
    #61
    Another Fen likes this.
  2. Another Fen

    Another Fen Veteran Veteran

    Messages:
    526
    Likes Received:
    239
    First Language:
    German


    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: Jan 19, 2016
    #62
  3. Robin Hoot

    Robin Hoot Veteran Veteran

    Messages:
    83
    Likes Received:
    22
    Edit: I accidentally posted in the wrong thread.
     
    #63
  4. Taladro-Senpai

    Taladro-Senpai Villager Member

    Messages:
    12
    Likes Received:
    1
    Location:
    Argentina
    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?
     
    #64
  5. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    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.
     
    #65
  6. Taladro-Senpai

    Taladro-Senpai Villager Member

    Messages:
    12
    Likes Received:
    1
    Location:
    Argentina
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    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.
     
    #66
  7. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    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.
     
    #67
  8. Taladro-Senpai

    Taladro-Senpai Villager Member

    Messages:
    12
    Likes Received:
    1
    Location:
    Argentina
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    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.
     
    #68
  9. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    #69
  10. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    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?
     
    #70
  11. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    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.
     
    #71
  12. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    What is add_param? What script does that?
     
    #72
  13. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    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: Jun 30, 2019
    #73
  14. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    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?
     
    #74
  15. Sixth

    Sixth Veteran Veteran

    Messages:
    2,130
    Likes Received:
    798
    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.
     
    #75
  16. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    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: Jul 1, 2019
    #76
  17. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
    #77
  18. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    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.
     
    #78
  19. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Try changing add_param to this.add_param
     
    #79
  20. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,378
    Likes Received:
    4,948
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    You mean, self.add_param?
     
    #80
    Shaz likes this.

Share This Page