Simple universal third-person weapon [ZScript]

Sprites, textures, sounds, code, and other resources belong here. Share and share-alike!
Forum rules
Before posting your Resource, please make sure you can answer YES to any of the following questions:
  • Is the resource ENTIRELY my own work?
  • If no to the previous one, do I have permission from the original author?
  • If no to the previous one, did I put a reasonable amount of work into the resource myself, such that the changes are noticeably different from the source that I could take credit for them?
If you answered no to all three, maybe you should consider taking your stuff somewhere other than the Resources forum.

Consult the Resource/Request Posting Guidelines for more information.

Please don't put requests here! They have their own forum --> here. Thank you!
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1117
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Simple universal third-person weapon [ZScript]

Post by Jekyll Grim Payne »

This code will draw a very simple flat sprite in front of your player pawn that uses the spawn sprite of your currently selected weapon. It'll also tilt relative to your pitch. All you need to do is spawn this actor and set the PlayerPawn as its master.

Use it however you like. A video can be seen here: https://twitter.com/i/status/1656619729648230402

Code: Select all

class HeldWeapon : Actor
{
	Default
	{
		+NOBLOCKMAP
		+WALLSPRITE
		+ROLLSPRITE
		+MASTERNOSEE
		+NOTIMEFREEZE
		scale 0.5;
	}

	override void Tick()
	{
		if (!master || !master.player)
		{
			Destroy();
			return;
		}
		
		let weap = master.player.readyweapon;
		if (!weap || master.health <= 0)
		{
			A_SetRenderstyle(alpha, STYLE_None);
		}

		else
		{
			state sspawn = GetDefaultByType(weap.GetClass()).Spawnstate;
			if (!sspawn)
				return;
		
			A_SetRenderstyle(alpha, STYLE_Normal);	
			sprite = sspawn.sprite;
			frame = sspawn.frame;

			Warp(master, 4, -master.radius, master.height * 0.52, angle: -90, flags: WARPF_NOCHECKPOSITION|WARPF_INTERPOLATE);
			A_SetRoll(master.pitch);
		}
	}
}
cosmos10040
Posts: 199
Joined: Mon Dec 20, 2021 6:16 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: Simple universal third-person weapon [ZScript]

Post by cosmos10040 »

This is actually pretty cool, there is a hideous destructor mod that does this same thing called bubbles but when paired with a weaponless player sprite it looks awesome. I got this working into a pk3. If anybody wants me to upload I can. Seems to work just fine, but one thing I noticed is some weapon sprite are facing the wrong way, could be due to the original frame, also muzzle sprites would be a nice thing to add.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Simple universal third-person weapon [ZScript]

Post by ramon.dexter »

Sweet! Now just make a playersprite that would work with this system...
cosmos10040
Posts: 199
Joined: Mon Dec 20, 2021 6:16 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: Simple universal third-person weapon [ZScript]

Post by cosmos10040 »

ramon.dexter wrote: Mon Jun 05, 2023 8:33 am Sweet! Now just make a playersprite that would work with this system...
That would be nice, I know there are sprites out there.

Return to “Resources”