Help with notetag

Hello, I have a problem with note tags. I try to do my first script, which detect what kind of weapon actor use and after every successful hit it raises a variable, which represents diffrent skill. For the second part i use Todd's script Experience on hit, but the first part i can't get to work. I am pretty sure there is problem in my code. Here it is.
 

Code:
class RPG::Weapons < RPG::EquipItem  def weaponclasschek	if @note =~ /<Weapon Class:\s*(\w+)>/i 	  if $1 == "Melee"      $weaponclassmeleeistrue = true    if $1 == "Ranged"      $weaponclassrangedistrue = true    if $1 == "Improvised"      $weaponclassimprovisedistrue = true    end   end	end endend
You've got a lot of IF statements in there, but no ELSE statements.

$weaponclassimprovisedistrue will be set to true only if $1 is Melee AND Ranged AND Improvised, and we know that's not the case.

Try something like this instead:

if @note =~ /<Weapon Class:\s*(\w+)>/icase $1when 'Melee' $weaponclassmeleeistrue = truewhen 'Ranged' $weaponclassrangedistrue = truewhen 'Improvised' $weaponclassimprovisedistrue = trueendendIn addition, you would need to turn them off somewhere too. Is that happening somewhere else? If not, you better turn them ALL off before the case $1 statement. Otherwise you'll process a weapon that's melee and that flag will be turned on, then you'll process a weapon that's ranged and that will be turned on, but the melee flag will still be on from before.TBH I wouldn't use a global variable at all. I'd make methods on RPG::Weapon for each case, then call them like this:

Code:
class RPG::Weapons < RPG::EquipItem  def is_melee?    @note =~ /<Weapon Class: Melee>/i  end  def is_ranged?    @note =~ /<Weapon Class: Ranged>/i  end    def is_improvised?    @note =~ /<Weapon Class: Improvised>/i  endend... in your method# Is this a ranged weapon?if weapon.is_ranged?  ... do stuffend
This way, you also have the possibility of having several of these attributes set for the same weapon, if that was ever a need.
Thanks a lot, it's finaly work that way that i wont.
I tried first of yours methods, but issuse still exists. It seems that true or false just don't register.
Here the full script, I took the base from Todd's script Experience on hit, http://forums.rpgmakerweb.com/index.php?/topic/1708-experience-on-hit/ .

Code:
if @note =~ /<Weapon Class:\s*(\w+)>/icase $1when 'Melee'  $weaponclassmeleeistrue = truewhen 'Ranged'  $weaponclassrangedistrue = truewhen 'Improvised'  $weaponclassimprovisedistrue = trueendendclass Game_ActionResult  #--------------------------------------------------------------------------  # * Create Damage  #--------------------------------------------------------------------------  def make_damage(value, item)    @critical = false if value == 0    @hp_damage = value if item.damage.to_hp?    @mp_damage = value if item.damage.to_mp?    @mp_damage = [@battler.mp, @mp_damage].min    @hp_drain = @hp_damage if item.damage.drain?    @mp_drain = @mp_damage if item.damage.drain?    @hp_drain = [@battler.hp, @hp_drain].min    @success = true if item.damage.to_hp? || @mp_damage != 0    add_skillpoints if $weaponclassmeleeistrue == true  endend  #--------------------------------------------------------------------------  # * EXP Acquisition and Level Up Display  #-------------------------------------------------------------------------- def add_skillpoints  $meleecombat += 0.5endend
DeviantSetou, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.

You still have to put it inside the RPG::Weapons class.  And in your code, you didn't call it.  You have to call your method before looking at the variable.
I will keep that in mind for future. Bat can you specify, where  should I call the method? I didn't catch that right.

Sorry for being so dumb.
This is how I would do it:

