• How to use SetActiveWeapon
    8 replies, posted
I want something like the code below; [lua] self.Owner:SetActiveWeapon("weapon_pistol") [/lua] But I know that it wouldn't work, because you can't pass a string classname to the function. How would I get this functionality?
self.Owner:SetActiveWeapon(self) ? A lot of your questions could go into the "questions that don't need their own thread" thread. There's also [URL="http://wiki.garrysmod.com/page/Structures/SWEP"]SWEP.AutoSwitchTo[/URL], but I don't know if that works.
Wait, sorry; I phrased the question wrong. The code will be going inside a serverside hook, and the line would look like this; [lua]ply:SetActiveWeapon("weapon_pistol")[/lua] And the reason that I don't post inside that thread is that most of the time I never get an answer, or I get an unsatisfactory one that requires more discussion and I end up making a thread anyway. It's generally unhelpful.
[QUOTE=Maurdekye;47466202]Wait, sorry; I phrased the question wrong. The code will be going inside a serverside hook, and the line would look like this; [lua]ply:SetActiveWeapon("weapon_pistol")[/lua] And the reason that I don't post inside that thread is that most of the time I never get an answer, or I get an unsatisfactory one that requires more discussion and I end up making a thread anyway. It's generally unhelpful.[/QUOTE] Had you searched the wiki for the word 'weapon' you would have found PLAYER:GetWeapon() which does take a string and gives you an entity you could then pass into SetActiveWeapon. I think that's why you don't always get a response, some of your questions can be answered with one or two minutes searching the wiki.
[QUOTE=wh1t3rabbit;47466274]Had you searched the wiki for the word 'weapon' you would have found PLAYER:GetWeapon() which does take a string and gives you an entity you could then pass into SetActiveWeapon. I think that's why you don't always get a response, some of your questions can be answered with one or two minutes searching the wiki.[/QUOTE] I did in fact search the wiki for 'weapon', and found the function [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/weapons/Get]weapons.Get[/url] before the one you linked above. I tried it and it didn't work; so I came here for answers. Please don't assume. I made this line using that function, and it sort of works; [lua]ply:SetActiveWeapon(ply:GetWeapon("swep_name"))[/lua] Although it does change the weapon to the one selected, the viewmodel stays the same as the last weapon selected for some reason.
-snip- Edit: Lolcats' is better
You know there's [URL="http://wiki.garrysmod.com/page/Player/SelectWeapon"]Player:SelectWeapon[/URL].
ply:SelectWeapon("hi")
[QUOTE=Lolcats;47466348]You know there's [URL="http://wiki.garrysmod.com/page/Player/SelectWeapon"]Player:SelectWeapon[/URL].[/QUOTE] Thanks, that's even more helpful. And it even fixes the viewmodel problem.
Sorry, you need to Log In to post a reply to this thread.