Save-Point
LoanSharks - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: LoanSharks (/thread-7188.html)



LoanSharks - kyonides - 12-21-2017

LoanSharks

by Kyonides-Arkanthos


Introduction


This scriptlet lets your heroes get personal loans from your "friendly" loan sharks?

Features

You may set the maximum amount of gold your heroes can get from the loan shark, the number of steps the heroes might do before they get charged a "modest fee" by the loan shark, and the interest percent itself. Now you may even make good use of invisible timers and game switches to create interesting bone-breaking events! Laughing + Tongue sticking out

Script Calls

Total Amount
$game_party.loans

Get a New Loan!
$game_party.new_loan(loanshark_id, amount)

Make a payment!
$game_party.pay_loan(loanshark_id, amount)

Get extra money!
$game_party.increase_loan(loanshark_id, amount)

Disable Loans!
Loans.freeze_loans

Enable Loans!
Loans.thaw_loans

The Script Itself

Code:
# * LoanSharks
#   Scripter : Kyonides-Arkanthos
#   2017-12-24

module Loans
  MAX = { 1 => 99999999, 2 => 99999 }
  TIME_LIMIT = { 1 => 300, 2 => 120 }
  SWITCH_IDS = { 1 => 10, 2 => 11 }
  INTEREST_STEPS = 100
  INTEREST_PERCENT = 10
  @disable_loans = nil
  def self.disable_loans?() @disable_loans end
  def self.disable_loans=(bool) @disable_loans = bool end
  def self.freeze_loans() @disable_loans = true end
  def self.thaw_loans() @disable_loans = nil end
end

class Game_System
  alias loans_gm_sys_up update
  def update
    loans_gm_sys_up
    timers = $game_party.loans_timer
    timers.keys.each do |ls_id|
      timers[ls_id] -= 1
      next if timers[ls_id] > 0
      sid = Loans::SWITCH_IDS[ls_id]
      $game_switches[sid] = true
      timers.delete(ls_id)
    end
  end
end

class Game_Party
  attr_reader :loans
  alias loans_gm_party_init initialize
  alias loans_gm_party_increase_steps increase_steps
  def initialize
    @loans = {}
    @loans_steps = {}
    @loans_timer = {}
    @loans.default = 0
    @loans_steps.default = 0
    @loans_timer.default = 0
    Loans.thaw_loans
    loans_gm_party_init
  end

  def new_loan(ls_id, amount)
    return if Loans.disable_loans
    @loans[ls_id] = amount
    @loans_steps[ls_id] = @steps
    @loans_timer[ls_id] = Loans::TIME_LIMIT[ls_id] * Graphics.frame_rate
  end

  def pay_loan(ls_id, amount)
    old_loans = @loans[ls_id]
    @loans[ls_id] = [old_loans - amount, 0].max
    lose_gold(old_loans - @loans[ls_id])
    return unless @loans[ls_id] == 0
    @loans.delete(ls_id)
    @loans_steps.delete(ls_id)
    @loans_timer.delete(ls_id)
  end

  def increase_loan(ls_id, amount)
    return if Loans.disable_loans
    old_loans = @loans[ls_id]
    @loans = [old_loans + amount, Loans::MAX[ls_id]].min
    gain_gold(@loans[ls_id] - old_loans)
  end

  def increase_steps
    loans_gm_party_increase_steps
    return unless @loans_steps.size == 0
    i_steps = Loans::INTEREST_STEPS
    i_perc = Loans::INTEREST_PERCENT
    @loans_steps.each do |k,v|
      next unless (@steps - v) % i_steps == 0
      @loans[k] += @loans[k] * i_perc / 100
    end
  end
end

Terms & Conditions

You got to credit me for making this scriptlet! Laughing + Tongue sticking out


RE: LoanSharks - kyonides - 12-24-2017

Sneezing a Bump out of my reddish nose!

I was just hanging around when I came up with a way to implement a suggestion made by some boring people in the last couple of days. The results were a new version of my scriptlet, and I had to post it here obviously... Let's see if anyone really includes some bad ass mafioso or dozens of thugs in their videogames!