Advertisement
karatewalrus

drawhud nanites

May 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 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. local nanoshield = nil
  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. --This adds the hook to the player the first time nanites are picked up
  75. --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
  76. --the nanoshield variable is declared immediately after this so the hook below will work
  77. if nanoshield == nil then
  78. print ("nanoshield damage hook engaged")
  79. hook.Add( "EntityTakeDamage", "BulletAbsorb", function( target, dmginfo )
  80.  
  81. if ( target:IsPlayer() and dmginfo:IsFallDamage()) then
  82. print( "fall damage located")
  83. print(dmginfo:GetDamage())
  84.  
  85. ouchies = dmginfo:GetDamage()
  86.  
  87. --figure out how much damage to give the player while a shield is in place
  88. if ( ouchies - nanoshield ) > 0 then
  89. dmginfo:SetDamage( dmginfo:GetDamage() - nanoshield )
  90. else
  91. dmginfo:SetDamage( 0 )
  92. end
  93. --remove the shield if it's all used up
  94. if ( nanoshield - ouchies ) <= 0 then
  95. nanoshield = 0
  96.  
  97. print( "nanoshield is gone" )
  98. --you're out of nanites so you will bleed from now on
  99. activator:SetBloodColor(BLOOD_COLOR_RED)
  100. else
  101. --calculate the new nanoshield value
  102. nanoshield = (nanoshield - ouchies)
  103. print( nanoshield )
  104. end
  105.  
  106. end
  107.  
  108. end )
  109.  
  110. hook.Add( "HUDPaint", "nanohud", function()
  111. surface.SetDrawColor( 0, 0, 0, 128 )
  112. surface.DrawRect( 50, 50, 128, 128 )
  113. draw.SimpleText(nanoshield, "NaniteFont",100,100,bluenano,20,20)
  114. end )
  115.  
  116. end
  117.  
  118. --[[nanoshield variable initialization and values]]--
  119. --check to see if the nanoshield variable has already been established due to this item already being picked up before
  120. if nanoshield != nil then
  121. --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
  122. if nanoshield == healthamount * 2 then return end
  123. --if you already have one full shield or greater then set your shields to max
  124. if nanoshield >= healthamount then
  125. --nanoshield value can't be greater than 2 full shield charges
  126. nanoshield = healthamount * 2
  127.  
  128.  
  129.  
  130. else
  131. --add 'healthamount' shield to already existing shield
  132. nanoshield = nanoshield + shield
  133.  
  134.  
  135.  
  136. end
  137. else
  138. --sets the nanoshield value for the first time nanites are picked up to the overheal amount
  139. nanoshield = shield
  140.  
  141. --being shot with a bullet will cause sparks while the shield is active and being absorbed by the nanites
  142. activator:SetBloodColor(BLOOD_COLOR_MECH)
  143. end
  144.  
  145. --print("Trying to initiate drawhud")
  146. --drawhud( nanoshield )
  147.  
  148. print( "printing nanoshield value" )
  149. print( nanoshield )
  150.  
  151.  
  152. --play sound upon using the nanites
  153. activator:EmitSound("nanites/nanites.wav", 50, 100)
  154.  
  155. --make the nanites disappear if a player uses them
  156. self.Entity:Remove()
  157. return nanoshield
  158. end
  159. else
  160. --if the round hasn't begun or is over, display this chat message
  161. activator:ChatPrint( 'We are sorry, Nautilus Microhealth Systemsâ„¢ Healing Nanites may only be used during the round.' )
  162. end
  163.  
  164. end
  165.  
  166.  
  167. --draw the nanite shield hud
  168. local bluenano = Color(172,230,255,255)
  169.  
  170.  
  171.  
  172. if CLIENT then
  173. surface.CreateFont("NaniteFont",{
  174. font = "Felix Titling", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
  175. size = 20,
  176. weight = 100,
  177. blursize = 0,
  178. scanlines = 0,
  179. antialias = true,
  180. underline = false,
  181. italic = false,
  182. strikeout = false,
  183. symbol = false,
  184. rotary = false,
  185. shadow = false,
  186. additive = false,
  187. outline = false
  188. })
  189. end
  190.  
  191.  
  192. print ("nanoshield hud hook engaged")
  193.  
  194.  
  195. --spawn this item in the world when the map loads
  196. function ENT:SpawnFunction( ply, tr )
  197.  
  198. if ( !tr.Hit ) then return end
  199.  
  200. local SpawnPos = tr.HitPos + tr.HitNormal * 16
  201.  
  202. local ent = ents.Create( "nanite_suppliment" )
  203. ent:SetPos( SpawnPos )
  204. ent:Spawn()
  205. ent:Activate()
  206.  
  207. return ent
  208.  
  209. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement