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
[editline]29th July 2014[/editline]
Just noticed that self.Materials should be self.Material
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?
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]
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]
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
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