Blue Magic without script?

I have a character that I want to learn some skills if, and only if, he is hit by them.  I planned to do this by using Tsukihime's Blue Magic script (plus Effect Manager) and an accessory.  In essence, you tag the accessory as blue magic and put a blue magic tag on the skills that you want the character to learn.


Unfortunately, the character learns any and every skill he is hit with, whether it's an attack by an enemy or healing by an ally.  I suspect that some other script I am using is interfering with Tsukihime's, rendering it unusable.


Does anyone know a way of doing this (probably for no more than 3 or 4 skills) without a script so that it appears to the player that the character is learning it because he is equipped with this accessory?


Thanks.
Something like this might work in the damage formula:

Code:
b.add_skill(item.id) if b.equips[4] && b.equips[4].id == #; real_damage_formula_here



where # is the id of the accessory.


This is based on the following assumptions:


- you don't need to check the target actor id - as long as they have that accessory equipped, they should learn the skill - this means if you only want certain party members to learn the skill, you need to use the database settings to restrict who can equip the accessory.


- the damage formula above is only used on the skills you want them to learn (only add it to the blue magic skills)


- the blue magic skills can only be used on your party members, not on enemies (so if they're skills cast by your party, the target should be ally; if they're skills cast by enemies, the target should be enemy)


- actors who can wear the accessory and learn the skills are already set up in the database with the correct features to allow them to learn & use the skill / skill type


- the accessory will only be used in the default accessory slot - you don't have a script that gives additional equipment slots, where that accessory might be used


If any of these assumptions are not true, just say so, and how it should work instead, and I'll see if I can give you the necessary mods.


I haven't tested this, so it might need a little tweaking.  And hopefully the damage formula box is big enough to fit it all in.
@Shaz All your assumptions are correct.  However, although the enemy uses the skill correctly - I can see the damage to HP being done and the state which goes with this particular test skill being inflicted - the character still does not learn it.  This character has both Magic and Special skills allocated to him in the database.


Here is my exact formula.  I did wonder if I was supposed to do something with the part where it reads: (item.id)


b.add_skill(item.id) if b.equips[4] && b.equips[4].id == 94; a.atk * 4 - b.def * 2


I have assumed that [4] is what identifies the equipment type, i.e. that it's an accessory and therefore I do not change that.  I have double checked that the accessory is in slot 094 and have assumed no leading zero.


Are my assumptions correct?  Should I have changed (item.id)?
Ah - item may not be in the scope of the damage evaluation.


Yes, replace item.id with the skill's id.  You are correct with no leading zeros.
I tried changing it to the skill's id, but it still didn't work, and I can't see why.  I've tried it with different skills, but it seems to make no difference.  I'm now wondering about using a different approach.


Have a dummy skill which just calls up a common event.  That CE would look like this (pretend script calls)


CE skill dummy.png


There are 2 problems with this.


First, I don't know what those 2 script calls should be.


Second, how would I ensure it was the actual enemy which would take the action, rather than trying to guess, which 'Force Action' would oblige me to do?
Using formulae you can store the whole enemy into a variable using the $v[n] = a in the enemy attack formula. Then you can perform a check but you hve to use a script call to force action this way or you won't be able to point the correct enemy


Anyway I think Shaz option should work better, just I am not sure it's add_skill. The Script Call Collection for VX ace says it is learn_skill(id). Try using Shaz formula with that function instead of add_skill.
Yes, that's it - learn.skill works perfectly. Mission accomplished!


Thank you both very much.  If I hadn't got this to work I would have had to do some very significant re-jigging of my story and the reason why this character joins the party.  Now I can carry on with Plan A. 
I am glad you managed to do it. If you want to save some space in your damage formula (VX Ace really allow you to use a limited number of characters) you can use this:

Spoiler
Code:
module HLS
  # change this to be the id of the item that allows your character to learn
  # the skill used on it. Default is 1.
  ITEM = 1
  # change this to be the slot id you want to check. Default is 4.
  ITEM_SLOT = 4
end

class Game_Battler < Game_BattlerBase
  
  def pass_skill(id)
    if (b.actor? && b.equips[HLS::ITEM_SLOT] && (b.equips[HLS::ITEM_SLOT].id == HLS::ITEM))
      b.learn_skill(id)
    end
  end
  
end



This way you only have to add pass_skill(id) in your damage formula and it automatically checks if the target is an actor and if the selected slot contains the selected item. Since it checks if the trget is an actor you should be able to add it to any skill and it should work.


BUT I still didn't test it.
I'm not entirely sure that I understand what I need to put in (I'm a well-known scripting idiot), so for an accessory with an id of 94, and skill id of 260, would it read like this?


