I need help with my reloading code

Discuss all aspects of editing for ZDoom.
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

I need help with my reloading code

Postby lizardcommando » Thu Sep 07, 2006 12:47 pm

I've been trying for days to get this thing to work properly, but I can't figure it out. So the guns reload automatically if I shoot while I have an empty clip and it will play the reload animation and it will fill up the gun's magazine with fresh bullets, but the thing is that I can't reload manually pressing the R button. Also, ammo won't be taken from the inventory either. I think I can figure that second problem out, but I haven't the slightest effing clue as to why I can no longer press R to reload the guns.

I've been following the reloading tutorial which was posted on Wildweasel's Doom Armory website, but I can't figure out what's going on. Please help me.

Code: Select allExpand view
ACTOR .45Pistol : Weapon replaces Pistol
{
   +NOAUTOFIRE
   +AMMO_OPTIONAL
      Obituary "%o was capped by %k's trusty ol' .45."
   AttackSound "weapons/pistol"
   Weapon.AmmoType1 ".45MAG" //The guns magazine
   Weapon.AmmoType2 ".45BULLETS" //The real ammo
   Weapon.AmmoGive 0
   Weapon.AmmoGive2 1
   Weapon.AmmoUse 1
   Weapon.SelectionOrder 6000
   States
   {
   Ready:
      PISG A 1 A_WeaponReady
      PISG A 0 A_JumpIfInventory("IsReloading",1,11)
      Loop
   Deselect:
      PISG A 1 A_Lower
      Loop
   Select:
      PISG A 1 A_Raise
      Loop
   Fire:
      PISG A 0 A_JumpIfNoAmmo(9)
      PISG B 1 BRIGHT A_GunFlash
      PISG B 1 A_FireBullets(2,1,-1,10,0,1,0)
      PISG C 2
      PISG D 2
      PISG E 2
      PISG C 2
      PISG B 1
      PISG A 0
      Goto Ready
      PISG A 1 A_Playsound("weapons/click")
    //Reload:
      PISR A 0 A_JumpIfInventory(".45MAG",8,2)
      PISR A 0 A_JumpIfInventory(".45BULLETS",1,2)
      Goto Ready
      PISR A 0 A_TakeInventory(".45BULLETS",999)
      PISR A 4
      PISR B 3 A_PlaySound("weapons/pmagout")
      PISR C 8
      PISR B 3
      PISR A 3
      PISR A 4 A_PlaySound("weapons/pmagin")
      PISR A 4
      PISR D 4 A_PlaySound("weapons/pslide")
      PISR D 0 A_GiveInventory(".45MAG",8)
      PISR D 0 A_GiveInventory(".45BULLETS",999)
      PISG A 1
      Goto Ready
   Flash:
      PISF A 2 BRIGHT
      stop

  }

}

ACTOR .357Magnum : Weapon 14500
{
   +NOAUTOFIRE
   +AMMO_OPTIONAL
      Obituary "%o's head was blown clean off by %k's .357 Magnum."
        Inventory.Pickupmessage "You got the .357 Magnum!"
   AttackSound "weapons/357"
   Weapon.AmmoType "MAGNUMCLIP"
   Weapon.AmmoType2 "MAGNUMAMMO"
   Weapon.AmmoGive 0
   Weapon.AmmoGive2 6
   Weapon.AmmoUse 1
   Weapon.SelectionOrder 5000
   States
   {
   Spawn:
      MAGN A -1
      LOOP
   Ready:
      MAGG A 1 A_WeaponReady
      Loop
   Deselect:
      MAGG A 1 A_Lower
      Loop
   Select:
      MAGG A 1 A_Raise
      Loop
   Fire:
      MAGG A 0 A_JumpIfNoAmmo(7)
      MAGG A 1 BRIGHT A_GunFlash
      MAGG A 3 A_FireBullets(2,1,-1,25,0,1,0)
      MAGG B 5
      MAGG C 3
      MAGG D 2
      MAGG A 0
      Goto Ready
      MAGG A 1 A_Playsound("weapons/click")
  //Reload:
      MAGR A 0 A_JumpIfInventory("MAGNUMAMMO",6,2)
      MAGR A 0 A_JumpIfInventory("MAGNUMCLIP",1,2)
      Goto Ready
      MAGR A 0 A_TakeInventory("MAGNUMAMMO",999)
      MAGR A 2
      MAGR B 2
      MAGR C 5 A_PlaySound("weapons/magnumopen")
      MAGR D 1 A_PlaySound("weapons/magnumload1")
      MAGR E 1
      MAGR F 1
      MAGR G 5
      MAGR H 3
      MAGR I 3 A_PlaySound("weapons/magnumload2")
      MAGR I 0 A_GiveInventory("MAGNUMCLIP",6)
      MAGR I 0 A_GiveInventory("MAGNUMAMMO",999)
      MAGR J 2
      MAGR K 2
      MAGR L 2
      MAGR M 4 A_PlaySound("weapons/magnumclose")
      MAGR N 2
      Goto Ready
   Flash:
      MAGF A 2 BRIGHT
      stop

  }

}
User avatar
lizardcommando
Thread killer
 
Joined: 07 Sep 2006
Location: Boringland, California

Postby TheDarkArchon » Thu Sep 07, 2006 4:59 pm

Your jump offset for the check for IsReloading should be 13 if I have counted right.
User avatar
TheDarkArchon
OUT!
 
Joined: 07 Aug 2004
Location: Some cold place

