Throwing a Knife

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Galaxy_Stranger
Posts: 1326
Joined: Sat Aug 16, 2003 11:42 pm
Location: Shropshire
Contact:

Throwing a Knife

Post by Galaxy_Stranger »

I've made a knife that's designed to be used on monsters as a knife, but its altfire allows the player to throw it:
Spoiler:
With this configuration, when you altfire, it takes away the ammo - but apparently not the Dagger inventory item, unless TakeInventory() is placed above the JumpIfInventory.

Can anybody see what's wrong with this?
User avatar
edward850
Posts: 5892
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Throwing a Knife

Post by edward850 »

Don't you want to jump 2 frames, not 1?

Code: Select all

A_JumpIfInventory("DaggerAmmo", 1, "ThrowDagger")
Will land on A_TakeInventory("Dagger",1), not A_TakeInventory("DaggerAmmo",1).
Also, the current configuration will mean you will always have at least one "DaggerAmmo" left after taking "Dagger".
User avatar
Galaxy_Stranger
Posts: 1326
Joined: Sat Aug 16, 2003 11:42 pm
Location: Shropshire
Contact:

Re: Throwing a Knife

Post by Galaxy_Stranger »

Thanks for the reply.
edward850 wrote:Don't you want to jump 2 frames, not 1?
Ok, originally, I had a dagger. You picked it up and you could use it - without using ammo, and you could altfire it. The altfire spawned a dagger projectile and removed the dagger from the player's inventory. When the projectile died, it spawned a new dagger weapon. This works perfectly if all you want the player to have is ONE dagger.

So, to fix this, I created a weapon that doesn't use ammo per se. I remove the ammo only when it is altfired. Man, I'm going in circles. Maybe I should step away from this for a while... The idea was to check the amount of ammunition the player has and remove the weapon based on that.

edward850 wrote:

Code: Select all

A_JumpIfInventory("DaggerAmmo", 1, "ThrowDagger")
Will land on A_TakeInventory("Dagger",1), not A_TakeInventory("DaggerAmmo",1).
Also, the current configuration will mean you will always have at least one "DaggerAmmo" left after taking "Dagger".
I figured this was how it was acting - because if you altfire or fire, it acts like it cycles through and it removes the weapon from the inventory. Could you point how out it is doing this? I don't see it.


Ok, after going over this post a couple times, the wheels started turning and I found another approach. I was working on another computer and tried to send myself the new versions of the decorate definitions, but that didn't work out. So, tomorrow, I'll post my solution here. It was deceptively simple...

Edward, I would still like you to point out how it was keeping the item if you would.
User avatar
edward850
Posts: 5892
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Throwing a Knife

Post by edward850 »

Actually I'm misreading what you were doing there. I'm not entirely sure why you have a random stop statement there for and it's throwing me off.
User avatar
Galaxy_Stranger
Posts: 1326
Joined: Sat Aug 16, 2003 11:42 pm
Location: Shropshire
Contact:

Re: Throwing a Knife

Post by Galaxy_Stranger »

edward850 wrote:Actually I'm misreading what you were doing there. I'm not entirely sure why you have a random stop statement there for and it's throwing me off.
Yeah - that stop was in there just because I was trying anything to get things to work.

Here's the solution:

Code: Select all

		AltFire:
			KNIF C 1 A_FireCustomMissile("DaggerProjectile", 0, 0, 0, 0, 0, 0)
			KNIF C 1 A_TakeInventory("DaggerAmmo",1)
			KNIF C 1 A_JumpIfInventory("DaggerAmmo", 1, "Ready")
			KNIF C 1 A_TakeInventory("Dagger",1)
			Stop
And that's it. Here are the properties:

Code: Select all

	Obituary ""
	Weapon.SlotNumber 1
	//Weapon.AmmoUse 1
	Weapon.AmmoGive 1
	Weapon.AmmoType "DaggerAmmo"
	+WEAPON.NOAUTOFIRE
	+WEAPON.WIMPY_WEAPON
	+WEAPON.MELEEWEAPON
	+WEAPON.AMMO_OPTIONAL
	Inventory.PickupMessage "Got a Dagger!"
	Tag "Dagger"
I'm also working on a WWII grenade that will work very similar to this.
Locked

Return to “Editing (Archive)”