def pass_skill(260)


   [SIZE=10.5pt]if (b.actor? && b.equips[HLS::4] && (b.equips[HLS::4].id == HLS::94))[/SIZE]


[SIZE=10.5pt]     b.learn_skill(260)[/SIZE]


[SIZE= 10.5pt] [/SIZE][SIZE= 10.5pt]end[/SIZE]


[SIZE= 10.5pt]For the other skills, presumably I can add them in the same format between this 'end' and the final 'end'.  Is that correct?[/SIZE]
If your item id is always the same you can change the ITEM value in the HLS module like this:

Spoiler
module HLS
# change this to be the id of the item that allows your character to learn
# the skill used on it. Default is 1.
ITEM = 94
# change this to be the slot id you want to check. Default is 4.
ITEM_SLOT = 4
end

class Game_Battler < Game_BattlerBase

def pass_skill(id)
if (b.actor? && b.equips[HLS::ITEM_SLOT] && (b.equips[HLS::ITEM_SLOT].id == HLS::ITEM))
b.learn_skill(id)
end
end

end



And the second part doesn't need changes, just add pass_skill(id) before your skill damage formula. Just change id to fit your skill id. Example: your skill is 260 use pass_skill(260); your_damage_formula.


Telling your skill "pass_skill(260)" will automatically check if the target is an actor, if he has the item 94 equipped in the 4th slot and if the conditions are met it teaches the skill to the target.


Example of skill formula:

Code:
pass_skill(260); a.atk*4 - b.def*2
I have 2 test skills.  If I use the full formula in the damage formula box, the character learns them.


If, however, I use the script snippet, pasted exactly as in your post, with no alterations, i.e. with pass_skill(id) and with 


pass_skill(265); a.atk * 4 - b.def * 2


pass_skill(266); a.atk * 4 - b.def * 2


respectively in the damage formula boxes, nothing happens.
Use the script exactly as provided - no changes necessary (your version isn't working because you used HLS::4 and HLS::94 and there's no such thing).


So - copy the script from Heirukichi's post (the most recent one, not the first one) and put into your project, with no changes.  Your damage formula is correct.


If you can't get it to work, and my version is working (with the learn_skill rather than add_skill), you can just use that if you like.
@Shaz I don't quite follow what you wrote.  I copied the script exactly from the post without alteration, so it didn't read  HLS::4 and HLS::94 .  What I'm wondering is whether there's an error in his post.  He has two instances of [HLS::ITEM_SLOT].  But shouldn't one of them, (the second?) be just [HLS::ITEM] ?


I'm using your formula, but I want this as a backup in case my actual damage formula for any skill is so long that the two combined are too long for the damage box.  Some of them are a bit complex.
Code:
def pass_skill(id, b)

No, if you compare with my damage formula script, you'll see I referenced the slot twice too.  The first time is to check that the slot is used, and the second time is to check what is in the slot.  If you just check what's in the slot without seeing if there's anything there, you'll get an error.


But looking more closely, I think you're right - there is an error.  That function doesn't know what b is, because it hasn't been passed in, and it's not a class variable.


Change this:


def pass_skill(id)


to this:

Code:
def pass_skill(id, b)



and then your script call will be pass_skill(265, b ) (no space needed at the end - I had to add that to stop it turning into this: 😎
Change this:



def pass_skill(id)


to this:

Code:
def pass_skill(id, b)



and then your script call will be pass_skill(265, b ) (no space needed at the end - I had to add that to stop it turning into this: 😎


You are ABSOLUTELY right, I put b.learn_skill which is an error.


@ksjp17 You can either use that change or use b.pass_skill(number) if you change that code to be like this:

Spoiler
Code:
module HLS
  # change this to be the id of the item that allows your character to learn
  # the skill used on it. Default is 94.
  ITEM = 94
  # change this to be the slot id you want to check. Default is 4.
  ITEM_SLOT = 4
end

class Game_Battler < Game_BattlerBase
  
  def pass_skill(id)
    if (actor? && equips[HLS::ITEM_SLOT] && (equips[HLS::ITEM_SLOT].id == HLS::ITEM))
      learn_skill(id)
    end
  end
  
end

This should work to.



Just to be sure I'll test this now. Wait a few minutes for the result (now I am home and I can test it).


EDIT: Tested and it works.
Tested and both work fine. 


Thank you both very much.  It is a relief to get this sorted out, and I am very grateful.


Closing.

Original thread: https://forums.rpgmakerweb.com/threads/blue-magic-without-script.70813/