Postby lizardcommando » Thu Sep 07, 2006 5:45 pm

For which gun are you talking about?

EDIT: Ok, that seemed to have fixed part of the reloading problem. Now I can't seem take ammo from the inventory when I reload. How would I fix that?
User avatar
lizardcommando
Thread killer
 
Joined: 07 Sep 2006
Location: Boringland, California

Postby DoomRater » Thu Sep 07, 2006 6:42 pm

There needs to be an A_TakeInventory in that code somewhere. I see two "A_GiveInventory" pointers...
User avatar
DoomRater
Hi, I'm bob.
 
Joined: 28 Jul 2004
Location: WATR HQ
Discord: DoomRater#6308

Postby Ryan Cordell » Fri Sep 08, 2006 8:01 am

An expert from the above weapon in his request for help:

" PISR A 0 A_JumpIfInventory(".45MAG",8,2)
PISR A 0 A_JumpIfInventory(".45BULLETS",1,2)
Goto Ready
PISR A 0 A_TakeInventory(".45BULLETS",999)"
User avatar
Ryan Cordell
PDA Man
 
Joined: 06 Feb 2005
Location: Capital of Explodistan
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Postby lizardcommando » Fri Sep 08, 2006 7:23 pm

So what exactly do I need to do to fix this? I don't get it. :(
User avatar
lizardcommando
Thread killer
 
Joined: 07 Sep 2006
Location: Boringland, California

Postby Theshooter7 » Fri Sep 08, 2006 7:50 pm

Code: Select allExpand view
ACTOR .45Pistol : Weapon replaces Pistol
{
   +NOAUTOFIRE
   +AMMO_OPTIONAL
      Obituary "%o was capped by %k's trusty ol' .45."
   AttackSound "weapons/pistol"
   Weapon.AmmoType1 ".45MAG" //The guns magazine
   Weapon.AmmoType2 ".45BULLETS" //The real ammo
   Weapon.AmmoGive 0
   Weapon.AmmoGive2 1
   Weapon.AmmoUse 1
   Weapon.SelectionOrder 6000
   States
   {
   Ready:
      PISG A 1 A_WeaponReady
      PISG A 0 A_JumpIfInventory("IsReloading",1,2)
      PISG A 0
      Loop
      PISG A 1
      Goto Fire+9
   Deselect:
      PISG A 1 A_Lower
      Loop
   Select:
      PISG A 1 A_Raise
      Loop
   Fire:
      PISG A 0 A_JumpIfNoAmmo(9)
      PISG B 1 BRIGHT A_GunFlash
      PISG B 1 A_FireBullets(2,1,-1,10,0,1,0)
      PISG C 2
      PISG D 2
      PISG E 2
      PISG C 2
      PISG B 1
      PISG A 0
      Goto Ready
      PISG A 1 A_Playsound("weapons/click")
    //Reload:
      PISR A 0 A_JumpIfInventory(".45MAG",8,2)
      PISR A 0 A_JumpIfInventory(".45BULLETS",1,2)
      PISR A 0
      Goto Ready
      PISR A 0 //Left this frame in just for Offset reasons.
      PISR A 4
      PISR B 3 A_PlaySound("weapons/pmagout")
      PISR C 8
      PISR B 3
      PISR A 3
      PISR A 4 A_PlaySound("weapons/pmagin")
      PISR A 4
      PISR D 4 A_PlaySound("weapons/pslide")
      PISR D 0 A_GiveInventory(".45MAG",1)
      PISR D 0 A_TakeInventory(".45BULLETS",1)
      PISR A 0 A_JumpIfInventory(".45MAG",8,2)
      PISR A 0 A_JumpIfInventory(".45BULLETS",1,2)
      PISG A 1
      Goto Ready
      PISR A 0
      Goto Fire+22
   Flash:
      PISF A 2 BRIGHT
      stop

  }

}


That should do it...
Last edited by Theshooter7 on Fri Sep 08, 2006 8:59 pm, edited 1 time in total.
User avatar
Theshooter7
Don't talk about Fight Club
 
Joined: 06 Mar 2006

Postby lizardcommando » Fri Sep 08, 2006 8:53 pm

I just tested that code and when I reload, I get more ammo. Shouldn't there be a TakeInventory code somewhere?
User avatar
lizardcommando
Thread killer
 
Joined: 07 Sep 2006
Location: Boringland, California

Postby Theshooter7 » Fri Sep 08, 2006 8:59 pm

woops. Fixed.
User avatar
Theshooter7
Don't talk about Fight Club
 
Joined: 06 Mar 2006

Postby lizardcommando » Fri Sep 08, 2006 9:27 pm

Thanks. Now the .45Pistol works. So what changes would I need to do in the .357Magnum coding for it to work correctly?
User avatar
lizardcommando
Thread killer
 
Joined: 07 Sep 2006
Location: Boringland, California

Postby Theshooter7 » Fri Sep 08, 2006 9:29 pm

I'll do it. All I did was a bit of reorganizing of your code, changed several A_JumpIfInventory() Pointers around, and added a couple frames with Pointers.
User avatar
Theshooter7
Don't talk about Fight Club
 
Joined: 06 Mar 2006

Postby lizardcommando » Fri Sep 08, 2006 9:42 pm

Cool. Thanks again dude.
User avatar
lizardcommando
Thread killer
 
Joined: 07 Sep 2006
Location: Boringland, California


Return to Editing (Archive)

Who is online

Users browsing this forum: No registered users and 2 guests