Python1320

Untitled

Sep 21st, 2010
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.66 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") -- Not sure how I should do this (if it's a neat way)
  53.  
  54.     -- The world model is used by entity and weapon
  55.     ITEM.WorldModel = "models/weapons/w_rocket_launcher.mdl"
  56.     ITEM.ViewModel = "models/weapons/v_RPG.mdl"
  57.     ITEM.PrintName = "Tesla Gun"
  58.    
  59.     -- "both" means that the item is a weapon when equiped, and an entity when it's on ground
  60.     ITEM.State = "both"
  61.  
  62.     ITEM.Inventory = {
  63.         name = "Tesla Gun",
  64.         info = [[
  65.             Gun that fires tesla?
  66.         ]],
  67.  
  68.     }
  69.  
  70.     function ITEM:Initialize()
  71.         -- Don't really need this, it's just for constant reloading (I'm runstringing this) so the menu doesn't stack up
  72.         self.DermaMenuOptions = {}
  73.  
  74.         if CLIENT then
  75.            
  76.             self:AddBackpackOption()
  77.             self:AddEquipOption()
  78.            
  79.             self:AddSpacer()
  80.            
  81.             -- First argument is the label in the menu, second is the function name we're going to call when it's selected
  82.             self:AddSimpleOption("SelfDestruct", "Exp")
  83.  
  84.             self:AddSimpleOption("Fire Primary", "PrimaryAttack")
  85.         else
  86.             self:AllowOption("SelfDestruct", "Exp")
  87.         --  self:AllowOption("Fire Secondary", "SecondaryAttack")
  88.             self:AllowOption("Fire Primary", "PrimaryAttack")
  89.         --  self:AllowOption("Spawn Random", "MakeEnt")
  90.  
  91.             -- Only do this if it's not a weapon
  92.             if not self:IsWeapon() then
  93.                 self:SetModel(  self.WorldModel )
  94.                 self:PhysicsInit( SOLID_VPHYSICS )
  95.                 self:SetMoveType( MOVETYPE_VPHYSICS )
  96.                 self:SetSolid( SOLID_VPHYSICS )
  97.                 self:PhysWake()
  98.             end
  99.         end
  100.  
  101.     end
  102.  
  103.     if SERVER then
  104.  
  105.         function ITEM:MakeEnt(class)
  106.             self.Owner:MuzzleFlash()
  107.             self.Owner:SetAnimation( PLAYER_ATTACK1 )
  108.             self.Owner:EmitSound("ambient/levels/citadel/weapon_disintegrate1.wav")
  109.             self.Owner:ViewPunch(Angle( -5, 0, 0 ))
  110.            
  111.             local tr = self:GetTrace() -- This returns GetEyeTrace if it's held, and a custom trace if it's not held
  112.            
  113.             util.ScreenShake( tr.HitPos+tr.HitNormal*10, 5, 50, 1, 100 )       
  114.  
  115.             local ent=ents.Create(class)
  116.             ent:SetKeyValue("texture","models/effects/comball_sphere.vmt")
  117.             ent:SetKeyValue("m_flRadius" , "100")
  118.             ent:SetKeyValue("m_Color" , "255 255 255")
  119.             ent:SetKeyValue("beamcount_min" , "150")
  120.             ent:SetKeyValue("beamcount_max" , "150")
  121.             ent:SetKeyValue("thick_min" , "8")
  122.             ent:SetKeyValue("thick_max" , "20")
  123.             ent:SetKeyValue("lifetime_min" , "0.1")
  124.             ent:SetKeyValue("lifetime_max" , "0.2")
  125.             ent:SetKeyValue("interval_min" , "0.1")
  126.             ent:SetKeyValue("interval_max" , "0.1")
  127.             ent:SetPos(tr.HitPos+tr.HitNormal*10)
  128.             ent:Spawn()
  129.             ent:Activate()
  130.             ent:EmitSound("ambient/energy/spark6.wav")
  131.             ent:Fire"DoSpark"
  132.             util.BlastDamage(self , self.Owner, ent:GetPos(), 100, 10)
  133.             timer.Simple(0.1,function()
  134.                 if ent:IsValid() then
  135.                     ent:Remove()
  136.                 end
  137.             end)
  138.            
  139.             local effect = EffectData()
  140.             effect:SetStart(self.Owner:GetShootPos())
  141.             effect:SetEntity(ent)
  142.             effect:SetOrigin(tr.HitPos)
  143.             effect:SetAngle(self.Owner:EyeAngles())
  144.             util.Effect( "TeslaZap", effect )
  145.             util.Effect("CommandPointer", effect ) 
  146.            
  147.            
  148.         end
  149.  
  150.         function ITEM:PrimaryAttack()
  151.                 if self:IsWeapon() then
  152.                     self.Weapon:SetNextPrimaryFire( CurTime() + 0.2 )
  153.                     self:MakeEnt("point_tesla")
  154.                 else
  155.                     self:MakeEnt("point_tesla")
  156.                 end
  157.         end
  158.  
  159.         function ITEM:Exp()
  160.                     local ent2=ents.Create("point_tesla")
  161.                     ent2:SetKeyValue("texture","models/effects/comball_sphere.vmt")
  162.                     ent2:SetKeyValue("m_flRadius" , "5000")
  163.                     ent2:SetKeyValue("m_Color" , "255 255 255")
  164.                     ent2:SetKeyValue("beamcount_min" , "1000")
  165.                     ent2:SetKeyValue("beamcount_max" , "1000")
  166.                     ent2:SetKeyValue("thick_min" , "15")
  167.                     ent2:SetKeyValue("thick_max" , "20")
  168.                     ent2:SetKeyValue("lifetime_min" , "0.1")
  169.                     ent2:SetKeyValue("lifetime_max" , "0.2")
  170.                     ent2:SetKeyValue("interval_min" , "0.1")
  171.                     ent2:SetKeyValue("interval_max" , "0.1")
  172.                     ent2:SetPos(self:GetPos()+Vector(0,0,50))
  173.                     ent2:Spawn()
  174.                     ent2:Activate()
  175.                     ent2:EmitSound("ambient/explosions/explode_7.wav")
  176.                     ent2:Fire"DoSpark"
  177.                     util.ScreenShake( self:GetPos(), 50, 5, 3, 5000 )
  178.                     util.BlastDamage(self , self.Owner, ent2:GetPos(), 4500, 5000)
  179.                     self:Remove()
  180.             timer.Simple(0.1,function()
  181.                 if ent2:IsValid() then
  182.                     ent2:Remove()
  183.                 end
  184.             end)
  185.         end
  186.  
  187.     else
  188.  
  189.         function ITEM:PrimaryAttack()
  190.             self.Weapon:SetNextPrimaryFire( CurTime() + 0.2 )
  191.            
  192.             self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  193.             self.Owner:MuzzleFlash()
  194.             self.Owner:SetAnimation( PLAYER_ATTACK1 )
  195.            
  196.             sekf.firing = true
  197.            
  198.             timer.Create("TeslaGunPrimary"..self:EntIndex(), 0.2, 0, function()
  199.                 self.firing = false
  200.             end)
  201.         end
  202.        
  203.         function ITEM.HOOK:PostDrawOpaqueRenderables()
  204.             if not self.firing then return end
  205.        
  206.             start_pos = self:GetPos();
  207.             end_pos = LocalPlayer():GetTrace().HitPos
  208.             dir = ( end_pos - start_pos );
  209.             increment = dir:Length() / 12;
  210.             dir:Normalize();
  211.             render.SetMaterial( Material("models/effects/comball_sphere.vmt") );
  212.             render.StartBeam( 14 );
  213.             render.AddBeam(
  214.                 start_pos,         
  215.                 5,             
  216.                 CurTime(),             
  217.                 Color( 64, 255, 64, 255 )      
  218.                 );
  219.             local i;
  220.             for i = 1, 12 do
  221.                 local point = ( start_pos + dir * ( i * increment ) ) + VectorRand() * math.random( 1, 16 );
  222.                 local tcoord = CurTime() + ( 1 / 12 ) * i;
  223.                 render.AddBeam(
  224.                     point,
  225.                     5,
  226.                     tcoord,
  227.                     Color( 64, 255, 64, 255 )
  228.                 );
  229.             end
  230.             render.AddBeam(
  231.                 end_pos,
  232.                 5,
  233.                 CurTime() + 1,
  234.                 Color( 64, 255, 64, 255 )
  235.             );
  236.             render.EndBeam();
  237.         end
  238.        
  239.         function ITEM:DrawInBackPack(model, position, angles)
  240.             model:SetPos(position+Vector(0,0,20))
  241.             angles:RotateAroundAxis(angles:Forward(), 150)
  242.             model:SetAngles(angles)
  243.             model:DrawModel()
  244.         end
  245.  
  246.     end
  247.  
  248. items.EndItem()
  249.  
  250. if SERVER then
  251.  
  252.     items.EasyCreate("tesla_gun", nero.GetPlayer("mare"))
  253.  
  254. end
Add Comment
Please, Sign In to add comment