Garry's Mod

Garry's Mod

217 ratings
Reflection Laser Gun
2
   
Award
Favorite
Favorited
Unfavorite
Content Type: Addon
Addon Type: Weapon
Addon Tags: Fun, Realism
File Size
Posted
Updated
718.579 KB
21 Feb, 2021 @ 2:42am
23 Feb, 2021 @ 11:38am
4 Change Notes ( view )

Subscribe to download
Reflection Laser Gun

Description
How to use
Primary Fire - Shoots laser,
Secondary Fire - Launches a Energy grenade or creates an Energy Aura,
Reload - Changes fire mode.


Mode 1 - Branching laser. The beam splits into 3 more on hit and they branch too (recursive). Takes two rounds from the clip,
Mode 2 - Single reflecting laser. The beam bounces off a surface few times. Takes one round from the clip.


Secondary fire either launches a grenade when aiming far away or creates an Energy Aura that does not hurt the user but enemies around. Aura can also push player away, so it's good for situations when the player is surrounded by enemies and needs to either kill them or escape (jump and shoot aiming for the feet).

The ammo regenerates automatically after a while.
The SWep is located in "Jakub Baku" category (that's my name, that's why)

Passive aggressive FAQ (the tradition of my addon descriptions)
- THIS IS A COPY OF NOMAD NO SUBCRIPCION!
- It looks similar to Nomad, it feels similar to Nomad as well as any other Ammo-regenerating laser gun. I think my idea is quite interesting. Of course it's inspired by Nomad but it's not copied in any way.

- I see you like ParticleEmitter really much and you didn't bother to change the particles in different effects.
- Yes, I've used really similar particle settings and materials in my effects. At first I also thought it's a little bit repetitive but after a while I saw that it keeps everything in the same theme and I like it.

- What's the point of another energy weapon on the workshop? I already have 10 in my subscriptions.
- Then I guess you should unsubscribe to one of them and subscribe to mine.

- Can I use your code?
- Both "yes" and "no". If you're going to copy my code and label it as yours, then of course no! But if you're going to edit the weapon, add some cool effects, maybe improve it or just use it for learning purposes then yes, of course. You don't need to credit me if you really don't want to, but it would be nice of you :)

- How did you implement the recursion?
- If you're asking about the recursion then I assume you're not completely new to coding. You might have heard that recursion is dangerous because it can cause a stack overflow thus I didn't use the "pure" recursion but something different. Ever since I've used such method for quick sort I fell in love with it. It's simple, it does not cause a stack overflow, because the "pseudo-stack" is totally controllable by coder and it operates on regular RAM memory and not the hardware stack.

- What is the formula for vector reflection?
- This is how I do it in that addon:
local dir = (lastTrace.HitPos - lastOrigin):GetNormalized() endp = lastTrace.HitPos + (dir - 2 * dir:Dot(lastTrace.HitNormal) * lastTrace.HitNormal) * 65535
So the formula is
refVector = incomingVec - 2 * dotProduct(incomingVec, surfNormal) * surfNormal
incomingVec needs to be normalized and the result - refVector is a normalized, reflected vector.
You can calculate the incomingVec by substracting the start vector of a beam from the Hit position vector of that beam and then normalizing the result:
incomingVec = normalize(beamHitPos - beamStart)
In Lua you normalize a vector by calling a Vector:GetNormalized() on it.

- Okay, and how about that recursion method?
- First of, you don't do recursion. Instead of making a recursive function you make a table or Stack object called, let's say stack. Then you put a first entry to that stack:
stack = createStack() //in real Lua you use util.Stack() but it's a pseudo-code (something for you Bartek) stack.push({someParameter = something, someParameter2 = something, recIndex = 1})
recIndex is important - with that we can limit our recursion and not allow it to crash gmod by going on indefinitely.
After that we can enter the loop. The best type of loop for that purpose is a while loop.
while(stack.size() > 0){ var top = stack.pop() //get the last element off of the stack if(top.recIndex < maxRecursion){ //do something here and push the result on the stack, just like calling the recursive function. stack.push({someParameter = something, someParameter2 = something, recIndex = top.recIndex + 1}) //REMEMBER to increment the recIndex!!!! } } //here the recursion is done
As you can see it's really simple. Instead of calling a recursive function you pass those parameters onto a stack and then use it in another iteration by popping it. maxRecursion is a variable controlling the recursion to prevent the endless loop and using up all the available memory.
If you're familiar with recursion it's good to first design a "pure recursion" algorithm and then transform it into that stack-based fashion.
17 Comments
󠀡󠀡remi 8 Jul, 2023 @ 4:06am 
omg its the "laser gun from gmod 9" real!!1!!!!!
GasolineDrinker095 5 Jan, 2023 @ 5:45pm 
wtf is that weapon icon
Skeleton Cowboy 13 Mar, 2022 @ 10:03pm 
can you make a version of the gun where the lasers never stop reflecting? if possible?
Ancient 30 Dec, 2021 @ 4:38pm 
mentioning a past comment, what IS the background of the weapon in the hud?
Moon Bandit 28 Feb, 2021 @ 9:11pm 
Ok, this weapon is really fun. nice work
Pop4484 26 Feb, 2021 @ 1:56am 
what the heck is the weapon icon on the HUD? ಠ_ಠ
Rizelu 25 Feb, 2021 @ 2:05am 
Ok Don't Need This Weapon Like Admin Weapon Very Nice Weapon
Gordon Freeman The Annoyance 24 Feb, 2021 @ 2:07pm 
Hey, Do you think you could give this weapon a model that isn't the HL2 MP7?

Maybe one of the TF2 Hexes on this workshop could work as a new model for this weapon.

Do you want to implement any unique sounds for this weapon in the future?

https://steamproxy.net/sharedfiles/filedetails/?id=1974159232
I think this could make a good unique model for this weapon.
AwesomeGraczGie47  [author] 24 Feb, 2021 @ 1:20pm 
thank you so much :D And about an admin version - I don't think I'll make one, I want this weapon to be balanced and available for every player on server, hope you understand that
Rizelu 24 Feb, 2021 @ 12:22pm 
Make More Weapons Like This