The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: Mr G W on August 12, 2011, 08:24:16 PM

Title: [GW] Magical Weapons
Post by: Mr G W on August 12, 2011, 08:24:16 PM
GW Magical Weapons
Version: 1.2
Author: Mr G W
Date: (DD/MM/YYYY) - 30/8/2011

Version History



Planned Future Versions

Description

Allows weapons to deal magical damage on normal attack, so it uses SPI instead of ATK and DEF. Works with YEM RES stat.
This is similar to Magic Weapons in Fire Emblem, such as Runesword or Fire Lance.

Features


Screenshots

None.

Instructions
Place where it says Materials.
Use the <magical> tag to make a weapon magical.

Script


Code: [Select]
=begin
==================================================================================================
==================================================================================================
Magical Weapons
Version 1.2
By Mr G W - Rmrk.net
Date (DD/MM/YYYY) - 30/8/2011
<Version 1.2> 2011.8.30 - Tag can now be used to give enemies magical attacks.
<Version 1.1> 2011.8.18 - Fixed a crash when a enemy used a normal attack.
<Version 1.0> 2011.8.12 - Original Release

Allows creation of magic weapons, weapons that use your spirit (and resistance
stat, if using YEM stats) instead of attack and defense.

Use the <magical> tag to make a weapon magical.

If using Dual Weapons and one weapon is magical and the other isn't,
it will do "hybrid" damage, offensively uses both ATK and SPI and defensively
uses DEF and SPI (or RES).

The <magical> tag can also be used to give an enemy a magical attack.
Since enemies do not have weapons, the <hybrid> tag can be used to give the
enemy a mixed attack, which is equivalent to the use of two weapons,
1 magical and the other not.

Place below those scripts.
==================================================================================================
==================================================================================================
Compatibility:
This script overrides make_attack_damage_value.
This script will not work if another script is placed below this one that also
overrides the same method. If this script is placed below instead, the other
script will not work. If another script aliases this method, place it below
this script.


Any script that overrides make_attack_damage_value may not work with this or vice versa.

=end

$imported = {} if $imported == nil
$imported["GWMagicWeapons"] = true

class Game_Battler

  def make_attack_damage_value(attacker)
    damage = damage_calc(attacker)
    damage = 0 if damage < 0                        # if negative, make 0
    damage *= elements_max_rate(attacker.element_set)   # elemental adjustment
    damage /= 100
    if damage == 0                                  # if damage is 0,
      damage = rand(2)                              # half of the time, 1 dmg
    elsif damage > 0                                # a positive number?
      @critical = (rand(100) < attacker.cri)        # critical hit?
      @critical = false if prevent_critical         # criticals prevented?
      damage *= 3 if @critical                      # critical adjustment
    end
    damage = apply_variance(damage, 20)             # variance
    damage = apply_guard(damage)                    # guard adjustment
    @hp_damage = damage                             # damage HP
  end
 
  def damage_calc(attacker)
   damage = attacker.atk * 4 - self.def * 2        # base calculation
   if attacker.actor? == false #Enemies
   damage = attacker.spi * 2 - self.spi * 1 if attacker.enemy.magical == true and $imported["RES Stat"] == false
   damage = attacker.spi * 2 - self.res * 1 if attacker.enemy.magical == true and $imported["RES Stat"] == true
   damage = ((attacker.atk * 4 - self.def * 2) + (attacker.spi * 2 - self.spi * 1))/2 if attacker.enemy.hybrid == true and $imported["RES Stat"] == false
   damage = ((attacker.atk * 4 - self.def * 2) + (attacker.spi * 2 - self.res * 1))/2 if attacker.enemy.hybrid == true and $imported["RES Stat"] == true
   end
   return damage unless attacker.actor?
   if attacker.weapons[0] != nil and attacker.weapons[1] == nil #Using only weapon 0
    return damage unless attacker.weapons[0].magical == true
    damage = attacker.spi * 2 - self.spi * 1 if $imported["RES Stat"] == false
    damage = attacker.spi * 2 - self.res * 1 if $imported["RES Stat"] == true   
   elsif attacker.weapons[0] == nil and attacker.weapons[1] != nil #Using only weapon 1
    return damage unless attacker.weapons[1].magical == true
    damage = attacker.spi * 2 - self.spi * 1 if $imported["RES Stat"] == false
    damage = attacker.spi * 2 - self.res * 1 if $imported["RES Stat"] == true
   elsif attacker.weapons[0] != nil and attacker.weapons[1] != nil #Using both weapons
    return damage unless attacker.weapons[0].magical == true or attacker.weapons[1].magical == true
     if attacker.weapons[0].magical == attacker.weapons[1].magical #Both weapons are magical: Deal magic damage only
     damage = attacker.spi * 2 - self.spi * 1 if $imported["RES Stat"] == false
     damage = attacker.spi * 2 - self.res * 1 if $imported["RES Stat"] == true
     elsif attacker.weapons[0].magical != attacker.weapons[1].magical #One weapon is magical, the other isnt. Deals damage based on both stats.
     damage = ((attacker.atk * 4 - self.def * 2) + (attacker.spi * 2 - self.spi * 1))/2 if $imported["RES Stat"] == false
     damage = ((attacker.atk * 4 - self.def * 2) + (attacker.spi * 2 - self.res * 1))/2 if $imported["RES Stat"] == true
     end #If
   end #If
  return damage
  end #Def
 
