Getting the current users weapon and put a image on the hud
6 replies, posted
This is what i got so far and its not working im a little stuck anyone have a idea on how to do this?
[CODE]
surface.SetDrawColor( 255, 255, 255, 255 )
if ply:GetActiveWeapon("weapon_smg1") then
smg = Material( "materials/serioushud/weapon_smg1_image.png" )
surface.SetMaterial( smg )
elseif ply:GetActiveWeapon("weapon_shotgun") then
shotgun = Material( "materials/serioushud/weapon_shotgun_image.png" )
surface.SetMaterial( shotgun )
end
surface.DrawTexturedRect( ScrW()/1.92, ScrH()/1.16, ScrW()/20.39, ScrH()/12 )
[/CODE]
Firstly, it isn't working because your file path has 'materials' at the start of it. If you remove that bit it should work.
Secondly, you could do this without having to make a different image for every weapon by using a [URL="https://wiki.garrysmod.com/page/Category:DModelPanel"]DModelPanel[/URL] with the weapon's model. Don't create it every frame, though.
Thirdly, please cache that material! It even says to do that on the example of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawTexturedRect]surface.DrawTexturedRect[/url]. Using the Material function every frame is costly.
Fourtly, please create those variables locally rather than making them global, if they're global, another script could accidentally use them and screw up your script.
This version of your code will probably work if you don't want to use a DModelPanel:
[CODE]
local weapon = 'Whatever you want the default weapon image to be, or just nil'
if ply:GetActiveWeapon("weapon_smg1") then
weapon = Material( "serioushud/weapon_smg1_image.png" )
elseif ply:GetActiveWeapon("weapon_shotgun") then
weapon = Material( "serioushud/weapon_shotgun_image.png" )
end
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( weapon )
surface.DrawTexturedRect( ScrW()/1.92, ScrH()/1.16, ScrW()/20.39, ScrH()/12 )
[/CODE]
[QUOTE=MPan1;49563217]Firstly, it isn't working because your file path has 'materials' at the start of it. If you remove that bit it should work.
Secondly, you could do this without having to make a different image for every weapon by using a [URL="https://wiki.garrysmod.com/page/Category:DModelPanel"]DModelPanel[/URL] with the weapon's model. Don't create it every frame, though.
Thirdly, please cache that material! It even says to do that on the example of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawTexturedRect]surface.DrawTexturedRect[/url]. Using the Material function every frame is costly.
Fourtly, please create those variables locally rather than making them global, if they're global, another script could accidentally use them and screw up your script.
This version of your code will probably work if you don't want to use a DModelPanel:
[CODE]
local weapon = 'Whatever you want the default weapon image to be, or just nil'
if ply:GetActiveWeapon("weapon_smg1") then
weapon = Material( "serioushud/weapon_smg1_image.png" )
elseif ply:GetActiveWeapon("weapon_shotgun") then
weapon = Material( "serioushud/weapon_shotgun_image.png" )
end
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( weapon )
surface.DrawTexturedRect( ScrW()/1.92, ScrH()/1.16, ScrW()/20.39, ScrH()/12 )
[/CODE][/QUOTE]
i got it show the smg but it only shows the smg and i want it to change if they scroll and change there weapon
Wait, so are you using a DModelPanel or that code I posted? What are you using?
the one you posted was just like mine and i dont know much about DModelPanel so i started to mess with it
I think its the [CODE] ply:GetActiveWeapon [/CODE] thats messing up
Actually, I think it is. You can't put a weapon string in the brackets, it won't do anything. You need to do
[CODE]
ply:GetActiveWeapon():GetClass() == "weapon_smg1"
[/CODE]
[QUOTE=MPan1;49566597]Actually, I think it is. You can't put a weapon string in the brackets, it won't do anything. You need to do
[CODE]
ply:GetActiveWeapon():GetClass() == "weapon_smg1"
[/CODE][/QUOTE]
your a genius
Sorry, you need to Log In to post a reply to this thread.