TOOL.Category = "Trouble in Terrorist Town"TOOL.Name = "TTT Weapon Placer"TOOL.Command = nilTOOL.ConfigName = ""TOOL.ClientConVar["weapon"] = "weapon_zm_pistol"TOOL.ClientConVar["frozen"] = "0"TOOL.ClientConVar["replacespawns"] = "0"cleanup.Register("ttt_weapons")if CLIENT then language.Add( "Tool_tttweaponplacer_name", "TTT Weapon Placer" ) language.Add( "Tool_tttweaponplacer_desc", "Spawn TTT weapon dummies and export their placement" ) language.Add( "Tool_tttweaponplacer_0", "Left click to spawn entity. Right click for matching ammo." ) language.Add("Cleanup_ttt_weapons", "TTT Dummy Weapons/ammo/spawns")endlocal weps = { weapon_zm_pistol = {name="Pistol", snd="item_ammo_pistol_ttt"}, weapon_zm_shotgun = {name="Shotgun", snd="item_box_buckshot_ttt"}, weapon_zm_mac10 = {name="MAC10", snd="item_ammo_smg1_ttt"}, weapon_zm_revolver = {name="Deagle", snd="item_ammo_revolver_ttt"}, weapon_zm_rifle = {name="Rifle", snd="item_ammo_357_ttt"}, weapon_zm_sledge = {name="HUGE249", snd=nil}, weapon_ttt_m16 = {name="M16", snd="item_ammo_pistol_ttt"}, weapon_ttt_glock = {name="Glock", snd="item_ammo_pistol_ttt"}, weapon_zm_molotov = {name="Fire nade", snd=nil}, weapon_ttt_confgrenade = {name="Discombobulator", snd=nil}, weapon_ttt_smokegrenade = {name="Smoke nade", snd=nil}, weapon_ttt_customweapon = {name="Custom Weapon", snd=Ammo Type}, ttt_random_weapon = {name="Random weapon", snd=nil}, ttt_random_ammo = {name="Random ammo", snd=nil}, ttt_playerspawn = {name="Player spawn", snd=nil} }local mdls = { weapon_zm_pistol = "models/weapons/w_pist_fiveseven.mdl", weapon_zm_shotgun = "models/weapons/w_shot_xm1014.mdl", weapon_zm_mac10 = "models/weapons/w_smg_mac10.mdl", weapon_zm_revolver = "models/weapons/w_pist_deagle.mdl", weapon_zm_rifle = "models/weapons/w_snip_scout.mdl", weapon_zm_sledge = "models/weapons/w_mach_m249para.mdl", weapon_zm_molotov = "models/weapons/w_eq_flashbang.mdl", weapon_ttt_confgrenade = "models/weapons/w_eq_fraggrenade.mdl", weapon_ttt_smokegrenade = "models/weapons/w_eq_smokegrenade.mdl", weapon_ttt_m16 = "models/weapons/w_rif_m4a1.mdl", weapon_ttt_glock = "models/weapons/w_pist_glock18.mdl", weapon_ttt_customweapon = "yourweaponsmodel", ttt_random_weapon = "models/weapons/w_shotgun.mdl", ttt_random_ammo = "models/Items/battery.mdl", item_ammo_pistol_ttt= "models/items/boxsrounds.mdl", item_ammo_smg1_ttt= "models/items/boxmrounds.mdl", item_ammo_revolver_ttt = "models/items/357ammo.mdl", item_ammo_357_ttt = "models/items/357ammo.mdl", item_box_buckshot_ttt = "models/items/boxbuckshot.mdl", ttt_playerspawn = "models/player.mdl"};
TOOL.Category = "Trouble in Terrorist Town"TOOL.Name = "TTT Weapon Placer"TOOL.Command = nilTOOL.ConfigName = ""TOOL.ClientConVar["weapon"] = "weapon_zm_pistol"TOOL.ClientConVar["frozen"] = "0"TOOL.ClientConVar["replacespawns"] = "0"cleanup.Register("ttt_weapons")if CLIENT then language.Add( "Tool_tttweaponplacer_name", "TTT Weapon Placer" ) language.Add( "Tool_tttweaponplacer_desc", "Spawn TTT weapon dummies and export their placement" ) language.Add( "Tool_tttweaponplacer_0", "Left click to spawn entity. Right click for matching ammo." ) language.Add("Cleanup_ttt_weapons", "TTT Dummy Weapons/ammo/spawns")endlocal weps = { weapon_zm_pistol = {name="Pistol", snd="item_ammo_pistol_ttt"}, weapon_zm_shotgun = {name="Shotgun", snd="item_box_buckshot_ttt"}, weapon_zm_mac10 = {name="MAC10", snd="item_ammo_smg1_ttt"}, weapon_zm_revolver = {name="Deagle", snd="item_ammo_revolver_ttt"}, weapon_zm_rifle = {name="Rifle", snd="item_ammo_357_ttt"}, weapon_zm_sledge = {name="HUGE249", snd=nil}, weapon_ttt_m16 = {name="M16", snd="item_ammo_pistol_ttt"}, weapon_ttt_glock = {name="Glock", snd="item_ammo_pistol_ttt"}, weapon_ttt_ak47 = {name="AK47", snd="item_ammo_pistol_ttt"} weapon_ttt_aug = {name="AUG", snd="item_ammo_smg1_ttt"} weapon_ttt_galil = {name="Galil", snd="item_ammo_sm1_ttt"} weapon_ttt_famas = {name="Famas", snd="item_ammo_sm1_ttt"} weapon_ttt_m3 = {name="m3", snd="item_ammo_buckshot_ttt"} weapon_ttt_sg552 = {name="SG552", snd="item_ammo_sm1_ttt"} weapon_ttt_mp5 = {name="MP5", snd="item_ammo_pistol_ttt"} weapon_ttt_p90 = {name="P90", snd="item_ammo_sm1_ttt"} weapon_zm_molotov = {name="Fire nade", snd=nil}, weapon_ttt_confgrenade = {name="Discombobulator", snd=nil}, weapon_ttt_customweapon = {name="Custom Weapon", snd=Ammo Type}, ttt_random_weapon = {name="Random weapon", snd=nil}, ttt_random_ammo = {name="Random ammo", snd=nil}, ttt_playerspawn = {name="Player spawn", snd=nil} }local mdls = { weapon_zm_pistol = "models/weapons/w_pist_fiveseven.mdl", weapon_zm_shotgun = "models/weapons/w_shot_xm1014.mdl", weapon_zm_mac10 = "models/weapons/w_smg_mac10.mdl", weapon_zm_revolver = "models/weapons/w_pist_deagle.mdl", weapon_zm_rifle = "models/weapons/w_snip_scout.mdl", weapon_zm_sledge = "models/weapons/w_mach_m249para.mdl", weapon_zm_molotov = "models/weapons/w_eq_flashbang.mdl", weapon_ttt_confgrenade = "models/weapons/w_eq_fraggrenade.mdl", weapon_ttt_smokegrenade = "models/weapons/w_eq_smokegrenade.mdl", weapon_ttt_m16 = "models/weapons/w_rif_m4a1.mdl", weapon_ttt_glock = "models/weapons/w_pist_glock18.mdl", weapon_ttt_ak47 = "models/weapons/w_rif_ak47.mdl" weapon_ttt_aug = "models/weapons/w_rif_aug.mdl" weapon_ttt_galil = "models/weapons/w_rif_galil.mdl" weapon_ttt_famas = "models/weapons/w_rif_famas.mdl" weapon_ttt_m3 = "models/weapons/w_shot_m3super90.mdl" weapon_ttt_sg552 = "models/weapons/w_rif_sg552.mdl" weapon_ttt_mp5 = "models/weapons/w_smg_mp5.mdl" weapon_ttt_p90 = "models/weapons/w_smg_p90.mdl" weapon_ttt_customweapon = "yourweaponsmodel", ttt_random_weapon = "models/weapons/w_shotgun.mdl", ttt_random_ammo = "models/Items/battery.mdl", item_ammo_pistol_ttt= "models/items/boxsrounds.mdl", item_ammo_smg1_ttt= "models/items/boxmrounds.mdl", item_ammo_revolver_ttt = "models/items/357ammo.mdl", item_ammo_357_ttt = "models/items/357ammo.mdl", item_box_buckshot_ttt = "models/items/boxbuckshot.mdl", ttt_playerspawn = "models/player.mdl"};
local enttypes = { weapon_zm_pistol = WEAPON_PISTOL, weapon_zm_revolver = WEAPON_PISTOL, weapon_ttt_glock = WEAPON_PISTOL, weapon_zm_mac10 = WEAPON_HEAVY, weapon_zm_shotgun = WEAPON_HEAVY, weapon_zm_rifle = WEAPON_HEAVY, weapon_zm_sledge = WEAPON_HEAVY, weapon_ttt_m16 = WEAPON_HEAVY, weapon_ttt_aug = WEAPON_HEAVY, weapon_zm_molotov = WEAPON_NADE, weapon_ttt_smokegrenade = WEAPON_NADE, weapon_ttt_confgrenade = WEAPON_NADE, ttt_random_weapon = WEAPON_RANDOM, ttt_playerspawn = PLAYERSPAWN};
TOOL.Category = "Trouble in Terrorist Town"TOOL.Name = "TTT Weapon Placer"TOOL.Command = nilTOOL.ConfigName = ""TOOL.ClientConVar["weapon"] = "weapon_zm_pistol"TOOL.ClientConVar["frozen"] = "0"TOOL.ClientConVar["replacespawns"] = "0"cleanup.Register("ttt_weapons")if CLIENT then language.Add( "Tool_tttweaponplacer_name", "TTT Weapon Placer" ) language.Add( "Tool_tttweaponplacer_desc", "Spawn TTT weapon dummies and export their placement" ) language.Add( "Tool_tttweaponplacer_0", "Left click to spawn entity. Right click for matching ammo." ) language.Add("Cleanup_ttt_weapons", "TTT Dummy Weapons/ammo/spawns")endlocal weps = { weapon_zm_pistol = {name="Pistol", snd="item_ammo_pistol_ttt"}, weapon_zm_shotgun = {name="Shotgun", snd="item_box_buckshot_ttt"}, weapon_zm_mac10 = {name="MAC10", snd="item_ammo_smg1_ttt"}, weapon_zm_revolver = {name="Deagle", snd="item_ammo_revolver_ttt"}, weapon_zm_rifle = {name="Rifle", snd="item_ammo_357_ttt"}, weapon_zm_sledge = {name="HUGE249", snd=nil}, weapon_ttt_m16 = {name="M16", snd="item_ammo_pistol_ttt"}, weapon_ttt_glock = {name="Glock", snd="item_ammo_pistol_ttt"}, weapon_ttt_aug = {name="AUG", snd="item_ammo_pistol_ttt"}, weapon_zm_molotov = {name="Fire nade", snd=nil}, weapon_ttt_confgrenade = {name="Discombobulator", snd=nil}, weapon_ttt_smokegrenade = {name="Smoke nade", snd=nil}, ttt_random_weapon = {name="Random weapon", snd=nil}, ttt_random_ammo = {name="Random ammo", snd=nil}, ttt_playerspawn = {name="Player spawn", snd=nil}}local mdls = { weapon_zm_pistol = "models/weapons/w_pist_fiveseven.mdl", weapon_zm_shotgun = "models/weapons/w_shot_xm1014.mdl", weapon_zm_mac10 = "models/weapons/w_smg_mac10.mdl", weapon_zm_revolver = "models/weapons/w_pist_deagle.mdl", weapon_zm_rifle = "models/weapons/w_snip_scout.mdl", weapon_zm_sledge = "models/weapons/w_mach_m249para.mdl", weapon_zm_molotov = "models/weapons/w_eq_flashbang.mdl", weapon_ttt_aug = "models/weapons/v_rif_aug.mdl", weapon_ttt_confgrenade = "models/weapons/w_eq_fraggrenade.mdl", weapon_ttt_smokegrenade = "models/weapons/w_eq_smokegrenade.mdl", weapon_ttt_m16 = "models/weapons/w_rif_m4a1.mdl", weapon_ttt_glock = "models/weapons/w_pist_glock18.mdl", ttt_random_weapon = "models/weapons/w_shotgun.mdl", ttt_random_ammo = "models/Items/battery.mdl", item_ammo_pistol_ttt= "models/items/boxsrounds.mdl", item_ammo_smg1_ttt= "models/items/boxmrounds.mdl", item_ammo_revolver_ttt = "models/items/357ammo.mdl", item_ammo_357_ttt = "models/items/357ammo.mdl", item_box_buckshot_ttt = "models/items/boxbuckshot.mdl", ttt_playerspawn = "models/player.mdl"};-- special colours for certain entslocal colors = { ttt_random_weapon = Color(255, 255, 0), ttt_random_ammo = Color(0, 255, 0), item_ammo_revolver_ttt = Color(255, 100, 100), ttt_playerspawn = Color(0, 255, 0)};local function DummyInit(s) if colors[s:GetClass()] then local c = colors[s:GetClass()] s:SetColor(c.r, c.g, c.b, 255) end s:SetCollisionGroup(COLLISION_GROUP_WEAPON) s:SetSolid(SOLID_VPHYSICS) s:SetMoveType(MOVETYPE_VPHYSICS) if s:GetClass() == "ttt_playerspawn" then s:PhysicsInitBox(Vector(-18, -18, 0), Vector(18, 18, 66)) else s:PhysicsInit(SOLID_VPHYSICS) end s:SetModel(s.Model)endfor cls, mdl in pairs(mdls) do local tbl = { Type = "anim", Model = Model(mdl), Initialize = DummyInit }; scripted_ents.Register(tbl, cls, false)endfunction TOOL:SpawnEntity(cls, trace) local mdl = mdls[cls] if not cls or not mdl then return end local ent = ents.Create(cls) ent:SetModel(mdl) ent:SetPos(trace.HitPos) local tr = util.TraceEntity({start=trace.StartPos, endpos=trace.HitPos, filter=self:GetOwner()}, ent) if tr.Hit then ent:SetPos(tr.HitPos) end ent:Spawn() ent:PhysWake() undo.Create("TTTWeapon") undo.AddEntity(ent) undo.SetPlayer(self:GetOwner()) undo.Finish() self:GetOwner():AddCleanup("ttt_weapons", ent)endfunction TOOL:LeftClick( trace ) local cls = self:GetClientInfo("weapon") self:SpawnEntity(cls, trace)end function TOOL:RightClick( trace ) local cls = self:GetClientInfo("weapon") local info = weps[cls] if not info then return end local ammo = info.snd if not ammo then self:GetOwner():ChatPrint("No matching ammo for this type!") return end self:SpawnEntity(info.snd, trace)endfunction TOOL.BuildCPanel(panel) -- note that this is not a method, REAL NICE panel:AddControl( "Header", { Text = "#Tool_tttweaponplacer_name", Description = "#Tool_tttweaponplacer_desc"}) local opts = {} for w, info in pairs(weps) do opts[info.name] = {tttweaponplacer_weapon = w} end panel:AddControl("ListBox", { Label = "Weapons", Height = "200", Options = opts } ) panel:AddControl("Button", {Label="Report counts", Command="tttweaponplacer_count", Text="Count"}) panel:AddControl("Label", {Text="Export", Description="Export weapon placements"}) panel:AddControl("CheckBox", {Label="Replace existing player spawnpoints", Command="tttweaponplacer_replacespawns", Text="Replace spawns"}) panel:AddControl( "Button", { Label = "Export to file", Command = "tttweaponplacer_queryexport", Text = "Export"}) panel:AddControl("Label", {Text="Import", Description="Import weapon placements"}) panel:AddControl( "Button", { Label = "Import from file", Command = "tttweaponplacer_queryimport", Text = "Import"}) panel:AddControl("Button", {Label="Convert HL2 entities", Command = "tttweaponplacer_replacehl2", Text="Convert"}) panel:AddControl("Button", {Label="Remove all existing weapon/ammo", Command = "tttweaponplacer_removeall", Text="Remove all existing items"})end-- STOOLs not being loaded on client = headache bonanzaif CLIENT then function QueryFileExists() local map = string.lower(game.GetMap()) if not map then return end local fname = "ttt/maps/" .. map .. "_ttt.txt" if file.Exists(fname) then Derma_StringRequest("File exists", "The file \"" .. fname .. "\" already exists. Save under a different filename? Leave unchanged to overwrite.", fname, function(txt) RunConsoleCommand("tttweaponplacer_export", txt) end) else RunConsoleCommand("tttweaponplacer_export") end end function QueryImportName() local map = string.lower(game.GetMap()) if not map then return end local fname = "ttt/maps/" .. map .. "_ttt.txt" Derma_StringRequest("Import", "What file do you want to import? Note that files meant for other maps will result in crazy things happening.", fname, function(txt) RunConsoleCommand("tttweaponplacer_import", txt) end) endelse -- again, hilarious things happen when this shit is used in mp concommand.Add("tttweaponplacer_queryexport", function() BroadcastLua("QueryFileExists()") end) concommand.Add("tttweaponplacer_queryimport", function() BroadcastLua("QueryImportName()") end)endWEAPON_PISTOL = 1WEAPON_HEAVY = 2WEAPON_NADE = 3WEAPON_RANDOM = 4PLAYERSPAWN = 5local enttypes = { weapon_zm_pistol = WEAPON_PISTOL, weapon_zm_revolver = WEAPON_PISTOL, weapon_ttt_glock = WEAPON_PISTOL, weapon_zm_mac10 = WEAPON_HEAVY, weapon_zm_shotgun = WEAPON_HEAVY, weapon_zm_rifle = WEAPON_HEAVY, weapon_zm_sledge = WEAPON_HEAVY, weapon_ttt_m16 = WEAPON_HEAVY, weapon_ttt_aug = WEAPON_HEAVY, weapon_zm_molotov = WEAPON_NADE, weapon_ttt_smokegrenade = WEAPON_NADE, weapon_ttt_confgrenade = WEAPON_NADE, ttt_random_weapon = WEAPON_RANDOM, ttt_playerspawn = PLAYERSPAWN};local function PrintCount(ply) local count = { [WEAPON_PISTOL] = 0, [WEAPON_HEAVY] = 0, [WEAPON_NADE] = 0, [WEAPON_RANDOM] = 0, [PLAYERSPAWN] = 0 }; for cls, t in pairs(enttypes) do for _, ent in pairs(ents.FindByClass(cls)) do count[t] = count[t] + 1 end end ply:ChatPrint("Entity count (use report_entities in console for more detail):") ply:ChatPrint("Primary weapons: " .. count[WEAPON_HEAVY]) ply:ChatPrint("Secondary weapons: " .. count[WEAPON_PISTOL]) ply:ChatPrint("Grenades: " .. count[WEAPON_NADE]) ply:ChatPrint("Random weapons: " .. count[WEAPON_RANDOM]) ply:ChatPrint("Player spawns: " .. count[PLAYERSPAWN])endconcommand.Add("tttweaponplacer_count", PrintCount)-- This shit will break terribly in MPif SERVER or CLIENT then -- Could just do a GLON dump, but it's nice if the "scripts" are sort of -- human-readable so it's easy to go in and delete all pistols or something. local function Export(ply, cmd, args) if not IsValid(ply) then return end local map = string.lower(game.GetMap()) if not map then return end --local frozen_only = GetConVar("tttweaponplacer_frozen"):GetBool() local frozen_only = false -- Nice header, # is comment local buf = "# Trouble in Terrorist Town weapon/ammo placement overrides\n" buf = buf .. "# For map: " .. map .. "\n" buf = buf .. "# Exported by: " .. ply:Nick() .. "\n" -- Write settings ("setting: <name> <value>") local rspwns = GetConVar("tttweaponplacer_replacespawns"):GetBool() and "1" or "0" buf = buf .. "setting:\treplacespawns " .. rspwns .. "\n" local num = 0 for cls, mdl in pairs(mdls) do for _, ent in pairs(ents.FindByClass(cls)) do if IsValid(ent) then if not frozen_only or not ent:GetPhysicsObject():IsMoveable() then num = num + 1 buf = buf .. Format("%s\t%s\t%s\n", cls, tostring(ent:GetPos()), tostring(ent:GetAngles())) end end end end local fname = "ttt/maps/" .. map .. "_ttt.txt" if args[1] then fname = args[1] end file.Write(fname, buf) if not file.Exists(fname) then ErrorNoHalt("Exported file not found. Bug?\n") end ply:ChatPrint(num .. " placements saved to /garrysmod/data/" .. fname) end concommand.Add("tttweaponplacer_export", Export) local function SpawnDummyEnt(cls, pos, ang) if not cls or not pos or not ang then return false end local mdl = mdls[cls] if not mdl then return end local ent = ents.Create(cls) ent:SetModel(mdl) ent:SetPos(pos) ent:SetAngles(ang) ent:SetCollisionGroup(COLLISION_GROUP_WEAPON) ent:SetSolid(SOLID_VPHYSICS) ent:SetMoveType(MOVETYPE_VPHYSICS) ent:PhysicsInit(SOLID_VPHYSICS) ent:Spawn() local phys = ent:GetPhysicsObject() if IsValid(phys) then phys:SetAngle(ang) end end local function Import(ply, cmd, args) if not IsValid(ply) then return end local map = string.lower(game.GetMap()) if not map then return end local fname = "ttt/maps/" .. map .. "_ttt.txt" if args[1] then fname = args[1] end if not file.Exists(fname) then ply:ChatPrint(fname .. " not found!") return end local buf = file.Read(fname) local lines = string.Explode("\n", buf) local num = 0 for k, line in ipairs(lines) do if not string.match(line, "^#") and line != "" then local data = string.Explode("\t", line) local fail = true -- pessimism if #data > 0 then if data[1] == "setting:" and tostring(data[2]) then local raw = string.Explode(" ", data[2]) RunConsoleCommand("tttweaponplacer_" .. raw[1], tonumber(raw[2])) fail = false num = num - 1 elseif #data == 3 then local cls = data[1] local ang = nil local pos = nil local posraw = string.Explode(" ", data[2]) pos = Vector(tonumber(posraw[1]), tonumber(posraw[2]), tonumber(posraw[3])) local angraw = string.Explode(" ", data[3]) ang = Angle(tonumber(angraw[1]), tonumber(angraw[2]), tonumber(angraw[3])) fail = SpawnDummyEnt(cls, pos, ang) end end if fail then ErrorNoHalt("Invalid line " .. k .. " in " .. fname .. "\n") else num = num + 1 end end end ply:ChatPrint("Spawned " .. num .. " dummy ents") end concommand.Add("tttweaponplacer_import", Import) local function RemoveAll(ply, cmd, args) if not IsValid(ply) then return end local num = 0 local delete = function(ent) if not IsValid(ent) then return end print("\tRemoving", ent, ent:GetClass()) ent:Remove() num = num + 1 end print("Removing ammo...") for k, ent in pairs(ents.FindByClass("item_*")) do delete(ent) end print("Removing weapons...") for k, ent in pairs(ents.FindByClass("weapon_*")) do delete(ent) end ply:ChatPrint("Removed " .. num .. " weapon/ammo ents") end concommand.Add("tttweaponplacer_removeall", RemoveAll) local hl2_replace = { ["item_ammo_pistol"] = "item_ammo_pistol_ttt", ["item_box_buckshot"] = "item_box_buckshot_ttt", ["item_ammo_smg1"] = "item_ammo_smg1_ttt", ["item_ammo_357"] = "item_ammo_357_ttt", ["item_ammo_357_large"] = "item_ammo_357_ttt", ["item_ammo_revolver"] = "item_ammo_revolver_ttt", -- zm ["item_ammo_ar2"] = "item_ammo_pistol_ttt", ["item_ammo_ar2_large"] = "item_ammo_smg1_ttt", ["item_ammo_smg1_grenade"] = "weapon_zm_pistol", ["item_battery"] = "item_ammo_357_ttt", ["item_healthkit"] = "weapon_zm_shotgun", ["item_suitcharger"] = "weapon_zm_mac10", ["item_ammo_ar2_altfire"] = "weapon_zm_mac10", ["item_rpg_round"] = "item_ammo_357_ttt", ["item_ammo_crossbow"] = "item_box_buckshot_ttt", ["item_healthvial"] = "weapon_zm_molotov", ["item_healthcharger"] = "item_ammo_revolver_ttt", ["item_ammo_crate"] = "weapon_ttt_confgrenade", ["item_item_crate"] = "ttt_random_ammo", ["weapon_smg1"] = "weapon_zm_mac10", ["weapon_shotgun"] = "weapon_zm_shotgun", ["weapon_ar2"] = "weapon_ttt_m16", ["weapon_357"] = "weapon_zm_rifle", ["weapon_crossbow"] = "weapon_zm_pistol", ["weapon_rpg"] = "weapon_zm_sledge", ["weapon_slam"] = "item_ammo_pistol_ttt", ["weapon_frag"] = "weapon_zm_revolver", ["weapon_crowbar"] = "weapon_zm_molotov" }; local function ReplaceSingle(ent, newname) if ent:GetPos() == vector_origin then return false end if ent:IsWeapon() and IsValid(ent:GetOwner()) and ent:GetOwner():IsPlayer() then return false end ent:SetSolid(SOLID_NONE) local rent = ents.Create(newname) rent:SetModel(mdls[newname]) rent:SetPos(ent:GetPos()) rent:SetAngles(ent:GetAngles()) rent:Spawn() rent:Activate() rent:PhysWake() ent:Remove() return true end local function ReplaceHL2Ents(ply, cmd, args) if not IsValid(ply) then return end local c = 0 for _, ent in pairs(ents.GetAll()) do local rpl = hl2_replace[ent:GetClass()] if rpl then local success = ReplaceSingle(ent, rpl) if success then c = c + 1 end end end ply:ChatPrint("Replaced " .. c .. " HL2 entities with TTT versions.") end concommand.Add("tttweaponplacer_replacehl2", ReplaceHL2Ents)end
-- First some standard GMod stuffif SERVER then AddCSLuaFile( "shared.lua" )endif CLIENT then SWEP.PrintName = "Dual Elites" SWEP.Slot = 1 -- add 1 to get the slot number key SWEP.ViewModelFOV = 72 SWEP.ViewModelFlip = trueend-- Always derive from weapon_tttbase.SWEP.Base = "weapon_tttbase"--- Standard GMod valuesSWEP.HoldType = "pistol"SWEP.Primary.Delay = 0.1SWEP.Primary.Recoil = 1.5SWEP.Primary.Automatic = falseSWEP.Primary.Damage = 20SWEP.Primary.Cone = 0.020SWEP.Primary.Ammo = "Pistol"SWEP.Primary.ClipSize = 30SWEP.Primary.ClipMax = 60SWEP.Primary.DefaultClip = 30SWEP.ViewModel = "models/weapons/v_pist_elite.mdl"SWEP.WorldModel = "models/weapons/w_pist_elite.mdl"SWEP.Primary.Sound = Sound("Weapon_Elite.Single")SWEP.IronSightsPos = Vector (-4.955, -3.441, 2.9131)SWEP.IronSightsAng = Vector (-0.0325, -0.1378, 0.0087)--- TTT config values-- Kind specifies the category this weapon is in. Players can only carry one of-- each. Can be: WEAPON_... MELEE, PISTOL, HEAVY, NADE, CARRY, EQUIP1, EQUIP2 or ROLE.-- Matching SWEP.Slot values: 0 1 2 3 4 6 7 8SWEP.Kind = WEAPON_PISTOL-- If AutoSpawnable is true and SWEP.Kind is not WEAPON_EQUIP1/2, then this gun can-- be spawned as a random weapon. Of course this AK is special equipment so it won't,-- but for the sake of example this is explicitly set to false anyway.SWEP.AutoSpawnable = true-- The AmmoEnt is the ammo entity that can be picked up when carrying this gun.SWEP.AmmoEnt = "item_ammo_pistol_ttt"-- CanBuy is a table of ROLE_* entries like ROLE_TRAITOR and ROLE_DETECTIVE. If-- a role is in this table, those players can buy this.-- InLoadoutFor is a table of ROLE_* entries that specifies which roles should-- receive this weapon as soon as the round starts. In this case, none.SWEP.InLoadoutFor = nil-- If LimitedStock is true, you can only buy one per round.SWEP.LimitedStock = false-- If AllowDrop is false, players can't manually drop the gun with QSWEP.AllowDrop = true-- If IsSilent is true, victims will not scream upon death.SWEP.IsSilent = false-- If NoSights is true, the weapon won't have ironsightsSWEP.NoSights = false-- Equipment menu information is only needed on the clientif CLIENT then -- Path to the icon material SWEP.Icon = "VGUI/ttt/icon_pistol" -- Text shown in the equip menu end-- Tell the server that it should download our icon to clients.if SERVER then -- It's important to give your icon a unique name. GMod does NOT check for -- file differences, it only looks at the name. This means that if you have -- an icon_ak47, and another server also has one, then players might see the -- other server's dumb icon. Avoid this by using a unique name. resource.AddFile("materials/VGUI/ttt/icon_myserver_ak47.vmt")end
/*---------------------------------------------------------Think---------------------------------------------------------*/function SWEP:Think() if self.Owner:KeyPressed(IN_ATTACK) and self.Weapon:Clip1() > 0 and self:CanClip1Attack() then -- When the left click is pressed, then self.ViewModelFlip = true end if self.Owner:KeyPressed(IN_ATTACK2) and self.Weapon:Clip1() > 0 and self:CanClip2Attack() then -- When the right click is pressed, then self.ViewModelFlip = false endend/*---------------------------------------------------------PrimaryAttack---------------------------------------------------------*/function SWEP:PrimaryAttack() if not self:CanClip1Attack() or not self:CanPrimaryAttack() or self.Owner:WaterLevel() > 2 then return end -- If your gun have a problem or if you are under water, you'll not be able to fire self.Reloadaftershoot = CurTime() + self.Primary.Delay -- Set the reload after shoot to be not able to reload when firering self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay) -- Set next secondary fire after your fire delay self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay - 0.1) -- Set next secondary fire after your fire delay self.Weapon:EmitSound(self.Primary.Sound) -- Emit the gun sound when you fire self:RecoilPower() clip1 = clip1 - 1 -- Take 1 ammo in your clip if clip1 >= 0 then self:TakePrimaryAmmo(1) -- Take 1 ammo in you clip end if ((SinglePlayer() and SERVER) or CLIENT) then self.Weapon:SetNetworkedFloat("LastShootTime", CurTime()) endend/*---------------------------------------------------------SecondaryAttack---------------------------------------------------------*/function SWEP:SecondaryAttack() if not self:CanClip2Attack() or not self:CanPrimaryAttack() or self.Owner:WaterLevel() > 2 then return end -- If your gun have a problem or if you are under water, you'll not be able to fire self.Reloadaftershoot = CurTime() + self.Primary.Delay -- Set the reload after shoot to be not able to reload when firering self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay - 0.1) -- Set next secondary fire after your fire delay self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay) -- Set next secondary fire after your fire delay self.Weapon:EmitSound(self.Primary.Sound) -- Emit the gun sound when you fire self:RecoilPower() clip2 = clip2 - 1 -- Take 1 ammo in your clip if clip2 >= 0 then self:TakePrimaryAmmo(1) -- Take 1 ammo in you clip end if ((SinglePlayer() and SERVER) or CLIENT) then self.Weapon:SetNetworkedFloat("LastShootTime", CurTime()) endend/*---------------------------------------------------------Reload---------------------------------------------------------*/function SWEP:Reload() if ( self.Reloadaftershoot > CurTime() ) then return end -- If you're firering, you can't reload self.Weapon:DefaultReload(ACT_VM_RELOAD) -- Animation when you're reloading if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then timer.Simple(2, function() clip1 = 15 clip2 = 15 end) endend/*---------------------------------------------------------Deploy---------------------------------------------------------*/function SWEP:Deploy() self.Weapon:SendWeaponAnim( ACT_VM_DRAW ) -- Set the deploy animation when deploying self.Weapon:SetNextPrimaryFire(CurTime() + 1) -- Set the next primary fire to 1 second after deploying self.Weapon:SetNextSecondaryFire(CurTime() + 1) -- Set the next primary fire to 1 second after deploying if ( self.Weapon:Clip1() == 30 ) then clip1 = 15 clip2 = 15 end return trueend/*---------------------------------------------------------ShootBullet---------------------------------------------------------*/function SWEP:CSShootBullet(dmg, recoil, numbul, cone) numbul = numbul or 1 cone = cone or 0.01 local bullet = {} bullet.Num = numbul bullet.Src = self.Owner:GetShootPos() -- Source bullet.Dir = self.Owner:GetAimVector() -- Dir of bullet bullet.Spread = Vector(cone, cone, 0) -- Aim Cone bullet.Tracer = 1 -- Show a tracer on every x bullets bullet.Force = 0.5 * dmg -- Amount of force to give to phys objects bullet.Damage = dmg -- Amount of damage to give to the bullets bullet.Callback = HitImpact-- bullet.Callback = function ( a, b, c ) BulletPenetration( 0, a, b, c ) end self.Owner:FireBullets(bullet) -- Fire the bullets self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK) -- View model animation self.Owner:MuzzleFlash() -- Crappy muzzle light self.Owner:SetAnimation(PLAYER_ATTACK1) -- 3rd Person Animation local fx = EffectData() fx:SetEntity(self.Weapon) fx:SetOrigin(self.Owner:GetShootPos()) fx:SetNormal(self.Owner:GetAimVector()) fx:SetAttachment(self.MuzzleAttachment) util.Effect(self.MuzzleEffect,fx) -- Additional muzzle effects timer.Simple( self.EjectDelay, function() if not IsFirstTimePredicted() then return end local fx = EffectData() fx:SetEntity(self.Weapon) fx:SetNormal(self.Owner:GetAimVector()) fx:SetAttachment(self.ShellEjectAttachment) util.Effect(self.ShellEffect,fx) -- Shell ejection end) if ((SinglePlayer() and SERVER) or (not SinglePlayer() and CLIENT)) then local eyeang = self.Owner:EyeAngles() eyeang.pitch = eyeang.pitch - recoil self.Owner:SetEyeAngles(eyeang) endend/*---------------------------------------------------------CanClip1Attack---------------------------------------------------------*/function SWEP:CanClip1Attack() if clip1 <= 0 and self.Primary.ClipSize > -1 then self.Weapon:SetNextPrimaryFire(CurTime() + 0.5) self.Weapon:EmitSound("Weapons/ClipEmpty_Pistol.wav") clip1 = 0 return false end return trueend/*---------------------------------------------------------CanClip2Attack---------------------------------------------------------*/function SWEP:CanClip2Attack() if clip2 <= 0 and self.Primary.ClipSize > -1 then self.Weapon:SetNextSecondaryFire(CurTime() + 0.5) self.Weapon:EmitSound("Weapons/ClipEmpty_Pistol.wav") clip2 = 0 return false end return trueend