Skip to content

Instantly share code, notes, and snippets.

@lifesfun
Last active August 29, 2015 14:06
Show Gist options
  • Save lifesfun/71612e7d0da3f040c21b to your computer and use it in GitHub Desktop.
Save lifesfun/71612e7d0da3f040c21b to your computer and use it in GitHub Desktop.
lerklift
Lift = {
Interval = 0.5,
OnSound = "alien_vision_on",
OffSound = "alien_vision_off",
Offset = Vector( 0 , 2.8 , 0 ),
Tolerance = 0.28
}
function Lift:CanBeUsed( player )
if not player then return end
if not player:GetIsAlive() then return end
local liftID = player.liftID
local attachedPlayer = Shared.GetEntity( liftID )
if LiftID and attachedPlayer then self:Detach( player , attachedPlayer ) return
elseif LiftID then self:Detach( player , nil) return end
return true
end
function Lift:Liftable( player )
if player:isa( "Gorge" ) then return true end
end
function Lift:CanLift( player )
if player:isa( "Lerk" ) then return true end
end
function Lift:UseLift( user , used )
local userID = user:GetId()
local usedID = used:GetId()
if user.LiftID or used.LiftID then return end
if self:Liftable( user ) and self:CanLift( used ) then self:Attach( user , userID , used , usedID)
elseif self:Liftable( used ) and self:CanLift( user ) then self:Attach( used , usedID , user , userID ) end
end
function Lift:Detach( player , attachedPlayer )
player:TriggerEffects( self.OffSound )
if player then
if player.LiftID then player.LiftID = nil end
if player.IsLifter then player.IsLifter = nil end
end
if attachedPlayer then
if attachedPlayer.LiftID then attachedPlayer.LiftID = nil end
if attachedPlayer.IsLifter then attachedPlayer.IsLifter = nil end
end
end
function Lift:Attach( player , playerID , attachedPlayer , attachedPlayerID )
if not player or not playerID or not attachedPlayer or not attachedPlayerID then return end
player:TriggerEffects( self.OnSound )
player.LiftID = playerID
player.IsLifter = true
attachedPlayer.LiftID = attachedPlayerID
end
function Lift:KeepLifting( player )
if not player then return end
local liftID = player.liftID
if not liftID then return end
local attachedPlayer = Shared.GetEntity( liftID )
if not attachedPlayer then self:Detach( player , nil ) return end
if not player:GetIsAlive() or not attachedPlayer:GetIsAlive() then self:Detach( player , attachedPlayer ) return end
if player.IsLifter then self:Lift( player , attachedPlayer ) end
end
function Lift:Lift( player, attachedPlayer )
local tolerance = player.LiftTolerance
if not tolerance then tolerance = self.Tolerance end
local offset = player.LiftOffset
if not offset then offset = self.Offset end
local offsetXY = offset:GetLength()
local minTolerance = offsetXY - tolerance
local maxTolerance = offsetXY + tolerance
local attachPoint = player:GetOrigin() + offset
local attachedPlayerOrigin = attachedPlayer:GetOrigin()
local distanceXY = ( attachPoint - attachedPlayerOrigin ):GetLength()
if minTolerance < distanceXY and distanceXY < maxTolerance then return end
attachedPlayer:SetOrigin( attachPoint )
end
function Alien:GetCanBeUsed( target , useSuccessTable )
if Lift:CanBeUsed( self ) and Lift:CanBeUsed( target ) then useSuccessTable.UseSuccess = true
else useSuccessTable.UseSuccess = false end
end
function Alien:OnUse( target , elapsedTime , useSuccessTable )
if not target then return end
Lift:UseLift( target , self )
useSuccessTable.UseSuccess = true
end
function Alien:UpdateMove( input , runningPrediction )
if self.LiftID then Lift:KeepLifting( self ) end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment