Advertisement
Guest User

A edit to the toolgun to include M9k weapons

a guest
Sep 17th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.28 KB | None | 0 0
  1.  
  2. TOOL.Category = "Trouble in Terrorist Town"
  3. TOOL.Name = "TTT Weapon Placer"
  4. TOOL.Command = nil
  5. TOOL.ConfigName = ""
  6.  
  7. TOOL.ClientConVar["weapon"] = "weapon_zm_pistol"
  8. TOOL.ClientConVar["frozen"] = "0"
  9. TOOL.ClientConVar["replacespawns"] = "0"
  10.  
  11.  
  12. cleanup.Register("ttt_weapons")
  13.  
  14.  
  15. if CLIENT then
  16. language.Add("tool.tttweaponplacer.name", "TTT Weapon Placer" )
  17. language.Add("tool.tttweaponplacer.desc", "Spawn TTT weapon dummies and export their placement" )
  18. language.Add("tool.tttweaponplacer.0", "Left click to spawn entity. Right click for matching ammo." )
  19. language.Add("Cleanup_ttt_weapons", "TTT Dummy Weapons/ammo/spawns")
  20. language.Add("Undone_TTTWeapon", "Undone TTT item" )
  21. end
  22.  
  23. local weps = {
  24. weapon_zm_pistol = {name="Pistol", snd="item_ammo_pistol_ttt"},
  25. weapon_zm_shotgun = {name="Shotgun", snd="item_box_buckshot_ttt"},
  26. weapon_zm_mac10 = {name="MAC10", snd="item_ammo_smg1_ttt"},
  27. weapon_zm_revolver = {name="Deagle", snd="item_ammo_revolver_ttt"},
  28. weapon_zm_rifle = {name="Rifle", snd="item_ammo_357_ttt"},
  29. weapon_zm_sledge = {name="HUGE249", snd=nil},
  30. weapon_zm_molotov = {name="Fire nade", snd=nil},
  31.  
  32. weapon_ttt_confgrenade = {name="Discombobulator", snd=nil},
  33. weapon_ttt_smokegrenade = {name="Smoke nade", snd=nil},
  34. weapon_ttt_m16 = {name="M16", snd="item_ammo_pistol_ttt"},
  35. weapon_ttt_glock = {name="Glock", snd="item_ammo_pistol_ttt"},
  36. m9k_remington870 = {name="Remington870", snd="item_box_buckshot_ttt"},
  37. m9k_mossberg590 = {name="Mossberg590", snd="item_box_buckshot_ttt"},
  38. m9k_m1918bar = {name="M1918Bar", snd="item_ammo_smg1_ttt"},
  39. m9k_dragunov = {name="Dragunov", snd="item_ammo_357_ttt"},
  40. m9k_dbarrel = {name="Double Barrel Shotgun", snd="item_box_buckshot_ttt"},
  41. m9k_1897winchester = {name="Winchester1897", snd="item_box_buckshot_ttt"},
  42. m9k_m3 = {name="M3", snd="item_box_buckshot_ttt"},
  43. m9k_famas = {name="Famas", snd="item_ammo_smg1_ttt"},
  44. m9k_ak47 = {name="AK47", snd="item_ammo_smg1_ttt"},
  45. m9k_val = {name="FN Val", snd="item_ammo_smg1_ttt"},
  46. m9k_amd65 = {name="AMD65", snd="item_ammo_smg1_ttt"},
  47. m9k_scar = {name="Scar", snd="item_ammo_smg1_ttt"},
  48. m9k_acr = {name="ACR", snd="item_ammo_smg1_ttt"},
  49. m9k_mp9 = {name="MP9", snd="item_ammo_smg1_ttt"},
  50. m9k_mp7 = {name="MP7", snd="item_ammo_smg1_ttt"},
  51. m9k_ragingbull = {name="Raging Bull", snd="item_ammo_revolver_ttt"},
  52. m9k_m92beretta = {name="M92 Beretta", snd="item_ammo_pistol_ttt"},
  53. m9k_sten = {name="Sten", snd="item_ammo_smg1_ttt"},
  54. m9k_thompson = {name="Thompson", snd="item_ammo_smg1_ttt"},
  55. m9k_uzi = {name="UZI", snd="item_ammo_smg1_ttt"},
  56. m9k_model3russian = {name="Model 3 Russian", snd="item_ammo_revolver_ttt"},
  57. m9k_coltpython = {name="Colt Python", snd="item_ammo_revolver_ttt"},
  58. m9k_ithacam37 = {name="Ithacam37", snd="item_box_buckshot_ttt"},
  59. m9k_honeybadger = {name="Honey Badger", snd="item_ammo_smg1_ttt"},
  60.  
  61.  
  62. ttt_random_weapon = {name="Random weapon", snd="ttt_random_ammo"},
  63. ttt_random_ammo = {name="Random ammo", snd=nil},
  64.  
  65. ttt_playerspawn = {name="Player spawn", snd=nil}
  66.  
  67. }
  68.  
  69. local mdls = {
  70. weapon_zm_pistol = "models/weapons/w_pist_fiveseven.mdl",
  71. weapon_zm_shotgun = "models/weapons/w_shot_xm1014.mdl",
  72. weapon_zm_mac10 = "models/weapons/w_smg_mac10.mdl",
  73. weapon_zm_revolver = "models/weapons/w_pist_deagle.mdl",
  74. weapon_zm_rifle = "models/weapons/w_snip_scout.mdl",
  75. weapon_zm_sledge = "models/weapons/w_mach_m249para.mdl",
  76. weapon_zm_molotov = "models/weapons/w_eq_flashbang.mdl",
  77.  
  78. weapon_ttt_confgrenade = "models/weapons/w_eq_fraggrenade.mdl",
  79. weapon_ttt_smokegrenade = "models/weapons/w_eq_smokegrenade.mdl",
  80. weapon_ttt_m16 = "models/weapons/w_rif_m4a1.mdl",
  81. weapon_ttt_glock = "models/weapons/w_pist_glock18.mdl",
  82. m9k_remington870 = "models/weapons/w_remington_870_tact.mdl",
  83. m9k_mossberg590 = "models/weapons/w_mossberg_590.mdl",
  84. m9k_m1918bar = "models/weapons/w_m1918_bar.mdl",
  85. m9k_dragunov = "models/weapons/w_svd_dragunov.mdl",
  86. m9k_dbarrel = "models/weapons/w_double_barrel_shotgun.mdl",
  87. m9k_1897winchester = "models/weapons/w_winchester_1897_trench.mdl",
  88. m9k_m3 = "models/weapons/w_benelli_m3.mdl",
  89. m9k_famas = "models/weapons/w_tct_famas.mdl",
  90. m9k_ak47 = "models/weapons/w_tct_ak47.mdl",
  91. m9k_val = "models/weapons/w_dmg_vally.mdl",
  92. m9k_amd65 = "models/weapons/w_amd_65.mdl",
  93. m9k_scar = "models/weapons/w_fn_scar_h.mdl",
  94. m9k_acr = "models/weapons/w_masada_acr.mdl",
  95. m9k_mp9 = "models/weapons/w_brugger_thomet_mp9.mdl",
  96. m9k_mp7 = "models/weapons/w_mp7_silenced.mdl",
  97. m9k_ragingbull = "models/weapons/w_taurus_raging_bull.mdl",
  98. m9k_m92beretta = "models/weapons/w_beretta_m92.mdl",
  99. m9k_sten = "models/weapons/w_sten.mdl",
  100. m9k_thompson = "models/weapons/w_mp40smg.mdl",
  101. m9k_uzi = "models/weapons/w_uzi_imi.mdl",
  102. m9k_model3russian = "models/weapons/w_model_3_rus.mdl",
  103. m9k_coltpython = "models/weapons/w_colt_python.mdl",
  104. m9k_ithacam37 = "models/weapons/w_ithaca_m37.mdl",
  105. m9k_honeybadger = "models/weapons/w_aac_honeybadger.mdl",
  106.  
  107.  
  108.  
  109.  
  110. ttt_random_weapon = "models/weapons/w_shotgun.mdl",
  111. ttt_random_ammo = "models/Items/battery.mdl",
  112.  
  113. item_ammo_pistol_ttt= "models/items/boxsrounds.mdl",
  114. item_ammo_smg1_ttt= "models/items/boxmrounds.mdl",
  115. item_ammo_revolver_ttt = "models/items/357ammo.mdl",
  116. item_ammo_357_ttt = "models/items/357ammo.mdl",
  117. item_box_buckshot_ttt = "models/items/boxbuckshot.mdl",
  118.  
  119.  
  120. ttt_playerspawn = "models/player.mdl",
  121.  
  122. };
  123.  
  124. -- special colours for certain ents
  125. local colors = {
  126. ttt_random_weapon = Color(255, 255, 0),
  127. ttt_random_ammo = Color(0, 255, 0),
  128. item_ammo_revolver_ttt = Color(255, 100, 100),
  129. ttt_playerspawn = Color(0, 255, 0)
  130. };
  131.  
  132. local function DummyInit(s)
  133. if colors[s:GetClass()] then
  134. local c = colors[s:GetClass()]
  135. s:SetColor(c)
  136. end
  137.  
  138. s:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  139. s:SetSolid(SOLID_VPHYSICS)
  140. s:SetMoveType(MOVETYPE_VPHYSICS)
  141.  
  142. if s:GetClass() == "ttt_playerspawn" then
  143. s:PhysicsInitBox(Vector(-18, -18, -0.1), Vector(18, 18, 66))
  144. s:SetPos(s:GetPos() + Vector(0, 0, 1))
  145. else
  146. s:PhysicsInit(SOLID_VPHYSICS)
  147. end
  148.  
  149. s:SetModel(s.Model)
  150. end
  151.  
  152. for cls, mdl in pairs(mdls) do
  153. local tbl = {
  154. Type = "anim",
  155. Model = Model(mdl),
  156. Initialize = DummyInit
  157. };
  158.  
  159. scripted_ents.Register(tbl, cls, false)
  160. end
  161.  
  162. function TOOL:SpawnEntity(cls, trace)
  163. local mdl = mdls[cls]
  164.  
  165. if not cls or not mdl then return end
  166.  
  167. local ent = ents.Create(cls)
  168. ent:SetModel(mdl)
  169. ent:SetPos(trace.HitPos)
  170.  
  171. local tr = util.TraceEntity({start=trace.StartPos, endpos=trace.HitPos, filter=self:GetOwner()}, ent)
  172. if tr.Hit then
  173. ent:SetPos(tr.HitPos)
  174. end
  175.  
  176. ent:Spawn()
  177.  
  178. ent:PhysWake()
  179.  
  180. undo.Create("TTTWeapon")
  181. undo.AddEntity(ent)
  182. undo.SetPlayer(self:GetOwner())
  183. undo.Finish()
  184.  
  185. self:GetOwner():AddCleanup("ttt_weapons", ent)
  186. end
  187.  
  188. function TOOL:LeftClick( trace )
  189. local cls = self:GetClientInfo("weapon")
  190.  
  191. self:SpawnEntity(cls, trace)
  192. end
  193.  
  194. function TOOL:RightClick( trace )
  195. local cls = self:GetClientInfo("weapon")
  196. local info = weps[cls]
  197. if not info then return end
  198.  
  199. local ammo = info.snd
  200. if not ammo then
  201. self:GetOwner():ChatPrint("No matching ammo for this type!")
  202. return
  203. end
  204.  
  205. self:SpawnEntity(info.snd, trace)
  206. end
  207.  
  208. function TOOL.BuildCPanel(panel) -- note that this is not a method, REAL NICE
  209. panel:AddControl( "Header", { Text = "tool.tttweaponplacer.name", Description = language.GetPhrase("tool.tttweaponplacer.desc")})
  210.  
  211. local opts = {}
  212. for w, info in pairs(weps) do
  213. opts[info.name] = {tttweaponplacer_weapon = w}
  214. end
  215.  
  216. panel:AddControl("ListBox", { Label = "Weapons", Height = "200", Options = opts } )
  217.  
  218. panel:AddControl("Button", {Label="Report counts", Command="tttweaponplacer_count", Text="Count"})
  219.  
  220. panel:AddControl("Label", {Text="Export", Description="Export weapon placements"})
  221.  
  222. panel:AddControl("CheckBox", {Label="Replace existing player spawnpoints", Command="tttweaponplacer_replacespawns", Text="Replace spawns"})
  223.  
  224. panel:AddControl( "Button", { Label = "Export to file", Command = "tttweaponplacer_queryexport", Text = "Export"})
  225.  
  226. panel:AddControl("Label", {Text="Import", Description="Import weapon placements"})
  227.  
  228. panel:AddControl( "Button", { Label = "Import from file", Command = "tttweaponplacer_queryimport", Text = "Import"})
  229.  
  230. panel:AddControl("Button", {Label="Convert HL2 entities", Command = "tttweaponplacer_replacehl2", Text="Convert"})
  231.  
  232. panel:AddControl("Button", {Label="Remove all existing weapon/ammo", Command = "tttweaponplacer_removeall", Text="Remove all existing items"})
  233. end
  234.  
  235. -- STOOLs not being loaded on client = headache bonanza
  236. if CLIENT then
  237. function QueryFileExists()
  238.  
  239. local map = string.lower(game.GetMap())
  240. if not map then return end
  241.  
  242. local fname = "ttt/maps/" .. map .. "_ttt.txt"
  243.  
  244. if file.Exists(fname, "DATA") then
  245. Derma_StringRequest("File exists", "The file \"" .. fname .. "\" already exists. Save under a different filename? Leave unchanged to overwrite.",
  246. fname,
  247. function(txt)
  248. RunConsoleCommand("tttweaponplacer_export", txt)
  249. end)
  250. else
  251. RunConsoleCommand("tttweaponplacer_export")
  252. end
  253. end
  254.  
  255. function QueryImportName()
  256. local map = string.lower(game.GetMap())
  257. if not map then return end
  258.  
  259. local fname = "ttt/maps/" .. map .. "_ttt.txt"
  260.  
  261. Derma_StringRequest("Import", "What file do you want to import? Note that files meant for other maps will result in crazy things happening.",
  262. fname,
  263. function(txt)
  264. RunConsoleCommand("tttweaponplacer_import", txt)
  265. end)
  266.  
  267. end
  268. else
  269. -- again, hilarious things happen when this shit is used in mp
  270. concommand.Add("tttweaponplacer_queryexport", function() BroadcastLua("QueryFileExists()") end)
  271. concommand.Add("tttweaponplacer_queryimport", function() BroadcastLua("QueryImportName()") end)
  272. end
  273.  
  274. WEAPON_PISTOL = 1
  275. WEAPON_HEAVY = 2
  276. WEAPON_NADE = 3
  277. WEAPON_RANDOM = 4
  278.  
  279. PLAYERSPAWN = 5
  280.  
  281. local enttypes = {
  282. weapon_zm_pistol = WEAPON_PISTOL,
  283. weapon_zm_revolver = WEAPON_PISTOL,
  284. weapon_ttt_glock = WEAPON_PISTOL,
  285.  
  286. weapon_zm_mac10 = WEAPON_HEAVY,
  287. weapon_zm_shotgun = WEAPON_HEAVY,
  288. weapon_zm_rifle = WEAPON_HEAVY,
  289. weapon_zm_sledge = WEAPON_HEAVY,
  290. weapon_ttt_m16 = WEAPON_HEAVY,
  291.  
  292. weapon_zm_molotov = WEAPON_NADE,
  293. weapon_ttt_smokegrenade = WEAPON_NADE,
  294. weapon_ttt_confgrenade = WEAPON_NADE,
  295.  
  296. ttt_random_weapon = WEAPON_RANDOM,
  297.  
  298. ttt_playerspawn = PLAYERSPAWN
  299. };
  300.  
  301. local function PrintCount(ply)
  302. local count = {
  303. [WEAPON_PISTOL] = 0,
  304. [WEAPON_HEAVY] = 0,
  305. [WEAPON_NADE] = 0,
  306. [WEAPON_RANDOM] = 0,
  307. [PLAYERSPAWN] = 0
  308. };
  309.  
  310. for cls, t in pairs(enttypes) do
  311. for _, ent in pairs(ents.FindByClass(cls)) do
  312. count[t] = count[t] + 1
  313. end
  314. end
  315.  
  316. ply:ChatPrint("Entity count (use report_entities in console for more detail):")
  317. ply:ChatPrint("Primary weapons: " .. count[WEAPON_HEAVY])
  318. ply:ChatPrint("Secondary weapons: " .. count[WEAPON_PISTOL])
  319. ply:ChatPrint("Grenades: " .. count[WEAPON_NADE])
  320. ply:ChatPrint("Random weapons: " .. count[WEAPON_RANDOM])
  321. ply:ChatPrint("Player spawns: " .. count[PLAYERSPAWN])
  322. end
  323. concommand.Add("tttweaponplacer_count", PrintCount)
  324.  
  325. -- This shit will break terribly in MP
  326. if SERVER or CLIENT then
  327. -- Could just do a GLON dump, but it's nice if the "scripts" are sort of
  328. -- human-readable so it's easy to go in and delete all pistols or something.
  329. local function Export(ply, cmd, args)
  330. if not IsValid(ply) then return end
  331.  
  332. local map = string.lower(game.GetMap())
  333.  
  334. if not map then return end
  335.  
  336. --local frozen_only = GetConVar("tttweaponplacer_frozen"):GetBool()
  337. local frozen_only = false
  338.  
  339. -- Nice header, # is comment
  340. local buf = "# Trouble in Terrorist Town weapon/ammo placement overrides\n"
  341. buf = buf .. "# For map: " .. map .. "\n"
  342. buf = buf .. "# Exported by: " .. ply:Nick() .. "\n"
  343.  
  344. -- Write settings ("setting: <name> <value>")
  345. local rspwns = GetConVar("tttweaponplacer_replacespawns"):GetBool() and "1" or "0"
  346. buf = buf .. "setting:\treplacespawns " .. rspwns .. "\n"
  347.  
  348. local num = 0
  349. for cls, mdl in pairs(mdls) do
  350. for _, ent in pairs(ents.FindByClass(cls)) do
  351. if IsValid(ent) then
  352. if not frozen_only or not ent:GetPhysicsObject():IsMoveable() then
  353. num = num + 1
  354. buf = buf .. Format("%s\t%s\t%s\n", cls, tostring(ent:GetPos()), tostring(ent:GetAngles()))
  355. end
  356. end
  357. end
  358. end
  359.  
  360. local fname = "ttt/maps/" .. map .. "_ttt.txt"
  361.  
  362. if args[1] then
  363. fname = args[1]
  364. end
  365.  
  366. file.CreateDir("ttt/maps")
  367. file.Write(fname, buf)
  368.  
  369. if not file.Exists(fname, "DATA") then
  370. ErrorNoHalt("Exported file not found. Bug?\n")
  371. end
  372.  
  373. ply:ChatPrint(num .. " placements saved to /garrysmod/data/" .. fname)
  374. end
  375. concommand.Add("tttweaponplacer_export", Export)
  376.  
  377. local function SpawnDummyEnt(cls, pos, ang)
  378. if not cls or not pos or not ang then return false end
  379.  
  380. local mdl = mdls[cls]
  381. if not mdl then return end
  382.  
  383. local ent = ents.Create(cls)
  384. ent:SetModel(mdl)
  385. ent:SetPos(pos)
  386. ent:SetAngles(ang)
  387. ent:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  388. ent:SetSolid(SOLID_VPHYSICS)
  389. ent:SetMoveType(MOVETYPE_VPHYSICS)
  390. ent:PhysicsInit(SOLID_VPHYSICS)
  391.  
  392. ent:Spawn()
  393.  
  394. local phys = ent:GetPhysicsObject()
  395. if IsValid(phys) then
  396. phys:SetAngles(ang)
  397. end
  398. end
  399.  
  400.  
  401. local function Import(ply, cmd, args)
  402. if not IsValid(ply) then return end
  403. local map = string.lower(game.GetMap())
  404. if not map then return end
  405.  
  406. local fname = "ttt/maps/" .. map .. "_ttt.txt"
  407.  
  408. if args[1] then
  409. fname = args[1]
  410. end
  411.  
  412. if not file.Exists(fname, "DATA") then
  413. ply:ChatPrint(fname .. " not found!")
  414. return
  415. end
  416.  
  417. local buf = file.Read(fname, "DATA")
  418. local lines = string.Explode("\n", buf)
  419. local num = 0
  420. for k, line in ipairs(lines) do
  421. if not string.match(line, "^#") and line != "" then
  422. local data = string.Explode("\t", line)
  423.  
  424. local fail = true -- pessimism
  425.  
  426. if #data > 0 then
  427. if data[1] == "setting:" and tostring(data[2]) then
  428. local raw = string.Explode(" ", data[2])
  429. RunConsoleCommand("tttweaponplacer_" .. raw[1], tonumber(raw[2]))
  430.  
  431. fail = false
  432. num = num - 1
  433. elseif #data == 3 then
  434. local cls = data[1]
  435. local ang = nil
  436. local pos = nil
  437.  
  438. local posraw = string.Explode(" ", data[2])
  439. pos = Vector(tonumber(posraw[1]), tonumber(posraw[2]), tonumber(posraw[3]))
  440.  
  441. local angraw = string.Explode(" ", data[3])
  442. ang = Angle(tonumber(angraw[1]), tonumber(angraw[2]), tonumber(angraw[3]))
  443.  
  444. fail = SpawnDummyEnt(cls, pos, ang)
  445. end
  446. end
  447.  
  448. if fail then
  449. ErrorNoHalt("Invalid line " .. k .. " in " .. fname .. "\n")
  450. else
  451. num = num + 1
  452. end
  453. end
  454. end
  455.  
  456. ply:ChatPrint("Spawned " .. num .. " dummy ents")
  457. end
  458. concommand.Add("tttweaponplacer_import", Import)
  459.  
  460. local function RemoveAll(ply, cmd, args)
  461. if not IsValid(ply) then return end
  462.  
  463. local num = 0
  464. local delete = function(ent)
  465. if not IsValid(ent) then return end
  466. print("\tRemoving", ent, ent:GetClass())
  467. ent:Remove()
  468. num = num + 1
  469. end
  470.  
  471. print("Removing ammo...")
  472. for k, ent in pairs(ents.FindByClass("item_*")) do
  473. delete(ent)
  474. end
  475. for k, ent in pairs(ents.FindByClass("ttt_random_ammo")) do
  476. delete(ent)
  477. end
  478.  
  479. print("Removing weapons...")
  480. for k, ent in pairs(ents.FindByClass("weapon_*")) do
  481. delete(ent)
  482. end
  483. for k, ent in pairs(ents.FindByClass("ttt_random_weapon")) do
  484. delete(ent)
  485. end
  486.  
  487. ply:ChatPrint("Removed " .. num .. " weapon/ammo ents")
  488. end
  489. concommand.Add("tttweaponplacer_removeall", RemoveAll)
  490.  
  491. local hl2_replace = {
  492. ["item_ammo_pistol"] = "item_ammo_pistol_ttt",
  493. ["item_box_buckshot"] = "item_box_buckshot_ttt",
  494. ["item_ammo_smg1"] = "item_ammo_smg1_ttt",
  495. ["item_ammo_357"] = "item_ammo_357_ttt",
  496. ["item_ammo_357_large"] = "item_ammo_357_ttt",
  497. ["item_ammo_revolver"] = "item_ammo_revolver_ttt", -- zm
  498. ["item_ammo_ar2"] = "item_ammo_pistol_ttt",
  499. ["item_ammo_ar2_large"] = "item_ammo_smg1_ttt",
  500. ["item_ammo_smg1_grenade"] = "weapon_zm_pistol",
  501. ["item_battery"] = "item_ammo_357_ttt",
  502. ["item_healthkit"] = "weapon_zm_shotgun",
  503. ["item_suitcharger"] = "weapon_zm_mac10",
  504. ["item_ammo_ar2_altfire"] = "weapon_zm_mac10",
  505. ["item_rpg_round"] = "item_ammo_357_ttt",
  506. ["item_ammo_crossbow"] = "item_box_buckshot_ttt",
  507. ["item_healthvial"] = "weapon_zm_molotov",
  508. ["item_healthcharger"] = "item_ammo_revolver_ttt",
  509. ["item_ammo_crate"] = "weapon_ttt_confgrenade",
  510. ["item_item_crate"] = "ttt_random_ammo",
  511. ["weapon_smg1"] = "weapon_zm_mac10",
  512. ["weapon_shotgun"] = "weapon_zm_shotgun",
  513. ["weapon_ar2"] = "weapon_ttt_m16",
  514. ["weapon_357"] = "weapon_zm_rifle",
  515. ["weapon_crossbow"] = "weapon_zm_pistol",
  516. ["weapon_rpg"] = "weapon_zm_sledge",
  517. ["weapon_slam"] = "item_ammo_pistol_ttt",
  518. ["weapon_frag"] = "weapon_zm_revolver",
  519. ["weapon_crowbar"] = "weapon_zm_molotov"
  520. };
  521.  
  522. local function ReplaceSingle(ent, newname)
  523. if ent:GetPos() == vector_origin then
  524. return false
  525. end
  526.  
  527. if ent:IsWeapon() and IsValid(ent:GetOwner()) and ent:GetOwner():IsPlayer() then
  528. return false
  529. end
  530.  
  531. ent:SetSolid(SOLID_NONE)
  532.  
  533. local rent = ents.Create(newname)
  534. rent:SetModel(mdls[newname])
  535. rent:SetPos(ent:GetPos())
  536. rent:SetAngles(ent:GetAngles())
  537. rent:Spawn()
  538.  
  539. rent:Activate()
  540. rent:PhysWake()
  541.  
  542. ent:Remove()
  543. return true
  544. end
  545.  
  546. local function ReplaceHL2Ents(ply, cmd, args)
  547. if not IsValid(ply) then return end
  548.  
  549. local c = 0
  550. for _, ent in pairs(ents.GetAll()) do
  551. local rpl = hl2_replace[ent:GetClass()]
  552. if rpl then
  553. local success = ReplaceSingle(ent, rpl)
  554. if success then
  555. c = c + 1
  556. end
  557. end
  558. end
  559.  
  560. ply:ChatPrint("Replaced " .. c .. " HL2 entities with TTT versions.")
  561. end
  562. concommand.Add("tttweaponplacer_replacehl2", ReplaceHL2Ents)
  563. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement