Ammo counter thing for a Viewmodel

I’ve remade the Flak Cannon model from UT99 and getting help from a few others to code / rig it.
One of the neat features of the Flak cannon is an ammo counter display on it.
Whether this is possible on a view model I have no idea , but I know it would be pretty awesome to have it.

If you know how to do this , and needs in-model references , I will be glad to do it.

Ok this should work, as it’s based on the toolgun’s code, but I haven’t tested it.
Texture the ammo counter models/weapons/flak/screen (or something else and change the paths below) and have the background you want it as models/weapons/flak/screen_bg. (again change the name, but you do need a background otherwise it’ll look like a vortex.)
Put a file in youraddon/settings/render_targets/ called FlakCannon.txt and set it’s contents to this



"FlakCannon"
{
	"Name"		"FlakCannon"
	"Width"		"256"
	"Height"	"128"
}

Feel free to change the dimensions to the same as your counter texture, but remember to change them in the Lua too.
Then put this in a clientside portion of your SWep.
[lua]local matScreen = Material( “models/weapons/flaky/screen” )
local txBackground = surface.GetTextureID( “models/weapons/flaky/screen_bg” )
// GetRenderTarget returns the texture if it exists, or THROW LOTS OF DAMN ERRORS IF IT DOESN’T ARGH
local w,h = 256, 128-- Dimensions guessed at, put your own.
local RTTexture = GetRenderTarget( “FlakCannon”, w,h )
function SWEP:ViewModelDrawn()
local NewRT = RTTexture

// Set the material of the screen to our render target
matScreen:SetMaterialTexture( "$basetexture", NewRT )

local OldRT = render.GetRenderTarget();

// Set up our view for drawing to the texture
render.SetRenderTarget( NewRT )
render.SetViewPort( 0, 0, w,h )
cam.Start2D()

// Background
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( txBackground )
surface.DrawTexturedRect( 0, 0, w,h )
surface.SetFont( "GModToolScreen" )
surface.SetTextColor(255,255,255,255)
local words = self:Clip1() -- I think that's right, I can't remember off the top of my head
local w1,h1 = surface.GetTextSize(words)
surface.SetTextPos((w-w1)/2,(h-h1)/2)
surface.DrawText(words)
cam.End2D()
render.SetRenderTarget( OldRT )

end[/lua]If it doesn’t, drop me a PM and I’ll see what I can do.
I’ve always liked the flak cannon. :3:

Is it really necessary to use a render target? Everything always worked fine for me when using cam.Start3D2D.

I don’t know. I picked render target because that’s the method the only weapon I know of that has a screen embedded on it uses.

Ah. When I get my Lua coder to finish the script , I’ll nod this in his direction.
Thanks.

( If this doesn’t work I’ll post back. )