class RPG::Weapons < RPG::EquipItem def is_melee? @note =~ /<Weapon Class: Melee>/i end def is_ranged? @note =~ /<Weapon Class: Ranged>/i end def is_improvised? @note =~ /<Weapon Class: Improvised>/i endendclass Game_ActionResult alias make_damage_with_skillpoints make_damage def make_damage(value, item) make_damage_with_skillpoints(value, item) add_skillpoints(item) if item.is_a?(RPG::Weapon) end def add_skillpoints(item) $meleecombat += 0.5 if item.is_melee? $rangedcombat += 0.5 if item.is_ranged? $improvisedcombat += 0.5 if item.is_improvised? endend(assuming those are the global variable names you're using to accumulate your skill points into)Put the above into a NEW script slot below all the others, and remove (or comment out) anything you've already done to attempt to do this - so any changes to Game_ActionResult or any other changes to RPG::Weapon.

The other thing is, if you only want to increase the skill points if the hit is successful, you could change this line:

Code:
    add_skillpoints(item) if item.is_a?(RPG::Weapon)
to this:
Code:
    add_skillpoints(item) if @success and item.is_a?(RPG::Weapon)
For some reason, it doesn't work. Everytime i attack, but  global variable won't increase.
What global variable? The one(s) listed in add_skillpoints?


Can you show a screenshot of one of your weapons so I can see how the note tag is set up?


Where does the global variable get initialized?
Yeap, global variables in add_skillpoints.

I tried with different kinds of  weapons, but non of them work.

Here is screenshot WeaponNoteTags.png

The global variable initialize from script in Create Event menu.
Hi,

There is a typo left in your code. The class is called RPG::Weapon, so your script creates a new class instead.

The item argument passed to Game_ActionResult#make_damage is never a weapon object by default. It is an item or skill, depending on the attackers action.

Game_ActionResult#make_damage and Game_Battler#make_damage_value shouldn't be used for granting exp bonuses in the first place since they only calculate a theoretical damage value which is not necessarily executed. For instance, these methods are also used to calculate action preference of an ally with "Auto Battle" flag.

(As a result, when you are using the "Experience on Hit" - script you linked, the party gains <available actions> times <available targets> times the troops exp at the beginning of each turn for each ally with "Auto Battle")

Another few questions that would be interesting:
- Should every battler collect weapon exp for him-/herself or do you want a global exp value shared by all battlers?
- Should battlers gain exp per hit or per action? (Some actions result in multiple hits, e.g. area of effect techniques)

- Should battlers gain exp regardless of their action (including "Defend") or do you want to limit exp gain to specific actions?

(Sorry for all the nagging 😀 )
Hi.

1) Nope, only for one battler. I am going to create a game for one actor.
2) They should gain skill points more when they hit, and less when miss. But only skill points, not exp.
3) For now i focused on attack skill points, but it would be good to have an option for skills like "Defend"

And thanks for a eagle eye whit that typo.

(No problem with that)
Thank you Another Fen. So good to have another set of not-so-bleary eyes here! I completely missed that item could not be a weapon.


So we really can't do the calculation at this point, because this will act on the battler who is the target, and at this point, we don't know who the user was or what weapon they had equipped.


So a global variable for the weapon note WOULD be required (or a global variable for the weapon itself, which would require fewer mods to what I did), and set when the attack is made (and you have the user and target objects available), and then it could be used in the class above.
Shaz I understand what you mean, but my scripting skills is on newbie level. How can i access global variable in notebox?
And more importantly what tweaks and mod would be required?
no, not in the note box.


I was thinking Another Fen might be back with a better solution once you'd posted your answers to his/her questions.
When a battler executes an action, following steps are taken:

The attackers use_item method is called once, passing the skill/item used.

The targets item_apply method is called, passing the attacker and the skill/item used. This method is called once for every target and every repeat of the action item.

If you wanted to grant a fixed amount of experience for every use of a specific action I would have recommended to extend use_item, since it is called once regardless of the number of targets (even if there is no target at all).

If you want to reward every hit regarding on its result, I'd stick with item_apply instead:

class Game_Battler  alias_method🙂item_apply_with_skill_points, :item_apply)  def item_apply(user, item)    item_apply_with_skill_points(user, item)    # Here goes skill point calculation and distribution  endendStill to do:
- You probably want to check if the user is actually your actor and not an enemy attacking you.
- You probably want to check which skill/item is being used to determine the amount of experience. It could be any item with a scope other than "None", including "Defense", a (healing) spell or a potion.
- You have to determine which weapon type is currently being used by the actor. You might have to consider an actor can carry up to two weapons by default.

- Grant the experience.

A modification of Shaz' solution (not perfect, but it is almost 5 am... ^^):

Spoiler
Code:
class RPG::Weapons < RPG::EquipItem  def is_melee?    @note =~ /<Weapon Class: Melee>/i  end  def is_ranged?    @note =~ /<Weapon Class: Ranged>/i  end   def is_improvised?    @note =~ /<Weapon Class: Improvised>/i  endendclass Game_Battler  alias_method(:item_apply_with_skill_points, :item_apply)  def item_apply(user, item)    item_apply_with_skill_points(user, item)    user.add_skill_points  # <- Grant the User Skill Points  end   def add_skill_points    if actor?  # <- Attacker must be an actor to achieve Skill Points.      weapon_set = weapons.compact  # <- List of all equipped weapons.      $game_variables[15] += 1  if weapon_set.any? { |w| w.is_melee? }      $game_variables[16] += 1  if weapon_set.any? { |w| w.is_ranged? }      $game_variables[17] += 1  if weapon_set.any? { |w| w.is_improvised? }    end  endend
This solution uses variable 15-17 from the "event" variable set, since that saves the trouble keeping them synchronized with the savestate. However, for more flexibility I'd recomment using instance variables instead, which are unique for every actor.
Note though, the above solution (and anything I suggested) would not care what you attempted to do to the enemy - whether you attacked with a weapon, used a skill, or used an item on them.  If you only wanted it to happen when the player attacked with the weapon (using the attack skill) you would have to do additional tests to make sure 'item' is the Attack skill.
Yeap it works, thanks to you guys. I think your solution Shaz perfectly suits me. And i tested it, yeah 'item' is the Attack skill.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-notetag.34856/