I want to make it detect if I have crowbar in hand but it's alway stay on the same selection ("No") .
[LUA]function myhud()
surface.CreateFont( "HUDNumber3", 18, 200, false, true, "MyFont" )
local client = LocalPlayer()
local Clip1 = client:GetActiveWeapon():Clip1() // How much ammunition you have inside the current magazine
local PrimaryAmmo = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) // How much ammunition you have outside the current magazine
local SecondaryAmmo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType())// How much ammunition you have for your secondary fire, such as the MP7's grenade launcher
local Health = client:Health()
local NameOfWep = client:GetActiveWeapon( ):GetPrintName()
if !client:Alive() then return end
if(client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end
----- HEALTH INFO -----
-- draw.RoundedBox(4, ScrW() / 2 - 616 , ScrH() / 2 + 252 , 120 / 100 * Health , 20, table.concat(GreenH,", " ))
draw.RoundedBox(4, ScrW() / 2 - 616 , ScrH() / 2 + 250, 120, 25, Color(0, 0, 0, 145))
--draw.SimpleText("".. GetTheTool, "MyFont", ScrH() / 2 - 326, ScrW() / 2 - 27, Color(255, 255, 80, 255), 0, 0)
draw.SimpleText( Health .. " %", "MyFont", ScrH() / 2 - 331, ScrW() / 2 - 27 , Color(255, 255, 20, 255), 0, 0)
----- AMMO INFO -----
draw.RoundedBox(4, ScrW() / 2 - 536 , ScrH() / 2 + 220, 40, 20, Color(0, 0, 0, 145)) -- Clip 1 , Name Box
draw.RoundedBox(4, ScrW() / 2 - 616 , ScrH() / 2 + 220, 70, 20, Color(0, 0, 0, 145)) -- Clip 1 , Ammo Box
if (weapon_crowbar == NameOfWep) then
draw.SimpleText( "Yes" , "MyFont", ScrH() / 2 - 301, ScrW() / 2 - 60, Color(255, 255, 80, 255), 0, 0)
else
draw.SimpleText( "NO" , "MyFont", ScrH() / 2 - 301, ScrW() / 2 - 60, Color(255, 255, 80, 255), 0, 0)
end
-- draw.SimpleText( PrimaryAmmo , "MyFont", ScrH() / 2 - 301, ScrW() / 2 - 60, Color(255, 255, 80, 255), 0, 0)
-- draw.SimpleText( "/" , "MyFont", ScrH() / 2 - 311, ScrW() / 2 - 60, Color(255, 255, 80, 255), 0, 0)
-- draw.SimpleText( Clip1 , "MyFont", ScrH() / 2 - 331, ScrW() / 2 - 60, Color(255, 255, 80, 255), 0, 0)
end
hook.Add("HUDPaint", "myhud", myhud)[/LUA]
[b][url=http://wiki.garrysmod.com/?title=Weapon.GetPrintName]Weapon.GetPrintName [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] returns a [img]http://wiki.garrysmod.com/images/a/a0/String.png[/img], so use
[lua]
if ("weapon_crowbar" == NameOfWep) then
-- stuff
end
[/lua]
[QUOTE=_nonSENSE;25527211][b][url=http://wiki.garrysmod.com/?title=Weapon.GetPrintName]Weapon.GetPrintName [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b] returns a [img_thumb]http://wiki.garrysmod.com/images/a/a0/String.png[/img_thumb], so use
[lua]
if ("weapon_crowbar" == NameOfWep) then
-- stuff
end
[/lua][/QUOTE]
Wrong, that prints the name of the weapon. Eg Crowbar ect.
print(LocalPlayer():GetActiveWeapon( ):GetPrintName())
CROWBAR
print(LocalPlayer():GetActiveWeapon( ):GetClass())
weapon_crowbar
[lua]
local NameOfWep = client:GetActiveWeapon( ):GetClass()
if NameOfWep == "weapon_crowbar" then
...
end
[/lua]
Great it's working thanks Cubar
If I want to add 2 weapons in the condition ?
elseif?
[lua]
local weaponClass = LocalPlayer():GetActiveWeapon( ):GetClass()
tableWithClasses = {"weapon_crowbar", "weapon_a", "weapon_b"}
if table.hasValue(tableWithClasses , weaponClass ) then
-- do something
else
-- do something else
end
[/lua]
or
[lua]
local weaponClass = LocalPlayer():GetActiveWeapon( ):GetClass()
if (weaponClass == "weapon_crowbar") or (weaponClass == "weapon_a") or (weaponClass == "weapon_b") then
-- do something
else
-- do something else
end
[/lua]
I will try the first one with table
Thanks _nonSENSE !
[editline]20th October 2010[/editline]
I tried this but I have an error with table.hasValue
any clue ?
[LUA]local weaponClass = LocalPlayer():GetActiveWeapon( ):GetClass()
tableWithClasses = {"weapon_crowbar", "weapon_a", "weapon_b"}
if table.hasValue(tableWithClasses , weaponClass ) then
draw.SimpleText( "Yes" , "MyFont", ScrH() / 2 - 301, ScrW() / 2 - 60, Color(255, 255, 80, 255), 0, 0)
else
draw.SimpleText( "NO" , "MyFont", ScrH() / 2 - 301, ScrW() / 2 - 60, Color(255, 255, 80, 255), 0, 0)
end[/LUA]
[editline]20th October 2010[/editline]
Oh maybe table.HasValue ?
[editline]20th October 2010[/editline]
ok it's good
Sorry, you need to Log In to post a reply to this thread.