Guest User

Untitled

a guest
Feb 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.64 KB | None | 0 0
  1. ------------Allgemeine SWEP Informationen---------------
  2. SWEP.Contact         = ""
  3. SWEP.Purpose         = "Plug"              
  4. SWEP.Instructions    = "Basis SWEP!"    
  5. SWEP.Spawnable       = true            
  6. SWEP.AdminSpawnable  = true  
  7.  
  8. if SERVER then
  9.     AddCSLuaFile("cl_init.lua")
  10.     AddCSLuaFile("shared.lua")
  11.     SWEP.HoldType       = "pistol"
  12. end
  13.  
  14. if CLIENT then
  15.     SWEP.PrintName      = "plug_gun"  
  16.     SWEP.Author         = "Neutron"    
  17.     SWEP.Slot           = 2          
  18.     SWEP.SlotPos        = 1            
  19.     SWEP.ViewModelFOV   = 70
  20. end          
  21. -------------------------------------------------------------------
  22.  
  23. ------------Models---------------------------
  24. SWEP.ViewModel      = "models/weapons/v_pistol.mdl"
  25. SWEP.WorldModel   = "models/weapons/w_pistol.mdl"
  26. ----------------------------------------------
  27.  
  28. -------------Primäre SWEP Eigenschaften ( Linke Maustaste )------------------
  29. SWEP.Primary.Delay       = 0  
  30. SWEP.Primary.Recoil      = 0        
  31. SWEP.Primary.Damage      = 0
  32. SWEP.Primary.NumShots    = 0      
  33. SWEP.Primary.Cone        = 0    
  34. SWEP.Primary.ClipSize    = -1      
  35. SWEP.Primary.DefaultClip = -1        
  36. SWEP.Primary.Automatic   = false              
  37. SWEP.Primary.Ammo        = "none"  
  38. -----------------------------------------------------------------------------
  39.  
  40. -------------Sekundäre SWEP Eigenschaften ( Rechte Maustaste )---------------
  41. SWEP.Secondary.Delay        = 0
  42. SWEP.Secondary.Recoil       = 0
  43. SWEP.Secondary.Damage       = 0
  44. SWEP.Secondary.NumShots     = 0
  45. SWEP.Secondary.Cone         = 0
  46. SWEP.Secondary.ClipSize     = -1
  47. SWEP.Secondary.DefaultClip  = -1
  48. SWEP.Secondary.Automatic    = false
  49. SWEP.Secondary.Ammo         = "none"
  50.  
  51.  
  52. -----------------------Hauptfunktionen----------------------------
  53. SWEP.Creating = false
  54. SWEP.Ghost = NULL
  55.  
  56. function SWEP:Think()
  57.  
  58. if CLIENT then
  59.     if self.Owner ~= LocalPlayer() then return end
  60.  
  61.         if not self.Ghost:IsValid( ) then
  62.             self.Ghost = ents.Create("prop_physics")
  63.             self.Ghost:SetModel("models/props_lab/tpplugholder_single.mdl")
  64.             self.Ghost:SetOwner(self.Owner)
  65.         end
  66.        
  67.         local tr = {}
  68.         tr.start = self.Owner:GetShootPos()
  69.         tr.endpos = self.Owner:GetShootPos() + 200 * self.Owner:GetAimVector()
  70.         tr.filter = {self.Ghost, self.Owner}
  71.         local trace = util.TraceLine(tr)
  72.        
  73.         if not self.Ghost:IsValid() then return end
  74.  
  75.         local center = self.Ghost:LocalToWorld(self.Ghost:OBBCenter() + Vector(0,1,.6))
  76.         local pos = self.Ghost:GetPos()
  77.         local offset = center - pos
  78.         local PlugPos = trace.HitPos - offset
  79.        
  80.         RunConsoleCommand("SetPos", PlugPos)
  81.        
  82.         if trace.HitWorld then
  83.             self.Ghost:SetPos(PlugPos)
  84.             self.Ghost:SetAngles(trace.HitNormal:Angle())
  85.  
  86.             self.Ghost:SetColor(255, 255, 255, 100)
  87.         else
  88.             self.Ghost:SetColor(255, 255, 255, 0)
  89.         end
  90.        
  91.         if LocalPlayer():GetActiveWeapon():GetClass() != "plug_gun" then
  92.             self.Ghost:SetColor(0,0,0,0)
  93.         end
  94.     end
  95. end
  96.  
  97. function SWEP:PrimaryAttack()
  98.     if self.Creating then return end
  99.    
  100.     local trace = self.Owner:GetEyeTrace()
  101.     local Start = CurTime()
  102.     self.Owner:SetNWInt("Start", Start)
  103.     self.Creating = true
  104.     self.Owner:SetNWBool("Allow", true)
  105.    
  106.     if not trace.Hit then return end
  107.  
  108.     timer.Create("SpawnTimer", 15, 1, function() self:Create() end)
  109. end
  110.  
  111. function SWEP:SecondaryAttack()
  112.     return
  113. end    
  114.  
  115. function SWEP:Create()
  116.     local tr = {}
  117.     tr.start = self.Owner:GetShootPos()
  118.     tr.endpos = self.Owner:GetShootPos() + 200 * self.Owner:GetAimVector()
  119.     tr.filter = {self.Ghost, self.Owner}
  120.     local trace = util.TraceLine(tr)
  121.  
  122.     concommand.Add("SetPos", function(ply, cmd, args)
  123.         --if !ValidEntity(ply) then return end
  124.         --if !args[1] then return end
  125.         Position = args[1]
  126.         print(Position)
  127.     end)
  128.    
  129.     self.Plug = ents.Create("plug")
  130.     self.Plug:SetOwner(self.Owner)
  131.     self.Plug:SetAngles(trace.HitNormal:Angle())
  132.     self.Plug:SetColor(255,255,255,255)
  133.     self.Plug:SetPos(Position)
  134.     self.Plug:Spawn()
  135.     self.Creating = false
  136.     self.Owner:SetNWBool("Allow", false)
  137. end
  138.  
  139. function SWEP:Fail()
  140.     self.Creating = false
  141.     self.Owner:SetNWBool("Allow", false)
  142.     timer.Destroy("SpawnTimer")
  143. end
  144.  
  145. function SWEP:DrawHUD()
  146.     if self.Owner:GetNWBool("Allow") == true then
  147.         local time = 15
  148.         local curtime = CurTime() - self.Owner:GetNWInt("Start")
  149.         local status = curtime/time
  150.         local CreatingProgress = status * (ScrW() * 0.3)
  151.         local Progress = math.Clamp(CreatingProgress, 0, ScrW()*0.3)
  152.        
  153.         draw.RoundedBox(2, (ScrW() / 2) - ((ScrW()*0.3)/2), (ScrH() / 2) - 15, Progress, 30, Color(255-(status * 255), status * 255, 0, 255))
  154.         surface.SetDrawColor(100,100,100,255)
  155.         surface.DrawOutlinedRect((ScrW() / 2) - ((ScrW()*0.3)/2), (ScrH() / 2 - 16), ScrW()*0.3, 32)
  156.     end
  157. end
Add Comment
Please, Sign In to add comment