CapsAdmin

Untitled

Jan 3rd, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.92 KB | None | 0 0
  1. --[==[if
  2.     LocalPlayer() == player.GetByUniqueID(--[[BubuNddi(jp)]] "993888442") or
  3.     LocalPlayer() == player.GetByUniqueID(--[[CapsAdmin]] "1416729906") or
  4.     LocalPlayer() == player.GetByUniqueID(--[[[JP] L.Bodewig]] "3231181953")
  5. then]==]
  6.  
  7. if CLIENT then
  8.  
  9.     local function Create1BitMaterial(path)
  10.         return CreateMaterial(
  11.             path .. "_hotd_"..RealTime(),
  12.             "UnlitGeneric",
  13.             {
  14.                 ["$basetexture"] = path,
  15.                 ["$alphatest"] = 1,
  16.             }
  17.         )
  18.     end
  19.  
  20.     -- particles
  21.  
  22.     local particles = {}
  23.  
  24.     local fire_mat = Create1BitMaterial("effects/fire_cloud2")
  25.  
  26.     local function create_particles()
  27.         for i=1, math.random(2,10) do
  28.             particles[i] = {ang = math.random(0,360), len = math.random()*400}
  29.         end
  30.     end
  31.  
  32.     local function draw_particles(x,y)
  33.         if particles then
  34.             for k,v in pairs(particles) do
  35.                 surface.SetDrawColor(255, 255, 255, 255)
  36.                 surface.SetMaterial(fire_mat)
  37.                
  38.                 local dx = math.sin(math.rad(v.ang)) * v.len / 2
  39.                 local dy = math.cos(math.rad(v.ang)) * v.len / 2
  40.                
  41.                 surface.DrawTexturedRectRotated(x + dx, y+dy, 100, 100 + v.len, v.ang)
  42.             end
  43.         end
  44.     end
  45.  
  46.     -- crosshair
  47.  
  48.     local crosshair_mat = Material("VGUI/hud/xbox_reticle")
  49.     local size = 128
  50.  
  51.     local function draw_crosshair(x,y, alpha)
  52.         surface.SetDrawColor(255, 0, 0, alpha or 255)
  53.         surface.SetMaterial(crosshair_mat)
  54.         surface.DrawTexturedRect(x-size/2,y-size/2,size,size)
  55.     end
  56.  
  57.     -- flash
  58.  
  59.     local white_id = surface.GetTextureID("VGUI/white_additive")
  60.  
  61.     local function draw_flash(alpha)
  62.         surface.SetDrawColor(255, 255, 255, alpha)
  63.         surface.SetTexture(white_id)
  64.         surface.DrawTexturedRect(0,0,ScrW(), ScrH())
  65.     end
  66.  
  67.     -- ammo
  68.  
  69.     local max_ammo = 6
  70.     local ammo = max_ammo
  71.  
  72.     local ammo_id = surface.GetTextureID("VGUI/ico_box6")
  73.     local offset = 64
  74.     local spacing = 64
  75.     local size = 64
  76.  
  77.     local function draw_ammo()
  78.         local x = offset
  79.         local y = ScrH() - offset * 2
  80.        
  81.         for i = 0, ammo-1 do
  82.             surface.SetDrawColor(255, 255, 255, 255)
  83.             surface.SetTexture(ammo_id)
  84.             surface.DrawTexturedRect(x + (i * spacing), y, size, size)
  85.         end
  86.     end
  87.    
  88.     -- reload
  89.     local reload_text = "RELOAD"
  90.     surface.CreateFont(
  91.         "hotd_reload_font",
  92.         {
  93.             font = "coolvetica",
  94.             size = 128,
  95.             weight = 700,
  96.         }
  97.     )
  98.    
  99.     local function draw_reload()
  100.         surface.SetFont("hotd_reload_font")
  101.         local w, h = surface.GetTextSize(reload_text)
  102.         surface.SetTextPos((ScrW() / 2) - w / 2, (ScrH() / 2) - h / 2)
  103.         surface.SetTextColor(255, 0, 0, math.abs(math.sin(RealTime()*20)) * 255)
  104.         surface.DrawText(reload_text)
  105.     end
  106.    
  107.     -- sound
  108.    
  109.     local function play_gunshot(ent)
  110.         ent:EmitSound("npc/sniper/sniper1.wav", 100, 150)
  111.         ent:EmitSound("weapons/pistol/pistol_fire3.wav", 100, 75)
  112.     end
  113.  
  114.     -- graphics
  115.     local graphics_cvars =
  116.     {
  117.         r_lod = 5, 
  118.         mat_filterlightmaps = 0,
  119.         mat_filtertextures = 0,
  120.         mat_mipmaptextures = 0,
  121.         r_shadows = 0,
  122.         mat_fullbright = 1,
  123.     }
  124.  
  125.     hotd_old_graphics_cvars = hotd_old_graphics_cvars or {}
  126.  
  127.     local function enable_graphics()
  128.         for cmd, val in pairs(graphics_cvars) do
  129.             hotd_old_graphics_cvars[cmd] = hotd_old_graphics_cvars[cmd] or GetConVarString(cmd)
  130.            
  131.             RunConsoleCommand(cmd, val)
  132.         end
  133.        
  134.         hook.Add("RenderScreenspaceEffects", "hotd", function()
  135.             DrawColorModify
  136.             {
  137.                 ["$pp_colour_addr"] = 0.0,
  138.                 ["$pp_colour_addg"] = 0.01,
  139.                 ["$pp_colour_addb"] = 0.05,
  140.                 ["$pp_colour_brightness"] = -0.1,
  141.                 ["$pp_colour_contrast"] = 1.2,
  142.                 ["$pp_colour_colour"] = 0.8,
  143.                 ["$pp_colour_mulr"] = 0,
  144.                 ["$pp_colour_mulg"] = 0,
  145.                 ["$pp_colour_mulb"] = 0,   
  146.             }
  147.         end)
  148.     end
  149.  
  150.     local function disable_graphics()
  151.         for cmd, val in pairs(hotd_old_graphics_cvars) do
  152.             RunConsoleCommand(cmd, val)
  153.         end
  154.        
  155.         hotd_old_graphics_cvars = {}
  156.        
  157.         hook.Remove("RenderScreenspaceEffects", "hotd")
  158.     end
  159.    
  160.     -- network
  161.    
  162.     hotd_players = hotd_players or {}
  163.    
  164.     local players = hotd_players
  165.     local avatar_size = 32
  166.    
  167.     local function hide_avatars()
  168.         for id, pos in pairs(players) do
  169.             local pnl = players[id].panel or NULL
  170.            
  171.             if pnl:IsValid() then
  172.                 pnl:SetVisible(false)
  173.             end
  174.         end
  175.     end
  176.    
  177.     local function network_cursor(x, y)
  178.         RunConsoleCommand("hotd_mpos", x / ScrW(), y / ScrH())
  179.     end
  180.    
  181.     -- logic
  182.  
  183.     local last_attack = 0
  184.     local last_x, last_y
  185.     local reload_sound_played = false
  186.  
  187.     local function draw_hud()
  188.         if not vgui.CursorVisible() or not vgui.CursorVisible() or (pace and pace.Editor:IsValid()) or (g_SpawnMenu and g_SpawnMenu:IsVisible()) then
  189.             hide_avatars()
  190.         return end
  191.        
  192.         local x,y = gui.MousePos()
  193.         local ply = LocalPlayer()
  194.        
  195.         draw_ammo()
  196.  
  197.         if ammo < 0 then
  198.             if input.IsMouseDown(MOUSE_RIGHT) then
  199.                 ammo = max_ammo
  200.                 ply:EmitSound("weapons/shotgun/shotgun_cock.wav")
  201.             end
  202.            
  203.             draw_reload()
  204.            
  205.             draw_crosshair(x,y, math.abs(math.sin(RealTime()*20)) * 255)
  206.            
  207.             if not reload_sound_played then
  208.                 local snd = CreateSound(ply, "vo/npc/male01/reloadfm01.wav")
  209.                 snd:Play()
  210.                 timer.Simple(0.4, function()
  211.                     snd:Stop("vo/npc/male01/reloadfm01.wav")
  212.                 end)
  213.                 reload_sound_played = true
  214.                
  215.                 hide_avatars()
  216.             end
  217.            
  218.             return
  219.         end
  220.        
  221.         if last_attack > RealTime() then
  222.             draw_flash(50)
  223.             draw_crosshair(x, y)
  224.             draw_particles(last_x, last_y)
  225.             draw_flash(25)
  226.            
  227.             hide_avatars()
  228.             return
  229.         end
  230.            
  231.         draw_crosshair(x,y)
  232.            
  233.         if input.IsMouseDown(MOUSE_LEFT) then
  234.             particles = {}
  235.                        
  236.             if ammo > 0 then
  237.                 play_gunshot(ply)
  238.                
  239.                 local ent = ply:GetViewEntity()
  240.                 local aim = util.AimVector(ent:GetAngles(), ply:GetFOV(), x, y, ScrW(), ScrH())
  241.                
  242.                 local data = util.TraceLine({
  243.                     start = ent:GetPos(),
  244.                     endpos = ent:GetPos() + aim * 2048,
  245.                     mask = MASK_OPAQUE_AND_NPCS,
  246.                 })
  247.            
  248.                 if data.Entity:IsPlayer() or data.Entity:IsNPC() then          
  249.                     local params = EffectData()
  250.                         params:SetOrigin(data.HitPos)
  251.                         params:SetStart(data.HitPos)
  252.                     util.Effect("BloodImpact", params) 
  253.                 else
  254.                     ply:EmitSound("weapons/fx/rics/ric2.wav", 100, 100)
  255.                 end
  256.                
  257.                 -- this is terrible but it's only temporary
  258.                 -- update or is it ???????????????
  259.                 net.Start("hotd_fire")
  260.                     net.WriteVector(aim)
  261.                     net.WriteEntity(data.Entity)
  262.                 net.SendToServer()
  263.             else
  264.                 ply:EmitSound("weapons/pistol/pistol_empty.wav", 100, 125)
  265.             end
  266.            
  267.             last_attack = RealTime() + 0.1
  268.            
  269.             last_x = x
  270.             last_y = y
  271.            
  272.             create_particles()
  273.            
  274.             ammo = ammo - 1
  275.         end
  276.        
  277.         reload_sound_played = false
  278.        
  279.         for id, pos in pairs(players) do
  280.             local pnl = players[id].panel or NULL
  281.            
  282.             if Entity(id):IsValid() then
  283.                 local delta = FrameTime() * 16
  284.                    
  285.                 pos.sx = pos.sx or pos.x
  286.                 pos.sy = pos.sy or pos.y
  287.                
  288.                 pos.sx = pos.sx + ((pos.x - pos.sx) * delta)
  289.                 pos.sy = pos.sy + ((pos.y - pos.sy) * delta)
  290.            
  291.                 if pnl:IsValid() then  
  292.                     pnl:SetAlpha(255)
  293.                     pnl:SetVisible(true)
  294.                     pnl:SetPos((pos.sx - avatar_size/2), (pos.sy - avatar_size/2))
  295.                 end
  296.                
  297.                 draw_crosshair(pos.sx, pos.sy)
  298.                
  299.                 if pos.shoot then
  300.                     particles = {}
  301.                     last_attack = RealTime() + 0.1
  302.                     last_x = pos.x
  303.                     last_y = pos.y
  304.                     create_particles()
  305.                     pos.shoot = false
  306.                 end
  307.             else
  308.                 players[id] = nil
  309.                 if pnl:IsValid() then
  310.                     pnl:Remove()
  311.                 end
  312.             end
  313.         end
  314.        
  315.         network_cursor(x, y)
  316.     end
  317.  
  318.     usermessage.Hook("hotd_play_gunshot", function(umr)
  319.         local ent = umr:ReadEntity()
  320.        
  321.         if ent:IsValid() then
  322.             local id = ent:EntIndex()
  323.            
  324.             play_gunshot(ent)
  325.            
  326.             if players[id] then
  327.                 players[id].shoot = true
  328.             end
  329.         end
  330.     end)
  331.    
  332.     usermessage.Hook("hotd_mpos", function(umr)
  333.         local ply, x,y = umr:ReadEntity(), umr:ReadFloat(), umr:ReadFloat()
  334.    
  335.         if ply:IsValid() then
  336.             x = x * ScrW()
  337.             y = y * ScrH()
  338.        
  339.             local id = ply:EntIndex()
  340.             players[id] = players[id] or {}
  341.            
  342.             players[id].x = x
  343.             players[id].y = y
  344.            
  345.             local pnl = players[id].panel or NULL
  346.            
  347.             if not pnl:IsValid() then
  348.                 pnl = vgui.Create("AvatarImage")
  349.                 pnl:SetPlayer(ply)
  350.                 players[id].panel = pnl
  351.             end
  352.            
  353.             pnl:SetSize(avatar_size, avatar_size)      
  354.         end
  355.     end)
  356.    
  357.     function hotd_enable()
  358.         hook.Add("HUDPaint", "hotd", draw_hud)
  359.         enable_graphics()
  360.         gui.EnableScreenClicker(true)
  361.     end
  362.    
  363.     function hotd_disable()
  364.         hook.Remove("HUDPaint", "hotd")
  365.         disable_graphics()
  366.         gui.EnableScreenClicker(false)
  367.     end
  368. end
  369.  
  370. if SERVER then
  371.  
  372.     util.AddNetworkString("hotd_fire")
  373.    
  374.     hotd_scene_entity = NULL
  375.  
  376.     hotd_map_data = {map = game.GetMap(), points = {}}
  377.     local hotd_map_index = 1
  378.     local hotd_lerp = 0
  379.     hotd_active_npcs = hotd_active_npcs
  380.    
  381.     local male_thanks_sounds =
  382.     {
  383.         "vo/npc/male01/answer01.wav",
  384.         "vo/npc/male01/answer02.wav",
  385.         "vo/npc/male01/answer03.wav",
  386.         "vo/npc/male01/answer04.wav",
  387.         "vo/npc/male01/answer05.wav",
  388.         "vo/npc/male01/answer07.wav",
  389.         "vo/npc/male01/answer08.wav",
  390.         "vo/npc/male01/answer09.wav",
  391.         "vo/npc/male01/answer10.wav",
  392.         "vo/npc/male01/answer11.wav",
  393.         "vo/npc/male01/answer12.wav",
  394.         "vo/npc/male01/answer13.wav",
  395.         "vo/npc/male01/answer14.wav",
  396.         "vo/npc/male01/answer15.wav",
  397.         "vo/npc/male01/answer16.wav",
  398.         "vo/npc/male01/answer17.wav",
  399.         "vo/npc/male01/answer18.wav",
  400.         "vo/npc/male01/answer19.wav",
  401.         "vo/npc/male01/answer20.wav",
  402.         "vo/npc/male01/answer21.wav",
  403.         "vo/npc/male01/answer22.wav",
  404.         "vo/npc/male01/answer23.wav",
  405.         "vo/npc/male01/answer24.wav",
  406.         "vo/npc/male01/answer25.wav",
  407.         "vo/npc/male01/answer26.wav",
  408.         "vo/npc/male01/answer27.wav",
  409.         "vo/npc/male01/answer28.wav",
  410.         "vo/npc/male01/answer29.wav",
  411.         "vo/npc/male01/answer30.wav",
  412.         "vo/npc/male01/answer31.wav",
  413.         "vo/npc/male01/answer32.wav",
  414.         "vo/npc/male01/answer33.wav",
  415.         "vo/npc/male01/answer34.wav",
  416.         "vo/npc/male01/answer35.wav",
  417.         "vo/npc/male01/answer36.wav",
  418.         "vo/npc/male01/answer37.wav",
  419.         "vo/npc/male01/answer38.wav",
  420.         "vo/npc/male01/answer39.wav",
  421.         "vo/npc/male01/answer40.wav",
  422.     }
  423.     local female_thanks_sounds =
  424.     {
  425.         "vo/npc/female01/answer01.wav",
  426.         "vo/npc/female01/answer02.wav",
  427.         "vo/npc/female01/answer03.wav",
  428.         "vo/npc/female01/answer04.wav",
  429.         "vo/npc/female01/answer05.wav",
  430.         "vo/npc/female01/answer07.wav",
  431.         "vo/npc/female01/answer08.wav",
  432.         "vo/npc/female01/answer09.wav",
  433.         "vo/npc/female01/answer10.wav",
  434.         "vo/npc/female01/answer11.wav",
  435.         "vo/npc/female01/answer12.wav",
  436.         "vo/npc/female01/answer13.wav",
  437.         "vo/npc/female01/answer14.wav",
  438.         "vo/npc/female01/answer15.wav",
  439.         "vo/npc/female01/answer16.wav",
  440.         "vo/npc/female01/answer17.wav",
  441.         "vo/npc/female01/answer18.wav",
  442.         "vo/npc/female01/answer19.wav",
  443.         "vo/npc/female01/answer20.wav",
  444.         "vo/npc/female01/answer21.wav",
  445.         "vo/npc/female01/answer22.wav",
  446.         "vo/npc/female01/answer23.wav",
  447.         "vo/npc/female01/answer24.wav",
  448.         "vo/npc/female01/answer25.wav",
  449.         "vo/npc/female01/answer26.wav",
  450.         "vo/npc/female01/answer27.wav",
  451.         "vo/npc/female01/answer28.wav",
  452.         "vo/npc/female01/answer29.wav",
  453.         "vo/npc/female01/answer30.wav",
  454.         "vo/npc/female01/answer31.wav",
  455.         "vo/npc/female01/answer32.wav",
  456.         "vo/npc/female01/answer33.wav",
  457.         "vo/npc/female01/answer34.wav",
  458.         "vo/npc/female01/answer35.wav",
  459.         "vo/npc/female01/answer36.wav",
  460.         "vo/npc/female01/answer37.wav",
  461.         "vo/npc/female01/answer38.wav",
  462.         "vo/npc/female01/answer39.wav",
  463.         "vo/npc/female01/answer40.wav",
  464.     }
  465.  
  466.     function hotd_initialize()
  467.         hook.Add("Think", "hotd", hotd_think)
  468.         SafeRemoveEntity(hotd_scene_entity)
  469.        
  470.         if not hotd_load_map() then
  471.             hotd_shutdown()
  472.             return
  473.         end
  474.        
  475.         local ent = ents.Create("prop_dynamic")
  476.         ent:SetModel("models/tools/camera/camera.mdl")
  477.         ent:SetPos(hotd_map_data.points[1].pos)
  478.         ent:Spawn()
  479.        
  480.         hotd_scene_entity = ent
  481.     end
  482.    
  483.     function hotd_shutdown()
  484.         hook.Add("Think", "hotd", hotd_think)
  485.         SafeRemoveEntity(hotd_scene_entity)
  486.        
  487.         hotd_map_index = 1
  488.         hotd_lerp = 0      
  489.        
  490.         if table.Count(hotd_players) > 0 then
  491.             for key, ply in pairs(hotd_players) do
  492.                 hotd_disable(ply)
  493.             end
  494.         end
  495.        
  496.         if hotd_active_npcs then
  497.             for key, data in pairs(hotd_active_npcs) do
  498.                 SafeRemoveEntity(data.ent)
  499.             end
  500.         end
  501.     end
  502.                
  503.     local function hotd_think()
  504.         local ent = hotd_scene_entity
  505.        
  506.         if ent:IsValid() then  
  507.  
  508.             local data_cur = hotd_map_data.points[hotd_map_index]
  509.             local data_nxt = hotd_map_data.points[hotd_map_index + 1]
  510.            
  511.             if not data_cur then
  512.                 ErrorNoHalt("invalid map index ?? '" .. hotd_map_index .. "'")
  513.                 hotd_shutdown()
  514.             return end
  515.            
  516.             if data_nxt then
  517.                 ent:SetPos(LerpVector(hotd_lerp, data_cur.pos, data_nxt.pos))
  518.                 ent:SetAngles(LerpAngle(hotd_lerp, data_cur.ang, data_nxt.ang))
  519.             end
  520.            
  521.             if data_nxt.npcs then
  522.                 if not hotd_active_npcs then
  523.                     for _, data in pairs(data_nxt.npcs) do
  524.                         local npc = ents.Create(data.class)
  525.                             npc:SetPos(data.pos)
  526.                             data.ang.p = 0
  527.                             npc:SetAngles(data.ang)
  528.                             npc:Spawn()
  529.                             npc:DropToFloor()                          
  530.                         data.ent = npc
  531.                     end
  532.                
  533.                     hotd_active_npcs = table.Copy(data_nxt.npcs)
  534.                 end
  535.             end
  536.            
  537.             if hotd_active_npcs and data_cur.npcs then
  538.                
  539.                 local aim_pos = Vector(0,0,0)
  540.                 local enemy_count = 0
  541.                
  542.                 local friendly_count = 0
  543.                
  544.                 for key, data in pairs(hotd_active_npcs) do
  545.                     if not data.ent:IsValid() then
  546.                         hotd_active_npcs[key] = nil
  547.                     else
  548.                         if data.class ~= "npc_citizen" then
  549.                             aim_pos = aim_pos + data.ent:EyePos()
  550.                             enemy_count = enemy_count + 1
  551.                         else
  552.                             friendly_count = friendly_count + 1
  553.                         end
  554.                     end
  555.                 end
  556.                
  557.                 if enemy_count == 0 then
  558.                     if friendly_count > 0 then 
  559.                                            
  560.                         for key, data in pairs(hotd_active_npcs) do
  561.                             if data.ent.hotd_thanked then
  562.                                 if data.ent.hotd_thanked < os.clock() then
  563.                                     hotd_active_npcs[key] = nil
  564.                                 end
  565.                                 aim_pos = data.ent.hotd_last_pos
  566.                             elseif data.ent:GetPos():Distance(ent:GetPos()) < 100 then
  567.                                 if data.ent:GetModel():lower():find("female") then
  568.                                     data.ent:EmitSound(table.Random(female_thanks_sounds))
  569.                                 else
  570.                                     data.ent:EmitSound(table.Random(male_thanks_sounds))
  571.                                 end
  572.                                
  573.                                 data.ent.hotd_last_pos = data.ent:EyePos()
  574.                                 data.ent.hotd_thanked = os.clock() + 1
  575.                             else
  576.                                 if data.ent.hotd_goto ~= ent:GetPos() then
  577.                                     data.ent:SetLastPosition(ent:GetPos())
  578.                                     data.ent:SetSchedule(SCHED_FORCED_GO)
  579.                                     data.ent.hotd_goto = ent:GetPos()
  580.                                 end
  581.                                 aim_pos = aim_pos + data.ent:EyePos()
  582.                             end
  583.                         end
  584.                     else
  585.                         hotd_active_npcs = nil
  586.                         data_cur.npcs = nil
  587.                     end
  588.                 elseif enemy_count > 1 then
  589.                     aim_pos = aim_pos / enemy_count
  590.                 end
  591.                
  592.                 ent:SetAngles((aim_pos - ent:GetPos()):Angle())
  593.             else
  594.                 hotd_lerp = hotd_lerp + FrameTime() * 0.75
  595.  
  596.                 if hotd_lerp > 1 then
  597.                     hotd_lerp = 0
  598.                     hotd_map_index = hotd_map_index + 1
  599.                 end
  600.             end
  601.            
  602.             for key, ply in pairs(hotd_players) do
  603.                 ply:SetViewEntity(ent)
  604.                 ply:SetPos(ent:GetPos() - (ply:EyePos() - ply:GetPos()) + ent:GetForward() * -50)
  605.                 ply:SetEyeAngles(ent:GetAngles())
  606.                 ply:SetMoveType(MOVETYPE_NOCLIP)
  607.                 if not ply:Alive() then
  608.                     hotd_disable(ply)
  609.                 end
  610.             end
  611.         end
  612.     end
  613.    
  614.     hotd_players = hotd_players or {}
  615.    
  616.     function hotd_enable(ply)  
  617.         hotd_disable(ply)
  618.        
  619.         local count = table.Count(hotd_players)
  620.        
  621.         ply:SendLua("hotd_enable()")
  622.         hotd_players[ply:UniqueID()] = ply
  623.        
  624.         -- so we can shut down properly if there's an error
  625.         if count == 0 then
  626.             hotd_initialize()
  627.         end
  628.        
  629.         hook.Add("Think", "hotd", hotd_think)
  630.     end
  631.    
  632.     function hotd_disable(ply)
  633.         ply:SendLua("hotd_disable()")
  634.         hotd_players[ply:UniqueID()] = nil
  635.        
  636.         if table.Count(hotd_players) == 0 then
  637.             hotd_shutdown()
  638.         end
  639.        
  640.         ply:SetViewEntity(NULL)
  641.     end
  642.    
  643.     function hotd_save_map(str, data)
  644.         str = str or game.GetMap()
  645.         data = data or hotd_map_data
  646.        
  647.         data.map = data.map or game.GetMap()
  648.         luadata.WriteFile("hotd_map_" .. str .. ".txt", data)
  649.     end
  650.    
  651.     function hotd_load_map(str)
  652.         str = str or game.GetMap()
  653.        
  654.         local data = luadata.ReadFile("hotd_map_" .. str .. ".txt")
  655.        
  656.         if not data.map then
  657.             ErrorNoHalt("invalid hotd map " .. str .. "!")
  658.             hotd_shutdown()
  659.             return false
  660.         end
  661.        
  662.         if data.map ~= game.GetMap() then
  663.             ErrorNoHalt("hotd map " .. str .. " was made for " .. data.map .. "!")
  664.             hotd_shutdown()
  665.             return false
  666.         end
  667.        
  668.         hotd_map_data = data
  669.        
  670.         return true
  671.     end
  672.    
  673.     local editor_points = {}
  674.    
  675.     function hotd_enable_editor(ply)
  676.        
  677.         editor_points = {}
  678.         local current_class = "npc_zombie"
  679.        
  680.         local function remove_point(pos)
  681.             for key, data in pairs(editor_points) do
  682.                 if data.pos:Distance(pos) < 50 then
  683.                     SafeRemoveEntity(data.ent)
  684.                     table.remove(editor_points, key)
  685.                     break
  686.                 end
  687.             end
  688.         end
  689.    
  690.         hook.Add("KeyPress", "hotd", function(_ply, key)
  691.             if _ply ~= ply then return end 
  692.            
  693.             local pos = ply:EyePos()
  694.             local ang = ply:EyeAngles()
  695.        
  696.             if key == IN_ATTACK then               
  697.            
  698.                 remove_point(pos)
  699.                
  700.                 local ent = ents.Create("prop_dynamic")
  701.                     ent:SetModel("models/tools/camera/camera.mdl")
  702.                     ent:SetPos(pos)
  703.                     ent:SetAngles(ang)
  704.                     ent:Spawn()                
  705.                
  706.                 local key = table.insert(editor_points, {pos = pos, ang = ang, ent = ent})
  707.                
  708.                 ply:EmitSound("buttons/button17.wav")
  709.                
  710.                 print("adding point: ", key, pos, ang)
  711.                
  712.             elseif key == IN_ATTACK2 then
  713.            
  714.                 remove_point(pos)
  715.                
  716.                 ply:EmitSound("buttons/button16.wav")
  717.                
  718.                 print("removing point: ", key, pos, ang)
  719.                
  720.             elseif key == IN_DUCK then
  721.                
  722.                 local data = editor_points[#editor_points]
  723.                 data.npcs = data.npcs or {}
  724.                
  725.                 local ent = ents.Create("prop_dynamic")
  726.                 ent:SetModel("models/editor/playerstart.mdl")
  727.                 ent:SetPos(pos)
  728.                 ent:SetAngles(ang)
  729.                 ent:DropToFloor()
  730.                
  731.                 table.insert(
  732.                     data.npcs,
  733.                     {
  734.                         class = current_class,
  735.                         pos = pos,
  736.                         ang = ang,
  737.                         ent = ent,
  738.                     }
  739.                 )
  740.                
  741.                 print("adding npc ", "npc_zombie", pos, ang)
  742.                
  743.             elseif key == IN_RELOAD and ply:KeyDown(IN_WALK) then
  744.                 hotd_save_map(nil, {points = editor_points})
  745.                
  746.                 hotd_disable_editor(ply)
  747.                
  748.                 ply:EmitSound("buttons/button15.wav")
  749.             end
  750.         end)
  751.        
  752.         hook.Add("PlayerSay", "hotd", function(_ply, str)
  753.             if _ply ~= ply then return end
  754.            
  755.             class = str:match("setnpcclass (.+)")
  756.             current_class = class
  757.         end)
  758.        
  759.     end
  760.    
  761.     function hotd_disable_editor(ply)
  762.         for key, data in pairs(editor_points) do
  763.             SafeRemoveEntity(data.ent)
  764.             data.ent = nil
  765.            
  766.             if data.npcs then
  767.                 for key, data in pairs(data.npcs) do
  768.                     SafeRemoveEntity(data.ent)
  769.                     data.ent = nil
  770.                 end
  771.             end
  772.         end
  773.         hook.Remove("KeyPress", "hotd")
  774.         hook.Remove("PlayerSay", "hotd")
  775.     end
  776.    
  777.     net.Receive("hotd_fire", function(len, ply)
  778.         local aim = net.ReadVector()
  779.         local ent = net.ReadEntity()
  780.        
  781.         local view = ply:GetViewEntity()
  782.         local data = util.TraceLine({
  783.             start = view:GetPos(),
  784.             endpos = view:GetPos() + aim * 2048,
  785.             mask = MASK_OPAQUE_AND_NPCS,
  786.         })
  787.        
  788.         if data.Entity ~= ent then return end
  789.    
  790.         local hitpos = data.HitPos
  791.    
  792.         if ent:IsValid() then
  793.             if ent:IsPlayer() or ent:IsNPC() then
  794.                 local params = EffectData()
  795.                     params:SetOrigin(hitpos)
  796.                     params:SetStart(hitpos)
  797.                 util.Effect("BloodImpact", params) 
  798.             end
  799.        
  800.             local params = DamageInfo()
  801.                 params:SetAttacker(ply)
  802.                 params:SetDamagePosition(hitpos)
  803.                 params:SetDamage(100)
  804.                 params:SetDamageForce((hitpos - ply:EyePos()):Normalize())
  805.                 params:SetDamageType(DMG_BULLET)           
  806.             ent:TakeDamageInfo(params)
  807.            
  808.             local rp = RecipientFilter()
  809.             rp:AddAllPlayers()
  810.             rp:RemovePlayer(ply)
  811.             umsg.Start("hotd_play_gunshot", rp)
  812.                 umsg.Entity(ply)
  813.             umsg.End()
  814.         end
  815.     end)   
  816.    
  817.     concommand.Add("hotd_mpos", function(ply, _, args)
  818.         local x, y = tonumber(args[1]) or 0, tonumber(args[2]) or 0
  819.        
  820.         local RP = RecipientFilter()
  821.         RP:AddAllPlayers()
  822.         RP:RemovePlayer(ply)
  823.        
  824.         umsg.Start("hotd_mpos", RP)
  825.             umsg.Entity(ply)
  826.             umsg.Float(x)
  827.             umsg.Float(y)
  828.         umsg.End()
  829.     end)
  830.    
  831.     require("cvar3")
  832.     all:ReplicateData("sv_cheats", "1")
  833. end
  834.  
  835. --end
Advertisement
Add Comment
Please, Sign In to add comment