Metropolice stunstick emitter

Is there a way make metropolices stunstick have blue effect at top like in actual game (Half-Life 2), because its just blank?

HL2:

http://img179.imageshack.us/img179/8441/metropicture.jpg

Yeah, attach a sprite to it.

I’m pretty sure the sprite for the stunstick is the exact same one used on the Phys Gun shooting a wall or floor.

Well what i need to do to make this?



	for k,v in pairs(ents.FindByClass("npc_metropolice")) do
              v:GetActiveWeapon():attachspiresomething(texture)


or?

No you’d need to use cam3D or cam3D2D and draw a sprite using render.DrawSprite and find the weapon attachment which I think would be something like,



cam.Start3D(EyePos(),EyeAngles())
for k,v in pairs(ents.FindByClass("npc_metropolice")) do
render.SetMaterial(Material("effects/physg_beama")) --I think it's that.
render.DrawSprite(v:GetViewModel():GetAttachment("1").Pos,10,10,Color(255,255,255,255))
end
cam.End3D()


That’s untested so I’m not 100% sure.

You know, internally, that’s not what the cam library was ever meant for.

“effects/stunstick” is the effect name. In the source code, size is a random float between 4 and 6.

my current autorun code now:



local function Emit()
	
	cam.Start3D(EyePos(),EyeAngles())
	for k,v in pairs(ents.FindByClass("npc_metropolice")) do
		render.SetMaterial(Material("effects/stunstick"))
		render.DrawSprite(v:GetViewModel():GetAttachment("1").Pos,4,6,Color(255,255,255,255))
	end
	cam.End3D()
	
	timer.Simple(0.1,Emit)
end
Emit()


(Not tested), but i think it will fail at EyePos and EyeAngles?

No, just no…


local stunsprite = Material("effects/stunstick")

hook.Add( "RenderScreenspaceEffects", "DrawStickSprite", function()

	cam.Start3D( EyePos(), EyeAngles() )
		for k,v in pairs( ents.FindByClass( "npc_metropolice" ) ) do
			render.SetMaterial( stunsprite )
			render.DrawSprite( v:GetViewModel():GetAttachment("1").Pos, 4, 6, color_white )
		end
	cam.End3D()

end )

Note: I just added the hook. It’s still not going to work. :stuck_out_tongue:

Since you can’t get the active weapon on this npc, this will work. But it will show it still with other weapons.



local material = Material("effects/stunstick");

hook.Add("RenderScreenspaceEffects", "draw_stunsticksprite", function()
	cam.Start3D(EyePos(), EyeAngles());
		for k, v in pairs(ents.FindByClass("npc_metropolice")) do
			if (IsValid(v)) then
				local attachment = v:GetAttachment(12);
			
				if (attachment) then
					local position, angle = attachment.Pos, attachment.Ang;
					
					render.SetMaterial(material);
					render.DrawSprite(position +angle:Right() *10, 6, 6, color_white);
				end;
			end;
		end;
	cam.End3D();
end);


You only have to create a cam once you know. No need to make one every loop.