I need the function that adds item to the player

Discussion in 'Javascript/Plugin Support' started by Aura_Gamer, Jul 1, 2018.

  1. Aura_Gamer

    Aura_Gamer Villager Member

    Messages:
    16
    Likes Received:
    2
    Location:
    India
    First Language:
    English
    Primarily Uses:
    RMMV
    Hello I'm trying to create a script(which is currently empty) which displays the message: found item name!
    :MV3:
    I tried finding the function which is called when player receives an item but no luck ;_;;_;:kaocry:

    Can someone tell me how to do it?
    Thanks in advance!!!!!!!!!! :kaojoy:
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    27,215
    Likes Received:
    6,007
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    search the forum - there is a pinned topic listing all script equivalents of all event commands, that is where you'll find it.
     
    #2
  3. Nolonar

    Nolonar Veteran Veteran

    Messages:
    106
    Likes Received:
    112
    First Language:
    French, German
    Primarily Uses:
    RMMV
    It's in rpg_objects.js, starting with the Game_Interpreter at line 9597:
    Code:
    // Change Items
    Game_Interpreter.prototype.command126 = function() {
        var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
        $gameParty.gainItem($dataItems[this._params[0]], value);
        return true;
    };
    
    You now know what code the event calls.
    The function is defined at line 4991:
    Code:
    Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
        var container = this.itemContainer(item);
        if (container) {
            var lastNumber = this.numItems(item);
            var newNumber = lastNumber + amount;
            container[item.id] = newNumber.clamp(0, this.maxItems(item));
            if (container[item.id] === 0) {
                delete container[item.id];
            }
            if (includeEquip && newNumber < 0) {
                this.discardMembersEquip(item, -newNumber);
            }
            $gameMap.requestRefresh();
        }
    };
    
     
    #3
    Aura_Gamer likes this.
  4. Aura_Gamer

    Aura_Gamer Villager Member

    Messages:
    16
    Likes Received:
    2
    Location:
    India
    First Language:
    English
    Primarily Uses:
    RMMV
    Thanks!
    :MV1:
     
    #4
  5. Aura_Gamer

    Aura_Gamer Villager Member

    Messages:
    16
    Likes Received:
    2
    Location:
    India
    First Language:
    English
    Primarily Uses:
    RMMV
    Nice but can someone tell me how can I know the item id of the item added???
     
    #5
  6. OmnislashXX

    OmnislashXX Veteran Veteran

    Messages:
    529
    Likes Received:
    3,309
    Location:
    Maryland
    First Language:
    English
    Primarily Uses:
    RMMV
    Actually, I put together a system that sets the variable of an item, then call the variable of the item and then goes to a common event that displays the value of the Item. Quite useful.
     
    #6
  7. Andar

    Andar Veteran Veteran

    Messages:
    27,215
    Likes Received:
    6,007
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    you are the one who decides what item the player should get, so you set the ID of the item to be added and include that in the function call
     
    #7
  8. Nolonar

    Nolonar Veteran Veteran

    Messages:
    106
    Likes Received:
    112
    First Language:
    French, German
    Primarily Uses:
    RMMV
    It's easier to help if we know what you're doing and what you're trying to do. For example, show us the code you're currently using and tell us what part isn't working.

    Right now, I'm assuming you're writing a plugin that overrides Game_Party.prototype.gainItem(item, amount, includeEquip) and want to know the Id of the item that's been added.
    In that case, simply use item.id
     
    #8

Share This Page