Garry's Mod
[CW 2.0] Cases (Unofficial)
 Acest topic a fost fixat, deci probabil este important
Kindred Flame  [dezvoltator] 28 iun. 2016 la 19:41
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.
Editat ultima dată de Kindred Flame; 12 aug. 2022 la 14:05
< >
Se afișează 1-9 din 9 comentarii
sрy 1 iul. 2016 la 3:45 
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
Editat ultima dată de sрy; 1 iul. 2016 la 3:49
Kindred Flame  [dezvoltator] 1 iul. 2016 la 11:03 
Postat inițial de 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  [dezvoltator] 7 iul. 2016 la 7:49 
Postat inițial de BridgeJumper3000:
Any ETA on when the new code will be implemented?

The new code is already implemented, go nuts.
Hey Snow, can you make a special case that stores 1 of any weapon, WITH attachments, in it?
Ejou 17 oct. 2017 la 7:15 
Can this be used for making FAS 2.0 SWEPS?
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  [dezvoltator] 15 aug. 2021 la 19:03 
Sure thing, go right ahead. :steamthumbsup:
< >
Se afișează 1-9 din 9 comentarii
Per pagină: 1530 50