Advertisement
ReverendV92

lua/entities/v92_edit_jumppad.lua

Oct 29th, 2022
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.78 KB | None | 0 0
  1.  
  2. ---------------------------------------------
  3. ---------------------------------------------
  4. -- Editable Jump Pad Entity
  5. -- Workshop: https://steamcommunity.com/sharedfiles/filedetails/?id=136546465
  6. ---------------------------------------------
  7. ---------------------------------------------
  8. -- V92: Code
  9. -- Valve: Faith Plate Icon
  10. ---------------------------------------------
  11. -- It's like the ones in HL1, but without the
  12. -- func_door fuckery.
  13. --
  14. -- Use the context menu in-game and right
  15. -- click on the entity to open the editor.
  16. ---------------------------------------------
  17. ---------------------------------------------
  18.  
  19. AddCSLuaFile()
  20.  
  21. ENT.Base = "base_anim"
  22. ENT.Type = "anim"
  23.  
  24. ENT.Spawnable = true -- Spawnable?
  25. ENT.AdminOnly = false -- Limited to admins?
  26. ENT.Editable = true -- Editable?
  27.  
  28. if CLIENT then
  29.  
  30.     ENT.Category        = "Editors"
  31.     ENT.PrintName       = "Jump Pad"
  32.     ENT.Author          = "V92"
  33.     ENT.Contact         = "Steam"
  34.     ENT.Purpose         = "Vertical Supremacy"
  35.     ENT.Instructions    = "Touch to jump, context menu to edit"
  36.    
  37.     language.Add("v92_edit_jumppad", "Jump Pad")
  38.     function ENT:Draw() self:DrawModel() end
  39.  
  40. end
  41.  
  42. function ENT:SetupDataTables()
  43.  
  44.     -- These are the public keys passed to the editable entity function.
  45.     self:NetworkVar( "String" , 0 , "CustomModel" , { ["KeyName"] = "CustomModel" , ["Edit"] = { ["title"] = "Custom Model" , ["order"] = 1 , ["type"] = "String" , ["waitforenter"] = true } } )
  46.     self:NetworkVar( "String" , 1 , "CustomSound" , { ["KeyName"] = "CustomSound" , ["Edit"] = { ["title"] = "Custom Sound" , ["order"] = 2 , ["type"] = "String" , ["waitforenter"] = true } } )
  47.     self:NetworkVar( "Int" ,    0 , "BouncePower" , { ["KeyName"] = "BouncePower" , ["Edit"] = { ["title"] = "Bounce Power" , ["order"] = 3 , ["type"] = "Int" , ["min"] = 0 , ["max"] = 15000 , ["waitforenter"] = false } } )
  48.  
  49.     if SERVER then
  50.  
  51.         -- Set the default keys for the data table. Change them here if you want to edit the entity's defaults.
  52.         self:SetCustomModel( "models/props_junk/trashdumpster02b.mdl"  )
  53.         self:SetCustomSound( "weapons/crossbow/fire1.wav"  )
  54.         self:SetBouncePower( 500 )
  55.  
  56.     end
  57.  
  58. end
  59.  
  60. if SERVER then
  61.  
  62.     function ENT:Initialize()
  63.  
  64.         -- Get the model from the data table keys and set it.
  65.         self:SetModel( self:GetCustomModel() )
  66.  
  67.         self:PhysicsInit( SOLID_VPHYSICS )
  68.         self:SetSolid( SOLID_VPHYSICS )
  69.         self:SetMoveType( MOVETYPE_VPHYSICS )
  70.         self:SetTrigger( true ) -- Required to use Touch functions
  71.  
  72.         self:GetPhysicsObject():Wake()
  73.         self:DropToFloor()
  74.  
  75.     end
  76.  
  77.     -- TOUCH! Patrick, don't touch!
  78.     function ENT:StartTouch( Toucher )     
  79.  
  80.         -- Adding a slight delay because sometimes you'll touch it more than once and it'll send you into low orbit.
  81.         local Delay = CurTime()
  82.         if Delay > CurTime() then return end
  83.         Delay = CurTime() + 0.2
  84.  
  85.         -- There's probably a cleaner way to do this, but it works.
  86.         local DefaultModel = Model("models/props_junk/trashdumpster02b.mdl")
  87.         -- If the CustomModel data isn't the default...
  88.         if self:GetCustomModel() != DefaultModel then
  89.             -- Re-run the initialize function to change the model
  90.             self:Initialize()
  91.         end
  92.  
  93.         -- If we're touching a player...
  94.         if Toucher:IsPlayer() then
  95.  
  96.             -- Throw the son of a bitch into the air!
  97.             Toucher:SetVelocity( Toucher:GetVelocity() + Vector( 0, 0, self:GetBouncePower() ) )
  98.  
  99.         -- Players behave differently so we have to call a different function for everything else...
  100.         else
  101.  
  102.             -- Punt the shit like an ugly baby!
  103.             Toucher:GetPhysicsObject():SetVelocity( Toucher:GetVelocity() + Vector( 0, 0, self:GetBouncePower() ) )
  104.  
  105.         end
  106.  
  107.         -- Play some nice(?) sounds!
  108.         self:EmitSound( self:GetCustomSound() )
  109.  
  110.     end
  111.  
  112.     function ENT:OnRemove()
  113.  
  114.         -- self:Remove() is about as trustworthy as a used car salesman with Honest in his name
  115.         SafeRemoveEntity( self )
  116.  
  117.     end
  118.  
  119. end
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement