Firearm scripting - hitting a wall

Hi all, I'm making a wild west themed RPG and trying to put together the basic scripts for making my guns work, and I'm hitting a wall at every turn.

Because the attack stat is tied so deeply to other systems, I decided to use the "weapon" slot for melee tools and make guns technically "armor". Once you equip a gun, it adds the "Fire [weapon-name]" skill to your character - so far so good.

But I would like to make some guns single-action, meaning the hammer must be re-cocked between shots, so the original idea was to create a state called "cocking" which takes away your next turn and displays "X cocks the hammer"....HOWEVER, because of the way skills work, the state gets added to the TARGET instead of the USER.

If you change the scope to 'user', the damage will go to the user instead of the target, meaning I'd have to figure out a new way to calculate the damage as the target could no longer be chosen in the traditional way.

A common event seems the way to fix all of this, but I can't figure out how to make said event tag the right actor. It can check to see if you HAVE a skill, but it can't check to see if you're USING the skill. So - if two people have the same gun - it'll set them both to cock the hammer.

Basically, I'm trying to figure out how to get a skill to reference both the user AND the target with different effects - damage to the target, cocking to the user. How do you do this?

And - for a bonus - I've already given up trying to figure out how to make an ammo counter work. I can get it to count ammo correctly....unless you hand your weapon from one party member to the other, in which case the gun either fills or empties according to its default setup. I've gone to just destroying bullet items from the shared inventory.....but it's kind of cartoony.

Thanks in advance. Me = noob.
You can do all of this with Yanfly's skill core. It allows you to put scripts into the skill note box. You can reference user and target and do whatever you need with them. You could use it to set a variable or switch which would be unique to each actor (or maybe party index) to designate cocked or not cocked and have the skill do whatever you need based on that. I use it for bows and crossbows. It checks if actor has arrows or bolts before firing and if not displays out of ammo message. It also subtracts ammo when used. I use Galv's actor equip items script to give individual actors ammo. Storing ammo for an individual weapon rather than an actor would be more complicated, but I'm sure it could be done. You'll definitely need to know some scripting though. If you can learn how to write basic functions and put them into your own plugin, you can make them as complicated as you need and just reference individual functions in the skill notebox rather than trying to write out long complicated scripts in a tiny box.
Thanks for the reply. I managed to solve the original problem by using the damage formula (an even tinier box). If anyone out there is a googler from the future, the solution works like so:

(a.addState(14));

Change the 14 to the correct state index in your game and add your original damage formula after the ; (no spaces)

For the present: I've been trying to get the bullets to come out of my inventory the same way, consumeItem(##) is supposed to work, but I can't figure out where to squeeze it into the formula without everything else going haywire. Computers are so picky!!

Your methods sound easier....but when you say that I can write script in the note section, would this be Java or RPG Maker's "basic" thing used in eventing? I ask because this project is meant as a small portfolio piece to demonstrate my skill as a writer, so the game needs to function and the art needs to be passable, but I'm not learning any new, time-intensive skills like coding for this project. I just need to make the systems stand up, make the player feel like a cowboy, roll this sucker out as a 25 minute demo, throw it at anyone who'll listen, and make another one.

So are these plugins ready to rock out of the box without much knowledge beyond RPG Maker? Or would it take fewer hours for a dabbler like me to figure out how to make the bullets disappear using the consumeItem command plus a common event?
To use yanfly's skill core plugin ( http://yanfly.moe/2015/10/13/yep-8-skill-core/ ), install it, then put this in the note section on the skill.



Code:
<After Eval>

a.addState(14);

</After Eval>

'a' refers to the person using the skill (no need to change that), the number is the state ID.

Underneath that, you can add

Code:
<Custom Requirement>

if (user.isStateAffected(14)) {

value = false;

} else {

value = true;

}

</Custom Requirement>

Which will make your gun skill only work when you do NOT have the 'needs to reload' state.

Now, if you want to use up bullets from the inventory without hassle, yanfly ALSO has a plugin for that ( http://yanfly.moe/2015/12/12/yep-43-skill-cost-items/ ). You need to have already added the skill core plugin if you want to use it.

Add this to the skill's notes as well:
Code:
<Item x Cost: y>
Replace 'x' with your bullet item ID, and 'y' with the number of bullets you want to use.
Thanks again for great advice....which I stubbornly did not take! I put the problem on the back-burner while I made other pieces of the game, and the whole ammo system came to me, fully formed and buggy as sin.

It has since been de-bugged and organized into a script that's supposed to be easy to understand and functional for my game. If you're experienced, I would LOVE some feedback on this script.....but if you're looking to make your guns work like mine, I'm perfectly happy to donate my ideas to the internet brain trust.

The only thing that isn't identified in the script is what these states are doing, so I'll go through that:
"TAGGED CHARACTER" is a dummy state to identify which of my actors is using any given item at any given moment (a gun, in this case)
The rest take away a set number of turns depending on the weapon and output text to that effect.

Otherwise, there's a label heading for each character and everything else leads to the exit point:

◆Label:ANGELA
◆Comment:**************************************************************
◆If:Angela is affected by TAGGED CHARACTER
◆Change State:Angela, - TAGGED CHARACTER
◆Jump to Label:ANGELA FIRE SEQUENCE
◆
:Else
◆Jump to Label:DJANGO
◆
:End
◆Label:ANGELA FIRE SEQUENCE
◆Control Variables:#0054 Angela Cult Revolver += 1
◆If:Angela Cult Revolver < 5
◆Change State:Angela, + Cocking
◆Jump to Label:EXIT
◆
:Else
◆Change State:Angela, + Revolver reload
◆Control Variables:#0054 Angela Cult Revolver = 0
◆Jump to Label:EXIT
◆
:End
◆Label:DJANGO
◆Comment:Script is nearly identical for each character, so we'll skip to the end
◆Comment:*****************************(new script before exit)***********************
◆Label:EXIT
◆Exit Event Processing

Original thread: https://forums.rpgmakerweb.com/threads/firearm-scripting-hitting-a-wall.107184/