Script Call Request

Discussion in 'RGSS2 Script Requests' started by ShinNessTen, Dec 30, 2018.

Thread Status:
Not open for further replies.
  1. ShinNessTen

    ShinNessTen Valedictorian of Wonderland Veteran

    Messages:
    78
    Likes Received:
    153
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMVX
    I'm using one of Yanflys old (VX, not ace) scripts that lets me buy common events. In that script, I can set a limit to how many times I can buy one common event.
    But it seems you cannot reset the number of times you have bought a common event, once you buy one. I want to know if there is a potential script call I can use to increase the number of times I can buy a common event again.
    Here's the script in question:
     
    #1
  2. A-Moonless-Night

    A-Moonless-Night WINTER IS COMING Veteran

    Messages:
    476
    Likes Received:
    341
    Location:
    New Zealand
    First Language:
    English
    Primarily Uses:
    RMVXA
    Untested, and I'm a bit rusty with VX, but give this a shot:
    Code:
    class Game_System
      attr_accessor :ces_limits
    
      alias amn_ces_gamesystem_init initialize
      def initialize
        amn_ces_gamesystem_init
        load_ces_limits
      end
     
      def load_ces_limits
        @ces_limits = Hash.new(1)
        YE::EVENT::COMMON_EVENT_ITEM_HASH.each_key do |key|
          @ces_limits[key] = YE::EVENT::COMMON_EVENT_ITEM_HASH[key][2]
        end
      end
     
    end
    
    class Game_Interpreter
    
      def set_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] = amount
      end
     
      def increase_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] += amount
      end
     
      def decrease_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] = [$game_system.ces_limits[ce_id] - amount, 1].max
      end
     
    end
    class Window_Common_Event < Window_Selectable
    
      #--------------------------------------------------------------------------
      # draw item #OVERWRITE
      #--------------------------------------------------------------------------
      def draw_item(index)
        rect = item_rect(index)
        self.contents.clear_rect(rect)
        rx = rect.x; ry = rect.y; rw = rect.width; rh = rect.height
        sw = self.width - 32
        @common_event_id  = @data[index]
        ce_array = YE::EVENT::COMMON_EVENT_ITEM_HASH[@common_event_id]
        @common_event_name  = $data_common_events[@common_event_id].name
        @common_event_cost  = ce_array[0]
        @common_event_icon  = ce_array[1]
        @common_event_limit = $game_system.ces_limits[@common_event_id]
        draw_icon(@common_event_icon, rx+2, ry, enabled)
        self.contents.font.color.alpha = enabled ? 255 : 128
        self.contents.draw_text(rx+26, ry, rw-278, rh, @common_event_name, 0)
        if YE::EVENT::CE_SHOW_LIMIT
          limit = $game_party.ces_limit[@common_event_id]
          text = sprintf(YE::EVENT::CE_LIMIT_TEXT, limit, @common_event_limit)
          if !YE::EVENT::CE_SHOW_LIMIT_0 and @common_event_limit == 0
            text = ""
          end
          if !YE::EVENT::CE_SHOW_LIMIT_1  and @common_event_limit == 1
            text = ""
          end
          self.contents.draw_text(rw-242, ry, 80, rh, text, 1)
        end
        unless !YE::EVENT::CE_SHOW_FREE_COST and @common_event_cost <= 0
          text = sprintf("%s%s", @common_event_cost, @currency)
          self.contents.draw_text(rw-152, ry, 150, rh, text, 2)
        end
      end
     
    end
    
    class Scene_Common_Event_Shop < Scene_Base
    
      #--------------------------------------------------------------------------
      # can purchase event? #OVERWRITE
      #--------------------------------------------------------------------------
      def can_purchase_event?(event)
        return false if $data_common_events[event] == nil
        cost = YE::EVENT::COMMON_EVENT_ITEM_HASH[event][0]
        if YE::EVENT::CE_SHOP_LIST[@shop_id][0] == 0
          return false if $game_party.gold < cost
        else
          return false if $game_variables[@currency] < cost
        end
        $game_party.ces_limit = {} if $game_party.ces_limit == nil
        $game_party.ces_limit[event] = 0 if $game_party.ces_limit[event] == nil
        if YE::EVENT::COMMON_EVENT_ITEM_HASH[event][2] != 0 and
        $game_party.ces_limit[event] >= $game_system.ces_limits[event]
          return false
        end
        return true
      end
     
    end
    

    With that, you should be able to use the following codes to increase and decrease limits:
    Code:
    increase_ces_limit(ID, amount)
    
    decrease_ces_limit(ID, amount)
    
    set_ces_limit(ID, amount)
    Where ID is the common event ID (as you set up in the COMMON_EVENT_ITEM_HASH).
     
    #2
    ShinNessTen likes this.
  3. ShinNessTen

    ShinNessTen Valedictorian of Wonderland Veteran

    Messages:
    78
    Likes Received:
    153
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMVX
    Unfortunately it did not work. But it also gave no errors when I tried to test it. I don't know much about scripting, but all my script calls start out with a dollar sign $
    I assumed it was mandatory, but here it would give me a syntax error.
     
    #3
  4. A-Moonless-Night

    A-Moonless-Night WINTER IS COMING Veteran

    Messages:
    476
    Likes Received:
    341
    Location:
    New Zealand
    First Language:
    English
    Primarily Uses:
    RMVXA
    I think I missed something originally:
    Code:
    class Game_System
      attr_accessor :ces_limits
    
      alias amn_ces_gamesystem_init initialize
      def initialize
        amn_ces_gamesystem_init
        load_ces_limits
      end
     
      def load_ces_limits
        @ces_limits = Hash.new(1)
        YE::EVENT::COMMON_EVENT_ITEM_HASH.each_key do |key|
          @ces_limits[key] = YE::EVENT::COMMON_EVENT_ITEM_HASH[key][2]
        end
        p(@ces_limits)
      end
     
    end
    
    class Game_Interpreter
    
      def set_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] = amount
      end
     
      def increase_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] += amount
      end
     
      def decrease_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] = [$game_system.ces_limits[ce_id] - amount, 1].max
      end
     
    end
    class Window_Common_Event < Window_Selectable
    
      #--------------------------------------------------------------------------
      # draw item #OVERWRITE
      #--------------------------------------------------------------------------
      def draw_item(index)
        rect = item_rect(index)
        self.contents.clear_rect(rect)
        rx = rect.x; ry = rect.y; rw = rect.width; rh = rect.height
        sw = self.width - 32
        @common_event_id  = @data[index]
        ce_array = YE::EVENT::COMMON_EVENT_ITEM_HASH[@common_event_id]
        @common_event_name  = $data_common_events[@common_event_id].name
        @common_event_cost  = ce_array[0]
        @common_event_icon  = ce_array[1]
        @common_event_limit = $game_system.ces_limits[@common_event_id]
        draw_icon(@common_event_icon, rx+2, ry, enabled)
        self.contents.font.color.alpha = enabled ? 255 : 128
        self.contents.draw_text(rx+26, ry, rw-278, rh, @common_event_name, 0)
        if YE::EVENT::CE_SHOW_LIMIT
          limit = $game_party.ces_limit[@common_event_id]
          text = sprintf(YE::EVENT::CE_LIMIT_TEXT, limit, @common_event_limit)
          if !YE::EVENT::CE_SHOW_LIMIT_0 and @common_event_limit == 0
            text = ""
          end
          if !YE::EVENT::CE_SHOW_LIMIT_1  and @common_event_limit == 1
            text = ""
          end
          self.contents.draw_text(rw-242, ry, 80, rh, text, 1)
        end
        unless !YE::EVENT::CE_SHOW_FREE_COST and @common_event_cost <= 0
          text = sprintf("%s%s", @common_event_cost, @currency)
          self.contents.draw_text(rw-152, ry, 150, rh, text, 2)
        end
      end
     
    end
    
    class Scene_Common_Event_Shop < Scene_Base
    
      #--------------------------------------------------------------------------
      # can purchase event? #OVERWRITE
      #--------------------------------------------------------------------------
      def can_purchase_event?(event)
        return false if $data_common_events[event] == nil
        cost = YE::EVENT::COMMON_EVENT_ITEM_HASH[event][0]
        if YE::EVENT::CE_SHOP_LIST[@shop_id][0] == 0
          return false if $game_party.gold < cost
        else
          return false if $game_variables[@currency] < cost
        end
        $game_party.ces_limit = {} if $game_party.ces_limit == nil
        $game_party.ces_limit[event] = 0 if $game_party.ces_limit[event] == nil
        if $game_system.ces_limits[event] != 0 and
        $game_party.ces_limit[event] >= $game_system.ces_limits[event]
          return false
        end
        return true
      end
     
    end

    Where are you using the script call? If it's in an event, it should work fine. If you're trying to do it inside another script, then you can just use:
    Code:
    $game_system.ces_limits[ID] += amount
    
    $game_system.ces_limits[ID] -= amount
    
    $game_system.ces_limits[ID] = amount
    
    etc.
     
    #4
  5. Isabella Ava

    Isabella Ava Veteran Veteran

    Messages:
    636
    Likes Received:
    751
    First Language:
    English
    run this script, change ID & X according
    $game_party.ces_limit[common event ID] = x
     
    #5
  6. ShinNessTen

    ShinNessTen Valedictorian of Wonderland Veteran

    Messages:
    78
    Likes Received:
    153
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMVX
    Yeah, I used it inside an event.

    Both suggestions didn't seem to do anything.
    And now I receive a message I've never even seen before in my life lol
    [​IMG]
     
    #6
  7. A-Moonless-Night

    A-Moonless-Night WINTER IS COMING Veteran

    Messages:
    476
    Likes Received:
    341
    Location:
    New Zealand
    First Language:
    English
    Primarily Uses:
    RMVXA
    Oops, yeah, that was me just testing that it was being set up properly. I've just tested it and it works fine for me.
    Code:
    class Game_System
      attr_accessor :ces_limits
    
      alias amn_ces_gamesystem_init initialize
      def initialize
        amn_ces_gamesystem_init
        load_ces_limits
      end
     
      def load_ces_limits
        @ces_limits = Hash.new(0)
        YE::EVENT::COMMON_EVENT_ITEM_HASH.each_key do |key|
          @ces_limits[key] = YE::EVENT::COMMON_EVENT_ITEM_HASH[key][2]
        end
      end
     
    end
    
    class Game_Interpreter
    
      def set_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] = amount
      end
     
      def increase_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] += amount
      end
     
      def decrease_ces_limit(ce_id, amount)
        return unless $game_system.ces_limits.has_key?(ce_id)
        $game_system.ces_limits[ce_id] = [$game_system.ces_limits[ce_id] - amount, 1].max
      end
     
    end
    class Window_Common_Event < Window_Selectable
    
      #--------------------------------------------------------------------------
      # draw item #OVERWRITE
      #--------------------------------------------------------------------------
      def draw_item(index)
        rect = item_rect(index)
        self.contents.clear_rect(rect)
        rx = rect.x; ry = rect.y; rw = rect.width; rh = rect.height
        sw = self.width - 32
        @common_event_id  = @data[index]
        ce_array = YE::EVENT::COMMON_EVENT_ITEM_HASH[@common_event_id]
        @common_event_name  = $data_common_events[@common_event_id].name
        @common_event_cost  = ce_array[0]
        @common_event_icon  = ce_array[1]
        @common_event_limit = $game_system.ces_limits[@common_event_id]
        draw_icon(@common_event_icon, rx+2, ry, enabled)
        self.contents.font.color.alpha = enabled ? 255 : 128
        self.contents.draw_text(rx+26, ry, rw-278, rh, @common_event_name, 0)
        if YE::EVENT::CE_SHOW_LIMIT
          limit = $game_party.ces_limit[@common_event_id]
          text = sprintf(YE::EVENT::CE_LIMIT_TEXT, limit, @common_event_limit)
          if !YE::EVENT::CE_SHOW_LIMIT_0 and @common_event_limit == 0
            text = ""
          end
          if !YE::EVENT::CE_SHOW_LIMIT_1  and @common_event_limit == 1
            text = ""
          end
          self.contents.draw_text(rw-242, ry, 80, rh, text, 1)
        end
        unless !YE::EVENT::CE_SHOW_FREE_COST and @common_event_cost <= 0
          text = sprintf("%s%s", @common_event_cost, @currency)
          self.contents.draw_text(rw-152, ry, 150, rh, text, 2)
        end
      end
     
    end
    
    class Scene_Common_Event_Shop < Scene_Base
    
      #--------------------------------------------------------------------------
      # can purchase event? #OVERWRITE
      #--------------------------------------------------------------------------
      def can_purchase_event?(event)
        return false if $data_common_events[event] == nil
        cost = YE::EVENT::COMMON_EVENT_ITEM_HASH[event][0]
        if YE::EVENT::CE_SHOP_LIST[@shop_id][0] == 0
          return false if $game_party.gold < cost
        else
          return false if $game_variables[@currency] < cost
        end
        $game_party.ces_limit = {} if $game_party.ces_limit == nil
        $game_party.ces_limit[event] = 0 if $game_party.ces_limit[event] == nil
        if $game_system.ces_limits[event] != 0 and
        $game_party.ces_limit[event] >= $game_system.ces_limits[event]
          return false
        end
        return true
      end
     
    end

    CES Limits 1.png CES Limits 3.png CES Limits 2.png
     
    #7
  8. ShinNessTen

    ShinNessTen Valedictorian of Wonderland Veteran

    Messages:
    78
    Likes Received:
    153
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMVX
    Ok, maybe I know what's wrong. Is it supposed to ONLY increase the limit? Because I actually wanted to just have it so that when I buy a common event, I can restock it with a script call. Maybe my wording was a little confusing, but I need that to basically reset the stock for new game+ kind of deal.
     
    #8
  9. A-Moonless-Night

    A-Moonless-Night WINTER IS COMING Veteran

    Messages:
    476
    Likes Received:
    341
    Location:
    New Zealand
    First Language:
    English
    Primarily Uses:
    RMVXA
    In that case, you can probably do the following script call:
    Code:
    $game_party.ces_limit[ID] = $game_system.ces_limits[ID]
    
    # or (if you don't want to use my script to change the limits)
    
    $game_party.ces_limit[ID] = YE::EVENT::COMMON_EVENT_ITEM_HASH[ID][2]
    EDIT:
    Or to restock all of them at once, add this snippet into your scripts:
    Code:
    class Game_Party < Game_Unit
     
      def reset_ces_limits
        return unless @ces_limit
        YE::EVENT::COMMON_EVENT_ITEM_HASH.each_key do |key|
          next unless $game_party.ces_limit.has_key?(key)
          $game_party.ces_limit[key] = 0
        end
      end
     
    end
    
    class Game_Interpreter
    
      def reset_ces_limits
        $game_party.reset_ces_limits
      end
     
    end
    And use the script call:
    Code:
    reset_ces_limits
     
    Last edited: Dec 31, 2018
    #9
    ShinNessTen likes this.
  10. ShinNessTen

    ShinNessTen Valedictorian of Wonderland Veteran

    Messages:
    78
    Likes Received:
    153
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMVX
    Yes, finally! This works very well! :)
    Thank you so much, once again!
     
    #10
    A-Moonless-Night likes this.
  11. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    5,181
    Likes Received:
    3,926
    Location:
    Belgium
    First Language:
    Dutch
    Primarily Uses:
    RMXP

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #11
Thread Status:
Not open for further replies.

Share This Page