Is there a way where I could add a Lua file to make it so people can type /destroy and their weapon disappears
[QUOTE=Shenesis;50772256]In a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSay]GM:PlayerSay[/url] hook, see if the "text" argument is "/destroy". If so, then call [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Remove]Entity:Remove[/url] on the player's active weapon (obtained with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetActiveWeapon]Player:GetActiveWeapon[/url])[/QUOTE]
Could you make the code for me?
this is not a make me dank scripts forum but i will help you please dont just copy paste this and try to understand the code it should be easy since the comments i will put and the simplicity of this code.You will put it in addons/youraddonname/lua/autorun/yourscriptname.lua (if i remember it correctly)(dont name these generic things because you might make addons conlict ie:addon)
[lua]
hook.Add( "PlayerSay", "WeaponDestroyEntity", function( ply, text ) // it the players says something
if ( string.sub( text, 1, 8 ) == "/destroy" ) then // and if its first 8 charcters are /destroy
local plyWeapon = ply:GetActiveWeapon() // get the players active weapon and save it in a variable
ply:StripWeapon(plyWeapon:GetClass()) // remove the weapon using ent:Remove is not a good idea
end
end)
[/lua]
i know this could be simpleified into 2-3 lines of code but its for understanding reasons.
[QUOTE=shootbysteve;50772571]
[...]
[/QUOTE]
This one won't leave the player without weapons when the previous one got erased, sends a feedback and has a fail-safe in case you're not holding a weapon.
[lua]
local DestroyCommand = {}
--- ...
DestroyCommand["!destroy"] = true // Enabled
DestroyCommand["/destroy"] = true
DestroyCommand[">destroy"] = false // Disabled
hook.Add( "PlayerSay", "CMD_DestroyWeapon", function( ply, text )
if ( DestroyCommand[string.sub( text, 1, 8 )] == true ) // Might set other value
local plyWeapon = ply:GetActiveWeapon()
local plyWeapons
if plyWeapon then
ply:ChatPrint("You've destroyed your ".. (plyWeapon.PrintName or "current weapon").."!")
ply:StripWeapon(plyWeapon:GetClass())
plyWeapons = ply:GetWeapons()
if (plyWeapons[1]) then ply:SelectWeapon( plyWeapons[1]:GetClass() ) end
else
ply:ChatPrint("You are not holding a weapon!")
end
end
end)
[/lua]
Based on shootbysteve <3
Also, untested.
Sorry, you need to Log In to post a reply to this thread.