[QUOTE=zzaacckk;30836913][b][url=http://wiki.garrysmod.com/?title=Player.GetActiveWeapon]Player.GetActiveWeapon [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b][/QUOTE]
You still need to get the class of the weapon using GetClass().
So an example of this could be
if LocalPlayer():GetActiveWeapon() == "weapon_pistol" then
print( "Your current weapon is a hl2 pistol." )
end
??
if LocalPlayer():GetActiveWeapon():GetClass() == "weapon_pistol" then
print( "Your current weapon is a hl2 pistol." )
end
:GetActiveWeapon() returns the weapon entity, :GetClass() returns the class name of the entity, and "weapon_pistol" is the classname.
^^ kk ty that helps a lot more than the actual answer. :)
[editline]2nd July 2011[/editline]
K so I did this with the given information:
[lua]
function SetKnifeSpeed()
for k,v in pairs( player.GetAll() ) do
if v:GetActiveWeapon():GetClass() == "weapon_ttt_knife" then -- line 12
v:SetSpeed( 1 )
end
end
end
hook.Add( "Think", "SetKnifeSpeed", SetKnifeSpeed )
[/lua]
and recieved an error saying..
Hook 'SetKnifeSpeed' Failed: [@gamemodes\terrortown\gamemode\speed.lua:12[ Tried to sue a NULL entity!
(Don't worry about SetSpeed, it works fine with something else I have)
[lua]
function SetKnifeSpeed()
for k,v in pairs( player.GetAll() ) do
if v:GetActiveWeapon() && v:GetActiveWeapon():GetClass() == "weapon_ttt_knife" then -- line 12
v:SetSpeed( 1 )
end
end
end
hook.Add( "Think", "SetKnifeSpeed", SetKnifeSpeed )
[/lua]
Still getting the error.
[lua]
function SetKnifeSpeed()
for k,v in pairs( player.GetAll() ) do
if IsValid(v) && v:IsPlayer() && v:GetActiveWeapon() && v:GetActiveWeapon():GetClass() == "weapon_ttt_knife" then -- line 12
v:SetSpeed( 1 )
end
end
end
hook.Add( "Think", "SetKnifeSpeed", SetKnifeSpeed )
[/lua]
Still.
Bump. Anyone know what's wrong with the above code?
[CODE]
function SetKnifeSpeed()
for k,v in pairs( player.GetAll() ) do
if IsValid(v) && v:IsPlayer() && v:GetActiveWeapon():GetClass() == "weapon_ttt_knife" then -- line 12
v:SetSpeed( 1 )
end
end
end
hook.Add( "Think", "SetKnifeSpeed", SetKnifeSpeed )
[/CODE]
not sure if this is the problem but I
Removed an extra v:GetActiveWeapon().
Sorry, you need to Log In to post a reply to this thread.