end #Class

class RPG::BaseItem
 
  def magical
    self.note.scan(/<magical>/i){
    return true}
    return false
  end
end

class RPG::Enemy
 
  def magical
    self.note.scan(/<magical>/i){
    return true}
    return false
  end
 
  def hybrid
    self.note.scan(/<hybrid>/i){
    return true}
    return false
  end
 
end

You can also get it from the attachment.

Credit



Thanks


Support

Just post here. If i don't answer, it's because I can't be on.
Any errors or glitches, feel free to post.

Known Compatibility Issues

This script overrides make_attack_damage_value.
This script will not work if another script is placed below this one that also
overrides the same method. If this script is placed below instead, the other
script will not work. If another script aliases this method, place it below
this script.

Any script that overrides make_attack_damage_value may not work with this or vice versa.

Demo


None.

Author's Notes


Older scripts are kept for whatever reason you want.

Restrictions

For commercial use, contact me first. You can use this script how you want as long as you credit.
Title: Re: [GW] Magical Weapons
Post by: modern algebra on August 15, 2011, 06:54:49 PM
Nice idea. Thanks for sharing!
Title: Re: [GW] Magical Weapons
Post by: lightnox on August 15, 2011, 09:59:14 PM
very nice   :lol:, thanks for sharing  ;)
Title: Re: [GW] Magical Weapons
Post by: Mr G W on August 18, 2011, 12:09:50 PM
BUG FIX: When a enemy attacks the game will no longer crash.

I forgot that enemies do not have weapons... >_>
Title: Re: [GW] Magical Weapons
Post by: Infinate X on August 20, 2011, 01:35:22 AM
Is there a way to make them cost MP to use?
Title: Re: [GW] Magical Weapons
Post by: Mr G W on August 23, 2011, 09:11:41 AM
At the moment, no but it could be done. I'll see what i can do.

You could use KGC_RestoredFunctions to add a mana cost to your weapon.
Title: Re: [GW] Magical Weapons
Post by: Infinate X on August 26, 2011, 04:52:45 AM
Tracking down KGC scripts is hard...
Title: Re: [GW] Magical Weapons
Post by: pacdiggity on August 26, 2011, 07:59:58 AM
TWENTY SECONDS on Google found me this:
http://www.rpgmakervx.net/index.php?showtopic=19726 (http://www.rpgmakervx.net/index.php?showtopic=19726)
I don't know if Restored Functions is in there, but there are definitely KGC scripts.
Title: Re: [GW] Magical Weapons
Post by: Mr G W on August 26, 2011, 07:19:31 PM
Translated KGC Scripts by Mr. Anonymous here.

http://riggstooples.wordpress.com/kgc-scripts/
Title: Re: [GW] Magical Weapons
Post by: Mr G W on August 30, 2011, 06:55:43 PM
UPDATE: The <magical> tag can now be used on enemies. Use the <hybrid> tag to give eenmies a hybrid attack since they do not have weapons.
Title: Re: [GW] Magical Weapons
Post by: Infinate X on September 03, 2011, 02:24:35 PM
TWENTY SECONDS on Google found me this:
http://www.rpgmakervx.net/index.php?showtopic=19726 (http://www.rpgmakervx.net/index.php?showtopic=19726)
I don't know if Restored Functions is in there, but there are definitely KGC scripts.

:( I can't use that forum
Title: Re: [GW] Magical Weapons
Post by: Mr G W on September 10, 2011, 08:21:56 AM
Translated KGC Scripts by Mr. Anonymous here.

http://riggstooples.wordpress.com/kgc-scripts/

Use this for KGC scripts. The Restored Functions allows you to add MP cost to normal attack.
Title: Re: [GW] Magical Weapons
Post by: Infinate X on September 11, 2011, 01:41:14 AM
Translated KGC Scripts by Mr. Anonymous here.

http://riggstooples.wordpress.com/kgc-scripts/

Use this for KGC scripts. The Restored Functions allows you to add MP cost to normal attack.

Thanks!