Garry's Mod

Garry's Mod

View Stats:
Kale Dec 6, 2015 @ 5:03pm
Issue With SWEP
So I made a SWEP and I tested it before uploading and it showed up on the list and worked fine with no errors, but when I uploaded it to the workshop I deleted the files in my folder to make sure it uploaded properly. My problem is that the addon is download and it shows up on my list in Gmod, but the SWEP doesn't appear in the weapon list anymore. I checked the file that was uploaded and everything is there and nothing was changed and I have no idea what might be the problem.
< >
Showing 31-45 of 55 comments
maroon Dec 7, 2015 @ 4:22pm 
Originally posted by Tyler Two Timer:
Originally posted by Okami:
Having SWEP in the name of something wont cause an issue (Since its a string, it wont matter no matter what you put there). Is that the first time SWEP appears in your code?
The only other time is right before it at the very beginning that says:

/*---------------------------------
Created with buu342s Swep Creator
---------------------------------*/

other than that no it doesn't come up any earlier.

Ok, so I reached the conclusion that SWEP was never declared as an item, so its nil as the error says.
Kale Dec 7, 2015 @ 4:23pm 
Originally posted by Okami:
Originally posted by Tyler Two Timer:
The only other time is right before it at the very beginning that says:

/*---------------------------------
Created with buu342s Swep Creator
---------------------------------*/

other than that no it doesn't come up any earlier.

Ok, so I reached the conclusion that SWEP was never declared as an item, so its nil as the error says.
So what exactly do I have to do then?
maroon Dec 7, 2015 @ 4:33pm 
Originally posted by Tyler Two Timer:
Originally posted by Okami:

Ok, so I reached the conclusion that SWEP was never declared as an item, so its nil as the error says.
So what exactly do I have to do then?
At this point, I'm just as confused as you are.
I don't even know if SWEP is sometype of fuction.
Kale Dec 7, 2015 @ 4:35pm 
Originally posted by Okami:
Originally posted by Tyler Two Timer:
So what exactly do I have to do then?
At this point, I'm just as confused as you are.
I don't even know if SWEP is sometype of fuction.
Well I guess my real problem is using an outdated SWEP creator from a few years ago. I guess I'll save the audio file considering it's the only real file I can salvage from this and start over.
Shallex Dec 7, 2015 @ 4:43pm 
I'd suggest perhaps making the SWEP from scratch.
maroon Dec 7, 2015 @ 4:45pm 
Originally posted by Shallex:
I'd suggest perhaps making the SWEP from scratch.
He/she said that he/she was doing that.
Forgetting what I said before, when creating the swep, make it a Weapon() class

MySwep = Weapon()
I use the wiki[wiki.garrysmod.com] for help with coding, and discovered this class, which is what you want to set it to when you redo your code.
Kale Dec 7, 2015 @ 4:45pm 
Originally posted by Shallex:
I'd suggest perhaps making the SWEP from scratch.
I'm looking at that, but all the tutorials are 5+ years old and correct me if I'm wrong, but SWEP isn't a function or at least isn't anymore considering all these old tutorials still use SWEP as a function.
Shallex Dec 7, 2015 @ 4:49pm 
Originally posted by Okami:
Originally posted by Shallex:
I'd suggest perhaps making the SWEP from scratch.
He/she said that he/she was doing that.
Forgetting what I said before, when creating the swep, make it a Weapon() class

MySwep = Weapon()
I use the wiki[wiki.garrysmod.com] for help with coding, and discovered this class, which is what you want to set it to when you redo your code.
Originally posted by Okami:
Originally posted by Shallex:
I'd suggest perhaps making the SWEP from scratch.
He/she said that he/she was doing that.
Forgetting what I said before, when creating the swep, make it a Weapon() class

MySwep = Weapon()
I use the wiki[wiki.garrysmod.com] for help with coding, and discovered this class, which is what you want to set it to when you redo your code.
I don't have that in any SWEPs I've ever made, nor have I seen that in any modern tutorial, and my SWEPs work just fine.

https://wiki.garrysmod.com/page/Chair_Throwing_Gun

This is a SWEP tutorial on the Garry's Mod wiki, but it fires physics props instead of bullets, but you can modify the fire function to fire bullets instead. If you need help with that, I could paste code for a primary fire function that fires bullets.
Last edited by Shallex; Dec 7, 2015 @ 4:49pm
Kale Dec 7, 2015 @ 4:50pm 


