Pointshop crosshairs

So, this is a bit of an odd one, but I was wondering how you could set crosshairs using the pointshop.
I have my attempt below so far:
[lua]ITEM.Name = ‘Crosshair Test’
ITEM.Price = 0
ITEM.Material = ‘crosshair/crosshair_001.vmt’
ITEM.AllowedUserGroups = {“owner”}

function ITEM:OnEquip(ply, modifications)
surface.SetTexture( self.Materials )
surface.DrawTexturedRect( ( x ) - 32, ( y ) - 16, 64, 32 )
end

function ITEM:OnHolster(ply)
SafeRemoveEntity(surface.SetTexture)
end
[/lua]
Only issue is that it won’t allow me to equip it. Thanks for any help in advance :slight_smile:

[editline]29th July 2014[/editline]

Just noticed that self.Materials should be self.Material :stuck_out_tongue:

If you do it on ITEM:OnEquip, the thing will only draw once when the function runs, if that’s how surface.* functions work. Why not do ITEM:HUDPaint() instead?

I’ll try that, thanks :slight_smile:

here, hasn’t been tested, but should work.

[lua]
ITEM.Name = ‘Crosshair Test’
ITEM.Price = 0
ITEM.Material = ‘crosshair/crosshair_001.vmt’
ITEM.AllowedUserGroups = {“owner”}

function ITEM:OnEquip(ply, modifications)

hnaknaw = vgui.Create("DImage")
hnaknaw:SetImage(self.Material)

function GM:HUDPaint()
	hnaknaw:SetSize(64,32)
  	hnaknaw:SetPos(ScrW()/2-64/2, ScrH()/2-32/2)      	
end

end

function ITEM:OnHolster(ply)
function GM:HUDPaint()
hnaknaw:Remove()
end
end
[/lua]

Why would you override the gamemode’s hook just to draw a crosshair?

[lua]
ITEM.Name = ‘Crosshair Test’
ITEM.Price = 0
ITEM.Material = ‘crosshair/crosshair_001.vmt’
ITEM.AllowedUserGroups = {“owner”}

function ITEM:OnEquip(ply, modifications)
if not CLIENT then return end
hook.Add(“HUDPaint”,“DrawPointshopCrosshair”,function()
surface.SetMaterial(self.Material)
surface.SetDrawColor(255,255,255)
surface.DrawTexturedRectRotated(ScrW()/2,ScrH()/2,32,32,0)
end)
end

function ITEM:OnHolster(ply)
if not CLIENT then return end
hook.Remove(“HUDPaint”,“DrawPointShopCrosshair”)
end
[/lua]

Looks complex which means it’ll most likely work. I’ll try this, thanks :smiley:

[editline]29th July 2014[/editline]

Doesnt seem to work. Would changing vmt to vtf make any difference?

Yeah you would want to reference the texture

Didn’t work. I thought a VMT would do that anyway?

Why don’t you use pngs? They are much easier to drop into the game :slight_smile:

I’ll try this, cheers :slight_smile:

[editline]30th July 2014[/editline]

Nope, didn’t work. Maybe there is an error codewise?

Replace


ITEM.Material = 'crosshair/crosshair_001.vmt'

with


ITEM.Material = Material('crosshair/crosshair_001.vmt')

or if its a png:


ITEM.Material = Material('crosshair/crosshair_001.png', "nocull"))

Why don’t you made pointshop items like they should be made?

ITEM:HUDPaint, instead of hook.Add.

Broke the pointshop

How would you go about doing this?

Never used pointshop … but setting the material to a string don’t work.

I guess:



ITEM.Name = 'Crosshair Test'
ITEM.Price = 0
ITEM.Material = 'crosshair/crosshair_001.vmt'
ITEM.AllowedUserGroups = {"owner"}

function ITEM:OnEquip(ply, modifications)
	if string.find( self.Material, ".png" ) then
		ply.Crosshair = Material(self.Material, "nocull"))
	else
		ply.Crosshair = Material(self.Material))
	end
end

function ITEM:OnHolster(ply)
    ply.Crosshair = nil
end
function ITEM:HUDPaint()
    if !LocalPlayer().Crosshair then return end
    surface.SetMaterial(LocalPlayer().Crosshair)
    surface.SetDrawColor(255,255,255)
    surface.DrawTexturedRectRotated(ScrW()/2,ScrH()/2,32,32,0)
end

Yeah.

Not sure if you’d need to surround the HUDPaint function in an if statement tocheck if the client’s running it:

[lua]
if CLIENT then
function ITEM:HUDPaint()
–code
end
end
[/lua]

I am using [lua]ITEM.Name = ‘Crosshair Test’
ITEM.Price = 0
ITEM.Material = ‘crosshair/crosshair_001.vmt’
ITEM.AllowedUserGroups = {“owner”}

function ITEM:OnEquip(ply, modifications)
if string.find(self.Material) then
ply.Crosshair = Material(self.Material, “nocull”)
else
ply.Crosshair = Material(self.Material)
end
end

function ITEM:OnHolster(ply)
ply.Crosshair = nil
end

if CLIENT then
function ITEM:HUDPaint()
if !LocalPlayer().Crosshair then return end
surface.SetMaterial(LocalPlayer().Crosshair)
surface.SetDrawColor(255,255,255)
surface.DrawTexturedRectRotated(ScrW()/2,ScrH()/2,32,32,0)
end
end[/lua] and it doesn’t seem to work. I’d say this is progress though :stuck_out_tongue: