Python1320

Untitled

Sep 24th, 2010
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.75 KB | None | 0 0
  1. --[[
  2.     SHARED:
  3.         DEFINED:
  4.             ITEM:State = "both/weapon/entity"
  5.    
  6.         MISC:
  7.             ITEM:HOOK:Name(...)
  8.        
  9.         FUNCTIONS:
  10.             ITEM:GetTrace()
  11.             ITEM:GetInventoryInfo()
  12.            
  13.     CLIENT:
  14.         MENU:
  15.             ITEM:AddSimpleOption(name, function, ...)
  16.             ITEM:AddEquipOption()
  17.             ITEM:AddBackpackOption()
  18.             ITEM:AddDropOption()
  19.             ITEM:AddSpacer()
  20.             ITEM:AddCustomOption(function)
  21.             ITEM:CallOption(name, function, ...)
  22.             ITEM:MakeMenu()
  23.             ITEM:GetMenu()
  24.            
  25.         DATA:
  26.             ITEM:CallOnServer(...)
  27.             ITEM:ReceiveUserMessage(...)
  28.            
  29.         HOOKS:
  30.             ITEM:PreDraw()
  31.             ITEM:PostDraw()
  32.            
  33.     SERVER:
  34.         MENU:
  35.             ITEM:AllowOption(name, function)
  36.            
  37.         DATA:
  38.             ITEM:ReceiveFromClient(ply, ...)
  39.             ITEM:SendUserMessage(ply, ...)
  40.    
  41.         HOOKS:
  42.             ITEM:PreBackpack(ply)
  43.             ITEM:OnEquip(ply)
  44.             ITEM:PreDrop(ply)
  45.            
  46.         FUNCTIONS:
  47.             ITEM:SetSate(state)
  48.             ITEM:RemoveActiveItem()
  49.    
  50. ]]
  51.  
  52. items.StartItem("tesla_gun", nil, "weapon_base", "base_anim")
  53.  
  54.     -- ITEM.WorldModel      = "models/weapons/w_rocket_launcher.mdl"
  55.     -- ITEM.ViewModel           = "models/weapons/v_RPG.mdl"
  56.     ITEM.WorldModel         = "models/weapons/w_physics.mdl"
  57.     ITEM.ViewModel          = "models/weapons/v_superphyscannon.mdl"
  58.    
  59.     ITEM.PrintName          = "Tesla Gun"
  60.     ITEM.ViewModelFOV       = 50
  61.     ITEM.Instructions       = "Aim at the enemy"
  62.     ITEM.Slot               = 3
  63.     ITEM.State              = "both"
  64.  
  65.     ITEM.Inventory = {
  66.         name = "Tesla Gun",
  67.         info = [[
  68.             Gun that fires tesla?
  69.         ]],
  70.  
  71.     }
  72.  
  73.     function ITEM:Initialize()
  74.         self.DermaMenuOptions = {}
  75.         if CLIENT then
  76.            
  77.             self:AddBackpackOption()
  78.             self:AddEquipOption()
  79.            
  80.             self:AddSpacer()
  81.        
  82.             self:AddSimpleOption("Self Destruct", "StartTimer", LocalPlayer())
  83.             self:AddSimpleOption("Fire Primary", "PrimaryAttack")
  84.            
  85.             --self:SetModelScale(Vector()*1.5) HitBox failure
  86.         else
  87.             self:AllowOption("Self Destruct", "StartTimer")
  88.             self:AllowOption("Fire Primary", "PrimaryAttack")
  89.            
  90.             if not self:IsWeapon() then
  91.                 self:SetModel(  self.WorldModel )
  92.                 self:PhysicsInit( SOLID_VPHYSICS )
  93.                 self:SetMoveType( MOVETYPE_VPHYSICS )
  94.                 self:SetSolid( SOLID_VPHYSICS )
  95.                 self:PhysWake()
  96.                 self:SetSkin(1)
  97.             end
  98.         end
  99.  
  100.     end
  101.    
  102.     function ITEM:SecondaryAttack()
  103.    
  104.     end
  105.    
  106.     if SERVER then
  107.  
  108.         function ITEM:FireTesla()
  109.        
  110.             self.Owner:MuzzleFlash()
  111.             self.Owner:SetAnimation( PLAYER_ATTACK1 )
  112.  
  113.             self:EmitSound("ambient/levels/citadel/weapon_disintegrate1.wav")
  114.            
  115.             local tr = self:GetTrace()
  116.            
  117.             util.ScreenShake( tr.HitPos, 5, 50, 1, 100 )   
  118.        
  119.             local ent=ents.Create("point_tesla")
  120.            
  121.             ent:SetKeyValue("texture","models/effects/comball_sphere.vmt")
  122.             ent:SetKeyValue("m_flRadius" , "100")
  123.             ent:SetKeyValue("m_Color" , "255 255 255")
  124.             ent:SetKeyValue("beamcount_min" , "150")
  125.             ent:SetKeyValue("beamcount_max" , "150")
  126.             ent:SetKeyValue("thick_min" , "8")
  127.             ent:SetKeyValue("thick_max" , "20")
  128.             ent:SetKeyValue("lifetime_min" , "0.1")
  129.             ent:SetKeyValue("lifetime_max" , "0.2")
  130.             ent:SetKeyValue("interval_min" , "0.1")
  131.             ent:SetKeyValue("interval_max" , "0.1")
  132.            
  133.             ent:SetPos(tr.HitPos+tr.HitNormal*10)
  134.            
  135.             ent:Spawn()
  136.             ent:Activate()
  137.            
  138.             ent:EmitSound("ambient/energy/spark6.wav")
  139.             ent:Fire("DoSpark")
  140.             ent:Fire("Kill", 0.1)
  141.            
  142.             util.BlastDamage(self , self.Owner, ent:GetPos(), 100, 10)
  143.                
  144.         end
  145.  
  146.         function ITEM:PrimaryAttack()
  147.             if self:IsWeapon() then
  148.                 self:SetNextPrimaryFire( CurTime() + 0.1 )
  149.                 self:FireTesla()   
  150.             else
  151.                 self:FireTesla()
  152.             end
  153.            
  154.             self:SetNWBool("firing", true)
  155.            
  156.             timer.Create("TeslaGunPrimary"..self:EntIndex(), 0.1, 1, function()
  157.                 self:SetNWBool("firing", false)
  158.             end)
  159.         end
  160.  
  161.         function ITEM:Explode(ply)         
  162.             local ent = ents.Create("point_tesla")
  163.            
  164.             ent:SetKeyValue("texture","models/effects/comball_sphere.vmt")
  165.             ent:SetKeyValue("m_flRadius" , "5000")
  166.             ent:SetKeyValue("m_Color" , "255 255 255")
  167.             ent:SetKeyValue("beamcount_min" , "1000")
  168.             ent:SetKeyValue("beamcount_max" , "1000")
  169.             ent:SetKeyValue("thick_min" , "15")
  170.             ent:SetKeyValue("thick_max" , "20")
  171.             ent:SetKeyValue("lifetime_min" , "0.1")
  172.             ent:SetKeyValue("lifetime_max" , "0.2")
  173.             ent:SetKeyValue("interval_min" , "0.1")
  174.             ent:SetKeyValue("interval_max" , "0.1")
  175.            
  176.             ent:SetPos(self:GetPos()+Vector(0,0,50))
  177.            
  178.             ent:Spawn()
  179.             ent:Activate()
  180.            
  181.             ent:EmitSound("ambient/explosions/explode_7.wav")
  182.            
  183.             ent:Fire("DoSpark")
  184.             ent:Fire("Kill", "", 0.3)
  185.            
  186.             util.ScreenShake( self:GetPos(), 50, 5, 3, 5000 )
  187.             util.BlastDamage(self , ply, ent:GetPos(), 4500, 5000)
  188.            
  189.             self:Remove()
  190.         end
  191.        
  192.         function ITEM:StartTimer(ply)
  193.            
  194.             self:SendUserMessage("StartTimer")
  195.            
  196.             local count = 10
  197.             self:SetNWBool("Counting", true)
  198.             local index = self:EntIndex()
  199.             timer.Create("tesla_gun_countdown: " .. self:EntIndex(), 1, 10, function()
  200.                 count = count - 1
  201.                
  202.                 if count == 0 then
  203.                     self:Explode(ply)
  204.                 elseif not IsValid(self) then
  205.                     timer.Remove("tesla_gun_countdown: " .. index)
  206.                 end
  207.             end)
  208.         end
  209.        
  210.         function ITEM:RemoveFunctionByName(name)
  211.             self.DermaMenuOptions[name] = nil
  212.         end
  213.        
  214.     else
  215.    
  216.         function ITEM:ReceiveUserMessage(value)
  217.             if value == "StartTimer" then self:RemoveFunctionByName("Self Destruct") end
  218.            
  219.             self.count = 10
  220.             local index = self:EntIndex()
  221.             timer.Create("tesla_gun_countdown: " .. index, 1, 10, function()
  222.                 if IsValid(self) then
  223.                     self.count = self.count - 1            
  224.                 else
  225.                     timer.Remove("tesla_gun_countdown: " .. index)
  226.                 end
  227.             end)
  228.         end
  229.    
  230.         function ITEM:RemoveFunctionByName(name)
  231.             for key, data in pairs(self.DermaMenuOptions) do
  232.                 if type(data) == "table" and data.name == name then
  233.                     self.DermaMenuOptions[key] = nil
  234.                     break
  235.                 end
  236.             end
  237.         end
  238.        
  239.         function ITEM:PrimaryAttack()
  240.             self:SetNextPrimaryFire( CurTime() + 0.2 )     
  241.             self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  242.             self.Owner:MuzzleFlash()
  243.             self.Owner:SetAnimation( PLAYER_ATTACK1 )
  244.         end
  245.        
  246.         local beam_mat = Material("models/effects/splodearc_sheet")
  247.        
  248.         function ITEM.HOOK:PostDrawOpaqueRenderables()
  249.  
  250.             if self:GetNWBool("Counting") then
  251.                 cam.Start3D2D( self:GetPos()+Vector( 0, 0, 20 )+LocalPlayer():EyeAngles():Up(), Angle( 0, LocalPlayer():EyeAngles().y-90, 90) , 1 )
  252.                         draw.DrawText(self.count, "ScoreboardText", 0, 0, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER )
  253.                 cam.End3D2D()  
  254.             end
  255.            
  256.             if not self:GetNWBool("firing") then return end
  257.            
  258.             if self:IsWeapon() then
  259.                 start_pos = self.Owner:GetShootPos()+self.Owner:EyeAngles():Forward()*40+self.Owner:EyeAngles():Up()*-6+self.Owner:EyeAngles():Right()*6
  260.             else
  261.                 start_pos = self:GetPos()
  262.             end
  263.            
  264.             --local start_pos = self:GetAttachment(self:LookupAttachment("Muzzle")).Pos
  265.            
  266.             local end_pos = self:GetTrace().HitPos
  267.             local dir = ( end_pos - start_pos )
  268.             local increment = dir:Length() / 30
  269.            
  270.             dir:Normalize()
  271.            
  272.             render.SetMaterial( beam_mat )
  273.             render.StartBeam( 14 )
  274.                 render.AddBeam(
  275.                     start_pos,         
  276.                     10,            
  277.                     CurTime(),             
  278.                     Color( 64, 255, 64, 255 )      
  279.                     )
  280.                
  281.                 local i
  282.                
  283.                 for i = 1, 12 do
  284.                     local point = ( start_pos + dir * ( i * increment ) ) + VectorRand() * math.random( 1, 16 )
  285.                     local tcoord = CurTime() + ( 1 / 12 ) * i
  286.                     render.AddBeam(
  287.                         point,
  288.                         10,
  289.                         tcoord,
  290.                         Color( 64, 255, 64, 255 )
  291.                     )
  292.                 end
  293.                
  294.                 render.AddBeam(
  295.                     end_pos,
  296.                     10,
  297.                     CurTime() + 1,
  298.                     Color( 64, 255, 64, 255 )
  299.                 )
  300.             render.EndBeam()
  301.         end
  302.        
  303.         function ITEM:DrawInBackPack(model, position, angles)
  304.             model:SetPos(position+Vector(0,0,20))
  305.             angles:RotateAroundAxis(angles:Forward(), 150)
  306.             model:SetAngles(angles)
  307.             model:DrawModel()
  308.         end
  309.  
  310.     end
  311.  
  312. items.EndItem()
  313.  
  314. if SERVER then
  315.  
  316.     items.EasyCreate("tesla_gun", nero.GetPlayer("caps"))
  317.  
  318. end
Advertisement
Add Comment
Please, Sign In to add comment