mattjeanes

Dr. Matt - Adv Core Base - V3.0

Oct 24th, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.92 KB | None | 0 0
  1. -- The advanced base core, only use if you are a MORE ADVANCED PERSON! Thank you, Dr. Matt.
  2. ENT.Type = "anim"
  3. ENT.Base = "base_gmodentity"
  4. /*---------------------------------------------------------
  5.     START EDITABLE AREA
  6. ---------------------------------------------------------*/
  7. ENT.PrintName       = "Adv Base Core" -- The name the Core will come up as in the Spawnmenu
  8. ENT.Author          = "Matt J" -- Self Explanatory, The author of the addon, AKA Your name.
  9. ENT.Contact         = "Facepunch (MattJeanes)" -- Your contact, Perhaps an email address or a Steam username
  10. ENT.Purpose         = "This is what I do!" -- The purpose of the entity
  11. ENT.Instructions    = "Instruct me!" -- The instructions of the entity, Perhaps "Insert 1 chocolate cookie to activate."
  12. ENT.Category        = "Portal 2 Cores"
  13. ENT.Animation       = "sphere_idle_happy" -- Set's the animation of the core, Look in Portal 2 Authoring Tools for more info.
  14. ENT.Dir             = "base" -- The name of your sub-folder, must be 4 characters.
  15. ENT.ModelPath       = "models/cores/base/core.mdl"
  16. ENT.MusicCore       = false
  17. ENT.AutomaticFrameAdvance = true
  18. if ( CLIENT ) then
  19.  
  20.     function ENT:Draw()
  21.         self.Entity:DrawModel()
  22.     end
  23.    
  24. elseif ( SERVER ) then
  25.  
  26.     AddCSLuaFile()
  27.    
  28.    
  29.    
  30.     // This is the spawn function. It's called when a client calls the entity to be spawned.
  31.     // If you want to make your SENT spawnable you need one of these functions to properly create the entity
  32.     //
  33.     // ply is the name of the player that is spawning it
  34.     // tr is the trace from the player's eyes
  35.     //
  36.     function ENT:SpawnFunction( ply, tr )
  37.  
  38.         if ( !tr.Hit ) then return end
  39.        
  40.         local SpawnPos = tr.HitPos + tr.HitNormal * 16
  41.        
  42.         local ent = ents.Create( ClassName )
  43.         ent:SetPos( SpawnPos )
  44.         ent:Spawn()
  45.         ent:Activate()
  46.        
  47.         return ent
  48.        
  49.     end
  50.  
  51.     /*---------------------------------------------------------
  52.        Name: Initialize
  53.     ---------------------------------------------------------*/
  54.     function ENT:Initialize()
  55.    
  56.         self.SayTimer = CurTime()
  57.         self.Entity:SetModel( self.ModelPath )
  58.         //self.Entity:SetModel( "models/cores/basecore.mdl" )
  59.         local anim = self.Entity:LookupSequence(self.Animation)
  60.         self.Entity:ResetSequence(anim)
  61.         self.Entity:PhysicsInit( SOLID_VPHYSICS )
  62.         self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
  63.         self.Entity:SetSolid( SOLID_VPHYSICS )
  64.         if (self.AnimSpeed) then
  65.             self.Entity:SetPlaybackRate(self.AnimSpeed)
  66.         end
  67.         if (self.Skin) then
  68.             self.Entity:SetSkin(self.Skin)
  69.         end
  70.  
  71.         local phys = self.Entity:GetPhysicsObject()
  72.         if (phys:IsValid()) then
  73.             phys:Wake()
  74.         end
  75.        
  76.         self.Sounds = {}
  77.         self.SoundLengths = {}
  78.         self.Sounds1 = file.Find( "sound/cores/".. self.Dir .. "/*", "GAME" )
  79.        
  80.         if #self.Sounds1 > 1 and self.MusicCore then
  81.             print("ERROR: Too many sounds for a Music-based Core! - Only 1 sound please!")
  82.         elseif #self.Sounds1 == 1 and self.MusicCore then
  83.             self.MusicSound = "cores/".. self.Dir .. "/".. self.Sounds1[1]
  84.             util.PrecacheSound(self.MusicSound)
  85.             self.Music = CreateSound(self.Entity, self.MusicSound )
  86.             self.Music:Play()
  87.         end
  88.  
  89.         if not self.MusicCore then
  90.             for k,v in ipairs(self.Sounds1) do
  91.                 table.insert(self.Sounds, "cores/".. self.Dir .. "/".. v)
  92.             end
  93.            
  94.             for k,v in pairs(self.Sounds) do
  95.                 util.PrecacheSound(v) -- Precaches all the ENT.Sounds1 for use.
  96.                 table.insert(self.SoundLengths, SoundDuration(v)) -- New! This automatically get's the sound lengths to eliminate a lot of time and effort!
  97.             end
  98.         end
  99.        
  100.         local f = file.Open( "sound/cores/"..self.Dir.."/special/dmg.wav", "r", "GAME" )
  101.         if ( f ) then self.DmgSound = true f:Close() end
  102.        
  103.         local f = file.Open( "sound/cores/"..self.Dir.."/special/use.wav", "r", "GAME" )
  104.         if ( f ) then self.UseSound = true f:Close() end
  105.        
  106.        
  107.         local f = file.Open( "sound/cores/"..self.Dir.."/special/undo.wav", "r", "GAME" )
  108.         if ( f ) then self.UndoSound = true f:Close() end
  109.        
  110.         local f = nil
  111.        
  112.         if #self.Sounds1 == 0 then
  113.             print("WARNING: No sounds are included with the core, expect errors!")
  114.         end
  115.        
  116.         self.CustomInitialize(self)
  117.        
  118.     end
  119.    
  120.     function ENT.CustomInitialize()
  121.         // This function is empty, and may be overridden by the core itself.
  122.     end
  123.     /*---------------------------------------------------------
  124.        Name: PhysicsCollide
  125.     ---------------------------------------------------------*/
  126.     function ENT:PhysicsCollide( data, physobj )
  127.         //Nothing here
  128.     end
  129.  
  130.     /*---------------------------------------------------------
  131.        Name: OnTakeDamage
  132.     ---------------------------------------------------------*/
  133.     function ENT:OnTakeDamage( dmginfo )
  134.         local snd = "cores/"..self.Dir.."/special/dmg.wav"
  135.         if self.DmgSound then
  136.             self.Entity:EmitSound(snd)
  137.         end
  138.     end
  139.  
  140.  
  141.     /*---------------------------------------------------------
  142.        Name: Use
  143.     ---------------------------------------------------------*/
  144.     function ENT:Use( activator, caller, Player )
  145.         local snd = "cores/"..self.Dir.."/special/use.wav"
  146.         if self.UseSound then
  147.             self.Entity:EmitSound(snd)
  148.         end
  149.     end
  150.  
  151.     /*---------------------------------------------------------
  152.        Name: OnRemove
  153.     ---------------------------------------------------------*/
  154.     function ENT:OnRemove( )
  155.         local snd = "cores/"..self.Dir.."/special/undo.wav"
  156.         if self.UndoSound then
  157.             self.Entity:EmitSound(snd)
  158.         end
  159.         if self.MusicCore then
  160.             self.Music:Stop()
  161.         end
  162.     end
  163.  
  164.     /*---------------------------------------------------------
  165.        Name: Think
  166.     ---------------------------------------------------------*/
  167.  
  168.     local LastRandom = 0
  169.    
  170.     function ENT:Think()
  171.         if not self.Playing and not self.MusicCore then
  172.             local r = math.Round(math.random(1,#self.Sounds))
  173.             if r == self.LastRandom then
  174.                 r = math.Round(math.random(1,#self.Sounds))
  175.             end
  176.             self.LastRandom = r
  177.             self.Entity:EmitSound(self.Sounds[r])
  178.             self.Playing = true
  179.             timer.Simple(self.SoundLengths[r] + self.Delay, function()
  180.                 self.Playing = false
  181.             end)
  182.         end
  183.         self:NextThink( CurTime() + 0.1 )
  184.         return true
  185.     end
  186. end
Advertisement
Add Comment
Please, Sign In to add comment