How to equip a weapon/armor via script

● ARCHIVED · READ-ONLY
Started by knightsandgals 7 posts View original ↗
  1. Hello,

    we would like to know if there's a way to equip a weapon or armor, according to what the "hero" is currently wearing (equipping). :p

    For example, if our hero is equipping the weapon with ID n. 100 we want that, via script, our hero changes the weapon automatically to a new weapon with the ID 200.

    If he's wearing weapon id120 we'd like that, after call script, he wears weapon id220, if 121:221 and so on...

    What we tried to do is manipulate the id number of the weapon the hero is equipping through this script:

    1. Create Variable Operation called:  0061:weaponid

        Operand: SCRIPT $game_actors[1].equips[0].id

    2. In the event we put a call script:

        add_weapon($game_variables[61],1)

    This actually works but if we add a costant to the $game_variable, the game crashes ex. add_weapon($game_variables[61]+100,1)

    +100 represents the increase rate of our weapon id, which means that old weapon should be replaced with a new weapon which can be found at the position +100 in the database

    The return error is:

    Script 'Game Interpreter' line 1411: NoMethodErrorOccured. Undefined method 'note' for nil:NilClass

    Please help us!!!!!! :D :D :D

    We will pay u with lots of beeers!

    Lots of...
  2. I think to help on this we need to know what the function add_weapon does, as it sounds like the error is in that function. Can you post that please?
  3. I think you'll just have to add the 100 the the variable before you apply it with the add_weapon.

    Is there a reason why you cannot do this?

    $game_variables[61] = $game_actors[1].equips[0].id

    $game_variables[61] += 100

    add_weapon($game_variables[61],1)
  4. I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.
  5. Your code is doing more than just adding 100 to a variable when it's telling you that it tried to access a "note" attribute.
  6. At the start of the game, would $game_variables[61] be nil?  I know it displays and acts as "0" but it might be the nil object.

    You'd probably want a check for nil before trying to add 100 to it.
  7. Variables are never nil.


    If you take a look at the Game_Variables class, you will see that if it is not defined, it always returns 0.