Garry's Mod

Garry's Mod

TTT to CW2.0 Weapon Conversion Addon V2
This topic has been locked
Myślibór 3 Apr, 2020 @ 8:14am
Making M4A1 spawn with silencer
So I wanted to make M4A1 from Unoffical Extra CW 2.0 to spawn with silencer but i can't do it.

["weapon_ttt_m4a1_s"] = { false, "cw_g4p_m4a1", nil, m4a1_stable }

local SF_WEAPON_START_CONSTRAINED = 1
function m4a1_stable:Equip( newowner )
if self.equipFunc then
self:equipFunc()
end

if not CustomizableWeaponry:hasSpecifiedAttachments(self:GetOwner(), {"md_saker"}) then
CustomizableWeaponry.giveAttachments(self:GetOwner(), {"md_saker"})
end

timer.Simple( 0.5, function()
self:detach(1)
timer.Simple( 0, function()
self:attachSpecificAttachment( "md_saker" )
end )
end )

if SERVER then --TTT's base Equip function
if self:IsOnFire() then
self:Extinguish()
end

self.fingerprints = self.fingerprints or {}

if not table.HasValue(self.fingerprints, newowner) then
table.insert(self.fingerprints, newowner)
end

if self:HasSpawnFlags(SF_WEAPON_START_CONSTRAINED) then
local flags = self:GetSpawnFlags()
local newflags = bit.band(flags, bit.bnot(SF_WEAPON_START_CONSTRAINEDA))
self:SetKeyValue("spawnflags", newflags)
end
end
if SERVER and IsValid(newowner) and self.StoredAmmo > 0 and self.Primary.Ammo != "none" then
local ammo = newowner:GetAmmoCount(self.Primary.Ammo)
local given = math.min(self.StoredAmmo, self.Primary.ClipMax - ammo)

newowner:GiveAmmo( given, self.Primary.Ammo)
self.StoredAmmo = 0
end
end

I copied the sipistol code and repleced table name and silencer name but it spawn with no silencer. How can i change it?
< >
Showing 1-3 of 3 comments
Logan  [developer] 4 Apr, 2020 @ 1:24pm 
Did you create a local table called m4a1_stable? Like "local sipistoltable = {}" but "local m4a1_stable = {}" instead?

That's the only thing I can see.

Also, you edited ammo-giving portion of the Equip function. Make sure the addon isn't producing any errors.
Myślibór 4 Apr, 2020 @ 2:50pm 
It works! I didn't add "local m4a1stable = {}". Thanks for help!
Logan  [developer] 4 Apr, 2020 @ 5:54pm 
Glad to hear
< >
Showing 1-3 of 3 comments
Per page: 1530 50