Garry's Mod

Garry's Mod

[CW 2.0] Cases (Unofficial)
 This topic has been pinned, so it's probably important
Kindred Flame  [developer] 28 Jun, 2016 @ 7:41pm
Permissions and making your own CW 2.0 weapon case
Permissions:
To begin, use anything you want from this pack. However if you are using anything case model related please credit tigg for his modeling work on the cases. With regrades to the code, use whatever you like, you do not have to credit me but I will be happy if you do. I also ask you to not redistribute the base and rename taken models in order to avoid conflicts with this addon.

Making your own case:
The base that is included with this addon handles the client and server side tasks. In Order to make your own case you got to add a few pieces of information in the shared.lua. I will make a proper documentation of this, but this is basically the important things you need, this example is for the AR-15:

ENT.BodyGroupCoverMain = 1 -- the main bodygroup section that the cover bodygroup is located
ENT.BodyGroupOpenSet = 1 -- the open case cover bodygroup index
ENT.BodyGroupCloseSet = 0 -- the close case cover bodygroup index

ENT.WeaponUsed= "cw_ar15" -- name of the swep that the case is for

ENT.GunsNum = 2 -- number of guns in the case

Below are tables, each index on the table represents the number amount of the guns in the case for example wepBGGunsTableMain = {2,3,4,5}, this means that there are 4 guns in this case and for gun 1 its value is 2, for 2 it is 3, for 3 it is 4, and for 4 it is 5.

ENT.wepBGGunsTableMain = {2,3} -- the main bodygroup sections that the guns are
ENT.wepBGAmmoTableMain = {4,5} -- the main bodygroup sections that the magazines are

ENT.wepBGGunsTableStored = {0,0} -- the stored guns bodygroup indexs
ENT.wepBGAmmoTableStored = {0,0} -- the stored magazine bodygroup indexs

ENT.wepBGGunsTableGone = {1,1} -- the taken (gone) guns bodygroup indexs
ENT.wepBGAmmoTableGone = {1,1} -- the taken (gone) magazines bodygroup indexs

If your model does not have any bodygroups, then set all your values to zero.
Last edited by Kindred Flame; 12 Aug, 2022 @ 2:05pm
< >
Showing 1-9 of 9 comments
sрy 1 Jul, 2016 @ 3:45am 
you can simplify a lot of this and reduce the amount of code necessary for people to write

ENT.WeaponUsed= "cw_ar15" -- name of the swep that the case is for
^ this variable already lets us know what weapon class it is, so you can just get it's data by doing:

local wepData = weapons.GetStored(self.WeaponUsed)

and then assign SwepName, AmmoUsed and AmmoAmountToGive like this:

self.SwepName = wepData.PrintName
self.AmmoUsed = wepData.Primary.Ammo
self.AmmoAmountToGive = wepData.Primary.ClipSize

you'd need to put this in a shared ENT:Initialize hook, the entire code snippet (which is pseudo-code, but it should work) would look like this:

ENT:Initialize()
-- do stuff that your cases do

local wepData = weapons.GetStored(self.WeaponUsed)

self.SwepName = wepData.PrintName
self.AmmoUsed = wepData.Primary.Ammo
self.AmmoAmountToGive = wepData.Primary.ClipSize
end

and bam, now you only have to enter 1 variable (instead of 4), and the rest would be handled for you

this way you'll reduce the amount of code needed to enter to just 1 variable, and it also means that if there are changes to the weapon code at any time in the base CW 2.0 pack or elsewhere (ie. weapon name change, mag size change, caliber change, etc.) you don't have to change anything at all in your case code
Last edited by sрy; 1 Jul, 2016 @ 3:49am
Kindred Flame  [developer] 1 Jul, 2016 @ 11:03am 
Originally posted by just:
you can simplify a lot of this and reduce the amount of code necessary for people to write

ENT.WeaponUsed= "cw_ar15" -- name of the swep that the case is for
^ this variable already lets us know what weapon class it is, so you can just get it's data by doing:

local wepData = weapons.GetStored(self.WeaponUsed)

and then assign SwepName, AmmoUsed and AmmoAmountToGive like this:

self.SwepName = wepData.PrintName
self.AmmoUsed = wepData.Primary.Ammo
self.AmmoAmountToGive = wepData.Primary.ClipSize

you'd need to put this in a shared ENT:Initialize hook, the entire code snippet (which is pseudo-code, but it should work) would look like this:

ENT:Initialize()
-- do stuff that your cases do

local wepData = weapons.GetStored(self.WeaponUsed)

self.SwepName = wepData.PrintName
self.AmmoUsed = wepData.Primary.Ammo
self.AmmoAmountToGive = wepData.Primary.ClipSize
end

and bam, now you only have to enter 1 variable (instead of 4), and the rest would be handled for you

this way you'll reduce the amount of code needed to enter to just 1 variable, and it also means that if there are changes to the weapon code at any time in the base CW 2.0 pack or elsewhere (ie. weapon name change, mag size change, caliber change, etc.) you don't have to change anything at all in your case code

This is perfect, thank you just, I will defenitly use this. I am still new to lua so I will accept all advice given, even to a professional such as yourself.
aye, is it possible to use my own case models?
Any ETA on when the new code will be implemented?
Kindred Flame  [developer] 7 Jul, 2016 @ 7:49am 
Originally posted by BridgeJumper3000:
Any ETA on when the new code will be implemented?

The new code is already implemented, go nuts.
Volcanic163 13 Jul, 2016 @ 12:39pm 
Hey Snow, can you make a special case that stores 1 of any weapon, WITH attachments, in it?
Ejou 17 Oct, 2017 @ 7:15am 
Can this be used for making FAS 2.0 SWEPS?
GopnikCommissar 15 Aug, 2021 @ 5:51pm 
Hey, i modified your code so you can't pull from the case if the player already has one, removed all the code for body groups, removed all functionality for opening and closing the case and the variables self.hark; self.empty; self.open; self.fristTimeOpen, and the tables for the weapons in the case
i ask permission to upload this for use as an pseudo-shipment of sorts.
Kindred Flame  [developer] 15 Aug, 2021 @ 7:03pm 
Sure thing, go right ahead. :steamthumbsup:
< >
Showing 1-9 of 9 comments
Per page: 1530 50