I'm trying to change a DrawHUD texture by changing the actual texture and then recalling self.DrawHud()
This is the code:
[LUA]
local ourMat = Material( "models/wireframe" ) -- Calling Material() every frame is quite expensive
function SWEP:DrawHUD()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( ourMat ) -- If you use Material, cache it!
surface.DrawTexturedRect( 0, 0, 256, 256 )
end
function SWEP:Reload()
print(ourMat)
ourMat = "decals/decalgraffiti024a"
print(ourMat)
self.DrawHUD()
/*
self:DefaultReload(ACT_VM_RELOAD)
return true
*/
end
[/LUA]
What do? :ohno:
Edit:
Error is:
[CODE]
[ERROR] addons/santa/lua/weapons/joyofpainting.lua:596: attempt to index global 'surface' (a nil value)
[/CODE]
It's all wrong.
First of all, type of your variable "ourMat" is IMaterial, and in your reload function you set it to string.
Secondly, you are
1) Trying to call SWEP.DrawHUD manually for some reason ( don't, its called for you every fram )
2) Trying to call it in a non rendering hook ( it won't work, surface functions only work in 2 rendering context )
3) Also trying to call it ON THE SERVER ( server doesn't do rendering, which is why you are getting that error
4) Please read the wiki page for SWEP.Reload. IT WILL NOT BE CALLED ON CLIENT IN SINGLE PLAYER!
[QUOTE=Robotboy655;50687464]It's all wrong.
First of all, type of your variable "ourMat" is IMaterial, and in your reload function you set it to string.
Secondly, you are
1) Trying to call SWEP.DrawHUD manually for some reason ( don't, its called for you every fram )
2) Trying to call it in a non rendering hook ( it won't work, surface functions only work in 2 rendering context )
3) Also trying to call it ON THE SERVER ( server doesn't do rendering, which is why you are getting that error
4) Please read the wiki page for SWEP.Reload. IT WILL NOT BE CALLED ON CLIENT IN SINGLE PLAYER![/QUOTE]
So where do I put the texture change? On key press or what? :ohno: instant halp pls
Robotboy already clearly explained what to do. Nobody's going to give you instant help if you can't even be bothered doing anything people tell you to do.
[QUOTE=MPan1;50688345]Robotboy already clearly explained what to do. Nobody's going to give you instant help if you can't even be bothered doing anything people tell you to do.[/QUOTE]
Yea I'm tryna fix it
This is my current code but I believe it's also serverside :\ (givin me the same error)
[CODE]
hook.Add( "KeyPress", "keypress-changegrafitti", function( LocalPlayer, IN_RELOAD )
if ( key == IN_RELOAD ) then
ourMat = Material ( "decals/decalgraffiti024a" )
end
end )
[/CODE]
How do I make a clientside keypress? :ohno:
[QUOTE=Aarone2004;50689622]Yea I'm tryna fix it
This is my current code but I believe it's also serverside :\ (givin me the same error)
[CODE]
hook.Add( "KeyPress", "keypress-changegrafitti", function( LocalPlayer, IN_RELOAD )
if ( key == IN_RELOAD ) then
ourMat = Material ( "decals/decalgraffiti024a" )
self.DrawHUD()
end
end )
[/CODE]
How do I make a clientside keypress? :ohno:[/QUOTE]
If you're trying to call a clientside function on KeyPress just have KeyPress do a net.Start and net.Send() to the client and on the client do net.Receive. Don't forget to util.AddNetworkString("String") on the server before all of that.
[QUOTE=Thane;50689647]If you're trying to call a clientside function on KeyPress just have KeyPress do a net.Start and net.Send() to the client and on the client do net.Receive. Don't forget to util.AddNetworkString("String") on the server before all of that.[/QUOTE]
wat
[QUOTE=Aarone2004;50689655]wat[/QUOTE]
Can you better explain what you're trying to do. I think I'm missing it.
If I remember correctly there's a way to get SWEP functions like Reload to run on the client even if they don't by default... I'll see if I can find it
[editline]11th July 2016[/editline]
[URL="http://wiki.garrysmod.com/page/Weapon/CallOnClient"]Yeah, here it is.[/URL] I'll try and make an example
[editline]11th July 2016[/editline]
Try this:
[CODE]
if CLIENT then
local ourMat = Material( "models/wireframe" )
function SWEP:DrawHUD()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( ourMat )
surface.DrawTexturedRect( 0, 0, 256, 256 )
end
function SWEP:Reload()
ourMat = Material( "decals/decalgraffiti024a" )
end
end
if SERVER then
function SWEP:Reload()
self:CallOnClient( "Reload" ) -- Run the reload function clientside
end
end
[/CODE]
No clue if it works though.
[QUOTE=MPan1;50689693]If I remember correctly there's a way to get SWEP functions like Reload to run on the client even if they don't by default... I'll see if I can find it
[editline]11th July 2016[/editline]
[URL="http://wiki.garrysmod.com/page/Weapon/CallOnClient"]Yeah, here it is.[/URL] I'll try and make an example
[editline]11th July 2016[/editline]
Try this:
[CODE]
if CLIENT then
local ourMat = Material( "models/wireframe" )
function SWEP:DrawHUD()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( ourMat )
surface.DrawTexturedRect( 0, 0, 256, 256 )
end
function SWEP:Reload()
ourMat = Material( "decals/decalgraffiti024a" )
end
end
if SERVER then
function SWEP:Reload()
self:CallOnClient( "Reload" ) -- Run the reload function clientside
end
end
[/CODE]
No clue if it works though.[/QUOTE]
oh man thannkkks
Sorry, you need to Log In to post a reply to this thread.