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 :P
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 :)
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]
[QUOTE=Richtofen;45537216]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][/QUOTE]
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]
[QUOTE=gonzalolog;45537722][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][/QUOTE]
Looks complex which means it'll most likely work. I'll try this, thanks :D
[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
[QUOTE=Exho;45538001]Yeah you would want to reference the texture[/QUOTE]
Didn't work. I thought a VMT would do that anyway?
[QUOTE=Baron von Hax;45538276]Didn't work. I thought a VMT would do that anyway?[/QUOTE]
Why don't you use pngs? They are much easier to drop into the game :)
[QUOTE=mib999;45538314]Why don't you use pngs? They are much easier to drop into the game :)[/QUOTE] I'll try this, cheers :)
[editline]30th July 2014[/editline]
Nope, didn't work. Maybe there is an error codewise?
Replace[code]ITEM.Material = 'crosshair/crosshair_001.vmt'[/code] with
[code]ITEM.Material = Material('crosshair/crosshair_001.vmt')[/code]
or if its a png:
[code]ITEM.Material = Material('crosshair/crosshair_001.png', "nocull"))[/code]
Why don't you made pointshop items like they should be made?
ITEM:HUDPaint, instead of hook.Add.
[url]http://pointshop.burt0n.net/items/hooks[/url]
[QUOTE=Nak;45542860]Replace[code]ITEM.Material = 'crosshair/crosshair_001.vmt'[/code] with
[code]ITEM.Material = Material('crosshair/crosshair_001.vmt')[/code]
or if its a png:
[code]ITEM.Material = Material('crosshair/crosshair_001.png', "nocull"))[/code][/QUOTE]
Broke the pointshop
[QUOTE=HumbleTH;45543056]Why don't you made pointshop items like they should be made?
ITEM:HUDPaint, instead of hook.Add.
[url]http://pointshop.burt0n.net/items/hooks[/url][/QUOTE]
How would you go about doing this?
Never used pointshop .. but setting the material to a string don't work.
[QUOTE=Baron von Hax;45543217]How would you go about doing this?[/QUOTE]
I guess:
[code]
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[/code]
[QUOTE=Nak;45543385]Never used pointshop .. but setting the material to a string don't work.
I guess:
[code]
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[/code][/QUOTE]
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 :P
Sorry, you need to Log In to post a reply to this thread.