Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then AddCSLuaFile() end
- ENT.Type = "anim"
- --ENT.Base = "base_gmodentity"
- ENT.PrintName = "Nanites"
- ENT.Author = "RKellyJelly"
- ENT.Contact = ""
- ENT.Purpose = "Healing a player"
- ENT.Information = "Gives 50 health"
- ENT.Category = "TTT Health Pickup"
- --makes it a part of the TTT base ammo type so it's part of the group that spawns from random ammo pickups
- ENT.Base = "base_ammo_ttt"
- --set the model location for the entity so it can be seen by the player and be interacted with
- ENT.Model = Model("models/nanites.mdl")
- --makes it so it can automatically spawn from places where random ammo is set to spawn in ttt gamemode
- ENT.AutoSpawnable = true
- ENT.Spawnable = true
- ENT.AdminSpawnable = true
- local healthamount = 40 //How much health does the player get?
- --if I want to create a physics based object that would be kicked around when the player walks over it I could enable this
- --[[
- if Server then
- function ENT:Initialize()
- self.Entity:SetModel( "models/nanites.mdl" )
- self.Entity:PhysicsInit( SOLID_VPHYSICS )
- self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
- --self.Entity:SetSolid( SOLID_VPHYSICS )
- self.Entity:SetUseType( SIMPLE_USE )
- local phys = self.Entity:GetPhysicsObject()
- if ( phys:IsValid() ) then
- phys:Wake()
- end
- end
- ]]--
- --when the player touches it, this checks to see if the player is less than 150 health, and if so, adds health
- --Activated if a player touches the nanite suppliment
- function ENT:StartTouch( activator, ent )
- --check to see if the round is active before a player can pick this item up
- if GetRoundState() == ROUND_ACTIVE then
- --check if the activator is a player
- if ( activator:IsPlayer() ) then
- --if the player is at 100 or higher health do not let them use the nanites
- if ( activator:Health() >= 100 ) then end --return end
- --if healing would raise health above 100, set it to 100
- shield = healthamount
- --calculate the amount that would be overhealed for use in adding the rest to the nanoshield
- if ( activator:Health() > 100 - healthamount ) then
- shield = activator:Health() + healthamount - 100
- --set the health to 100
- activator:SetHealth( 100 )
- else
- --give the player the value of healthamount added to their current health, there is no overheal to add to the shield
- activator:SetHealth( activator:Health() + healthamount )
- shield = 0
- end
- --[[nanoshield hook for absorbing bullet damage]]--
- --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
- --the nanoshield variable is declared immediately after this so the hook below will work
- if nanoshield == nil then
- print ("nanoshield damage hook engaged")
- hook.Add( "EntityTakeDamage", "BulletAbsorb", function( target, dmginfo )
- if ( target:IsPlayer() and dmginfo:IsFallDamage()) then
- print( "fall damage located")
- print(dmginfo:GetDamage())
- ouchies = dmginfo:GetDamage()
- if ( ouchies - nanoshield ) > 0 then
- dmginfo:SetDamage( dmginfo:GetDamage() - nanoshield )
- else
- dmginfo:SetDamage( 0 )
- end
- if ( nanoshield - ouchies ) <= 0 then
- nanoshield = 0
- print( "nanoshield is gone" )
- --you're out of nanites so you will bleed from now on
- activator:SetBloodColor(BLOOD_COLOR_RED)
- else
- nanoshield = (nanoshield - ouchies)
- print( nanoshield )
- end
- end
- end )
- end
- --[[Nanoshield variable initialization and values]]--
- --check to see if the nanoshield variable has already been established due to this item already being picked up before
- if nanoshield != nil then
- --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
- if nanoshield == healthamount * 2 then return end
- --if you already have one full shield or greater then set your shields to max
- if nanoshield >= healthamount then
- --nanoshield value can't be greater than 2 full shield charges
- nanoshield = healthamount * 2
- else
- --add 'healthamount' shield to already existing shield
- nanoshield = nanoshield + shield
- end
- else
- --establish the nanoshield variable and set shield to 'healthamount' if no existing shield is found
- nanoshield = shield
- --being shot with a bullet will cause sparks while the shield is active and being absorbed by the nanites
- activator:SetBloodColor(BLOOD_COLOR_MECH)
- end
- print( "printing nanoshield value" )
- print( nanoshield )
- --play sound upon using the nanites
- activator:EmitSound("nanites/nanites.wav", 50, 100)
- --make the nanites disappear if a player uses them
- self.Entity:Remove()
- end
- else
- --if the round hasn't begun or is over, display this chat message
- activator:ChatPrint( 'We are sorry, Nautilus Microhealth Systemsâ„¢ Healing Nanites may only be used during the round.' )
- end
- end
- --draw the nanite shield hud
- local bluenano = Color(172,230,255,255)
- print ("nanoshield hud hook engaged")
- if CLIENT then
- surface.CreateFont("NaniteFont",{
- font = "Felix Titling", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
- size = 20,
- weight = 100,
- blursize = 0,
- scanlines = 0,
- antialias = true,
- underline = false,
- italic = false,
- strikeout = false,
- symbol = false,
- rotary = false,
- shadow = false,
- additive = false,
- outline = false
- })
- end
- hook.Add( "HUDPaint", "HelloThere", function()
- surface.SetDrawColor( 0, 0, 0, 128 )
- surface.DrawRect( 50, 50, 128, 128 )
- draw.SimpleText(nanoshield, "NaniteFont",100,100,bluenano,20,20)
- end )
- function ENT:SpawnFunction( ply, tr )
- if ( !tr.Hit ) then return end
- local SpawnPos = tr.HitPos + tr.HitNormal * 16
- local ent = ents.Create( "medkit" )
- ent:SetPos( SpawnPos )
- ent:Spawn()
- ent:Activate()
- return ent
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement