Different item effects in and out of battle

Discussion in 'RGSS3 Script Requests' started by mjshi, Aug 20, 2015.

  1. mjshi

    mjshi Jack of Most Trades Veteran

    Messages:
    874
    Likes Received:
    701
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    N/A
    I have an item that is supposed to heal a player, but mostly for in-battle purposes. What I had in mind was a pill-type item that restores HP in battle without asking any questions, but if it's used outside of battle a message will tell the player that using it too much becomes detrimental to the player's health (i.e. Max HP goes down), then asks if the player still wants to use it.

    I have attempted using a conditional branch inside of a common event, but putting them in the effects box:

    [​IMG]

    causes the heal to occur first, then the common event runs. If I do the HP heal inside the common event, I'll need to do a bunch of conditionals checking who's using the item, then applying the heal to that person.

    So. Is there a way to have different item "effects" depending on whether or not the item user is currently fighting a horde of Orcs?
     
    Last edited by a moderator: Aug 20, 2015
    #1
  2. Lecode

    Lecode (─‿‿─) Veteran

    Messages:
    490
    Likes Received:
    644
    First Language:
    French
    Primarily Uses:
    N/A
    What i can do is allow to use discreetly another item instead of the selected one in the item menu.

    I don't know if it'll help. 

    EDIT: Script removed.

    Erh...wait, i forgot something x)
     
    Last edited by a moderator: Aug 20, 2015
    #2
  3. mjshi

    mjshi Jack of Most Trades Veteran

    Messages:
    874
    Likes Received:
    701
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    N/A
    @Lecode That sounds good as well, it doesn't really matter if it's the same item or not, as long as it achieves the same effect :3

    Thank you, I'll wait here for the edit ^_^
     
    #3
  4. Lecode

    Lecode (─‿‿─) Veteran

    Messages:
    490
    Likes Received:
    644
    First Language:
    French
    Primarily Uses:
    N/A
    Try this ^^

    #==============================================================================# Different effects outside the battle# By Lecode#----------------------# Use <when_outside: x> on skills and items notetags.# When the party is outside, the effects of the skill/item with # the ID x w'll be used instead of the selected skill/item's effects#==============================================================================module Lecode_ItemOutside def self.get_outside_item(item) return item if $game_party.in_battle other_id = item.outside_item_id if other_id > 0 if item.is_a?(RPG::Skill) return $data_skills[other_id] elsif item.is_a?(RPG::Item) return $data_items[other_id] end end return item end endclass Scene_ItemBase def use_item_to_actors true_item = Lecode_ItemOutside.get_outside_item(item) item_target_actors.each do |target| true_item.repeats.times { target.item_apply(user, true_item) } end end endclass Game_Battler def use_item(item) pay_skill_cost(item) if item.is_a?(RPG::Skill) consume_item(item) if item.is_a?(RPG::Item) true_item = Lecode_ItemOutside.get_outside_item(item) true_item.effects.each {|effect| item_global_effect_apply(effect) } end endclass RPG::UsableItem def outside_item_id self.note =~ /<when_outside:[ ]?(.+)>/ ? $1.to_i : 0 end end 
    However, there may be some compatibility issues with the use_item method. Send me a PM if it's the case.
     
    Last edited by a moderator: Aug 20, 2015
    #4
    mjshi likes this.
  5. mjshi

    mjshi Jack of Most Trades Veteran

    Messages:
    874
    Likes Received:
    701
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    N/A
    Tested, no error messages are popping up. It works, thank you!

    Side question that you might be able to help me with:

    Is there a way to set a variable to equal the actor id of the actor the item was used on?

    For future reference:

    In the item/skill damage formula, do this:

    v[variable id]=a.id
     
    Last edited by a moderator: Aug 20, 2015
    #5
    Lecode likes this.
  6. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,504
    Likes Received:
    318
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
    Fixed Script Formatting.
    Haven't tested.
    Code:
    #==============================================================================
    # Different effects outside the battle
    # By Lecode
    #----------------------
    # Use <when_outside: x> on skills and items notetags.
    # When the party is outside, the effects of the skill/item with
    # the ID x w'll be used instead of the selected skill/item's effects
    #==============================================================================
    module Lecode_ItemOutside
        def self.get_outside_item(item)
            return item if $game_party.in_battle
            other_id = item.outside_item_id
            if other_id > 0
                if item.is_a?(RPG::Skill)
                    return $data_skills[other_id]
                elsif item.is_a?(RPG::Item)
                    return $data_items[other_id]
                end
            end
            return item
        end
    end
    
    class Scene_ItemBase
        def use_item_to_actors
            true_item = Lecode_ItemOutside.get_outside_item(item)
            item_target_actors.each do |target|
                true_item.repeats.times { target.item_apply(user, true_item) }
            end
        end
    end
    
    class Game_Battler
        def use_item(item)
            pay_skill_cost(item) if item.is_a?(RPG::Skill)
            consume_item(item) if item.is_a?(RPG::Item)
            true_item = Lecode_ItemOutside.get_outside_item(item)
            true_item.effects.each {|effect| item_global_effect_apply(effect) }
        end
    end
    
    class RPG::UsableItem
        def outside_item_id
            self.note =~ /<when_outside:[ ]?(.+)>/ ? $1.to_i : 0
        end
    end 
     
    #6

Share This Page