Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Bob423

Checking if the player has a weapon.

Question

I'm using a customized battle formula and I want there to make fighting without a weapon a very bad idea without making it impossible (the default battle system makes unarmed attacks do 0 damage) since the default battle system calculates damage in a weird way, it doesn't check if the character has a weapon, only their ATK stat, which, without a weapon, is 0 of course.
I want to make damage dealt without a weapon do either half as much, or 1/4 as much (haven't decided) so I need to know how to say, in the Game_Battler class...
"if the attacker is not an enemy and has no weapon, divide self.damage by 2"
 
All I need is the simplest way to do it. please dont try to explain how everything works, because i wont understand. here is my battle formula script if you need it:

 

 

 

class Game_Battler
#--------------------------------------------------------------------------
# * Applying Normal Attack Effects
# attacker : battler
#--------------------------------------------------------------------------
def attack_effect(attacker)
# Clear critical flag
self.critical = false
# First hit detection
hit_result = (rand(100) < attacker.hit)
# If hit occurs
if hit_result == true
# Calculate basic damage
atk = [((attacker.atk + attacker.str) - ((self.dex + self.pdef) / 2)), 0].max
self.damage = atk
# If actor is unarmed
def check_weapon
weapon = $data_weapons[@weapon_id]
return weapon != nil ? self.damage : [atk / 2]
end
check_weapon
# Element correction
self.damage *= elements_correct(attacker.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Critical correction
if rand(100) < 4 * attacker.crt / self.crt
self.damage *= 2
self.critical = true
end
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# Dispersion
if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
# Second hit detection
eva = 8 * self.agi / attacker.agi + self.eva
hit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
end
# If hit occurs
if hit_result == true
# State Removed by Shock
remove_states_shock
# Substract damage from HP
self.hp -= self.damage
# State change
@state_changed = false
states_plus(attacker.plus_state_set)
states_minus(attacker.minus_state_set)
# When missing
else
# Set damage to "Miss"
self.damage = "Miss"
# Clear critical flag
self.critical = false
end
# End Method
return true
end
#--------------------------------------------------------------------------
# * Apply Skill Effects
# user : the one using skills (battler)
# skill : skill
#--------------------------------------------------------------------------
def skill_effect(user, skill)
# Clear critical flag
self.critical = false
# If skill scope is for ally with 1 or more HP, and your own HP = 0,
# or skill scope is for ally with 0, and your own HP = 1 or more
if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
# End Method
return false
end
# Clear effective flag
effective = false
# Set effective flag if common ID is effective
effective |= skill.common_event_id > 0
# First hit detection
hit = skill.hit
if skill.atk_f > 0
hit *= user.hit / 100
end
hit_result = (rand(100) < hit)
if hit_result == true
# if atk is used
if skill.atk_f > 0
self.damage = [((attacker.atk + attacker.str + skill.power) - ((self.dex + self.pdef) / 2)), 0].max
end
# if int is used
if skill.int_f > 0
self.damage = [((attacker.int + skill.power) - (self.mdef / 2)), 0].max
end
# Element correction
self.damage *= elements_correct(skill.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# Dispersion
if skill.variance > 0 and self.damage.abs > 0
amp = [self.damage.abs * skill.variance / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
# Second hit detection
eva = 8 * self.agi / attacker.agi + self.eva
hit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
# Set effective flag if skill is uncertain
effective |= hit < 100
end
# If hit occurs
if hit_result == true
# If physical attack has power other than 0
if skill.power != 0 and skill.atk_f > 0
# State Removed by Shock
remove_states_shock
# Set to effective flag
effective = true
end
# Substract damage from HP
last_hp = self.hp
self.hp -= self.damage
effective |= self.hp != last_hp
# State change
@state_changed = false
effective |= states_plus(skill.plus_state_set)
effective |= states_minus(skill.minus_state_set)
# If power is 0
if skill.power == 0
# Set damage to an empty string
self.damage = ""
# If state is unchanged
unless @state_changed
# Set damage to "Miss"
self.damage = "Miss"
end
end
# If miss occurs
else
# Set damage to "Miss"
self.damage = "Miss"
end
# If not in battle
unless $game_temp.in_battle
# Set damage to nil
self.damage = nil
end
# End Method
return effective
end
 
end
 

 

 

Edited by bigace

Share this post


Link to post
Share on other sites

24 answers to this question

Recommended Posts

  • 0

YES! I DID IT! WOOT

 

I made it so, when the player is unarmed, their ATK is 0, but it's 1 when armed. (there's an option for that in SBS

then I did this:

 

 

if attacker.atk != 0
        atk = [((attacker.atk + attacker.str) - (self.dex / 2)), 0].max
elsif attacker.atk == 0
        atk = [(((attacker.atk + attacker.str) - (self.dex / 2)) / 2), 0].max
end
now for that stupid skill formula >.> Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

I might be able to help... Recently I made an array for my project which involved checking for weapons and all that. So what do you need exactly?

Share this post


Link to post
Share on other sites
  • 0

Was I not clear? I just need to know what to put in an if statement, and to know if there's anything i need to define.

so something like...

if actor_weapon == nil

self.damage = atk / 2

end

Share this post


Link to post
Share on other sites
  • 0

Maybe try;

 

if $game_party.actors[0].weapon_id == nil

self.damage = (atk / 2)

end

 

Not too sure.. I know that the if statement should work, just not sure about it working with nil.

Share this post


Link to post
Share on other sites
  • 0

but wouldn't that only check if the first character is unarmed?

It didn't do anything anyway though :(

hm...

 

YAY! I figured it out! Don't know why I couldn't before. I used some of the code from the Advanced Status system I'm using.

 

I ended up with this:

class Game_Battler < Game_Actor
 
  def weapons
    result = []
    for i in 0...@equip_kind.size
      id = @equip_kind[i]
      if id == 0 or (id == 1 and two_swords_style)
        result << $data_weapons[@equip_id[i]]
      end
    end
    return result.compact
  end
      # If actor is unarmed
       if weapons.empty?
          self.damage /= 2
          self.critical = false
        end

edit: this isn't working right...hold on...

 

edit: fixed above

 

edit: ok maybe not...this is weird. the damage is always between 0 and 3 now. It should be around 5-8 i think. and for some reason it does it even when the actor is armed.

 

edit: now it's around 5-8, but with a weapon it's lower >.>

 

edit: ok im lost...

Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

where'd you find the weapons.empty? code from? Maybe try if weapons.empty = true

Share this post


Link to post
Share on other sites
  • 0

Okay, when there's no weapon equip, the ID is 0. So try;

 

if $game_party.actors[0].weapon_id == 0

self.damage = (atk / 2)

end

Share this post


Link to post
Share on other sites
  • 0

Nope. and I've realized that setting the super class to Game_Actor only made it worse. And even if what you gave me worked, it still only checks if the first actor has a weapon. if an enemy attacks, and the actor in the first slot has no weapon, the enemy's damage will be halfed. same goes with any other actor that has a weapon while actor 0 in unarmed.

Share this post


Link to post
Share on other sites
  • 0

you want to edit game_actor, where the base attack is calculated here:

def base_atk
    weapon = $data_weapons[@weapon_id]
    return weapon != nil ? weapon.atk : 0
  end

 

just make the 0 whatever you want the base attack for an unarmed character to be

Share this post


Link to post
Share on other sites
  • 0

No I don't. Well at least not that part. i already have a script that has an option for that, and I don't like it. What I want is, not to change the base ATK stat, when unarmed, but to divide the damage by 2 after everything else has been calculated, if the attacker is unarmed. in the battle system I'm using, enemies can also have weapons.

because of the way my damage formula works, that would do no good at all.

Share this post


Link to post
Share on other sites
  • 0

well you will need at least some base attack or its just gonna do 0 damage anyway, then in game_actor add a method to check the character for a weapon like:

def weapon_equipped?
    return !$data_weapons[@weapon_id].nil?
end

 

then in your battle formula you can check the character for a weapon and go from there, also check if the attacker is a Game_Actor

 

if attacker.is_a?(Game_Actor)
    self.damage /= 2 unless attacker.weapon_equipped?
end

Share this post


Link to post
Share on other sites
  • 0

don't know if that will work, but I do know that I have it set to that damage isn't always 0 when unarmed anyway. If it was, I wouldn't be doing this, because I wouldn't have changed the battle formula.

gonna try that now.

 

edit: undefined variable or method "weapon_equipped?"

Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

oh, DERP

added that, and it does nothing. (also fixed your "nill" typo)

this is getting really annoying >.<

 

hm...nope, new game doesn't help. this is weird.

Share this post


Link to post
Share on other sites
  • 0

us a print before and after the damage is changed, like this:

p self.damage
if attacker.is_a?(Game_Actor)
    self.damage /= 2 unless attacker.weapon_equipped?
end
p self.damage

 

tell me what result you get, if the damage is successfully divided then your problem lies elsewhere, it would be nice to see how you implemented forcing your character to do damage when having no weapon equiped

 

edit:

also where abouts you add the edit will make a diference, I would probably add it in where the guarding corection is done

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

All I did was change "self.damage = atk * (20 + attacker.str) / 20" to "self.damage = atk" and I made the "atk =" use both the str and atk stat.

 

also pol gave me an awesome debug console that lets me debug stuff like that without annoying pop-ups

3g1OqkF.png

the 15 is the damage.

Share this post


Link to post
Share on other sites
  • 0

I still need to know how your forcing the damage to not be 0 when unarmed, when I edit the base attack like I mentioned before and make the same edits you made to the damage equations it divides perfectly when unarmed, are you giving your character a base attack power and adding the weapons attack onto that?

 

here is the script I got it to work with:

 

 

#============================================================================
# ** Game Actor (added weapon check and edited base attack)
#============================================================================
class Game_Actor < Game_Battler
  def weapon_equipped?
    return !$data_weapons[@weapon_id].nil?
  end
  
  def base_atk
    weapon = $data_weapons[@weapon_id]
    return weapon != nil ? weapon.atk : 10
  end
end

#============================================================================
# ** Game Battler (damage equation modified)
#============================================================================
class Game_Battler
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    # Clear critical flag
    self.critical = false
    # First hit detection
    hit_result = (rand(100) < attacker.hit)
    # If hit occurs
    if hit_result == true
      # Calculate basic damage
      self.damage = [((attacker.atk + attacker.str) - 
        ((self.dex + self.pdef) / 2)), 0].max 
      #atk = [attacker.atk - self.pdef / 2, 0].max
      #self.damage = atk * (20 + attacker.str) / 20
      # Element correction
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Critical correction
        if rand(100) < 4 * attacker.dex / self.agi
          self.damage *= 2
          self.critical = true
        end
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
        if attacker.is_a?(Game_Actor)
          p self.damage
          self.damage /= 2 unless attacker.weapon_equipped?
          p self.damage
        end
      end
      # Dispersion
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
    # If hit occurs
    if hit_result == true
      # State Removed by Shock
      remove_states_shock
      # Substract damage from HP
      self.hp -= self.damage
      # State change
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # When missing
    else
      # Set damage to "Miss"
      self.damage = "Miss"
      # Clear critical flag
      self.critical = false
    end
    # End Method
    return true
  end
end

 

 

Edited by bigace

Share this post


Link to post
Share on other sites
  • 0

this is mine

 

class Game_Battler
  include N01
 
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : battler
  #--------------------------------------------------------------------------  
  def attack_effect(attacker)
    # Clear critical flag
    self.critical = false
 
    # First hit detection
    hit_result = (rand(100) < attacker.hit)
 
    # If hit occurs
    if hit_result == true
      
      puts "hit_result == true"
      # Calculate basic damage
      atk = [((attacker.atk + attacker.str) - ((self.dex + self.pdef) / 2)), 0].max
      self.damage = atk
      puts "damage calculated"
 
      # Element correction
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
 
      # If damage value is strictly positive
      if self.damage > 0
        puts "damage is greater than 0"
      # Critical correction
        if rand(100) < 4 * attacker.crt / self.crt - (self.eva / 2)
          self.damage *= 2
          self.critical = true
        end
      
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      
      puts "damage is" self.damage
      puts "checking if actor is unarmed"
      # Check if actor is unarmed
      if attacker.is_a?(Game_Actor)
        puts "actor is unarmed"
        self.damage /= 10 unless attacker.weapon_equipped?
        puts "damage is" self.damage
        self.critical = false
      end
      
      puts "calculating dispersion"
      # Dispersion
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      puts "end turn"
      puts ""
      puts ""
      # Second hit detection
      eva = 8 * self.agi / attacker.agi + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
    # If hit occurs
    if hit_result == true
      # State Removed by Shock
      remove_states_shock
      # Substract damage from HP
      self.hp -= self.damage
      # State change
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # When missing
    else
      self.critical = false
      # Set damage to "Miss"
      self.damage = "Miss"
      # Clear critical flag
      self.critical = false
    end
    # End Method
    return true
  end
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #     user  : the one using skills (battler)
  #     skill : skill
  #--------------------------------------------------------------------------
 def skill_effect(user, skill)
    # Clear critical flag
    self.critical = false
    # If skill scope is for ally with 1 or more HP, and your own HP = 0,
    # or skill scope is for ally with 0, and your own HP = 1 or more
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
       ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
# Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= skill.common_event_id > 0
    
    # First hit detection
    hit = skill.hit
    if skill.atk_f > 0
      hit *= user.hit / 100
    end
    hit_result = (rand(100) < hit)
  
  if hit_result == true
    # if atk is used
    if skill.atk_f > 0
      self.damage = [((attacker.atk + attacker.str + skill.power) - ((self.dex + self.pdef) / 2)), 0].max
    end
    
    # if int is used
    if skill.int_f > 0
      self.damage = [((attacker.int + skill.power) - (self.mdef / 2)), 0].max
    end
      
    # Element correction
      self.damage *= elements_correct(skill.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if skill.variance > 0 and self.damage.abs > 0
        amp = [self.damage.abs * skill.variance / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      
      # Second hit detection
      eva = 8 * self.agi / attacker.agi + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    # Set effective flag if skill is uncertain
      effective |= hit < 100
    end
    # If hit occurs
    if hit_result == true
      # If physical attack has power other than 0
      if skill.power != 0 and skill.atk_f > 0
        # State Removed by Shock
        remove_states_shock
        # Set to effective flag
        effective = true
      end
      # Substract damage from HP
      last_hp = self.hp
      self.hp -= self.damage
      effective |= self.hp != last_hp
      # State change
      @state_changed = false
      effective |= states_plus(skill.plus_state_set)
      effective |= states_minus(skill.minus_state_set)
      # If power is 0
      if skill.power == 0
        # Set damage to an empty string
        self.damage = ""
        # If state is unchanged
        unless @state_changed
          # Set damage to "Miss"
          self.damage = "Miss"
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return effective
  end
end

 


I'm also using the SBS Tankatai thing with the advanced status script, which I edited because it messed with my menus >.>
and im using enemy equipped weapons, and Atoa's ATB add-on.

Edited by bigace

Share this post


Link to post
Share on other sites
  • 0

can you post a scripts.rxdata and i can do a full debug, as it is that should work as long as you got no weapon equipped, remember to make sure your unequipping your weapon, I made that mistake a few times

Share this post


Link to post
Share on other sites
  • 0

cool, i'm not going to be able to be able to check it for a couple of days as I have a 30hr travel journey to the UK ahead of me :/ but as soon as i get the chance ill look into it 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...