• Can I make the Reload button to shoot only once?
    2 replies, posted
I was following this [url=http://wiki.garrysmod.com/page/Chair_Throwing_Gun]Chair Throwing Gun Tutorial[/url] and reached the melon challenge. I have to make the gun throw a melon when I press relaod. I made it, but it creates melons for every game tick. So I tried slowing it down to become similar to the automatic primary fire like so: [CODE] local ReloadTimer = false function SWEP:Reload( ) if ReloadTimer == false then self:ThrowChair( "models/props_junk/watermelon01.mdl" ) ReloadTimer = true timer.Simple( 0.3, function() ReloadTimer = false end) end end [/CODE] How can I make it so only one melon is thrown and the player has to tap the reload again to throw another one, similar to the seondary attack, like I believe it's described in the challenge? edit: Also I made the third challenge by making the gun shoot bursts of three chairs instead of all three at once, because they just scatter around. Initially I tried adding variables to the SetPos like this [code] ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) + Vector(0,0,variable) ) [/code] but no matter where I put the vector with the variable, the chairs' relative spawn position is always relative to the map instead of the direction the player is looking. For example if I am looking east the chairs would spawn in front of me and next to each other, but if I am looking north, the chairs would still spawn in front of me, but one in front of another.
Was the question too difficult or too easy to be answered? It must be too easy, since it's part of a tutorial, but I still can't find a way to do it.
[QUOTE=Kethus;41924741]Also I made the third challenge by making the gun shoot bursts of three chairs instead of all three at once, because they just scatter around. Initially I tried adding variables to the SetPos like this [code] ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) + Vector(0,0,variable) ) [/code] but no matter where I put the vector with the variable, the chairs' relative spawn position is always relative to the map instead of the direction the player is looking. For example if I am looking east the chairs would spawn in front of me and next to each other, but if I am looking north, the chairs would still spawn in front of me, but one in front of another.[/QUOTE] I assume you're trying to give each of the three chairs a different starting position so that they don't collide with each other when spawned. Use [CODE](self.Owner:GetAimVector()*variablex+self.Owner:GetAimVector():Right()*variabley+self.Owner:GetAimVector():Up()*variablez)[/CODE] as your offset. The Right and Up functions are just returning a normal vector perpendicular to the aim vector on the respective axis. You multiply a normal vector with a number to return a vector that's "extended" along the direction the normal is pointing. Variablex will extend along the direction you're facing, variabley will extend left and right perpendicular to your direction, and variablez will extend up and down perpendicular to your direction. Hope that helps. As for the first question, I'm not familiar enough with hooks to be able to answer that, sorry. I assure you that, at least by my own standards, that is not an easy question.
Sorry, you need to Log In to post a reply to this thread.