• Adding Custom Ammo to a TTT Server
    4 replies, posted
Hello, I am trying to add a new ammo type to my TTT server. I copied all the code for the ammo LUA file correctly and have made the edits to the guns that will use the new ammo. However, whenever I try to pick up the ammo with the gun in inventory the ammo box simply disappears without picking up the ammo. I'm not very versed in LUA. I think there is something else in the server files that I may need to edit. I tried putting the ammo in the ttt.fgd file as well, but to no avail. I have looked everywhere in the server files and have yet to find anything. -Thanks in advance
Can you post your code?
Code for the ammo LUA file -- custom ammo override AddCSLuaFile() ENT.Type = "anim" ENT.Base = "base_ammo_ttt" ENT.AmmoType = "Unique" ENT.AmmoAmount = 1 ENT.AmmoMax = 1 ENT.Model = Model("models/items/357ammo.mdl") ENT.AutoSpawnable = true function ENT:Initialize() -- Differentiate from rifle ammo self:SetColor(Color(100, 50, 100, 255)) return self.BaseClass.Initialize(self) end Code for one of the guns I set to use the custom ammo AddCSLuaFile() SWEP.HoldType = "shotgun" sound.Add( { name = "ZMP_UNU.Fire", channel = CHAN_WEAPON, volume = 1.0, soundlevel = 100, pitchstart = 95, pitchend = 105, sound = "weapons/3thieves/lazegun2.mp3" }) if CLIENT then SWEP.PrintName = "Unusual Shotgun" SWEP.Slot = 2 SWEP.Icon = "vgui/ttt/zmp/susshotgun.png" SWEP.IconLetter = "B" end SWEP.Base = "weapon_tttbase" SWEP.Spawnable = false SWEP.Kind = WEAPON_HEAVY --SWEP.WeaponID = AMMO_SHOTGUN SWEP.Primary.Ammo = "Unique" SWEP.Primary.Damage = 12 SWEP.Primary.Cone = 0.085 SWEP.Primary.Delay = 0.1 SWEP.Primary.ClipSize = 4 SWEP.Primary.ClipMax = 24 SWEP.Primary.DefaultClip = 4 SWEP.Primary.Automatic = false SWEP.Primary.NumShots = 8 SWEP.AutoSpawnable = false --AmmoEnt = "Uni" SWEP.AmmoEnt = "item_ammo_custom_ttt" SWEP.DeploySpeed = 3 SWEP.CanBuy = { ROLE_TRAITOR } SWEP.LimitedStock = true SWEP.InLoadoutFor = nil SWEP.IsSilent = true SWEP.UseHands = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 54 SWEP.ViewModel = "models/weapons/cstrike/c_shot_xm1014.mdl" SWEP.WorldModel = "models/weapons/w_shot_xm1014.mdl" SWEP.Primary.Sound = Sound( "ZMP_UNU.Fire" ) SWEP.Primary.Recoil = 7 SWEP.IronSightsPos = Vector(-6.881, -9.214, 2.66) SWEP.IronSightsAng = Vector(-0.101, -0.7, -0.201) SWEP.reloadtimer = 0 function SWEP:SetupDataTables() self:DTVar("Bool", 0, "reloading") return self.BaseClass.SetupDataTables(self) end function SWEP:Reload() --if self:GetNetworkedBool( "reloading", false ) then return end if self.dt.reloading then return end if not IsFirstTimePredicted() then return end if self:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 then if self:StartReload() then return end end end function SWEP:StartReload() --if self:GetNWBool( "reloading", false ) then if self.dt.reloading then return false end self:SetIronsights( false ) if not IsFirstTimePredicted() then return false end self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) local ply = self.Owner if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then return false end local wep = self if wep:Clip1() >= self.Primary.ClipSize then return false end wep:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START) self.reloadtimer = CurTime() + wep:SequenceDuration() --wep:SetNWBool("reloading", true) self.dt.reloading = true return true end function SWEP:PerformReload() local ply = self.Owner -- prevent normal shooting in between reloads self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if not ply or ply:GetAmmoCount(self.Primary.Ammo) <= 0 then return end if self:Clip1() >= self.Primary.ClipSize then return end self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false ) self:SetClip1( self:Clip1() + 1 ) self:SendWeaponAnim(ACT_VM_RELOAD) self.reloadtimer = CurTime() + self:SequenceDuration() end function SWEP:FinishReload() self.dt.reloading = false self:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH) self.reloadtimer = CurTime() + self:SequenceDuration() end function SWEP:CanPrimaryAttack() if self:Clip1() <= 0 then self:EmitSound( "Weapon_Shotgun.Empty" ) self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) return false end return true end function SWEP:Think() if self.dt.reloading and IsFirstTimePredicted() then if self.Owner:KeyDown(IN_ATTACK) then self:FinishReload() return end if self.reloadtimer <= CurTime() then if self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0 then self:FinishReload() elseif self:Clip1() < self.Primary.ClipSize then self:PerformReload() else self:FinishReload() end return end end end function SWEP:Deploy() self.dt.reloading = false self.reloadtimer = 0 return self.BaseClass.Deploy(self) end -- The shotgun's headshot damage multiplier is based on distance. The closer it -- is, the more damage it does. This reinforces the shotgun's role as short -- range weapon by reducing effectiveness at mid-range, where one could score -- lucky headshots relatively easily due to the spread. function SWEP:GetHeadshotMultiplier(victim, dmginfo) local att = dmginfo:GetAttacker() if not IsValid(att) then return 3 end local dist = victim:GetPos():Distance(att:GetPos()) local d = math.max(0, dist - 140) -- decay from 3.1 to 1 slowly as distance increases return 1 + math.max(0, (2.1 - 0.002 * (d ^ 1.25))) end function SWEP:SecondaryAttack() if self.NoSights or (not self.IronSightsPos) or self.dt.reloading then return end --if self:GetNextSecondaryFire() > CurTime() then return end self:SetIronsights(not self:GetIronsights()) self:SetNextSecondaryFire(CurTime() + 0.3) end if CLIENT then -- Text shown in the equip menu SWEP.EquipMenuData = { type = "item_weapon", desc = "Something is off about it..." }; end Where I put the ammo in the ttt.fgd file: @PointClass base(Item) studio("models/items/boxsrounds.mdl")= item_ammo_pistol_ttt : "Box of Pistol ammo" [] @PointClass base(Item) studio("models/items/boxmrounds.mdl")= item_ammo_smg1_ttt : "MAC10 ammo" [] @PointClass base(Item) studio("models/items/357ammo.mdl")= item_ammo_357_ttt : "Box of Carbine ammo" [] @PointClass base(Item) studio("models/items/BoxBuckshot.mdl")= item_box_buckshot_ttt : "Box Buckshot" [] @PointClass base(Item) studio("models/items/357ammo.mdl")= item_ammo_revolver_ttt : "Box of Deagle ammo" [] @PointClass base(Item) studio("models/items/357ammo.mdl")= item_ammo_custom_ttt : "Box of Deagle ammo" []
The ammo type needs to be a pre-existing ammo type, such as "airboatgun" or "Gauss". Then you set the ammo entire in the shotgun to the filename of the ammo (item_ammo_custom_ttt) and the ammo type to the same as the custom ammo ent.
Oh god, please put the code in [CODE]your code[/(nospace)CODE]
Sorry, you need to Log In to post a reply to this thread.