Advertisement
karatewalrus

nanite shield testing

May 25th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. if SERVER then AddCSLuaFile() end
  2.  
  3. ENT.Type = "anim"
  4. --ENT.Base = "base_gmodentity"
  5.  
  6. ENT.PrintName = "Nanites"
  7. ENT.Author = "RKellyJelly"
  8. ENT.Contact = ""
  9. ENT.Purpose = "Healing a player"
  10. ENT.Information = "Gives 50 health"
  11. ENT.Category = "TTT Health Pickup"
  12.  
  13. --makes it a part of the TTT base ammo type so it's part of the group that spawns from random ammo pickups
  14. ENT.Base = "base_ammo_ttt"
  15. --set the model location for the entity so it can be seen by the player and be interacted with
  16. ENT.Model = Model("models/nanites.mdl")
  17. --makes it so it can automatically spawn from places where random ammo is set to spawn in ttt gamemode
  18. ENT.AutoSpawnable = true
  19.  
  20. ENT.Spawnable = true
  21. ENT.AdminSpawnable = true
  22.  
  23. local healthamount = 40 //How much health does the player get?
  24.  
  25.  
  26. --if I want to create a physics based object that would be kicked around when the player walks over it I could enable this
  27.  
  28. --[[
  29. if Server then
  30.  
  31. function ENT:Initialize()
  32.  
  33. self.Entity:SetModel( "models/nanites.mdl" )
  34. self.Entity:PhysicsInit( SOLID_VPHYSICS )
  35. self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
  36. --self.Entity:SetSolid( SOLID_VPHYSICS )
  37. self.Entity:SetUseType( SIMPLE_USE )
  38. local phys = self.Entity:GetPhysicsObject()
  39.  
  40. if ( phys:IsValid() ) then
  41.  
  42. phys:Wake()
  43.  
  44. end
  45.  
  46. end
  47. ]]--
  48.  
  49. --when the player touches it, this checks to see if the player is less than 150 health, and if so, adds health
  50.  
  51.  
  52. --Activated if a player touches the nanite suppliment
  53. function ENT:StartTouch( activator, ent )
  54. --check to see if the round is active before a player can pick this item up
  55. if GetRoundState() == ROUND_ACTIVE then
  56. --check if the activator is a player
  57. if ( activator:IsPlayer() ) then
  58. --if the player is at 100 or higher health do not let them use the nanites
  59. if ( activator:Health() >= 100 ) then end --return end
  60. --if healing would raise health above 100, set it to 100
  61. shield = healthamount
  62. --calculate the amount that would be overhealed for use in adding the rest to the nanoshield
  63. if ( activator:Health() > 100 - healthamount ) then
  64. shield = activator:Health() + healthamount - 100
  65. --set the health to 100
  66. activator:SetHealth( 100 )
  67. else
  68. --give the player the value of healthamount added to their current health, there is no overheal to add to the shield
  69. activator:SetHealth( activator:Health() + healthamount )
  70. shield = 0
  71. end
  72.  
  73. --[[nanoshield hook for absorbing bullet damage]]--
  74. --check to see if this script has already been run before via picking up nanites in this round already because we don't want multiple of the same hooks
  75. --the nanoshield variable is declared immediately after this so the hook below will work
  76. if nanoshield == nil then
  77. print ("nanoshield damage hook engaged")
  78. hook.Add( "EntityTakeDamage", "BulletAbsorb", function( target, dmginfo )
  79.  
  80. if ( target:IsPlayer() and dmginfo:IsFallDamage()) then
  81. print( "fall damage located")
  82. print(dmginfo:GetDamage())
  83.  
  84. ouchies = dmginfo:GetDamage()
  85.  
  86. if ( ouchies - nanoshield ) > 0 then
  87. dmginfo:SetDamage( dmginfo:GetDamage() - nanoshield )
  88. else
  89. dmginfo:SetDamage( 0 )
  90. end
  91.  
  92. if ( nanoshield - ouchies ) <= 0 then
  93. nanoshield = 0
  94.  
  95. print( "nanoshield is gone" )
  96. --you're out of nanites so you will bleed from now on
  97. activator:SetBloodColor(BLOOD_COLOR_RED)
  98. else
  99. nanoshield = (nanoshield - ouchies)
  100. print( nanoshield )
  101. end
  102.  
  103. end
  104.  
  105. end )
  106.  
  107. end
  108.  
  109. --[[Nanoshield variable initialization and values]]--
  110. --check to see if the nanoshield variable has already been established due to this item already being picked up before
  111. if nanoshield != nil then
  112. --if there are two full health amounts worth of nanoshield then you can't pick up the nanites as you have full health and shield
  113. if nanoshield == healthamount * 2 then return end
  114. --if you already have one full shield or greater then set your shields to max
  115. if nanoshield >= healthamount then
  116. --nanoshield value can't be greater than 2 full shield charges
  117. nanoshield = healthamount * 2
  118.  
  119.  
  120.  
  121. else
  122. --add 'healthamount' shield to already existing shield
  123. nanoshield = nanoshield + shield
  124.  
  125.  
  126.  
  127. end
  128. else
  129. --establish the nanoshield variable and set shield to 'healthamount' if no existing shield is found
  130. nanoshield = shield
  131.  
  132. --being shot with a bullet will cause sparks while the shield is active and being absorbed by the nanites
  133. activator:SetBloodColor(BLOOD_COLOR_MECH)
  134. end
  135.  
  136.  
  137. print( "printing nanoshield value" )
  138. print( nanoshield )
  139.  
  140.  
  141. --play sound upon using the nanites
  142. activator:EmitSound("nanites/nanites.wav", 50, 100)
  143.  
  144. --make the nanites disappear if a player uses them
  145. self.Entity:Remove()
  146.  
  147. end
  148. else
  149. --if the round hasn't begun or is over, display this chat message
  150. activator:ChatPrint( 'We are sorry, Nautilus Microhealth Systemsâ„¢ Healing Nanites may only be used during the round.' )
  151. end
  152.  
  153. end
  154.  
  155. --draw the nanite shield hud
  156. local bluenano = Color(172,230,255,255)
  157. print ("nanoshield hud hook engaged")
  158.  
  159. if CLIENT then
  160. surface.CreateFont("NaniteFont",{
  161. font = "Felix Titling", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
  162. size = 20,
  163. weight = 100,
  164. blursize = 0,
  165. scanlines = 0,
  166. antialias = true,
  167. underline = false,
  168. italic = false,
  169. strikeout = false,
  170. symbol = false,
  171. rotary = false,
  172. shadow = false,
  173. additive = false,
  174. outline = false
  175. })
  176. end
  177.  
  178. hook.Add( "HUDPaint", "HelloThere", function()
  179. surface.SetDrawColor( 0, 0, 0, 128 )
  180. surface.DrawRect( 50, 50, 128, 128 )
  181. draw.SimpleText(nanoshield, "NaniteFont",100,100,bluenano,20,20)
  182. end )
  183.  
  184. function ENT:SpawnFunction( ply, tr )
  185.  
  186. if ( !tr.Hit ) then return end
  187.  
  188. local SpawnPos = tr.HitPos + tr.HitNormal * 16
  189.  
  190. local ent = ents.Create( "medkit" )
  191. ent:SetPos( SpawnPos )
  192. ent:Spawn()
  193. ent:Activate()
  194.  
  195. return ent
  196.  
  197. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement