Help with Attack Fomula! OR finding another solution?

Hello fellow RPG makers.

I am running into a problem with a mechanic I have been trying to figure out for months now.  Here is my problem from a mechanical and flavor context:

What I want is for a character to be able to use blood magic but only when using a weapon called "Glass Dagger".  The Glass dagger will magically draw blood into it whenever it attacks something living (in other words skeletons don't bleed so they wouldn't "stack" blood into the dagger).  Upon using blood magic spells the "stacks" of blood in the dagger will be removed based on the cost of the spell (in blood).  

I went about accomplishing these goals by first creating a state called "Bloodied" which would be applied to the User instead of the target upon attacking. (used a notetag to do this)

I then used the tag "cost[state 9]" on a skill called "Violent Thirst" to restrict access to this skill to only when the "Bloodied" State is on the user.  The cost is the "bloodied" state, so the blood is then removed and in order to use the skill again, the user would have to attack, filling the dagger with blood once again.

The only problem here was that all actors would receive bloodied.  So I used the following adjustment to the attack formula:

# This is supposed to do the following:Check to see which actor is attacking

If actor1 is attacking

apply “bloodied” state and go to “Attack”

If not actor1 go to “Attack”

Attack: Actually calculate and apply damage.

if a.id==1; a.add_state(9); else; end; + (20 + a.atk * 0.4 - b.def * 0.2)

The problem here was that Actor1 would receive the “Bloodied” state from the very beginning of the game no matter which weapon he was using. I would like “Bloodied” to only be applied after he has learned blood magic, and only when he is using the “Glass Dagger”.

edited script: I noticed that I did not need to check which actor was using the Glass Dagger since it would only ever be used by the main character.

if weapon.id==63; a.add_state(9); else; end; + (20 + a.atk * 0.4 - b.def * 0.2)

However, this does not work. For some reason the formula does not check to see which weapon is being used. The formula returns zero damage (does not crash the game).

Is there something wrong with my syntax? But more importantly is there a solution to my problem? Or even another way of accomplishing my goals?

So long as the character can only use specific skills when they have blood in the dagger, the dagger receives blood only after attacking an enemy, and the blood is removed from the dagger upon using the skill, the methodology is of no concern to me. Any possible ways to accomplish this? I need you guys to get creative for me! Hehe! Any help is much appreciated!

Thanks in advance for your time and effort!

Salty.

 
I have to understand this correctly.

You want a certain weapon, in this case the Glass Dagger to add a certain state to a certain character correct?

I would do something as low tech as using the battle event command.

Bloodied.png

Unless you need that state for something else, it's actually not really needed I think.

For getting blood off enemies and use that to cast spells..

Do you want it so if the main character attacks an enemy (that can bleed) he can then use a blood spell?

That one is a little tricky, since as you mention certain enemies can't bleed (skeletons) but this should work, it's a little wonky and may have a different and better way to do it.

But firstly I made a dagger:

Glass Dagger.png

That will apply a state (Enemy blood stolen) 100% on hit - which you then can make certain enemies immune to, and thus prevent the blood stealing on skeletons.

Then I made another battle event command:

Blood stolen.png

This checks every round, if the main character have stolen blood and not used it, if not, then it checks if an enemy (you need a conditional branch for every enemy that can bleed in a fight)

If any of them have been hit by the dagger (Enemy blood stolen) and if that's true, they will give the (blood stolen) state, and remove their own (enemy blood stolen) state.

And finally for the magic skill group thingy:

Blood magic.png

Then you just make the spells cast from that school remove the (blood stolen) state, either through a common event, or as part of the action.
Ok I am going to try this out I have not used battle events before.  I will have to fiddle around and see if I can get it to work.  As far as the magic goes you sort of lost me on the last step but I think I have that part of the problem working already through notetags: making the skill cost a state, but I will see.  

The final part which I suppose is optional but would make the concept complete, is the ability to stack more than 1 blood charge.  For example if he attacks once, he gets 1 unit of blood.  If he does not use a blood magic spell but attacks again instead he would then have 2 units of blood.  Some blood magic spells may have a higher blood cost and so these charges would stay in the dagger after a battle finishes.

Thank you so much for the help from what I can see this will make things a lot simpler!  Let me know if you have any thoughts on the stacking.  Thanks.
I am messing around with battle events and I can only find them in the "troops" tab in the database.  Will I have to create a battle event for every monster that can bleed?  
try to use this

 

if a.id=1 and a.skills.include?($data_skills[id]); a.add_state(id); else; end; damage formula

 

Not sure as I don't test it.
Ok. So I couldn't get that method to work.  For some reason the state was not being applied to the user of the skill.  I did however, find another solution to my problem which involved a script from Yanfly but simplifies things a great deal.

The script I used allows me to set different skills (other than 001: Attack) as the default attack skill.  What this allowed me to do is create a damage formula which applies a state to Actor X. Here is the damage formula I used:

if a.id==1; a.add_state(29); else; end; + (20 + a.atk * 0.4 - b.def * 0.2)

So using the script and a note tag ("<attack skill: 2>) I was able to set attack 2 (normally guard) to the default attack for Weapon: Glass Dagger.

This works perfectly.  The main character cannot use blood magic unless they have the blood stolen state, and once they use a blood magic spell, the state is removed.  Furthermore, other characters are unaffected by this and their states do not change after attacking.  

I am so glad this worked!  I do not know if I will keep this solution but for now it is doing the job!  I would still like to know what I might be doing wrong with your concept though.  

Thanks for your time.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-attack-fomula-or-finding-another-solution.38433/