I'll see what I can do for you. This doesn't sound terribly hard, and I'm working on LWepon items at present, so I can likely tie this into the other scripting work. I'm going to make this as one script that uses attributes to cover ROF, damage, counter, etc., so that you need only assign the variables once you start to use it. The tricky part will be in covering reload time.
Do you want a secondary item (ammo) to use to (manually) reload, so the counter max is always fixed (per weapon) and the reload item replenishes the stock? (That would probably make this easier and more logical.)
This would mean needing two counters per weapon: One for ammo loaded, and a second for reloads on hand, and to reload the player would need to either select the ammo box, or have it selected already, and press the button to reload the firearm used by that ammo type. (Reading the pistol, way you described it earlier, it seems as if the player would have infinite ammunition, which I suspect was not your goal by reading about different ammo types in 'revolver' and 'rifle'.)
FYI, a machine gun that the player can fire continually with a 50R drum would be easy-peasy to make if you still want it. Limiting the ROF and maximum projectiles is harder than making something that the player can fire constantly.
What is the time period of this quest? From the descriptions of desired weapons, barring the 'submachine gun', I am picturing 1850s-1920s, although a semi-automatic pistol wasn't common until the Great War era and later.
I will work on the weapons first, and then on the reloading, so that you can test them and see if they come out as you want.
Here's something quick and basic for you to try. it doesn't include ROF, but it does allow you to start trying out firearm weapons. Please note that this is merely put of my head. It compiles, but I haven't tested it. I see no reason that it would not work, but if you have any problems, please let me know so that I can fix them.
import "std.zh"
/////////////////////////////////////////////////
//Import mandatory script headers and packages.//
/////////////////////////////////////////////////
//import "ffcscript.zh"
//import "string.zh"
//import "ghost.zh"
//import "ghost_legacy.zh"
//import "std_extra.zh"
/////////////////////////////////////////////////////////////////////
// Set up environment, Base Ints, Consts, Floats, Bools, Vars, etc.//
// Set Sounds in Quest->Audio->SFX Data ////////////////////////////
/////////////////////////////////////////////////////////////////////
const int SFX_ERROR = 61; //In case you want an error SFX
const int SFX_GUN = 71; //Set to a bang SFX as desired.
const int SFX_RELOAD = 72; //Set to a bang SFX as desired.
/////////////////
/// Firearm ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/// D0: Number of Hearts to Use when Activating Subweapon. ///
/// D1: Time bfore Link can use Subweapon Again. ///
/// D2: Type of lweapon to generate. ///
/// D3: Amount of Damage that Subweapon Deals to Enemies. ///
/// D4: Speed that Subweapon Travels across screen; suggest 240. ///
/// D5: Sprite used by Subweapon; select from: ///
/// Quest->Graphics->Sprites->WeaponsMisc. ///
/// D6: Rate of Fire; Not yet functional. ///
/// D7: Counter to use for this weapon. ///
////////////////////////////////////////////////////////////////////
item script Firearm{
void run(int ammo, int nouse, int subweapon, int power, int speed, int SWsprite, int rof, int GunCounter){
if (Game->Counter[GunCounter] >= 1){
Game->Counter[GunCounter] -= ammo;
Link->ItemJinx = nouse;
lweapon subweapon;
Link->Action = LA_ATTACKING;
Game->PlaySound(SFX_GUN);
subweapon = NextToLink(LW_ARROW, 8); //Create in front of Link
subweapon->UseSprite(SWsprite); //Graphics
subweapon->Damage = power; //Damage
subweapon->Step = speed; //Speed
for ( int i = 0; i < 30; i++ ){ //For 30 frames
subweapon->DeadState = WDS_ALIVE; //Keep it alive at all times
Waitframe();
}
subweapon->DeadState = WDS_ALIVE;}
else{
Game->PlaySound(SFX_ERROR);
}
}
}
//////////////////
/// Ammo Pickup ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/// D0: Set to Counter for Type of Amunition You are Using ///
/// D1: Amount of Ammo Boxes to Gain ///
/// D2: Minimum Aount to Increase CounterMax; suggest 1. ///
////////////////////////////////////////////////////////////////////
item script AmmoPickup{
void run(int AmmoCounter, int amount, int increaseAmmoCount){
Game->Counter[AmmoCounter]+=amount;
Game->MCounter[AmmoCounter]+=increaseAmmoCount;
}
}
//////////////////
/// Ammo Pickup ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/// D0: Set to Counter for Type of Amunition You are Using ///
/// D1: Set to Counter for Firearm Being Loaded. ///
/// D2: Amount of Rounds to Give player on Loading. ///
/// D3: Time before Link can use this item again. ///
////////////////////////////////////////////////////////////////////
item script AmmoLoad{
void run(int AmmoCounter, int GunCounter, int GunAmount, int nouse){
if (Game->Counter[AmmoCounter] >= 1 && Game->Counter[GunCounter] <= 0){
Game->Counter[AmmoCounter] -= 1;
Game->Counter[GunCounter]+=GunAmount;
Link->ItemJinx = nouse;
Game->PlaySound(SFX_RELOAD);
}
else{
Game->PlaySound(SFX_ERROR);
}
}
}
///////////////////////////////////
///// Counters Reference //////////
///////////////////////////////////
/// CR_SCRIPT1 = 7; ///
/// CR_SCRIPT2 = 8; ///
/// CR_SCRIPT3 = 9; ///
/// CR_SCRIPT4 = 10; ///
/// CR_SCRIPT5 = 11; ///
/// CR_SCRIPT6 = 12; ///
/// CR_SCRIPT7 = 13; ///
/// CR_SCRIPT8 = 14; ///
/// CR_SCRIPT9 = 15; ///
/// CR_SCRIPT10 = 16; ///
/// CR_SCRIPT11 = 17; ///
/// CR_SCRIPT12 = 18; ///
/// CR_SCRIPT13 = 19; ///
/// CR_SCRIPT14 = 20; ///
/// CR_SCRIPT15 = 21; ///
/// CR_SCRIPT16 = 22; ///
/// CR_SCRIPT17 = 23; ///
/// CR_SCRIPT18 = 24; ///
/// CR_SCRIPT19 = 25; ///
/// CR_SCRIPT20 = 26; ///
/// CR_SCRIPT21 = 27; ///
/// CR_SCRIPT22 = 28; ///
/// CR_SCRIPT23 = 29; ///
/// CR_SCRIPT24 = 30; ///
/// CR_SCRIPT25 = 31; ///
///////////////////////////////////
You will need to add counters to your subscreen, and then attach these to items. The AmmoPickup should be set as the Pickup script on all ammunition, and the AmmoUse should be set as the Action script for all ammunition.
Once you have counters on a subscreen, you can tie these all to weapons and ammo types. If you need a sample quest, I can put a small test game together for you using these.
I'll work on ROF and reload time concerns; I've already been doing something along those lines elsewhere, so I hope that this will work with that.
Update: Updated script above, and made test quest. You can try it by downloading it HERE.
I didn't use the pickup script in the end, but assigned the pickup attributes in the item editor. The AmmoPickup script is in essence, an extra that I may need to use later to get some of what you want to work the way you desire. It uses the Firearm item and AmmoLoad item Action scripts, with sound effects, in an arena.
Update II: Here's a second script that features auto-loading. The load time takes twice as much time as you allocate to ROF.
import "std.zh"
/////////////////////////////////////////////////
//Import mandatory script headers and packages.//
/////////////////////////////////////////////////
//import "ffcscript.zh"
//import "string.zh"
//import "ghost.zh"
//import "ghost_legacy.zh"
//import "std_extra.zh"
/////////////////////////////////////////////////////////////////////
// Set up environment, Base Ints, Consts, Floats, Bools, Vars, etc.//
// Set Sounds in Quest->Audio->SFX Data ////////////////////////////
/////////////////////////////////////////////////////////////////////
const int SFX_ERROR = 61; //In case you want an error SFX
const int SFX_GUN = 71; //Set to a bang SFX as desired.
const int SFX_RELOAD = 72; //Set to a bang SFX as desired.
/////////////////
/// Firearm /////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/// D0: Number of Bullets to expend when Activating Subweapon. ///
/// D1: Time before Link can use Subweapon Again (ROF) in frames. ///
/// D2: Rounds weapon can hold. ///
/// D3: Amount of Damage that Subweapon Deals to Enemies. ///
/// D4: Speed that Subweapon Travels across screen; suggest 240. ///
/// D5: Sprite used by Subweapon; select from: ///
/// Quest->Graphics->Sprites->WeaponsMisc. ///
/// D6: Counter for Amo Boxes for this weapon ///
/// D7: Counter to use for this weapon. ///
/////////////////////////////////////////////////////////////////////
item script Firearm{
void run(int ammo, int nouse, int ShotsPerLoad, int power, int speed, int SWsprite, int AmmoToLoad, int GunCounter){
if (Game->Counter[GunCounter] >= 1){
Game->Counter[GunCounter] -= ammo;
Link->ItemJinx = nouse;
lweapon subweapon;
if(subweapon->X >= 1 && subweapon->X <= 254 && subweapon->Y >= 1 && subweapon->Y <= 160)
{
subweapon->DeadState = WDS_ALIVE;
//update sprites when dead state is refreshed
subweapon->UseSprite(SWsprite);
if(subweapon->Dir == DIR_DOWN)
{
subweapon->Flip = 2;
}
if(subweapon->Dir == DIR_RIGHT)
{
subweapon->Tile += 1;
}
if(subweapon->Dir == DIR_LEFT)
{
subweapon->Tile += 1;
subweapon->Flip = 1;
}
}
Link->Action = LA_ATTACKING;
Game->PlaySound(SFX_GUN);
subweapon = NextToLink(LW_ARROW, 8); //Create in front of Link
subweapon->UseSprite(SWsprite); //Graphics
subweapon->Damage = power; //Damage
subweapon->Step = speed; //Speed
{
//set to alive if within screen boundaries
}
subweapon->DeadState = WDS_ALIVE;}
if (Game->Counter[GunCounter] <=0 && Game->Counter[AmmoToLoad] >=1){
Game->Counter[AmmoToLoad] -= 1;
Game->Counter[GunCounter] += ShotsPerLoad;
Game->PlaySound(SFX_RELOAD);
Link->ItemJinx = (nouse * 2);
}
else{
Game->PlaySound(SFX_ERROR);
}
}
}
//////////////////
/// Ammo Pickup ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/// D0: Set to Counter for Type of Amunition You are Using ///
/// D1: Amount of Ammo Boxes to Gain ///
/// D2: Minimum Aount to Increase CounterMax; suggest 1. ///
////////////////////////////////////////////////////////////////////
item script AmmoPickup{
void run(int AmmoCounter, int amount, int increaseAmmoCount){
Game->Counter[AmmoCounter]+=amount;
Game->MCounter[AmmoCounter]+=increaseAmmoCount;
}
}
//////////////////
/// Ammo Pickup ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/// D0: Set to Counter for Type of Amunition You are Using ///
/// D1: Set to Counter for Firearm Being Loaded. ///
/// D2: Amount of Rounds to Give player on Loading. ///
/// D3: Time before Link can use this item again. ///
////////////////////////////////////////////////////////////////////
item script AmmoLoad{
void run(int AmmoCounter, int GunCounter, int GunAmount, int nouse){
if (Game->Counter[AmmoCounter] >= 1 && Game->Counter[GunCounter] <= 0){
Game->Counter[AmmoCounter] -= 1;
Game->Counter[GunCounter]+=GunAmount;
Link->ItemJinx = nouse;
Game->PlaySound(SFX_RELOAD);
}
else{
Game->PlaySound(SFX_ERROR);
}
}
}
///////////////////////////////////
///// Counters Reference //////////
///////////////////////////////////
/// CR_SCRIPT1 = 7; ///
/// CR_SCRIPT2 = 8; ///
/// CR_SCRIPT3 = 9; ///
/// CR_SCRIPT4 = 10; ///
/// CR_SCRIPT5 = 11; ///
/// CR_SCRIPT6 = 12; ///
/// CR_SCRIPT7 = 13; ///
/// CR_SCRIPT8 = 14; ///
/// CR_SCRIPT9 = 15; ///
/// CR_SCRIPT10 = 16; ///
/// CR_SCRIPT11 = 17; ///
/// CR_SCRIPT12 = 18; ///
/// CR_SCRIPT13 = 19; ///
/// CR_SCRIPT14 = 20; ///
/// CR_SCRIPT15 = 21; ///
/// CR_SCRIPT16 = 22; ///
/// CR_SCRIPT17 = 23; ///
/// CR_SCRIPT18 = 24; ///
/// CR_SCRIPT19 = 25; ///
/// CR_SCRIPT20 = 26; ///
/// CR_SCRIPT21 = 27; ///
/// CR_SCRIPT22 = 28; ///
/// CR_SCRIPT23 = 29; ///
/// CR_SCRIPT24 = 30; ///
/// CR_SCRIPT25 = 31; ///
///////////////////////////////////
This version ties the ammo boxes to the weapon, so the AmmoLoad items are only necessary if you want to include manual loading on weapons, versus automatically reloading (by pressing the weapon button when empty). You need to specify the number of rounds the firearm holds per load in the script arguments, as well as other information, but I think this is more along the lines of what you wanted.
Update 3: Everything is going over HERE ; I have a pistol, rifle, revolver and sub-machine-gun in the demo, all based on this script. making a shotgun will take additional work and an entirely different script. I also have yet to get bullets to pierce (WDS_ALIVE).
Edited by ZoriaRPG, 29 July 2013 - 04:18 AM.