Advertisement
Guest User

init.lua

a guest
Feb 10th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.88 KB | None | 0 0
  1. AddCSLuaFile( "cl_init.lua" )
  2. AddCSLuaFile( "shared.lua" )
  3.  
  4. include('entities/base_wire_entity/init.lua');
  5. include('shared.lua')
  6.  
  7. util.PrecacheSound("LightDemon/tardis.wav")
  8. util.PrecacheModel("Models/The_Sniper_9/DoctorWho/Tardis/tardis.mdl")
  9. local tardis = Model("Models/The_Sniper_9/DoctorWho/Tardis/tardis.mdl")
  10.  
  11. function ENT:Initialize()  
  12.  
  13.     self.Entity:SetModel( tardis )  
  14.     self.Entity:PhysicsInit( SOLID_VPHYSICS )      -- Make us work with physics,   
  15.     self.Entity:SetMoveType( MOVETYPE_VPHYSICS )   --after all, gmod is a physics  
  16.     self.Entity:SetSolid( SOLID_VPHYSICS )        -- Toolbox    
  17.     self.X = 0
  18.     self.Y = 0
  19.     self.Z = 0
  20.     self.Za = 0
  21.     self.Fade = 255
  22.     self.Target = Vector(0,0,0)    
  23.     self.num = 255 
  24.     self.phys2 = self.Entity:GetPhysicsObject()  
  25.     self.In = false
  26.     self.Pilot = nil
  27.     self.Fading = 0
  28.     self.FadeTime = 10
  29.     self.NextTime = CurTime()
  30.     self:SpawnProp()
  31.     self.Light = SpawnLight( self.PropTardis )
  32.     self.Light:Fire("hidesprite","",0)
  33.     self:SetNWInt("health",300)
  34.     self:StartMotionController()
  35.     self:SetColor(Color(255,255,255,0))
  36.     self.Accel={FWD=0,RIGHT=0,UP=0}
  37.     if (self.phys2:IsValid()) then         
  38.         self.phys2:Wake()
  39.     end
  40.     self.Inputs = Wire_CreateInputs( self.Entity, { "Dematerilize", "X", "Y", "Z"} )
  41. end  
  42.  
  43. function ENT:SpawnFunction( ply, tr)
  44.    
  45.     if ( !tr.Hit ) then return end
  46.    
  47.     local ent = ents.Create( "tardis" )
  48.     ent:SetPos( tr.HitPos + Vector(0,0,2) )
  49.     ent:Spawn("tardis")
  50.     ent:Activate()
  51.     ent:SetVar("Owner",ply)
  52.     return ent
  53.  
  54. end
  55.  
  56. function ENT:Think()
  57.    
  58.     self.Za = self.Z +10
  59.    
  60.     if self.Shifting then
  61.        
  62.         if not self.Remote then
  63.             self.Target = Vector(self.X, self.Y, self.Za)
  64.         end
  65.         for _,v in pairs(ents.FindInSphere(self:GetPos(),150)) do
  66.             if IsValid(v and v:GetPhysicsObject()) then
  67.                 v:GetPhysicsObject():ApplyForceCenter(Vector(100,100,100))
  68.             end
  69.         end
  70.        
  71.        
  72.         if self.Shifted then
  73.             self.FadeTime = math.Approach(self.FadeTime, 35, 1)
  74.             if self.Fading == 1 then
  75.                 self.Fade = math.Approach(self.Fade, 0, self.FadeTime)
  76.                 self.Fading = 1
  77.             elseif self.Fading == 2 then
  78.                 self.Fade = math.Approach(self.Fade, 255, self.FadeTime)
  79.                 self.Fading = 2
  80.             end
  81.         else
  82.             self.Fade = math.Approach(self.Fade,0,10)
  83.         end
  84.     end
  85.    
  86.     if self.CanShift then
  87.         if(self.Fade==0) then
  88.             self.Entity:SetPos(self.Target)
  89.             self:SetAngles(Angle(0,0,0))
  90.             self.PropTardis:SetAngles(Angle(0,0,0))        
  91.             self.CanShift = false
  92.             self.Shifted = true
  93.         end
  94.     end
  95.    
  96.     if self.Fading == 1 and self.Fade == 0 then
  97.         self.Fading = 2
  98.     elseif self.Fading == 2 and self.Fade == 255 then
  99.         self.Fading = 1
  100.     end
  101.    
  102.     if not self.Shifting and self.Fade == 255 then
  103.         self.Fading = 0
  104.         self.FadeTime = 10
  105.         self.Shifted = false
  106.     elseif not self.Shifting and self.Fade < 255 then
  107.         self.Fade = math.Approach(self.Fade, 255, 50)
  108.     end
  109.  
  110.     self.PropTardis:SetColor(Color(255,255,255,self.Fade))
  111.    
  112.     if not IsValid(self.Pilot) then self.Pilot=nil self.In=false end
  113.     if self.In and IsValid(self.Pilot) then
  114.         self.Pilot:SetPos(self.Entity:GetPos())
  115.         if self.Pilot:KeyDown(IN_USE) and self.NextTime < CurTime() then
  116.             self:ExitTARDIS()
  117.         elseif self.Pilot:KeyDown(IN_RELOAD) and self.NextTime < CurTime() then
  118.             self:ToggleFlight()
  119.         end
  120.     end
  121. end
  122.  
  123. function ENT:ToggleFlight()
  124.  
  125.     if not IsValid(self and self.PropTardis) then return end
  126.     if self.Shifting then return end
  127.     if not( self.NextTime < CurTime() ) then return end
  128.    
  129.     if not self.Flightmode then
  130.         self.Flightmode = true
  131.         self.Pilot:ChatPrint("Flightmode On")
  132.         self.Light:Fire("showsprite","",0) -- Show the light when in flight
  133.         self.Hover = true
  134.         self.phys2:ApplyForceCenter(Vector(1,1,1))
  135.     else
  136.         self.Flightmode = false
  137.         self.Pilot:ChatPrint("Flightmode Off")
  138.         self.Light:Fire("hidesprite","",0) -- Turn off the light
  139.         self.Hover = false
  140.         self.Accel={FWD=0,RIGHT=0,UP=0} -- Reset acceleration
  141.         self.SpinAccel = 0
  142.     end
  143.     self:SetAngles(Angle(0,0,0))
  144.     self.PropTardis:SetAngles(self:GetAngles())
  145. end
  146.  
  147. function ENT:ExitTARDIS()
  148.  
  149.     self.Pilot:UnSpectate()
  150.     self.Pilot:DrawViewModel(true)
  151.     self.Pilot:DrawWorldModel(true)
  152.     self.Pilot:Spawn()
  153.     self.Pilot:SetNetworkedBool("isDriveTardis",false)
  154.     self.Pilot:SetPos(self.Entity:GetPos()+self:GetForward()*60)
  155.     self.Pilot:SetHealth(self.PHealth)
  156.     for k,v in pairs(self.weps) do
  157.         self.Pilot:Give(tostring(v))
  158.     end
  159.     self.In=false
  160.     self.Pilot:CrosshairDisable(false)
  161.     self.Pilot:CrosshairEnable(true)
  162.     self.Pilot=nil
  163.     self.NextTime = CurTime() + 1
  164.     self.SpinAccel = 0
  165.     self.Accel = {FWD=0,RIGHT=0,UP=0}  
  166.     if self.Flightmode then
  167.         self.Light:Fire("hidesprite","",0)
  168.         self:SetAngles(Angle(0,0,0))
  169.         self.PropTardis:SetAngles(self:GetAngles())    
  170.     end
  171. end
  172.  
  173. function ENT:TriggerInput(k, v)
  174.     if(k=="Dematerilize") then
  175.         if(v >= 1) then
  176.             self:Shift()
  177.         end
  178.     elseif(k=="X") then
  179.         self.X = v
  180.         self.Remote = false
  181.     elseif(k=="Y") then
  182.         self.Y = v
  183.         self.Remote = false
  184.     elseif(k=="Z") then
  185.         self.Z = v
  186.         self.Remote = false
  187.     end
  188. end
  189.  
  190.  
  191. function ENT:LockTardis(lock)
  192.  
  193.     if lock then
  194.         self.Locked = true
  195.     else
  196.         self.Locked = false
  197.     end
  198. end
  199.  
  200. function ENT:Shift()
  201.  
  202.     if self.Shifting then return end -- So we can't dematerialize twice
  203.     if self.Locked then return end -- If were locked we can't move.
  204.    
  205.     if not self.Flightmode then
  206.    
  207.         self.Light:Fire("showsprite","",0)
  208.         self.Light:Fire("hidesprite","",14)
  209.         self.Flash = true
  210.         self.Shifting = true
  211.         self.Fading = 1
  212.         self.Entity:EmitSound( "LightDemon/tardis.wav", 500, math.Rand(95,105))
  213.         self.PropTardis:PhysicsInit( SOLID_VPHYSICS ) -- Turns out using PhysicsInit screws everything up, so I'm using this now. **EDIT 10/02/2013** Made it use PhysicsInit again. Works so far!
  214.        
  215.         timer.Simple(5, function ()
  216.             if not IsValid(self) then return end
  217.             self.CanShift = true
  218.         end)
  219.         timer.Simple(14, function ()
  220.             if not IsValid(self) then return end
  221.             self.Flash = false
  222.             self.Shifting = false
  223.             self:SetCollisionGroup(0)
  224.         end)
  225.     end
  226. end
  227.  
  228. function ENT:Use(ply,caller)
  229.     if not self.In and self.NextTime < CurTime() then
  230.         self:EnterTARDIS(ply)
  231.     end
  232. end
  233.  
  234. function ENT:EnterTARDIS(ply)
  235.  
  236.     if self.Locked then return end -- If were locked we can't get in
  237.  
  238.     self.In=true
  239.     self.Pilot=ply
  240.     self.weps = {}
  241.     for k,v in pairs(ply:GetWeapons()) do
  242.         table.insert(self.weps, v:GetClass())
  243.     end
  244.     self.PHealth = ply:Health()
  245.     ply:Spectate( OBS_MODE_ROAMING )
  246.     ply:StripWeapons()
  247.     ply:DrawWorldModel(false)
  248.     ply:DrawViewModel(false)
  249.     ply:SetNetworkedBool("isDriveTardis",true)
  250.     ply:SetNetworkedEntity("Tardis",self.Entity)
  251.     ply:CrosshairDisable(true)
  252.     self.NextTime = CurTime() + 1
  253.     if self.Flightmode then
  254.         self.Light:Fire("showsprite","",0)
  255.     end
  256. end
  257.  
  258. function SpawnLight( ent )
  259.     local  Light = ents.Create("env_sprite")
  260.     Light:SetPos(ent:GetPos() + ent:GetUp() * 113)
  261.     Light:SetAngles(ent:GetAngles())
  262.     Light:SetKeyValue("renderfx", 4)
  263.     Light:SetKeyValue("rendermode", 3)
  264.     Light:SetKeyValue("renderamt", "200")
  265.     Light:SetKeyValue("rendercolor", "255 255 255")
  266.     Light:SetKeyValue("model", "sprites/light_glow02.spr")
  267.     Light:SetKeyValue("scale", 1)
  268.     Light:SetKeyValue("glowproxysize", 9)
  269.     Light:Spawn()
  270.     Light:SetParent(ent)
  271.    
  272.     return Light
  273. end
  274.  
  275. function ENT:OnRemove(p)
  276.     if not IsValid(self.Pilot) then return end
  277.     self.Pilot:UnSpectate()
  278.     self.Pilot:DrawViewModel(true)
  279.     self.Pilot:DrawWorldModel(true)
  280.     self.Pilot:Spawn()
  281.     self.Pilot:SetNetworkedBool("isDriveTardis",false)
  282.     self.Pilot:SetPos(self.Entity:GetPos()+self:GetForward()*10+self:GetRight()*10)
  283.     self:StopSound("LightDemon/tardis.wav")
  284.     self.In=false
  285.     self.Pilot=nil
  286. end
  287.  
  288. function ENT:OnTakeDamage(dmg)   --######### @ RononDex,Catdaemon
  289.    
  290.     if not self.Done then
  291.         local health=self:GetNetworkedInt("health")
  292.         self:SetNetworkedInt("health",health-dmg:GetDamage())
  293.  
  294.         if health<=1 then
  295.             self:GoBoom()
  296.             self:SetNetworkedBool("isDriveTardis",false)
  297.             self:SetNetworkedEntity("Tardis",NULL)
  298.             self.Done=true
  299.         end
  300.     end
  301. end
  302.  
  303. function ENT:SpawnProp()
  304.  
  305.     if IsValid(self) then
  306.         local e = ents.Create("prop_physics")
  307.         e:SetModel(tardis)
  308.         e:SetPos(self:GetPos())
  309.         e:SetAngles(self:GetAngles())
  310.         e:Spawn()
  311.         e:Activate()
  312.         e:SetParent(self)
  313.         e:SetSolid(SOLID_NONE)
  314.         e:GetPhysicsObject():Wake()
  315.         e:GetPhysicsObject():SetMass(1)
  316.         self.PropTardis = e
  317.     end
  318. end
  319.  
  320. function ENT:GoBoom(ply)   --######### @ RononDex
  321.  
  322.     local velocity = self:GetForward();
  323.  
  324.     local effectdata = EffectData();
  325.         effectdata:SetOrigin( self:GetPos() );
  326.         effectdata:SetStart(self:GetUp());
  327.     util.Effect( "dirtyxplo", effectdata );
  328.    
  329.     self:EmitSound("RononDex/explosion.mp3", 100, 100);
  330.     self:Remove();
  331.  
  332.     if self.In then
  333.         self:ExitTARDIS()
  334.     end
  335. end
  336.  
  337. local ZAxis = Vector(0,0,1)
  338. local num = 0
  339. local num2 = 0
  340. local num3 = 0
  341. local num4 = 0
  342. ENT.SpinAccel = 0
  343. function ENT:PhysicsSimulate( phys, deltatime )--############## Flight code@ RononDex
  344.    
  345.     local FWD = self:GetForward()
  346.     local UP = ZAxis
  347.     local RIGHT = FWD:Cross(UP):GetNormal()
  348.  
  349.    
  350.     self.SpinAccel = math.Approach(self.SpinAccel,num4,0.05)
  351.    
  352.     if IsValid(self) then
  353.         if self.In and self.Flightmode then
  354.        
  355.             self.PropTardis:SetAngles(Angle(5, self.PropTardis:GetAngles().Yaw+self.SpinAccel, 0))
  356.  
  357.             -- Accelerate
  358.             if(self.Pilot:KeyDown(IN_FORWARD) and not self.Pilot:KeyDown(IN_SPEED)) then
  359.                 num=1000
  360.                 num4 = 4
  361.             elseif(self.Pilot:KeyDown(IN_FORWARD) and self.Pilot:KeyDown(IN_SPEED)) then
  362.                 num=1250
  363.                 num4 = 5
  364.             else
  365.                 num=0
  366.                 num4=0
  367.             end
  368.             self.Accel.FWD=math.Approach(self.Accel.FWD,num,8)
  369.  
  370.             -- Strafe
  371.             if(self.Pilot:KeyDown(IN_MOVERIGHT)) then
  372.                 num2 = 650
  373.             elseif(self.Pilot:KeyDown(IN_MOVELEFT)) then
  374.                 num2 = -650
  375.             else
  376.                 num2=0
  377.             end
  378.             self.Accel.RIGHT=math.Approach(self.Accel.RIGHT,num2,7)
  379.            
  380.             --Up and Down
  381.             if(self.Pilot:KeyDown(IN_JUMP)) then
  382.                 num3 = 650
  383.             elseif(self.Pilot:KeyDown(IN_DUCK)) then
  384.                 num3 = -650
  385.             else
  386.                 num3=0
  387.             end
  388.             self.Accel.UP=math.Approach(self.Accel.UP,num3,6)
  389.            
  390.             if not self.Hover then
  391.                 if self.Accel.FWD>-200 and self.Accel.FWD < 200 then return end --with out this you float
  392.                 if self.Accel.RIGHT>-200 and self.Accel.RIGHT < 200 then return end
  393.                 if self.Accel.UP>-200 and self.Accel.UP < 200 then return end
  394.             end
  395.            
  396.             phys:Wake()
  397.             self.PropTardis:GetPhysicsObject():Wake()
  398.            
  399.             self.FlightPhys={
  400.                 secondstoarrive = 1;
  401.                 pos = self:GetPos()+(FWD*self.Accel.FWD)+(RIGHT*self.Accel.RIGHT)+(UP*self.Accel.UP);
  402.                 maxangular      = 9000;
  403.                 maxangulardamp  = 1000;
  404.                 maxspeed            = 1000000;
  405.                 maxspeeddamp        = 500000;
  406.                 dampfactor      = 1;
  407.                 teleportdistance    = 5000;
  408.             }
  409.  
  410.            
  411.             local pos = self:GetPos()
  412.             local velocity = self:GetVelocity()    
  413.             local aim = self.Pilot:GetAimVector();
  414.             local ang = aim:Angle();
  415.             self.FlightPhys.angle           = ang --+ Vector(90 0, 0)
  416.             self.FlightPhys.deltatime       = deltatime
  417.            
  418.             self.Pilot:SetPos(pos);            
  419.                            
  420.             phys:ComputeShadowControl(self.FlightPhys)
  421.         end
  422.     end
  423. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement