Way to make a script only work if I'm holding a specific weapon?
5 replies, posted
I'm trying to make a script that makes a env_entity_dissolver at my hitpos, ONLY if I'm the valid client, my attack2 button is being held down, AND if I have the 357 out.
Currently, this is what I have:
[lua]if (IsValid(client) and client:KeyDown( IN_ATTACK2 ) and client:HasWeapon("weapon_357")) then
blah blah the code here that has no relation to the above[/lua]
All of that works as it should except for HasWeapon (no errors). But I was told that that function doesn't search for the active weapon, but if you have that weapon in your loadout overall. Which I don't really want. Last thing I want to do is accidentally vaporize someone's stuff because it vaporizes with IN_ATTACK2 for all weapons.
I looked over the Gmod wiki to find any functions that could do this, but I can't find anything. The closest thing I can find is [url=http://wiki.garrysmod.com/page/Player/GetActiveWeapon]Player:GetActiveWeapon()[/url] but I don't know how to implement that into my script.
Bear with me as I'm pretty much a nooblet when it comes to lua..
Thanks in advance.
you can do [B]client:GetActiveWeapon() == "weapon_357"[/B] in that [I]if[/I] statement
Like this?
[lua]if (IsValid(client) and client:KeyDown( IN_ATTACK2 ) and client:GetActiveWeapon() == "weapon_357") then
codeshitsefjafgs[/lua]
It didn't work, no error, just nothing happens now. But knowing me I'm doing something wrong.
[lua]
client:GetActiveWeapon():GetClass()
[/lua]
GetActiveWeapon() doesn't return a class by itself.
And your code works fine serverside?
[QUOTE=arcaneex;42877456][lua]
client:GetActiveWeapon():GetClass()
[/lua]
GetActiveWeapon() doesn't return a class by itself.[/QUOTE]
This worked! Thank you very very very much.
Gosh if I knew it was that simple... :v:
I should try to make more scripts...
Solved.
Sorry, you need to Log In to post a reply to this thread.