Originally posted by Okami:
Originally posted by Shallex:
I'd suggest perhaps making the SWEP from scratch.
He/she said that he/she was doing that.
Forgetting what I said before, when creating the swep, make it a Weapon() class

MySwep = Weapon()
I use the wiki[wiki.garrysmod.com] for help with coding, and discovered this class, which is what you want to set it to when you redo your code.
So basically I need to go back through and change every SWEP. into Weapon() such as:

SWEP.Spawnable= true > Weapon(Spawnable= true)
Shallex Dec 7, 2015 @ 4:56pm 
Originally posted by Tyler Two Timer:
Originally posted by Okami:
He/she said that he/she was doing that.
Forgetting what I said before, when creating the swep, make it a Weapon() class

MySwep = Weapon()
I use the wiki[wiki.garrysmod.com] for help with coding, and discovered this class, which is what you want to set it to when you redo your code.
So basically I need to go back through and change every SWEP. into Weapon() such as:

SWEP.Spawnable= true > Weapon(Spawnable= true)
No, I'm fairly certain you don't; my addons don't require that, and neither do my friend's addons nor any modern addon I've ever seen.
maroon Dec 7, 2015 @ 5:00pm 
Originally posted by Shallex:
Originally posted by Okami:
He/she said that he/she was doing that.
Forgetting what I said before, when creating the swep, make it a Weapon() class

MySwep = Weapon()
I use the wiki[wiki.garrysmod.com] for help with coding, and discovered this class, which is what you want to set it to when you redo your code.
I don't have that in any SWEPs I've ever made, nor have I seen that in any modern tutorial, and my SWEPs work just fine.

https://wiki.garrysmod.com/page/Chair_Throwing_Gun

This is a SWEP tutorial on the Garry's Mod wiki, but it fires physics props instead of bullets, but you can modify the fire function to fire bullets instead. If you need help with that, I could paste code for a primary fire function that fires bullets.

Hmm, that link doesn't work.
Looking at other mods I don't see any requirements for it, so your're right.

I haven't done sweps in a long time, so I have to relearn them again
maroon Dec 7, 2015 @ 5:05pm 
Wow.

Looking at the wiki tutorial gave me a huge understanding why alot of stuff was wrong.
If you want, try renaming your shared.lua myweaponname.lua and placing it in addon/lua/weapons/
This will most likely make a difference, but still might have some errors, since its made for Gmod 10.
Last edited by maroon; Dec 7, 2015 @ 5:05pm
Shallex Dec 7, 2015 @ 5:05pm 
Go to your Garry's Mod folder in

GarrysMod > garrysmod > gamemodes > base > entities > weapons > weapon_base > shared.lua

You can see the base SWEP and see how that works. Keep in mind you don't need to copy and paste it in its entirety for your SWEP, because when you define the weapon base in your SWEP and setting it to "base", you're referring to this file, and setting a SWEP base basically just makes your SWEP inherit traits from the base that aren't defined in your SWEP.

For example you could make a SWEP base which has some realistic recoil mechanics, then in your SWEP refer to that base so that your SWEPs inherit that recoil system without having to rewrite it every time, and if you wanted to make a change to the recoil system you could just modify the base which applies to all your weapons that use this base rather than having to rewrite the recoil system individually in each SWEP.

Anyway, copy and pasting everything from the base for your SWEP isn't a good idea unless you're actually going to change those aspects for your own SWEP, so you probably want to just use the parts that will actually differ from the base swep such as variables like damage, spread, and all that.
Kale Dec 7, 2015 @ 5:09pm 
I found an easy way to fix this (hopefully). Someone uploaded a bunch of lua templates onto garrysmod.org including a scripted weapon and they were uploaded not even a year ago and they were updated recently so it seems like I can trust it to work on recent versions.
Shallex Dec 7, 2015 @ 5:10pm 
Also, just in case you maybe got it wrong, the file path for addons is

GarrysMod > garrysmod > addons > myaddonnamehere > lua > weapons > weaponnamehere > shared.lua

Of course replacing myaddonnamehere and weaponnamehere with your own names, and make sure there's a .json file in myaddonnamehere, which defines certain things for the workshop such as name, tags, etc.
< >
Showing 31-45 of 55 comments
Per page: 1530 50

Date Posted: Dec 6, 2015 @ 5:03pm
Posts: 55