This commit is contained in:
lifestorm
2024-08-04 22:55:00 +03:00
parent 8064ba84d8
commit 73479cff9e
7338 changed files with 1718883 additions and 14 deletions

View File

@@ -0,0 +1,49 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
--[[---------------------------------------------------------
Returns the right shoot start position for a tracer - based on 'data'.
-----------------------------------------------------------]]
function EFFECT:GetTracerShootPos( Position, Ent, Attachment )
self.ViewModelTracer = false
if ( !IsValid( Ent ) ) then return Position end
if ( !Ent:IsWeapon() ) then return Position end
-- Shoot from the viewmodel
if ( Ent:IsCarriedByLocalPlayer() && !LocalPlayer():ShouldDrawLocalPlayer() ) then
local ViewModel = LocalPlayer():GetViewModel()
if ( ViewModel:IsValid() ) then
local att = ViewModel:GetAttachment( Attachment )
if ( att ) then
Position = att.Pos
self.ViewModelTracer = true
end
end
-- Shoot from the world model
else
local att = Ent:GetAttachment( Attachment )
if ( att ) then
Position = att.Pos
end
end
return Position
end

View File

@@ -0,0 +1,65 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
EFFECT.Mat = Material( "pp/dof" )
function EFFECT:Init( data )
table.insert( DOF_Ents, self )
self.Scale = data:GetScale()
local size = 32
self:SetCollisionBounds( Vector( -size, -size, -size ), Vector( size, size, size ) )
end
function EFFECT:Think()
-- If the spacing or offset has changed we need to reconfigure our positions
local ply = LocalPlayer()
self.spacing = DOF_SPACING * self.Scale
self.offset = DOF_OFFSET
-- Just return if it hasn't
--if ( spacing == self.spacing && offset == self.offset ) then return true end
local pos = ply:EyePos()
local fwd = ply:EyeAngles():Forward()
if ( ply:GetViewEntity() != ply ) then
pos = ply:GetViewEntity():GetPos()
fwd = ply:GetViewEntity():GetForward()
end
pos = pos + ( fwd * self.spacing ) + ( fwd * self.offset )
self:SetParent( nil )
self:SetPos( pos )
self:SetParent( ply )
-- We don't kill this, the pp effect should
return true
end
function EFFECT:Render()
-- Note: UpdateScreenEffectTexture fucks up the water, RefractTexture is lower quality
render.UpdateRefractTexture()
--render.UpdateScreenEffectTexture()
local SpriteSize = ( self.spacing + self.offset ) * 8
render.SetMaterial( self.Mat )
render.DrawSprite( self:GetPos(), SpriteSize, SpriteSize, color_white )
end

View File

@@ -0,0 +1,68 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
EFFECT.Mat = Material( "effects/tool_tracer" )
function EFFECT:Init( data )
self.Position = data:GetStart()
self.WeaponEnt = data:GetEntity()
self.Attachment = data:GetAttachment()
-- Keep the start and end pos - we're going to interpolate between them
self.StartPos = self:GetTracerShootPos( self.Position, self.WeaponEnt, self.Attachment )
self.EndPos = data:GetOrigin()
self.Alpha = 255
self.Life = 0
self:SetRenderBoundsWS( self.StartPos, self.EndPos )
end
function EFFECT:Think()
self.Life = self.Life + FrameTime() * 4
self.Alpha = 255 * ( 1 - self.Life )
return self.Life < 1
end
function EFFECT:Render()
if ( self.Alpha < 1 ) then return end
render.SetMaterial( self.Mat )
local texcoord = math.Rand( 0, 1 )
local norm = ( self.StartPos - self.EndPos ) * self.Life
self.Length = norm:Length()
for i = 1, 3 do
render.DrawBeam( self.StartPos - norm, -- Start
self.EndPos, -- End
8, -- Width
texcoord, -- Start tex coord
texcoord + self.Length / 128, -- End tex coord
color_white ) -- Color (optional)
end
render.DrawBeam( self.StartPos,
self.EndPos,
8,
texcoord,
texcoord + ( ( self.StartPos - self.EndPos ):Length() / 128 ),
Color( 255, 255, 255, 128 * ( 1 - self.Life ) ) )
end

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,33 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
include( "shared.lua" )
--[[---------------------------------------------------------
Name: Draw
Desc: Draw it!
-----------------------------------------------------------]]
function ENT:Draw()
self:DrawModel()
end
--[[---------------------------------------------------------
Name: DrawTranslucent
Desc: Draw translucent
-----------------------------------------------------------]]
function ENT:DrawTranslucent()
-- This is here just to make it backwards compatible.
-- You shouldn't really be drawing your model here unless it's translucent
self:Draw()
end

View File

@@ -0,0 +1,147 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
include( "schedules.lua" )
include( "tasks.lua" )
-- Variables
ENT.m_fMaxYawSpeed = 200 -- Max turning speed
ENT.m_iClass = CLASS_CITIZEN_REBEL -- NPC Class
AccessorFunc( ENT, "m_iClass", "NPCClass" )
AccessorFunc( ENT, "m_fMaxYawSpeed", "MaxYawSpeed" )
function ENT:Initialize()
-- Some default calls to make the NPC function
self:SetModel( "models/alyx.mdl" )
self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal()
self:SetSolid( SOLID_BBOX )
self:SetMoveType( MOVETYPE_STEP )
self:CapabilitiesAdd( bit.bor( CAP_MOVE_GROUND, CAP_OPEN_DOORS, CAP_ANIMATEDFACE, CAP_SQUAD, CAP_USE_WEAPONS, CAP_DUCK, CAP_MOVE_SHOOT, CAP_TURN_HEAD, CAP_USE_SHOT_REGULATOR, CAP_AIM_GUN ) )
self:SetHealth( 100 )
end
--[[---------------------------------------------------------
Name: OnTakeDamage
Desc: Called when the NPC takes damage
-----------------------------------------------------------]]
function ENT:OnTakeDamage( dmginfo )
--[[
Msg( tostring(dmginfo) .. "\n" )
Msg( "Inflictor:\t" .. tostring(dmginfo:GetInflictor()) .. "\n" )
Msg( "Attacker:\t" .. tostring(dmginfo:GetAttacker()) .. "\n" )
Msg( "Damage:\t" .. tostring(dmginfo:GetDamage()) .. "\n" )
Msg( "Base Damage:\t" .. tostring(dmginfo:GetBaseDamage()) .. "\n" )
Msg( "Force:\t" .. tostring(dmginfo:GetDamageForce()) .. "\n" )
Msg( "Position:\t" .. tostring(dmginfo:GetDamagePosition()) .. "\n" )
Msg( "Reported Pos:\t" .. tostring(dmginfo:GetReportedPosition()) .. "\n" ) -- ??
--]]
-- return 1
end
--[[---------------------------------------------------------
Name: Use
-----------------------------------------------------------]]
function ENT:Use( activator, caller, type, value )
end
--[[---------------------------------------------------------
Name: StartTouch
-----------------------------------------------------------]]
function ENT:StartTouch( entity )
end
--[[---------------------------------------------------------
Name: EndTouch
-----------------------------------------------------------]]
function ENT:EndTouch( entity )
end
--[[---------------------------------------------------------
Name: Touch
-----------------------------------------------------------]]
function ENT:Touch( entity )
end
--[[---------------------------------------------------------
Name: GetRelationship
Return the relationship between this NPC and the
passed entity. If you don't return anything then
the default disposition will be used.
-----------------------------------------------------------]]
function ENT:GetRelationship( entity )
--return D_NU
end
--[[---------------------------------------------------------
Name: ExpressionFinished
Called when an expression has finished. Duh.
-----------------------------------------------------------]]
function ENT:ExpressionFinished( strExp )
end
--[[---------------------------------------------------------
Name: OnChangeActivity
-----------------------------------------------------------]]
function ENT:OnChangeActivity( act )
end
--[[---------------------------------------------------------
Name: Think
-----------------------------------------------------------]]
function ENT:Think()
end
-- Called to update which sounds the NPC should be able to hear
function ENT:GetSoundInterests()
-- Hear thumper sound hints
-- return 256
end
-- Called when NPC's movement fails
function ENT:OnMovementFailed()
end
-- Called when NPC's movement succeeds
function ENT:OnMovementComplete()
end
-- Called when the NPC's active weapon changes
function ENT:OnActiveWeaponChanged( old, new )
end
--[[---------------------------------------------------------
Name: GetAttackSpread
How good is the NPC with this weapon? Return the number
of degrees of inaccuracy for the NPC to use.
-----------------------------------------------------------]]
function ENT:GetAttackSpread( Weapon, Target )
return 0.1
end

View File

@@ -0,0 +1,216 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
--[[---------------------------------------------------------
Name: RunAI - Called from the engine every 0.1 seconds
-----------------------------------------------------------]]
function ENT:RunAI( strExp )
-- If we're running an Engine Side behaviour
-- then return true and let it get on with it.
if ( self:IsRunningBehavior() ) then
return true
end
-- If we're doing an engine schedule then return true
-- This makes it do the normal AI stuff.
if ( self:DoingEngineSchedule() ) then
return true
end
-- If we're currently running a schedule then run it.
if ( self.CurrentSchedule ) then
self:DoSchedule( self.CurrentSchedule )
end
-- If we have no schedule (schedule is finished etc)
-- Then get the derived NPC to select what we should be doing
if ( !self.CurrentSchedule ) then
self:SelectSchedule()
end
-- Do animation system
self:MaintainActivity()
end
--[[---------------------------------------------------------
Name: SelectSchedule - Set the schedule we should be
playing right now.
-----------------------------------------------------------]]
function ENT:SelectSchedule( iNPCState )
self:SetSchedule( SCHED_IDLE_WANDER )
end
--[[---------------------------------------------------------
Name: StartSchedule - Start a Lua schedule. Not to be
confused with SetSchedule which starts an Engine based
schedule.
-----------------------------------------------------------]]
function ENT:StartSchedule( schedule )
self.CurrentSchedule = schedule
self.CurrentTaskID = 1
self:SetTask( schedule:GetTask( 1 ) )
end
--[[---------------------------------------------------------
Name: DoSchedule - Runs a Lua schedule.
-----------------------------------------------------------]]
function ENT:DoSchedule( schedule )
if ( self.CurrentTask ) then
self:RunTask( self.CurrentTask )
end
if ( self:TaskFinished() ) then
self:NextTask( schedule )
end
end
--[[---------------------------------------------------------
Name: ScheduleFinished
-----------------------------------------------------------]]
function ENT:ScheduleFinished()
self.CurrentSchedule = nil
self.CurrentTask = nil
self.CurrentTaskID = nil
end
--[[---------------------------------------------------------
Name: DoSchedule - Set the current task.
-----------------------------------------------------------]]
function ENT:SetTask( task )
self.CurrentTask = task
self.bTaskComplete = false
self.TaskStartTime = CurTime()
self:StartTask( self.CurrentTask )
end
--[[---------------------------------------------------------
Name: NextTask - Start the next task in specific schedule.
-----------------------------------------------------------]]
function ENT:NextTask( schedule )
-- Increment task id
self.CurrentTaskID = self.CurrentTaskID + 1
-- If this was the last task then finish up.
if ( self.CurrentTaskID > schedule:NumTasks() ) then
self:ScheduleFinished( schedule )
return
end
-- Switch to next task
self:SetTask( schedule:GetTask( self.CurrentTaskID ) )
end
--[[---------------------------------------------------------
Name: StartTask - called once on starting task
-----------------------------------------------------------]]
function ENT:StartTask( task )
task:Start( self )
end
--[[---------------------------------------------------------
Name: RunTask - called every think on running task.
The actual task function should tell us when
the task is finished.
-----------------------------------------------------------]]
function ENT:RunTask( task )
task:Run( self )
end
--[[---------------------------------------------------------
Name: TaskTime - Returns how many seconds we've been
doing this current task
-----------------------------------------------------------]]
function ENT:TaskTime()
return CurTime() - self.TaskStartTime
end
--[[---------------------------------------------------------
Name: OnTaskComplete - Called from the engine when
TaskComplete is called. This allows us to move
onto the next task - even when TaskComplete was
called from an engine side task.
-----------------------------------------------------------]]
function ENT:OnTaskComplete()
self.bTaskComplete = true
end
--[[---------------------------------------------------------
Name: TaskFinished - Returns true if the current
running Task is finished.
-----------------------------------------------------------]]
function ENT:TaskFinished()
return self.bTaskComplete
end
--[[---------------------------------------------------------
Name: StartTask
Start the task. You can use this to override engine
side tasks. Return true to not run default stuff.
-----------------------------------------------------------]]
function ENT:StartEngineTask( iTaskID, TaskData )
end
--[[---------------------------------------------------------
Name: RunTask
Run the task. You can use this to override engine
side tasks. Return true to not run default stuff.
-----------------------------------------------------------]]
function ENT:RunEngineTask( iTaskID, TaskData )
end
--[[---------------------------------------------------------
These functions handle the engine schedules
When an engine schedule is set the engine calls StartEngineSchedule
Then when it's finished it calls EngineScheduleFinishHelp me decide
-----------------------------------------------------------]]
function ENT:StartEngineSchedule( scheduleID ) self:ScheduleFinished() self.bDoingEngineSchedule = true end
function ENT:EngineScheduleFinish() self.bDoingEngineSchedule = nil end
function ENT:DoingEngineSchedule() return self.bDoingEngineSchedule end
function ENT:OnCondition( iCondition )
--Msg( self, " Condition: ", iCondition, " - ", self:ConditionName(iCondition), "\n" )
end
function ENT:TranslateActivity( act )
-- Return a value to translate the activity to a new one
-- if ( act == ACT_WALK ) then return ACT_RUN end
end

View File

@@ -0,0 +1,54 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
ENT.Base = "base_entity"
ENT.Type = "ai"
ENT.PrintName = "Base SNPC"
ENT.Author = ""
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
ENT.AutomaticFrameAdvance = false
--[[---------------------------------------------------------
Name: OnRemove
Desc: Called just before entity is deleted
-----------------------------------------------------------]]
function ENT:OnRemove()
end
--[[---------------------------------------------------------
Name: PhysicsCollide
Desc: Called when physics collides. The table contains
data on the collision
-----------------------------------------------------------]]
function ENT:PhysicsCollide( data, physobj )
end
--[[---------------------------------------------------------
Name: PhysicsUpdate
Desc: Called to update the physics .. or something.
-----------------------------------------------------------]]
function ENT:PhysicsUpdate( physobj )
end
--[[---------------------------------------------------------
Name: SetAutomaticFrameAdvance
Desc: If you're not using animation you should turn this
off - it will save lots of bandwidth.
-----------------------------------------------------------]]
function ENT:SetAutomaticFrameAdvance( bUsingAnim )
self.AutomaticFrameAdvance = bUsingAnim
end

View File

@@ -0,0 +1,90 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
--[[---------------------------------------------------------
Task: PlaySequence
Accepts:
data.ID - sequence id
data.Name - sequence name (Must provide either id or name)
data.Wait - Optional. Should we wait for sequence to finish
data.Speed - Optional. Playback speed of sequence
data.Loop - Optional. Should the sequence be looped
-----------------------------------------------------------]]
function ENT:TaskStart_PlaySequence( data )
local SequenceID = data.ID
if ( data.Name ) then SequenceID = self:LookupSequence( data.Name ) end
self:ResetSequence( SequenceID )
self:SetNPCState( NPC_STATE_SCRIPT )
local Duration = self:SequenceDuration()
if ( data.Speed && data.Speed > 0 ) then
SequenceID = self:SetPlaybackRate( data.Speed )
Duration = Duration / data.Speed
end
self.TaskSequenceEnd = CurTime() + Duration
self.Loop = data.Loop or false
end
function ENT:Task_PlaySequence( data )
-- Wait until sequence is finished
if ( CurTime() < self.TaskSequenceEnd or self.Loop ) then return end
self:TaskComplete()
self:SetNPCState( NPC_STATE_NONE )
-- Clean up
self.TaskSequenceEnd = nil
end
--[[---------------------------------------------------------
Task: FindEnemy
Accepts:
data.ID - sequence id
data.Name - sequence name (Must provide either id or name)
data.Wait - Optional. Should we wait for sequence to finish
data.Speed - Optional. Playback speed of sequence
-----------------------------------------------------------]]
function ENT:TaskStart_FindEnemy( data )
for k, v in ipairs( ents.FindInSphere( self:GetPos(), data.Radius or 512 ) ) do
if ( v:IsValid() && v != self && v:GetClass() == data.Class ) then
self:SetEnemy( v, true )
self:UpdateEnemyMemory( v, v:GetPos() )
self:TaskComplete()
return
end
end
self:SetEnemy( NULL )
end
function ENT:Task_FindEnemy( data )
end

View File

@@ -0,0 +1,114 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile()
ENT.Base = "base_entity"
ENT.Type = "anim"
ENT.PrintName = ""
ENT.Author = ""
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
-- Defaulting this to OFF. This will automatically save bandwidth
-- on stuff that is already out there, but might break a few things
-- that are out there. I'm choosing to break those things because
-- there are a lot less of them that are actually using the animtime
ENT.AutomaticFrameAdvance = false
function ENT:SetAutomaticFrameAdvance( bUsingAnim )
self.AutomaticFrameAdvance = bUsingAnim
end
function ENT:OnRemove()
end
function ENT:PhysicsCollide( data, physobj )
end
function ENT:PhysicsUpdate( physobj )
end
if ( CLIENT ) then
function ENT:Draw( flags )
self:DrawModel( flags )
end
function ENT:DrawTranslucent( flags )
-- This is here just to make it backwards compatible.
-- You shouldn't really be drawing your model here unless it's translucent
self:Draw( flags )
end
end
if ( SERVER ) then
function ENT:OnTakeDamage( dmginfo )
--[[
Msg( tostring(dmginfo) .. "\n" )
Msg( "Inflictor:\t" .. tostring(dmginfo:GetInflictor()) .. "\n" )
Msg( "Attacker:\t" .. tostring(dmginfo:GetAttacker()) .. "\n" )
Msg( "Damage:\t" .. tostring(dmginfo:GetDamage()) .. "\n" )
Msg( "Base Damage:\t" .. tostring(dmginfo:GetBaseDamage()) .. "\n" )
Msg( "Force:\t" .. tostring(dmginfo:GetDamageForce()) .. "\n" )
Msg( "Position:\t" .. tostring(dmginfo:GetDamagePosition()) .. "\n" )
Msg( "Reported Pos:\t" .. tostring(dmginfo:GetReportedPosition()) .. "\n" ) -- ??
--]]
end
function ENT:Use( activator, caller, type, value )
end
function ENT:StartTouch( entity )
end
function ENT:EndTouch( entity )
end
function ENT:Touch( entity )
end
--[[---------------------------------------------------------
Name: Simulate
Desc: Controls/simulates the physics on the entity.
Officially the most complicated callback in the whole mod.
Returns 3 variables..
1. A SIM_ enum
2. A vector representing the linear acceleration/force
3. A vector represending the angular acceleration/force
If you're doing nothing you can return SIM_NOTHING
Note that you need to call ent:StartMotionController to tell the entity
to start calling this function..
-----------------------------------------------------------]]
function ENT:PhysicsSimulate( phys, deltatime )
return SIM_NOTHING
end
end

View File

@@ -0,0 +1,66 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
ENT.Base = "base_entity"
ENT.Type = "brush"
--[[---------------------------------------------------------
Name: Initialize
-----------------------------------------------------------]]
function ENT:Initialize()
end
--[[---------------------------------------------------------
Name: StartTouch
-----------------------------------------------------------]]
function ENT:StartTouch( entity )
end
--[[---------------------------------------------------------
Name: EndTouch
-----------------------------------------------------------]]
function ENT:EndTouch( entity )
end
--[[---------------------------------------------------------
Name: Touch
-----------------------------------------------------------]]
function ENT:Touch( entity )
end
--[[---------------------------------------------------------
Name: PassesTriggerFilters
Desc: Return true if this object should trigger us
-----------------------------------------------------------]]
function ENT:PassesTriggerFilters( entity )
return true
end
--[[---------------------------------------------------------
Name: KeyValue
Desc: Called when a keyvalue is added to us
-----------------------------------------------------------]]
function ENT:KeyValue( key, value )
end
--[[---------------------------------------------------------
Name: Think
Desc: Entity's think function.
-----------------------------------------------------------]]
function ENT:Think()
end
--[[---------------------------------------------------------
Name: OnRemove
Desc: Called just before entity is deleted
-----------------------------------------------------------]]
function ENT:OnRemove()
end

View File

@@ -0,0 +1,34 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
include( "shared.lua" )
--[[---------------------------------------------------------
Name: Initialize
Desc: First function called. Use to set up your entity
-----------------------------------------------------------]]
function ENT:Initialize()
end
--[[---------------------------------------------------------
Name: Think
Desc: Client Think - called every frame
-----------------------------------------------------------]]
function ENT:Think()
end
--[[---------------------------------------------------------
Name: OnRestore
Desc: Called immediately after a "load"
-----------------------------------------------------------]]
function ENT:OnRestore()
end

View File

@@ -0,0 +1,87 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
include( "outputs.lua" )
--[[---------------------------------------------------------
Name: Initialize
Desc: First function called. Use to set up your entity
-----------------------------------------------------------]]
function ENT:Initialize()
end
--[[---------------------------------------------------------
Name: KeyValue
Desc: Called when a keyvalue is added to us
-----------------------------------------------------------]]
function ENT:KeyValue( key, value )
end
--[[---------------------------------------------------------
Name: OnRestore
Desc: The game has just been reloaded. This is usually the right place
to call the GetNW* functions to restore the script's values.
-----------------------------------------------------------]]
function ENT:OnRestore()
end
--[[---------------------------------------------------------
Name: AcceptInput
Desc: Accepts input, return true to override/accept input
-----------------------------------------------------------]]
function ENT:AcceptInput( name, activator, caller, data )
return false
end
--[[---------------------------------------------------------
Name: UpdateTransmitState
Desc: Set the transmit state
-----------------------------------------------------------]]
function ENT:UpdateTransmitState()
return TRANSMIT_PVS
end
--[[---------------------------------------------------------
Name: Think
Desc: Entity's think function.
-----------------------------------------------------------]]
function ENT:Think()
end
--
-- Default generic spawn function
-- So you don't have to add one your entitie unless you want to.
--
function ENT:SpawnFunction( ply, tr, ClassName )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 10
local SpawnAng = ply:EyeAngles()
SpawnAng.p = 0
SpawnAng.y = SpawnAng.y + 180
local ent = ents.Create( ClassName )
ent:SetCreator( ply )
ent:SetPos( SpawnPos )
ent:SetAngles( SpawnAng )
ent:Spawn()
ent:Activate()
ent:DropToFloor()
return ent
end

View File

@@ -0,0 +1,133 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is called from ENT:KeyValue(key,value) to store the output from
-- the map, it could also be called from ENT:AcceptInput I think, so if
-- ent_fire addoutput is used, we can store that too (that hasn't been
-- tested though).
-- Usage: self:StoreOutput("<name of output>","<entities to fire>,<input name>,<param>,<delay>,<times to be used>")
-- If called from ENT:KeyValue, then the first parameter is the key, and
-- the second is value.
function ENT:StoreOutput( name, info )
-- Newer Source Engine games use this symbol as a delimiter
local rawData = string.Explode( "\x1B", info )
if ( #rawData < 2 ) then
rawData = string.Explode( ",", info )
end
local Output = {}
Output.entities = rawData[1] or ""
Output.input = rawData[2] or ""
Output.param = rawData[3] or ""
Output.delay = tonumber( rawData[4] ) or 0
Output.times = tonumber( rawData[5] ) or -1
self.m_tOutputs = self.m_tOutputs or {}
self.m_tOutputs[ name ] = self.m_tOutputs[ name ] or {}
table.insert( self.m_tOutputs[ name ], Output )
end
-- This works like SetNetworkKeyValue, call it from ENT:KeyValue and it'll
-- return true if it successfully added an output from the passed KV pair.
function ENT:AddOutputFromKeyValue( key, value )
if ( key:sub( 1, 2 ) == "On" ) then
self:StoreOutput( key, value )
return true
end
return false
end
-- Call from ENT:AcceptInput and it'll return true if the input was AddOutput
-- and if it successfully added an output.
-- Note that to be strictly compatible with Source entities, AddOutput should
-- allow setting arbitrary keyvalues, but this implementation does not.
function ENT:AddOutputFromAcceptInput( name, value )
if ( name ~= "AddOutput" ) then
return false
end
local pos = string.find( value, " ", 1, true )
if ( pos == nil ) then
return false
end
name, value = value:sub( 1, pos - 1 ), value:sub( pos + 1 )
-- This is literally KeyValue but as an input and with ,s as :s.
value = value:gsub( ":", "," )
return self:AddOutputFromKeyValue( name, value )
end
-- Nice helper function, this does all the work. Returns false if the
-- output should be removed from the list.
local function FireSingleOutput( output, this, activator, data )
if ( output.times == 0 ) then return false end
local entitiesToFire = {}
if ( output.entities == "!activator" ) then
entitiesToFire = { activator }
elseif ( output.entities == "!self" ) then
entitiesToFire = { this }
elseif ( output.entities == "!player" ) then
entitiesToFire = player.GetAll()
else
entitiesToFire = ents.FindByName( output.entities )
end
for _, ent in ipairs( entitiesToFire ) do
ent:Fire( output.input, data or output.param, output.delay, activator, this )
end
if ( output.times ~= -1 ) then
output.times = output.times - 1
end
return ( output.times > 0 ) || ( output.times == -1 )
end
-- This function is used to trigger an output.
function ENT:TriggerOutput( name, activator, data )
if ( !self.m_tOutputs ) then return end
if ( !self.m_tOutputs[ name ] ) then return end
local OutputList = self.m_tOutputs[ name ]
for idx = #OutputList, 1, -1 do
if ( OutputList[ idx ] and !FireSingleOutput( OutputList[ idx ], self, activator, data ) ) then
-- Shift the indexes so this loop doesn't fail later
table.remove( self.m_tOutputs[ name ], idx )
end
end
end

View File

@@ -0,0 +1,16 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
ENT.Base = "base_entity"
ENT.Type = "anim"
ENT.Spawnable = false
ENT.AdminOnly = false

View File

@@ -0,0 +1,54 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
ENT.Base = "base_entity"
ENT.Type = "filter"
--[[---------------------------------------------------------
Name: Initialize
-----------------------------------------------------------]]
function ENT:Initialize()
end
--[[---------------------------------------------------------
Name: KeyValue
Desc: Called when a keyvalue is added to us
-----------------------------------------------------------]]
function ENT:KeyValue( key, value )
end
--[[---------------------------------------------------------
Name: Think
Desc: Entity's think function.
-----------------------------------------------------------]]
function ENT:Think()
end
--[[---------------------------------------------------------
Name: OnRemove
Desc: Called just before entity is deleted
-----------------------------------------------------------]]
function ENT:OnRemove()
end
--[[---------------------------------------------------------
Name: PassesFilter
-----------------------------------------------------------]]
function ENT:PassesFilter( trigger, ent )
return true
end
--[[---------------------------------------------------------
Name: PassesDamageFilter
-----------------------------------------------------------]]
function ENT:PassesDamageFilter( dmg )
return true
end

View File

@@ -0,0 +1,64 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile()
ENT.Base = "base_entity"
ENT.PrintName = ""
ENT.Author = ""
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
ENT.Type = "nextbot"
function ENT:Initialize()
end
if ( SERVER ) then
--
-- All of the AI logic is serverside - so we derive it from a
-- specialized class on the server.
--
include( "sv_nextbot.lua" )
else
--[[---------------------------------------------------------
Name: Draw
Desc: Draw it!
-----------------------------------------------------------]]
function ENT:Draw()
self:DrawModel()
end
--[[---------------------------------------------------------
Name: DrawTranslucent
Desc: Draw translucent
-----------------------------------------------------------]]
function ENT:DrawTranslucent()
-- This is here just to make it backwards compatible.
-- You shouldn't really be drawing your model here unless it's translucent
self:Draw()
end
--[[---------------------------------------------------------
Name: FireAnimationEvent
Desc: Called when an animation event is fired. Return true to suppress
-----------------------------------------------------------]]
function ENT:FireAnimationEvent( pos, ang, event, options )
end
end

View File

@@ -0,0 +1,425 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
--
-- Name: NEXTBOT:BehaveStart
-- Desc: Called to initialize the behaviour.\n\n You shouldn't override this - it's used to kick off the coroutine that runs the bot's behaviour. \n\nThis is called automatically when the NPC is created, there should be no need to call it manually.
-- Arg1:
-- Ret1:
--
function ENT:BehaveStart()
self.BehaveThread = coroutine.create( function() self:RunBehaviour() end )
end
function ENT:RunBehaviour()
end
--
-- Name: NEXTBOT:BehaveUpdate
-- Desc: Called to update the bot's behaviour
-- Arg1: number|interval|How long since the last update
-- Ret1:
--
function ENT:BehaveUpdate( fInterval )
if ( !self.BehaveThread ) then return end
--
-- Give a silent warning to developers if RunBehaviour has returned
--
if ( coroutine.status( self.BehaveThread ) == "dead" ) then
self.BehaveThread = nil
Msg( self, " Warning: ENT:RunBehaviour() has finished executing\n" )
return
end
--
-- Continue RunBehaviour's execution
--
local ok, message = coroutine.resume( self.BehaveThread )
if ( ok == false ) then
self.BehaveThread = nil
ErrorNoHalt( self, " Error: ", message, "\n" )
end
end
--
-- Name: NEXTBOT:BodyUpdate
-- Desc: Called to update the bot's animation
-- Arg1:
-- Ret1:
--
function ENT:BodyUpdate()
local act = self:GetActivity()
--
-- This helper function does a lot of useful stuff for us.
-- It sets the bot's move_x move_y pose parameters, sets their animation speed relative to the ground speed, and calls FrameAdvance.
--
if ( act == ACT_RUN || act == ACT_WALK ) then
self:BodyMoveXY()
-- BodyMoveXY() already calls FrameAdvance, calling it twice will affect animation playback, specifically on layers
return
end
--
-- If we're not walking or running we probably just want to update the anim system
--
self:FrameAdvance()
end
--
-- Name: NEXTBOT:OnLeaveGround
-- Desc: Called when the bot's feet leave the ground - for whatever reason
-- Arg1: Entity|ent|Entity that the NextBot "jumped" from
-- Ret1:
--
function ENT:OnLeaveGround( ent )
--MsgN( "OnLeaveGround", ent )
end
--
-- Name: NEXTBOT:OnLeaveGround
-- Desc: Called when the bot's feet return to the ground
-- Arg1: Entity|ent|Entity that the NextBot landed on
-- Ret1:
--
function ENT:OnLandOnGround( ent )
--MsgN( "OnLandOnGround", ent )
end
--
-- Name: NEXTBOT:OnStuck
-- Desc: Called when the bot thinks it is stuck
-- Arg1:
-- Ret1:
--
function ENT:OnStuck()
--MsgN( "OnStuck" )
end
--
-- Name: NEXTBOT:OnUnStuck
-- Desc: Called when the bot thinks it is un-stuck
-- Arg1:
-- Ret1:
--
function ENT:OnUnStuck()
--MsgN( "OnUnStuck" )
end
--
-- Name: NEXTBOT:OnTakeDamage
-- Desc: Called when the bot is about to take damage
-- Arg1: CTakeDamageInfo|info|damage info
-- Ret1: number|how much damage was taken, prevents default damage code from running
--
function ENT:OnTakeDamage( damageinfo )
-- return 0
end
--
-- Name: NEXTBOT:OnInjured
-- Desc: Called when the bot gets hurt
-- Arg1: CTakeDamageInfo|info|damage info
-- Ret1:
--
function ENT:OnInjured( damageinfo )
end
--
-- Name: NEXTBOT:OnKilled
-- Desc: Called when the bot gets killed
-- Arg1: CTakeDamageInfo|info|damage info
-- Ret1:
--
function ENT:OnKilled( dmginfo )
hook.Run( "OnNPCKilled", self, dmginfo:GetAttacker(), dmginfo:GetInflictor() )
self:BecomeRagdoll( dmginfo )
end
--
-- Name: NEXTBOT:OnOtherKilled
-- Desc: Called when someone else or something else has been killed
-- Arg1: Entity|victim|entity that was killed
-- Arg2: CTakeDamageInfo|info|damage info
-- Ret1:
--
function ENT:OnOtherKilled( victim, info )
--MsgN( "OnOtherKilled", victim, info )
end
function ENT:OnContact( ent )
--MsgN( "OnContact", ent )
end
function ENT:OnIgnite()
--MsgN( "OnIgnite" )
end
function ENT:OnNavAreaChanged( old, new )
--MsgN( "OnNavAreaChanged", old, new )
end
--
-- Name: NextBot:FindSpots
-- Desc: Returns a table of hiding spots.
-- Arg1: table|specs|This table should contain the search info.\n\n * 'type' - the type (either 'hiding')\n * 'pos' - the position to search.\n * 'radius' - the radius to search.\n * 'stepup' - the highest step to step up.\n * 'stepdown' - the highest we can step down without being hurt.
-- Ret1: table|An unsorted table of tables containing\n * 'vector' - the position of the hiding spot\n * 'distance' - the distance to that position
--
function ENT:FindSpots( tbl )
local tbl = tbl or {}
tbl.pos = tbl.pos or self:WorldSpaceCenter()
tbl.radius = tbl.radius or 1000
tbl.stepdown = tbl.stepdown or 20
tbl.stepup = tbl.stepup or 20
tbl.type = tbl.type or 'hiding'
-- Use a path to find the length
local path = Path( "Follow" )
-- Find a bunch of areas within this distance
local areas = navmesh.Find( tbl.pos, tbl.radius, tbl.stepdown, tbl.stepup )
local found = {}
-- In each area
for _, area in ipairs( areas ) do
-- get the spots
local spots
if ( tbl.type == 'hiding' ) then spots = area:GetHidingSpots() end
for k, vec in ipairs( spots ) do
-- Work out the length, and add them to a table
path:Invalidate()
path:Compute( self, vec ) -- TODO: This is bullshit - it's using 'self.pos' not tbl.pos
table.insert( found, { vector = vec, distance = path:GetLength() } )
end
end
return found
end
--
-- Name: NextBot:FindSpot
-- Desc: Like FindSpots but only returns a vector
-- Arg1: string|type|Either "random", "near", "far"
-- Arg2: table|options|A table containing a bunch of tweakable options. See the function definition for more details
-- Ret1: vector|If it finds a spot it will return a vector. If not it will return nil.
--
function ENT:FindSpot( type, options )
local spots = self:FindSpots( options )
if ( !spots || #spots == 0 ) then return end
if ( type == "near" ) then
table.SortByMember( spots, "distance", true )
return spots[1].vector
end
if ( type == "far" ) then
table.SortByMember( spots, "distance", false )
return spots[1].vector
end
-- random
return spots[ math.random( 1, #spots ) ].vector
end
--
-- Name: NextBot:HandleStuck
-- Desc: Called from Lua when the NPC is stuck. This should only be called from the behaviour coroutine - so if you want to override this function and do something special that yields - then go for it.\n\nYou should always call self.loco:ClearStuck() in this function to reset the stuck status - so it knows it's unstuck.
-- Arg1:
-- Ret1:
--
function ENT:HandleStuck()
--
-- Clear the stuck status
--
self.loco:ClearStuck()
end
--
-- Name: NextBot:MoveToPos
-- Desc: To be called in the behaviour coroutine only! Will yield until the bot has reached the goal or is stuck
-- Arg1: Vector|pos|The position we want to get to
-- Arg2: table|options|A table containing a bunch of tweakable options. See the function definition for more details
-- Ret1: string|Either "failed", "stuck", "timeout" or "ok" - depending on how the NPC got on
--
function ENT:MoveToPos( pos, options )
local options = options or {}
local path = Path( "Follow" )
path:SetMinLookAheadDistance( options.lookahead or 300 )
path:SetGoalTolerance( options.tolerance or 20 )
path:Compute( self, pos )
if ( !path:IsValid() ) then return "failed" end
while ( path:IsValid() ) do
path:Update( self )
-- Draw the path (only visible on listen servers or single player)
if ( options.draw ) then
path:Draw()
end
-- If we're stuck then call the HandleStuck function and abandon
if ( self.loco:IsStuck() ) then
self:HandleStuck()
return "stuck"
end
--
-- If they set maxage on options then make sure the path is younger than it
--
if ( options.maxage ) then
if ( path:GetAge() > options.maxage ) then return "timeout" end
end
--
-- If they set repath then rebuild the path every x seconds
--
if ( options.repath ) then
if ( path:GetAge() > options.repath ) then path:Compute( self, pos ) end
end
coroutine.yield()
end
return "ok"
end
--
-- Name: NextBot:PlaySequenceAndWait
-- Desc: To be called in the behaviour coroutine only! Plays an animation sequence and waits for it to end before returning.
-- Arg1: string|name|The sequence name
-- Arg2: number|the speed (default 1)
-- Ret1:
--
function ENT:PlaySequenceAndWait( name, speed )
local len = self:SetSequence( name )
speed = speed or 1
self:ResetSequenceInfo()
self:SetCycle( 0 )
self:SetPlaybackRate( speed )
-- wait for it to finish
coroutine.wait( len / speed )
end
--
-- Name: NEXTBOT:Use
-- Desc: Called when a player 'uses' the entity
-- Arg1: entity|activator|The entity that activated the use
-- Arg2: entity|called|The entity that called the use
-- Arg3: number|type|The type of use (USE_ON, USE_OFF, USE_TOGGLE, USE_SET)
-- Arg4: number|value|Any passed value
-- Ret1:
--
function ENT:Use( activator, caller, type, value )
end
--
-- Name: NEXTBOT:Think
-- Desc: Called periodically
-- Arg1:
-- Ret1:
--
function ENT:Think()
end
--
-- Name: NEXTBOT:HandleAnimEvent
-- Desc: Called for serverside events
--
function ENT:HandleAnimEvent( event, eventtime, cycle, typee, options )
end
--
-- Name: NEXTBOT:OnTraceAttack
-- Desc: Called serverside when the nextbot is attacked
--
function ENT:OnTraceAttack( dmginfo, dir, trace )
hook.Run( "ScaleNPCDamage", self, trace.HitGroup, dmginfo )
end
-- Called when we see a player or another nextbot
function ENT:OnEntitySight( subject )
end
-- Called when we see lose sight of a player or a nextbot we saw earlier
function ENT:OnEntitySightLost( subject )
end

View File

@@ -0,0 +1,55 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
ENT.Base = "base_entity"
ENT.Type = "point"
--[[---------------------------------------------------------
Name: Initialize
Desc: First function called. Use to set up your entity
-----------------------------------------------------------]]
function ENT:Initialize()
end
--[[---------------------------------------------------------
Name: KeyValue
Desc: Called when a keyvalue is added to us
-----------------------------------------------------------]]
function ENT:KeyValue( key, value )
end
--[[---------------------------------------------------------
Name: Think
Desc: Entity's think function.
-----------------------------------------------------------]]
function ENT:Think()
end
--
-- Name: OnRemove
-- Desc: Called just before entity is deleted
--
function ENT:OnRemove()
end
--
-- UpdateTransmitState
--
function ENT:UpdateTransmitState()
--
-- The default behaviour for point entities is to not be networked.
-- If you're deriving an entity and want it to appear clientside, override this
-- TRANSMIT_ALWAYS = always send, TRANSMIT_PVS = send if in PVS
--
return TRANSMIT_NEVER
end

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,142 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile()
ENT.Type = "point"
ENT.DisableDuplicator = true
--
-- Make this entity always networked
--
function ENT:UpdateTransmitState() return TRANSMIT_ALWAYS end
--
-- Networked / Saved Data
--
function ENT:SetupDataTables()
self:NetworkVar( "Vector", 0, "TopColor", { KeyName = "topcolor", Edit = { type = "VectorColor", category = "Main", order = 1 } } )
self:NetworkVar( "Vector", 1, "BottomColor", { KeyName = "bottomcolor", Edit = { type = "VectorColor", category = "Main", title = "Color Bottom", order = 2 } } )
self:NetworkVar( "Float", 0, "FadeBias", { KeyName = "fadebias", Edit = { type = "Float", category = "Main", min = 0, max = 1, order = 3 } } )
self:NetworkVar( "Float", 4, "SunSize", { KeyName = "sunsize", Edit = { type = "Float", min = 0, max = 10, category = "Sun" } } )
self:NetworkVar( "Vector", 2, "SunNormal", { KeyName = "sunnormal" } ) -- No editing this - it's for coders only
self:NetworkVar( "Vector", 3, "SunColor", { KeyName = "suncolor", Edit = { type = "VectorColor", category = "Sun" } } )
self:NetworkVar( "Float", 2, "DuskScale", { KeyName = "duskscale", Edit = { type = "Float", min = 0, max = 1, category = "Dusk" } } )
self:NetworkVar( "Float", 3, "DuskIntensity", { KeyName = "duskintensity", Edit = { type = "Float", min = 0, max = 10, category = "Dusk" } } )
self:NetworkVar( "Vector", 4, "DuskColor", { KeyName = "duskcolor", Edit = { type = "VectorColor", category = "Dusk" } } )
self:NetworkVar( "Bool", 0, "DrawStars", { KeyName = "drawstars", Edit = { type = "Boolean", category = "Stars", order = 10 } } )
self:NetworkVar( "String", 0, "StarTexture", { KeyName = "startexture", Edit = { type = "Texture", group = "Stars", category = "Stars", order = 11 } } )
self:NetworkVar( "Int", 0, "StarLayers", { KeyName = "starlayers", Edit = { type = "Int", min = 1, max = 3, category = "Stars", order = 12 } } )
self:NetworkVarElement( "Angle", 0, 'p', "StarScale", { KeyName = "starscale", Edit = { type = "Float", min = 0, max = 5, category = "Stars", order = 13 } } )
self:NetworkVarElement( "Angle", 0, 'y', "StarFade", { KeyName = "starfade", Edit = { type = "Float", min = 0, max = 5, category = "Stars", order = 14 } } )
self:NetworkVarElement( "Angle", 0, 'r', "StarSpeed", { KeyName = "starspeed", Edit = { type = "Float", min = 0, max = 2, category = "Stars", order = 15 } } )
self:NetworkVar( "Float", 1, "HDRScale", { KeyName = "hdrscale", Edit = { type = "Float", category = "Main", min = 0, max = 1, order = 4 } } )
--
-- Entity defaults
--
if ( SERVER ) then
self:SetTopColor( Vector( 0.2, 0.5, 1.0 ) )
self:SetBottomColor( Vector( 0.8, 1.0, 1.0 ) )
self:SetFadeBias( 1 )
self:SetSunNormal( Vector( 0.4, 0.0, 0.01 ) )
self:SetSunColor( Vector( 0.2, 0.1, 0.0 ) )
self:SetSunSize( 2.0 )
self:SetDuskColor( Vector( 1.0, 0.2, 0.0 ) )
self:SetDuskScale( 1 )
self:SetDuskIntensity( 1 )
self:SetDrawStars( true )
self:SetStarLayers( 1 )
self:SetStarSpeed( 0.01 )
self:SetStarScale( 0.5 )
self:SetStarFade( 1.5 )
self:SetStarTexture( "skybox/starfield" )
self:SetHDRScale( 0.66 )
end
end
function ENT:Initialize()
end
function ENT:KeyValue( key, value )
if ( self:SetNetworkKeyValue( key, value ) ) then
return
end
-- TODO: sunposmethod
-- 0 : "Custom - Use the Sun Normal to position the sun"
-- 1 : "Automatic - Find a env_sun entity and use that"
end
function ENT:Think()
--
-- Find an env_sun - if we don't already have one.
--
if ( SERVER && self.EnvSun == nil ) then
-- so this closure only gets called once - even if it fails
self.EnvSun = false
local sunlist = ents.FindByClass( "env_sun" )
if ( #sunlist > 0 ) then
self.EnvSun = sunlist[1]
end
end
--
-- If we have a sun - force our sun normal to its value
--
if ( SERVER && IsValid( self.EnvSun ) ) then
local vec = self.EnvSun:GetInternalVariable( "m_vDirection" )
if ( isvector( vec ) ) then
self:SetSunNormal( vec )
end
end
--
-- Become the active sky again if we're not already
--
if ( CLIENT && g_SkyPaint != self && !IsValid( g_SkyPaint ) ) then
g_SkyPaint = self
end
end
--
-- To prevent server insanity - only let admins edit the sky.
--
function ENT:CanEditVariables( ply )
return ply:IsAdmin() || game.SinglePlayer()
end

View File

@@ -0,0 +1,77 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile()
ENT.Type = "anim"
ENT.RenderGroup = RENDERGROUP_OTHER
function ENT:Initialize()
hook.Add( "OnViewModelChanged", self, self.ViewModelChanged )
self:SetNotSolid( true )
self:DrawShadow( false )
self:SetTransmitWithParent( true ) -- Transmit only when the viewmodel does!
end
function ENT:DoSetup( ply, spec )
-- Set these hands to the player
ply:SetHands( self )
self:SetOwner( ply )
-- Which hands should we use? Let the gamemode decide
hook.Call( "PlayerSetHandsModel", GAMEMODE, spec or ply, self )
-- Attach them to the viewmodel
local vm = ( spec or ply ):GetViewModel( 0 )
self:AttachToViewmodel( vm )
vm:DeleteOnRemove( self )
ply:DeleteOnRemove( self )
end
function ENT:GetPlayerColor()
--
-- Make sure there's an owner and they have this function
-- before trying to call it!
--
local owner = self:GetOwner()
if ( !IsValid( owner ) ) then return end
if ( !owner.GetPlayerColor ) then return end
return owner:GetPlayerColor()
end
function ENT:ViewModelChanged( vm, old, new )
-- Ignore other peoples viewmodel changes!
if ( vm:GetOwner() != self:GetOwner() ) then return end
self:AttachToViewmodel( vm )
end
function ENT:AttachToViewmodel( vm )
self:AddEffects( EF_BONEMERGE )
self:SetParent( vm )
self:SetMoveType( MOVETYPE_NONE )
self:SetPos( vector_origin )
self:SetAngles( angle_zero )
end

View File

@@ -0,0 +1,91 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"
function ENT:Initialize()
if ( self.RedTeam or self.GreenTeam or self.YellowTeam or self.BlueTeam ) then
-- If any of these are set to true then
-- make sure that any that aren't setup are
-- set to false.
self.BlueTeam = self.BlueTeam or false
self.GreenTeam = self.GreenTeam or false
self.YellowTeam = self.YellowTeam or false
self.RedTeam = self.RedTeam or false
else
-- If none are set then make it so that they all
-- are set to true since any team can spawn here.
-- This will also happen if we don't have the "spawnflags"
-- keyvalue setup.
self.BlueTeam = true
self.GreenTeam = true
self.YellowTeam = true
self.RedTeam = true
end
end
function ENT:KeyValue( key, value )
if ( key == "spawnflags" ) then
local sf = tonumber( value )
for i = 15, 0, -1 do
local bit = math.pow( 2, i )
-- Quick bit if bitwise math to figure out if the spawnflags
-- represent red/blue/green or yellow.
-- We have to use booleans since the TEAM_ identifiers
-- aren't setup at this point.
-- (this would be easier if we had bitwise operators in Lua)
if ( ( sf - bit ) >= 0 ) then
if ( bit == 8 ) then self.RedTeam = true
elseif ( bit == 4 ) then self.GreenTeam = true
elseif ( bit == 2 ) then self.YellowTeam = true
elseif ( bit == 1 ) then self.BlueTeam = true
end
sf = sf - bit
else
if ( bit == 8 ) then self.RedTeam = false
elseif ( bit == 4 ) then self.GreenTeam = false
elseif ( bit == 2 ) then self.YellowTeam = false
elseif ( bit == 1 ) then self.BlueTeam = false
end
end
end
end
end

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,20 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"

View File

@@ -0,0 +1,73 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- A spawnflag constant for addons
SF_LUA_RUN_ON_SPAWN = 1
ENT.Type = "point"
ENT.DisableDuplicator = true
AccessorFunc( ENT, "m_bDefaultCode", "DefaultCode" )
function ENT:Initialize()
-- If the entity has its first spawnflag set, run the code automatically
if ( self:HasSpawnFlags( SF_LUA_RUN_ON_SPAWN ) ) then
self:RunCode( self, self, self:GetDefaultCode() )
end
end
function ENT:KeyValue( key, value )
if ( key == "Code" ) then
self:SetDefaultCode( value )
end
end
function ENT:SetupGlobals( activator, caller )
ACTIVATOR = activator
CALLER = caller
if ( IsValid( activator ) && activator:IsPlayer() ) then
TRIGGER_PLAYER = activator
end
end
function ENT:KillGlobals()
ACTIVATOR = nil
CALLER = nil
TRIGGER_PLAYER = nil
end
function ENT:RunCode( activator, caller, code )
self:SetupGlobals( activator, caller )
RunString( code, "lua_run#" .. self:EntIndex() )
self:KillGlobals()
end
function ENT:AcceptInput( name, activator, caller, data )
if ( name == "RunCode" ) then self:RunCode( activator, caller, self:GetDefaultCode() ) return true end
if ( name == "RunPassedCode" ) then self:RunCode( activator, caller, data ) return true end
return false
end

View File

@@ -0,0 +1,82 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile()
ENT.Base = "base_nextbot"
ENT.Spawnable = false
function ENT:Initialize()
--self:SetModel( "models/props_halloween/ghost_no_hat.mdl" )
--self:SetModel( "models/props_wasteland/controlroom_filecabinet002a.mdl" )
self:SetModel( "models/mossman.mdl" )
end
function ENT:RunBehaviour()
while ( true ) do
self:StartActivity( ACT_WALK ) -- walk anims
self.loco:SetDesiredSpeed( 100 ) -- walk speeds
-- Choose a random location within 400 units of our position
local targetPos = self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 400
-- Search for walkable space there, or nearby
local area = navmesh.GetNearestNavArea( targetPos )
-- We found walkable space, get the closest point on that area to where we want to be
if ( IsValid( area ) ) then targetPos = area:GetClosestPointOnArea( targetPos ) end
-- walk to the target place (yielding)
self:MoveToPos( targetPos )
self:StartActivity( ACT_IDLE ) -- revert to idle activity
self:PlaySequenceAndWait( "idle_to_sit_ground" ) -- Sit on the floor
self:SetSequence( "sit_ground" ) -- Stay sitting
coroutine.wait( self:PlayScene( "scenes/eli_lab/mo_gowithalyx01.vcd" ) ) -- play a scene and wait for it to finish before progressing
self:PlaySequenceAndWait( "sit_ground_to_idle" ) -- Get up
-- find the furthest away hiding spot
local pos = self:FindSpot( "random", { type = "hiding", radius = 5000 } )
-- if the position is valid
if ( pos ) then
self:StartActivity( ACT_RUN ) -- run anim
self.loco:SetDesiredSpeed( 200 ) -- run speed
self:PlayScene( "scenes/npc/female01/watchout.vcd" ) -- shout something while we run just for a laugh
self:MoveToPos( pos ) -- move to position (yielding)
self:PlaySequenceAndWait( "fear_reaction" ) -- play a fear animation
self:StartActivity( ACT_IDLE ) -- when we finished, go into the idle anim
else
-- some activity to signify that we didn't find shit
end
coroutine.yield()
end
end
--
-- List the NPC as spawnable
--
list.Set( "NPC", "npc_tf2_ghost", {
Name = "Example NPC",
Class = "npc_tf2_ghost",
Category = "Nextbot"
} )

View File

@@ -0,0 +1,188 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile()
if ( CLIENT ) then
CreateConVar( "cl_draweffectrings", "1", 0, "Should the green effect rings be visible?" )
end
ENT.Type = "anim"
ENT.Spawnable = false
function ENT:Initialize()
local Radius = 6
local mins = Vector( 1, 1, 1 ) * Radius * -0.5
local maxs = Vector( 1, 1, 1 ) * Radius * 0.5
if ( SERVER ) then
self.AttachedEntity = ents.Create( "prop_dynamic" )
self.AttachedEntity:SetModel( self:GetModel() )
self.AttachedEntity:SetAngles( self:GetAngles() )
self.AttachedEntity:SetPos( self:GetPos() )
self.AttachedEntity:SetSkin( self:GetSkin() )
self.AttachedEntity:Spawn()
self.AttachedEntity:SetParent( self )
self.AttachedEntity:DrawShadow( false )
self:SetModel( "models/props_junk/watermelon01.mdl" )
self:DeleteOnRemove( self.AttachedEntity )
self.AttachedEntity:DeleteOnRemove( self )
-- Don't use the model's physics - create a box instead
self:PhysicsInitBox( mins, maxs )
self:SetSolid( SOLID_VPHYSICS )
-- Set up our physics object here
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:Wake()
phys:EnableGravity( false )
phys:EnableDrag( false )
end
self:DrawShadow( false )
self:SetCollisionGroup( COLLISION_GROUP_WEAPON )
else
-- So addons can override this
self.GripMaterial = Material( "sprites/grip" )
self.GripMaterialHover = Material( "sprites/grip_hover" )
-- Get the attached entity so that clientside functions like properties can interact with it
local tab = ents.FindByClassAndParent( "prop_dynamic", self )
if ( tab && IsValid( tab[ 1 ] ) ) then self.AttachedEntity = tab[ 1 ] end
end
-- Set collision bounds exactly
self:SetCollisionBounds( mins, maxs )
end
function ENT:Draw()
if ( halo.RenderedEntity() == self ) then
self.AttachedEntity:DrawModel()
return
end
if ( GetConVarNumber( "cl_draweffectrings" ) == 0 ) then return end
-- Don't draw the grip if there's no chance of us picking it up
local ply = LocalPlayer()
local wep = ply:GetActiveWeapon()
if ( !IsValid( wep ) ) then return end
local weapon_name = wep:GetClass()
if ( weapon_name != "weapon_physgun" && weapon_name != "weapon_physcannon" && weapon_name != "gmod_tool" ) then
return
end
if ( self:BeingLookedAtByLocalPlayer() ) then
render.SetMaterial( self.GripMaterialHover )
else
render.SetMaterial( self.GripMaterial )
end
render.DrawSprite( self:GetPos(), 16, 16, color_white )
end
-- Copied from base_gmodentity.lua
ENT.MaxWorldTipDistance = 256
function ENT:BeingLookedAtByLocalPlayer()
local ply = LocalPlayer()
if ( !IsValid( ply ) ) then return false end
local view = ply:GetViewEntity()
local dist = self.MaxWorldTipDistance
dist = dist * dist
-- If we're spectating a player, perform an eye trace
if ( view:IsPlayer() ) then
return view:EyePos():DistToSqr( self:GetPos() ) <= dist && view:GetEyeTrace().Entity == self
end
-- If we're not spectating a player, perform a manual trace from the entity's position
local pos = view:GetPos()
if ( pos:DistToSqr( self:GetPos() ) <= dist ) then
return util.TraceLine( {
start = pos,
endpos = pos + ( view:GetAngles():Forward() * dist ),
filter = view
} ).Entity == self
end
return false
end
function ENT:PhysicsUpdate( physobj )
if ( CLIENT ) then return end
-- Don't do anything if the player isn't holding us
if ( !self:IsPlayerHolding() && !self:IsConstrained() ) then
physobj:SetVelocity( vector_origin )
physobj:Sleep()
end
end
function ENT:OnEntityCopyTableFinish( tab )
-- We need to store the model of the attached entity
-- Not the one we have here.
tab.Model = self.AttachedEntity:GetModel()
-- Store the attached entity's table so we can restore it after being pasted
tab.AttachedEntityInfo = table.Copy( duplicator.CopyEntTable( self.AttachedEntity ) )
tab.AttachedEntityInfo.Pos = nil -- Don't even save angles and position, we are a parented entity
tab.AttachedEntityInfo.Angle = nil
-- Do NOT store the attached entity itself in our table!
-- Otherwise, if we copy-paste the prop with the duplicator, its AttachedEntity value will point towards the original prop's attached entity instead, and that'll break stuff
tab.AttachedEntity = nil
end
function ENT:PostEntityPaste( ply )
-- Restore the attached entity using the information we've saved
if ( IsValid( self.AttachedEntity ) && self.AttachedEntityInfo ) then
-- Apply skin, bodygroups, bone manipulator, etc.
duplicator.DoGeneric( self.AttachedEntity, self.AttachedEntityInfo )
if ( self.AttachedEntityInfo.EntityMods ) then
self.AttachedEntity.EntityMods = table.Copy( self.AttachedEntityInfo.EntityMods )
duplicator.ApplyEntityModifiers( ply, self.AttachedEntity )
end
if ( self.AttachedEntityInfo.BoneMods ) then
self.AttachedEntity.BoneMods = table.Copy( self.AttachedEntityInfo.BoneMods )
duplicator.ApplyBoneModifiers( ply, self.AttachedEntity )
end
self.AttachedEntityInfo = nil
end
end

View File

@@ -0,0 +1,317 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile()
ENT.Type = "anim"
ENT.Spawnable = false
ENT.AdminOnly = false
ENT.Editable = true
function ENT:SetupDataTables()
--
-- Scale - how far the ragdoll will move in the game world in relation to how far it moved in the real world
--
self:NetworkVar( "Float", 0, "Scale", { KeyName = "scale", Edit = { type = "Float", min = 1, max = 512, order = 1 } } )
--
-- Normalize - if enabled the limbs aren't stretched
--
self:NetworkVar( "Bool", 0, "Normalize", { KeyName = "normalize", Edit = { type = "Boolean", order = 2 } } )
--
-- Debug - Shows some debug info - only available on a listen server
--
self:NetworkVar( "Bool", 1, "Debug", { KeyName = "debug", Edit = { type = "Boolean", order = 100 } } )
--
-- Controller - the entity that is currently controlling the ragdoll
--
self:NetworkVar( "Entity", 0, "Controller" )
self:NetworkVar( "Entity", 1, "Target" )
--
-- Defaults
--
if ( SERVER ) then
self:SetScale( 36 )
self:SetDebug( false )
self:SetNormalize( true )
end
end
function ENT:Initialize()
if ( SERVER ) then
self:SetModel( "models/maxofs2d/motion_sensor.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
-- Don't collide with the player
self:SetCollisionGroup( COLLISION_GROUP_WEAPON )
self:DrawShadow( false )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:Wake()
phys:EnableGravity( false )
phys:EnableDrag( false )
end
local colors = {
Color( 180, 255, 50 ),
Color( 0, 150, 255 ),
Color( 255, 255, 0 ),
Color( 255, 50, 255 )
}
self:SetColor( table.Random( colors ) )
end
end
--
-- We don't want to move unless the player moves us or we're constrained to something.
--
function ENT:PhysicsUpdate( physobj )
if ( self:IsPlayerHolding() ) then return end
if ( self:IsConstrained() ) then return end
physobj:SetVelocity( vector_origin )
physobj:Sleep()
end
--
-- Clean up on remove
--
function ENT:OnRemove()
if ( SERVER ) then
local ragdoll = self:GetTarget()
if ( IsValid( ragdoll ) ) then
ragdoll:SetRagdollBuildFunction( nil )
if ( IsValid( ragdoll.MotionSensorController ) && ragdoll.MotionSensorController == self ) then
ragdoll.MotionSensorController = nil
end
end
end
end
function ENT:Draw()
--
-- Don't draw if we're holding the camera
--
local ply = LocalPlayer()
local wep = ply:GetActiveWeapon()
if ( IsValid( wep ) && wep:GetClass() == "gmod_camera" ) then
return
end
self:DrawModel()
end
function ENT:DrawDebug( ragdoll, controller, pos, ang, rotation, scale, center, changed_sensor )
local UpdateTime = 0.1
local StayTime = 0.15
if ( self.LastDebugUpdate && CurTime() - self.LastDebugUpdate < UpdateTime ) then return end
self.LastDebugUpdate = CurTime()
center = center
local col_bone = color_white
local col_point = Color( 255, 0, 0, 255 )
local col_tran_bn = Color( 0, 255, 0, 255 )
local realbonepos = {}
local fixedbonepos = {}
local min = Vector( 1, 1, 1 ) * -0.5
local max = Vector( 1, 1, 1 ) * 0.5
--
-- Draw Points
--
for i = 0, 19 do
realbonepos[i] = controller:MotionSensorPos( i ) * scale
realbonepos[i]:Rotate( rotation )
realbonepos[i] = realbonepos[i] + center
fixedbonepos[i] = changed_sensor[ i ] * scale
-- (already rotated)
fixedbonepos[i] = fixedbonepos[i] + center
debugoverlay.Box( realbonepos[i], min, max, StayTime, col_point )
debugoverlay.Box( fixedbonepos[i], min, max, StayTime, col_tran_bn )
end
--
-- Draw bones
--
for k, v in ipairs( motionsensor.DebugBones ) do
debugoverlay.Line( realbonepos[ v[1] ], realbonepos[ v[2] ], StayTime, col_bone, true )
end
--
-- Draw translated sensor bones
--
for k, v in ipairs( motionsensor.DebugBones ) do
debugoverlay.Line( fixedbonepos[ v[1] ], fixedbonepos[ v[2] ], StayTime, col_tran_bn, true )
end
--
-- Draw ragdoll physics bones
--
for i = 0, ragdoll:GetPhysicsObjectCount() - 1 do
local phys = ragdoll:GetPhysicsObjectNum( i )
local position = phys:GetPos()
local angle = phys:GetAngles()
local txt = tostring( i )
if ( ang[i] == nil ) then
txt = i .. " (UNSET)"
end
debugoverlay.Text( position, txt, StayTime )
debugoverlay.Axis( position, angle, 5, StayTime, true )
end
end
function ENT:SetRagdoll( ragdoll )
ragdoll.MotionSensorController = self
self:SetTarget( ragdoll )
ragdoll:PhysWake()
local buildername = motionsensor.ChooseBuilderFromEntity( ragdoll )
--
-- Set the ragdoll build function.
-- This function is called whenever the ragdoll bones are built.
-- in this function is the one place you can successfully call ent:SetRagdollBone
--
ragdoll:SetRagdollBuildFunction( function( ragdoll )
local controller = self:GetController()
if ( !IsValid( controller ) ) then return end
local builder = list.Get( "SkeletonConvertor" )[ buildername ]
local scale = self:GetScale()
local rotation = self:GetAngles()
local center = self:GetPos()
local normalize = self:GetNormalize()
local debug = self:GetDebug()
--
-- Call the build skeleton function.
-- This is thrown out to a pseudo class because we want to be
-- able to add new skeleton types nice and easily.
--
local pos, ang, changed_sensor = motionsensor.BuildSkeleton( builder, controller, rotation )
--
-- For development
--
if ( debug ) then
self:DrawDebug( ragdoll, controller, pos, ang, rotation, scale, center, changed_sensor )
end
--
-- If we don't have 85% of the points, just drop dead
--
local iSkipped = 0
local iMaxSkip = table.Count( pos ) * 0.25
for k, v in pairs( pos ) do
if ( math.abs( v.x ) > 0.05 ) then continue end
if ( math.abs( v.y ) > 0.05 ) then continue end
pos[k] = nil -- don't use this point to control the ragdoll
ang[k] = nil -- (use the ragdoll point)
iSkipped = iSkipped + 1
if ( iSkipped > iMaxSkip ) then
ragdoll:RagdollStopControlling()
return
end
end
--
-- Loop each returned position
--
for k, v in pairs( pos ) do
--
-- Set the bone angle
--
if ( ang[ k ] != nil ) then
ragdoll:SetRagdollAng( k, ang[ k ] )
end
--
-- The root bone, we directly set the position of this one.
--
if ( k == 0 || !normalize ) then
local new_position = center + v * scale
ragdoll:SetRagdollPos( k, new_position )
end
end
--
-- Normalize the ragdoll
--
if ( normalize ) then
ragdoll:RagdollSolve()
end
--
-- Makes the physics objects follow the set bone positions
--
ragdoll:RagdollUpdatePhysics()
end )
end

View File

@@ -0,0 +1,202 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
--[[---------------------------------------------------------
Name: SetupWeaponHoldTypeForAI
Desc: Sets up ACT translations from generic activities to NPC specific activies. In a seperate file to clean up the init.lua
Not all NPCs have support for all animations (for example Citizens don't have pistol animations)
This only supports the holdtypes the default NPC models can support
All of these are taken directly from IMPLEMENT_ACTTABLE() macro of the C++ weapons
-----------------------------------------------------------]]
function SWEP:SetupWeaponHoldTypeForAI( t )
self.ActivityTranslateAI = {}
-- Default is pistol/revolver for reasons
self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_ANGRY_PISTOL
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_RANGE_ATTACK_PISTOL
self.ActivityTranslateAI[ ACT_RELOAD ] = ACT_RELOAD_PISTOL
self.ActivityTranslateAI[ ACT_WALK_AIM ] = ACT_WALK_AIM_PISTOL
self.ActivityTranslateAI[ ACT_RUN_AIM ] = ACT_RUN_AIM_PISTOL
self.ActivityTranslateAI[ ACT_GESTURE_RANGE_ATTACK1 ] = ACT_GESTURE_RANGE_ATTACK_PISTOL
self.ActivityTranslateAI[ ACT_RELOAD_LOW ] = ACT_RELOAD_PISTOL_LOW
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ] = ACT_RANGE_ATTACK_PISTOL_LOW
self.ActivityTranslateAI[ ACT_COVER_LOW ] = ACT_COVER_PISTOL_LOW
self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ] = ACT_RANGE_AIM_PISTOL_LOW
self.ActivityTranslateAI[ ACT_GESTURE_RELOAD ] = ACT_GESTURE_RELOAD_PISTOL
self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK_PISTOL
self.ActivityTranslateAI[ ACT_RUN ] = ACT_RUN_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE_STIMULATED
self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_ANGRY_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_STEALTH ] = ACT_IDLE_STEALTH_PISTOL
self.ActivityTranslateAI[ ACT_WALK_RELAXED ] = ACT_WALK
self.ActivityTranslateAI[ ACT_WALK_STIMULATED ] = ACT_WALK_STIMULATED
self.ActivityTranslateAI[ ACT_WALK_AGITATED ] = ACT_WALK_AIM_PISTOL
self.ActivityTranslateAI[ ACT_WALK_STEALTH ] = ACT_WALK_STEALTH_PISTOL
self.ActivityTranslateAI[ ACT_RUN_RELAXED ] = ACT_RUN
self.ActivityTranslateAI[ ACT_RUN_STIMULATED ] = ACT_RUN_STIMULATED
self.ActivityTranslateAI[ ACT_RUN_AGITATED ] = ACT_RUN_AIM_PISTOL
self.ActivityTranslateAI[ ACT_RUN_STEALTH ] = ACT_RUN_STEALTH_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_AIM_RELAXED ] = ACT_IDLE_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_AIM_STIMULATED ] = ACT_IDLE_ANGRY_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_AIM_AGITATED ] = ACT_IDLE_ANGRY_PISTOL
self.ActivityTranslateAI[ ACT_IDLE_AIM_STEALTH ] = ACT_IDLE_STEALTH_PISTOL
self.ActivityTranslateAI[ ACT_WALK_AIM_RELAXED ] = ACT_WALK
self.ActivityTranslateAI[ ACT_WALK_AIM_STIMULATED ] = ACT_WALK_AIM_PISTOL
self.ActivityTranslateAI[ ACT_WALK_AIM_AGITATED ] = ACT_WALK_AIM_PISTOL
self.ActivityTranslateAI[ ACT_WALK_AIM_STEALTH ] = ACT_WALK_AIM_STEALTH_PISTOL
self.ActivityTranslateAI[ ACT_RUN_AIM_RELAXED ] = ACT_RUN
self.ActivityTranslateAI[ ACT_RUN_AIM_STIMULATED ] = ACT_RUN_AIM_PISTOL
self.ActivityTranslateAI[ ACT_RUN_AIM_AGITATED ] = ACT_RUN_AIM_PISTOL
self.ActivityTranslateAI[ ACT_RUN_AIM_STEALTH ] = ACT_RUN_AIM_STEALTH_PISTOL
self.ActivityTranslateAI[ ACT_CROUCHIDLE_STIMULATED] = ACT_CROUCHIDLE_STIMULATED
self.ActivityTranslateAI[ ACT_CROUCHIDLE_AIM_STIMULATED ] = ACT_RANGE_AIM_PISTOL_LOW
self.ActivityTranslateAI[ ACT_CROUCHIDLE_AGITATED ] = ACT_RANGE_AIM_PISTOL_LOW
self.ActivityTranslateAI[ ACT_READINESS_RELAXED_TO_STIMULATED ] = ACT_READINESS_PISTOL_RELAXED_TO_STIMULATED
self.ActivityTranslateAI[ ACT_READINESS_RELAXED_TO_STIMULATED_WALK ] = ACT_READINESS_PISTOL_RELAXED_TO_STIMULATED_WALK
self.ActivityTranslateAI[ ACT_READINESS_AGITATED_TO_STIMULATED ] = ACT_READINESS_PISTOL_AGITATED_TO_STIMULATED
self.ActivityTranslateAI[ ACT_READINESS_STIMULATED_TO_RELAXED ] = ACT_READINESS_PISTOL_STIMULATED_TO_RELAXED
if ( t == "ar2" || t == "smg" ) then
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_RANGE_ATTACK_AR2
self.ActivityTranslateAI[ ACT_RELOAD ] = ACT_RELOAD_SMG1
self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE_SMG1
self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_ANGRY_SMG1
self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK_RIFLE
self.ActivityTranslateAI[ ACT_WALK_AIM ] = ACT_WALK_AIM_RIFLE
self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE_SMG1_RELAXED
self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE_SMG1_STIMULATED
self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_ANGRY_SMG1
self.ActivityTranslateAI[ ACT_WALK_RELAXED ] = ACT_WALK_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_WALK_STIMULATED ] = ACT_WALK_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_WALK_AGITATED ] = ACT_WALK_AIM_RIFLE
self.ActivityTranslateAI[ ACT_RUN_RELAXED ] = ACT_RUN_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_RUN_STIMULATED ] = ACT_RUN_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_RUN_AGITATED ] = ACT_RUN_AIM_RIFLE
self.ActivityTranslateAI[ ACT_IDLE_AIM_RELAXED ] = ACT_IDLE_SMG1_RELAXED
self.ActivityTranslateAI[ ACT_IDLE_AIM_STIMULATED ] = ACT_IDLE_AIM_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_IDLE_AIM_AGITATED ] = ACT_IDLE_ANGRY_SMG1
self.ActivityTranslateAI[ ACT_WALK_AIM_RELAXED ] = ACT_WALK_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_WALK_AIM_STIMULATED ] = ACT_WALK_AIM_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_WALK_AIM_AGITATED ] = ACT_WALK_AIM_RIFLE
self.ActivityTranslateAI[ ACT_RUN_AIM_RELAXED ] = ACT_RUN_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_RUN_AIM_STIMULATED ] = ACT_RUN_AIM_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_RUN_AIM_AGITATED ] = ACT_RUN_AIM_RIFLE
self.ActivityTranslateAI[ ACT_WALK_CROUCH ] = ACT_WALK_CROUCH_RIFLE
self.ActivityTranslateAI[ ACT_WALK_CROUCH_AIM ] = ACT_WALK_CROUCH_AIM_RIFLE
self.ActivityTranslateAI[ ACT_RUN ] = ACT_RUN_RIFLE
self.ActivityTranslateAI[ ACT_RUN_AIM ] = ACT_RUN_AIM_RIFLE
self.ActivityTranslateAI[ ACT_RUN_CROUCH ] = ACT_RUN_CROUCH_RIFLE
self.ActivityTranslateAI[ ACT_RUN_CROUCH_AIM ] = ACT_RUN_CROUCH_AIM_RIFLE
self.ActivityTranslateAI[ ACT_GESTURE_RANGE_ATTACK1 ] = ACT_GESTURE_RANGE_ATTACK_AR2
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ] = ACT_RANGE_ATTACK_SMG1_LOW
self.ActivityTranslateAI[ ACT_COVER_LOW ] = ACT_COVER_SMG1_LOW
self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ] = ACT_RANGE_AIM_AR2_LOW
self.ActivityTranslateAI[ ACT_RELOAD_LOW ] = ACT_RELOAD_SMG1_LOW
self.ActivityTranslateAI[ ACT_GESTURE_RELOAD ] = ACT_GESTURE_RELOAD_SMG1
-- Extra overrides for SMG holdtype
if ( t == "smg" ) then
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_RANGE_ATTACK_SMG1
self.ActivityTranslateAI[ ACT_GESTURE_RANGE_ATTACK1 ] = ACT_GESTURE_RANGE_ATTACK_SMG1
self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ] = ACT_RANGE_AIM_SMG1_LOW
end
return
end
if ( t == "shotgun" || t == "crossbow" ) then
self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE_SMG1
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_RANGE_ATTACK_SHOTGUN
self.ActivityTranslateAI[ ACT_RELOAD ] = ACT_RELOAD_SHOTGUN
self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK_RIFLE
self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_ANGRY_SHOTGUN
self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE_SHOTGUN_RELAXED
self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE_SHOTGUN_STIMULATED
self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_SHOTGUN_AGITATED
self.ActivityTranslateAI[ ACT_WALK_RELAXED ] = ACT_WALK_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_WALK_STIMULATED ] = ACT_WALK_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_WALK_AGITATED ] = ACT_WALK_AIM_RIFLE
self.ActivityTranslateAI[ ACT_RUN_RELAXED ] = ACT_RUN_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_RUN_STIMULATED ] = ACT_RUN_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_RUN_AGITATED ] = ACT_RUN_AIM_RIFLE
self.ActivityTranslateAI[ ACT_IDLE_AIM_RELAXED ] = ACT_IDLE_SMG1_RELAXED
self.ActivityTranslateAI[ ACT_IDLE_AIM_STIMULATED ] = ACT_IDLE_AIM_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_IDLE_AIM_AGITATED ] = ACT_IDLE_ANGRY_SMG1
self.ActivityTranslateAI[ ACT_WALK_AIM_RELAXED ] = ACT_WALK_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_WALK_AIM_STIMULATED ] = ACT_WALK_AIM_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_WALK_AIM_AGITATED ] = ACT_WALK_AIM_RIFLE
self.ActivityTranslateAI[ ACT_RUN_AIM_RELAXED ] = ACT_RUN_RIFLE_RELAXED
self.ActivityTranslateAI[ ACT_RUN_AIM_STIMULATED ] = ACT_RUN_AIM_RIFLE_STIMULATED
self.ActivityTranslateAI[ ACT_RUN_AIM_AGITATED ] = ACT_RUN_AIM_RIFLE
self.ActivityTranslateAI[ ACT_WALK_AIM ] = ACT_WALK_AIM_SHOTGUN
self.ActivityTranslateAI[ ACT_WALK_CROUCH ] = ACT_WALK_CROUCH_RIFLE
self.ActivityTranslateAI[ ACT_WALK_CROUCH_AIM ] = ACT_WALK_CROUCH_AIM_RIFLE
self.ActivityTranslateAI[ ACT_RUN ] = ACT_RUN_RIFLE
self.ActivityTranslateAI[ ACT_RUN_AIM ] = ACT_RUN_AIM_SHOTGUN
self.ActivityTranslateAI[ ACT_RUN_CROUCH ] = ACT_RUN_CROUCH_RIFLE
self.ActivityTranslateAI[ ACT_RUN_CROUCH_AIM ] = ACT_RUN_CROUCH_AIM_RIFLE
self.ActivityTranslateAI[ ACT_GESTURE_RANGE_ATTACK1 ] = ACT_GESTURE_RANGE_ATTACK_SHOTGUN
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ] = ACT_RANGE_ATTACK_SHOTGUN_LOW
self.ActivityTranslateAI[ ACT_RELOAD_LOW ] = ACT_RELOAD_SHOTGUN_LOW
self.ActivityTranslateAI[ ACT_GESTURE_RELOAD ] = ACT_GESTURE_RELOAD_SHOTGUN
return
end
if ( t == "rpg" ) then
self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_RANGE_ATTACK_RPG
self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE_RPG_RELAXED
self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE_ANGRY_RPG
self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_ANGRY_RPG
self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE_RPG
self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_ANGRY_RPG
self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK_RPG
self.ActivityTranslateAI[ ACT_WALK_CROUCH ] = ACT_WALK_CROUCH_RPG
self.ActivityTranslateAI[ ACT_RUN ] = ACT_RUN_RPG
self.ActivityTranslateAI[ ACT_RUN_CROUCH ] = ACT_RUN_CROUCH_RPG
self.ActivityTranslateAI[ ACT_COVER_LOW ] = ACT_COVER_LOW_RPG
return
end
end

View File

@@ -0,0 +1,221 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
include( "ai_translations.lua" )
include( "sh_anim.lua" )
include( "shared.lua" )
SWEP.Slot = 0 -- Slot in the weapon selection menu
SWEP.SlotPos = 10 -- Position in the slot
SWEP.DrawAmmo = true -- Should draw the default HL2 ammo counter
SWEP.DrawCrosshair = true -- Should draw the default crosshair
SWEP.DrawWeaponInfoBox = true -- Should draw the weapon info box
SWEP.BounceWeaponIcon = true -- Should the weapon icon bounce?
SWEP.SwayScale = 1.0 -- The scale of the viewmodel sway
SWEP.BobScale = 1.0 -- The scale of the viewmodel bob
SWEP.RenderGroup = RENDERGROUP_OPAQUE
-- Override this in your SWEP to set the icon in the weapon selection
SWEP.WepSelectIcon = surface.GetTextureID( "weapons/swep" )
-- This is the corner of the speech bubble
SWEP.SpeechBubbleLid = surface.GetTextureID( "gui/speech_lid" )
--[[---------------------------------------------------------
You can draw to the HUD here - it will only draw when
the client has the weapon deployed..
-----------------------------------------------------------]]
function SWEP:DrawHUD()
end
--[[---------------------------------------------------------
Checks the objects before any action is taken
This is to make sure that the entities haven't been removed
-----------------------------------------------------------]]
function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
-- Set us up the texture
surface.SetDrawColor( 255, 255, 255, alpha )
surface.SetTexture( self.WepSelectIcon )
-- Lets get a sin wave to make it bounce
local fsin = 0
if ( self.BounceWeaponIcon == true ) then
fsin = math.sin( CurTime() * 10 ) * 5
end
-- Borders
y = y + 10
x = x + 10
wide = wide - 20
-- Draw that mother
surface.DrawTexturedRect( x + fsin, y - fsin, wide - fsin * 2 , ( wide / 2 ) + fsin )
-- Draw weapon info box
self:PrintWeaponInfo( x + wide + 20, y + tall * 0.95, alpha )
end
--[[---------------------------------------------------------
This draws the weapon info box
-----------------------------------------------------------]]
function SWEP:PrintWeaponInfo( x, y, alpha )
if ( self.DrawWeaponInfoBox == false ) then return end
if ( self.InfoMarkup == nil ) then
local title_color = "<color=230,230,230,255>"
local text_color = "<color=150,150,150,255>"
local str = "<font=HudSelectionText>"
if ( self.Author != "" ) then str = str .. title_color .. "Author:</color>\t" .. text_color .. self.Author .. "</color>\n" end
if ( self.Contact != "" ) then str = str .. title_color .. "Contact:</color>\t" .. text_color .. self.Contact .. "</color>\n\n" end
if ( self.Purpose != "" ) then str = str .. title_color .. "Purpose:</color>\n" .. text_color .. self.Purpose .. "</color>\n\n" end
if ( self.Instructions != "" ) then str = str .. title_color .. "Instructions:</color>\n" .. text_color .. self.Instructions .. "</color>\n" end
str = str .. "</font>"
self.InfoMarkup = markup.Parse( str, 250 )
end
surface.SetDrawColor( 60, 60, 60, alpha )
surface.SetTexture( self.SpeechBubbleLid )
surface.DrawTexturedRect( x, y - 64 - 5, 128, 64 )
draw.RoundedBox( 8, x - 5, y - 6, 260, self.InfoMarkup:GetHeight() + 18, Color( 60, 60, 60, alpha ) )
self.InfoMarkup:Draw( x + 5, y + 5, nil, nil, alpha )
end
--[[---------------------------------------------------------
Name: SWEP:FreezeMovement()
Desc: Return true to freeze moving the view
-----------------------------------------------------------]]
function SWEP:FreezeMovement()
return false
end
--[[---------------------------------------------------------
Name: SWEP:ViewModelDrawn( viewModel )
Desc: Called straight after the viewmodel has been drawn
-----------------------------------------------------------]]
function SWEP:ViewModelDrawn( vm )
end
--[[---------------------------------------------------------
Name: OnRestore
Desc: Called immediately after a "load"
-----------------------------------------------------------]]
function SWEP:OnRestore()
end
--[[---------------------------------------------------------
Name: CustomAmmoDisplay
Desc: Return a table
-----------------------------------------------------------]]
function SWEP:CustomAmmoDisplay()
end
--[[---------------------------------------------------------
Name: GetViewModelPosition
Desc: Allows you to re-position the view model
-----------------------------------------------------------]]
function SWEP:GetViewModelPosition( pos, ang )
return pos, ang
end
--[[---------------------------------------------------------
Name: TranslateFOV
Desc: Allows the weapon to translate the player's FOV (clientside)
-----------------------------------------------------------]]
function SWEP:TranslateFOV( current_fov )
return current_fov
end
--[[---------------------------------------------------------
Name: DrawWorldModel
Desc: Draws the world model (not the viewmodel)
-----------------------------------------------------------]]
function SWEP:DrawWorldModel()
self:DrawModel()
end
--[[---------------------------------------------------------
Name: DrawWorldModelTranslucent
Desc: Draws the world model (not the viewmodel)
-----------------------------------------------------------]]
function SWEP:DrawWorldModelTranslucent()
self:DrawModel()
end
--[[---------------------------------------------------------
Name: AdjustMouseSensitivity
Desc: Allows you to adjust the mouse sensitivity.
-----------------------------------------------------------]]
function SWEP:AdjustMouseSensitivity()
return nil
end
--[[---------------------------------------------------------
Name: GetTracerOrigin
Desc: Allows you to override where the tracer comes from (in first person view)
returning anything but a vector indicates that you want the default action
-----------------------------------------------------------]]
function SWEP:GetTracerOrigin()
--[[
local ply = self:GetOwner()
local pos = ply:EyePos() + ply:EyeAngles():Right() * -5
return pos
--]]
end
--[[---------------------------------------------------------
Name: FireAnimationEvent
Desc: Allows you to override weapon animation events
-----------------------------------------------------------]]
function SWEP:FireAnimationEvent( pos, ang, event, options )
if ( !self.CSMuzzleFlashes ) then return end
-- CS Muzzle flashes
if ( event == 5001 or event == 5011 or event == 5021 or event == 5031 ) then
local data = EffectData()
data:SetFlags( 0 )
data:SetEntity( self:GetOwner():GetViewModel() )
data:SetAttachment( math.floor( ( event - 4991 ) / 10 ) )
data:SetScale( 1 )
if ( self.CSMuzzleX ) then
util.Effect( "CS_MuzzleFlash_X", data )
else
util.Effect( "CS_MuzzleFlash", data )
end
return true
end
end

View File

@@ -0,0 +1,114 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "ai_translations.lua" )
AddCSLuaFile( "sh_anim.lua" )
AddCSLuaFile( "shared.lua" )
include( "ai_translations.lua" )
include( "sh_anim.lua" )
include( "shared.lua" )
SWEP.Weight = 5 -- Decides whether we should switch from/to this
SWEP.AutoSwitchTo = true -- Auto switch to if we pick it up
SWEP.AutoSwitchFrom = true -- Auto switch from if you pick up a better weapon
--[[---------------------------------------------------------
Name: OnRestore
Desc: The game has just been reloaded. This is usually the right place
to call the GetNW* functions to restore the script's values.
-----------------------------------------------------------]]
function SWEP:OnRestore()
end
--[[---------------------------------------------------------
Name: AcceptInput
Desc: Accepts input, return true to override/accept input
-----------------------------------------------------------]]
function SWEP:AcceptInput( name, activator, caller, data )
return false
end
--[[---------------------------------------------------------
Name: KeyValue
Desc: Called when a keyvalue is added to us
-----------------------------------------------------------]]
function SWEP:KeyValue( key, value )
end
--[[---------------------------------------------------------
Name: Equip
Desc: A player or NPC has picked the weapon up
-----------------------------------------------------------]]
function SWEP:Equip( newOwner )
end
--[[---------------------------------------------------------
Name: EquipAmmo
Desc: The player has picked up the weapon and has taken the ammo from it
The weapon will be removed immediately after this call.
-----------------------------------------------------------]]
function SWEP:EquipAmmo( newOwner )
end
--[[---------------------------------------------------------
Name: OnDrop
Desc: Weapon was dropped
-----------------------------------------------------------]]
function SWEP:OnDrop()
end
--[[---------------------------------------------------------
Name: ShouldDropOnDie
Desc: Should this weapon be dropped when its owner dies?
-----------------------------------------------------------]]
function SWEP:ShouldDropOnDie()
return true
end
--[[---------------------------------------------------------
Name: GetCapabilities
Desc: For NPCs, returns what they should try to do with it.
-----------------------------------------------------------]]
function SWEP:GetCapabilities()
return CAP_WEAPON_RANGE_ATTACK1
end
--[[---------------------------------------------------------
Name: NPCShoot_Secondary
Desc: NPC tried to fire secondary attack
-----------------------------------------------------------]]
function SWEP:NPCShoot_Secondary( shootPos, shootDir )
self:SecondaryAttack()
end
--[[---------------------------------------------------------
Name: NPCShoot_Secondary
Desc: NPC tried to fire primary attack
-----------------------------------------------------------]]
function SWEP:NPCShoot_Primary( shootPos, shootDir )
self:PrimaryAttack()
end
-- These tell the NPC how to use the weapon
AccessorFunc( SWEP, "fNPCMinBurst", "NPCMinBurst" )
AccessorFunc( SWEP, "fNPCMaxBurst", "NPCMaxBurst" )
AccessorFunc( SWEP, "fNPCFireRate", "NPCFireRate" )
AccessorFunc( SWEP, "fNPCMinRestTime", "NPCMinRest" )
AccessorFunc( SWEP, "fNPCMaxRestTime", "NPCMaxRest" )

View File

@@ -0,0 +1,97 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
local ActIndex = {
[ "pistol" ] = ACT_HL2MP_IDLE_PISTOL,
[ "smg" ] = ACT_HL2MP_IDLE_SMG1,
[ "grenade" ] = ACT_HL2MP_IDLE_GRENADE,
[ "ar2" ] = ACT_HL2MP_IDLE_AR2,
[ "shotgun" ] = ACT_HL2MP_IDLE_SHOTGUN,
[ "rpg" ] = ACT_HL2MP_IDLE_RPG,
[ "physgun" ] = ACT_HL2MP_IDLE_PHYSGUN,
[ "crossbow" ] = ACT_HL2MP_IDLE_CROSSBOW,
[ "melee" ] = ACT_HL2MP_IDLE_MELEE,
[ "slam" ] = ACT_HL2MP_IDLE_SLAM,
[ "normal" ] = ACT_HL2MP_IDLE,
[ "fist" ] = ACT_HL2MP_IDLE_FIST,
[ "melee2" ] = ACT_HL2MP_IDLE_MELEE2,
[ "passive" ] = ACT_HL2MP_IDLE_PASSIVE,
[ "knife" ] = ACT_HL2MP_IDLE_KNIFE,
[ "duel" ] = ACT_HL2MP_IDLE_DUEL,
[ "camera" ] = ACT_HL2MP_IDLE_CAMERA,
[ "magic" ] = ACT_HL2MP_IDLE_MAGIC,
[ "revolver" ] = ACT_HL2MP_IDLE_REVOLVER
}
--[[---------------------------------------------------------
Name: SetWeaponHoldType
Desc: Sets up the translation table, to translate from normal
standing idle pose, to holding weapon pose.
-----------------------------------------------------------]]
function SWEP:SetWeaponHoldType( t )
t = string.lower( t )
local index = ActIndex[ t ]
if ( index == nil ) then
Msg( "SWEP:SetWeaponHoldType - ActIndex[ \"" .. t .. "\" ] isn't set! (defaulting to normal)\n" )
t = "normal"
index = ActIndex[ t ]
end
self.ActivityTranslate = {}
self.ActivityTranslate[ ACT_MP_STAND_IDLE ] = index
self.ActivityTranslate[ ACT_MP_WALK ] = index + 1
self.ActivityTranslate[ ACT_MP_RUN ] = index + 2
self.ActivityTranslate[ ACT_MP_CROUCH_IDLE ] = index + 3
self.ActivityTranslate[ ACT_MP_CROUCHWALK ] = index + 4
self.ActivityTranslate[ ACT_MP_ATTACK_STAND_PRIMARYFIRE ] = index + 5
self.ActivityTranslate[ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ] = index + 5
self.ActivityTranslate[ ACT_MP_RELOAD_STAND ] = index + 6
self.ActivityTranslate[ ACT_MP_RELOAD_CROUCH ] = index + 6
self.ActivityTranslate[ ACT_MP_JUMP ] = index + 7
self.ActivityTranslate[ ACT_RANGE_ATTACK1 ] = index + 8
self.ActivityTranslate[ ACT_MP_SWIM ] = index + 9
-- "normal" jump animation doesn't exist
if ( t == "normal" ) then
self.ActivityTranslate[ ACT_MP_JUMP ] = ACT_HL2MP_JUMP_SLAM
end
self:SetupWeaponHoldTypeForAI( t )
end
-- Default hold pos is the pistol
SWEP:SetWeaponHoldType( "pistol" )
--[[---------------------------------------------------------
Name: weapon:TranslateActivity()
Desc: Translate a player's Activity into a weapon's activity
So for example, ACT_HL2MP_RUN becomes ACT_HL2MP_RUN_PISTOL
Depending on how you want the player to be holding the weapon
-----------------------------------------------------------]]
function SWEP:TranslateActivity( act )
if ( self:GetOwner():IsNPC() ) then
if ( self.ActivityTranslateAI[ act ] ) then
return self.ActivityTranslateAI[ act ]
end
return -1
end
if ( self.ActivityTranslate[ act ] != nil ) then
return self.ActivityTranslate[ act ]
end
return -1
end

View File

@@ -0,0 +1,280 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- Variables that are used on both client and server
SWEP.PrintName = "Scripted Weapon" -- 'Nice' Weapon name (Shown on HUD)
SWEP.Author = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.Spawnable = false
SWEP.AdminOnly = false
SWEP.Primary.ClipSize = 8 -- Size of a clip
SWEP.Primary.DefaultClip = 32 -- Default number of bullets in a clip
SWEP.Primary.Automatic = false -- Automatic/Semi Auto
SWEP.Primary.Ammo = "Pistol"
SWEP.Secondary.ClipSize = 8 -- Size of a clip
SWEP.Secondary.DefaultClip = 32 -- Default number of bullets in a clip
SWEP.Secondary.Automatic = false -- Automatic/Semi Auto
SWEP.Secondary.Ammo = "Pistol"
--[[---------------------------------------------------------
Name: SWEP:Initialize()
Desc: Called when the weapon is first loaded
-----------------------------------------------------------]]
function SWEP:Initialize()
self:SetHoldType( "pistol" )
end
--[[---------------------------------------------------------
Name: SWEP:PrimaryAttack()
Desc: +attack1 has been pressed
-----------------------------------------------------------]]
function SWEP:PrimaryAttack()
-- Make sure we can shoot first
if ( !self:CanPrimaryAttack() ) then return end
-- Play shoot sound
self:EmitSound( "Weapon_AR2.Single" )
-- Shoot 9 bullets, 150 damage, 0.75 aimcone
self:ShootBullet( 150, 1, 0.01, self.Primary.Ammo )
-- Remove 1 bullet from our clip
self:TakePrimaryAmmo( 1 )
-- Punch the player's view
local owner = self:GetOwner()
if ( !owner:IsNPC() ) then owner:ViewPunch( Angle( -1, 0, 0 ) ) end
end
--[[---------------------------------------------------------
Name: SWEP:SecondaryAttack()
Desc: +attack2 has been pressed
-----------------------------------------------------------]]
function SWEP:SecondaryAttack()
-- Make sure we can shoot first
if ( !self:CanSecondaryAttack() ) then return end
-- Play shoot sound
self:EmitSound("Weapon_Shotgun.Single")
-- Shoot 9 bullets, 150 damage, 0.75 aimcone
self:ShootBullet( 150, 9, 0.2, self.Secondary.Ammo )
-- Remove 1 bullet from our clip
self:TakeSecondaryAmmo( 1 )
-- Punch the player's view
local owner = self:GetOwner()
if ( !owner:IsNPC() ) then owner:ViewPunch( Angle( -10, 0, 0 ) ) end
end
--[[---------------------------------------------------------
Name: SWEP:Reload()
Desc: Reload is being pressed
-----------------------------------------------------------]]
function SWEP:Reload()
self:DefaultReload( ACT_VM_RELOAD )
end
--[[---------------------------------------------------------
Name: SWEP:Think()
Desc: Called every frame
-----------------------------------------------------------]]
function SWEP:Think()
end
--[[---------------------------------------------------------
Name: SWEP:Holster( weapon_to_swap_to )
Desc: Weapon wants to holster
RetV: Return true to allow the weapon to holster
-----------------------------------------------------------]]
function SWEP:Holster( wep )
return true
end
--[[---------------------------------------------------------
Name: SWEP:Deploy()
Desc: Whip it out
-----------------------------------------------------------]]
function SWEP:Deploy()
return true
end
--[[---------------------------------------------------------
Name: SWEP:ShootEffects()
Desc: A convenience function to create shoot effects
-----------------------------------------------------------]]
function SWEP:ShootEffects()
local owner = self:GetOwner()
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) -- View model animation
owner:MuzzleFlash() -- Crappy muzzle light
owner:SetAnimation( PLAYER_ATTACK1 ) -- 3rd Person Animation
end
--[[---------------------------------------------------------
Name: SWEP:ShootBullet()
Desc: A convenience function to shoot bullets
-----------------------------------------------------------]]
function SWEP:ShootBullet( damage, num_bullets, aimcone, ammo_type, force, tracer )
local owner = self:GetOwner()
local bullet = {}
bullet.Num = num_bullets
bullet.Src = owner:GetShootPos() -- Source
bullet.Dir = owner:GetAimVector() -- Dir of bullet
bullet.Spread = Vector( aimcone, aimcone, 0 ) -- Aim Cone
bullet.Tracer = tracer || 5 -- Show a tracer on every x bullets
bullet.Force = force || 1 -- Amount of force to give to phys objects
bullet.Damage = damage
bullet.AmmoType = ammo_type || self.Primary.Ammo
owner:FireBullets( bullet )
self:ShootEffects()
end
--[[---------------------------------------------------------
Name: SWEP:TakePrimaryAmmo()
Desc: A convenience function to remove ammo
-----------------------------------------------------------]]
function SWEP:TakePrimaryAmmo( num )
-- Doesn't use clips
if ( self:Clip1() <= 0 ) then
if ( self:Ammo1() <= 0 ) then return end
self:GetOwner():RemoveAmmo( num, self:GetPrimaryAmmoType() )
return end
self:SetClip1( self:Clip1() - num )
end
--[[---------------------------------------------------------
Name: SWEP:TakeSecondaryAmmo()
Desc: A convenience function to remove ammo
-----------------------------------------------------------]]
function SWEP:TakeSecondaryAmmo( num )
-- Doesn't use clips
if ( self:Clip2() <= 0 ) then
if ( self:Ammo2() <= 0 ) then return end
self:GetOwner():RemoveAmmo( num, self:GetSecondaryAmmoType() )
return end
self:SetClip2( self:Clip2() - num )
end
--[[---------------------------------------------------------
Name: SWEP:CanPrimaryAttack()
Desc: Helper function for checking for no ammo
-----------------------------------------------------------]]
function SWEP:CanPrimaryAttack()
if ( self:Clip1() <= 0 ) then
self:EmitSound( "Weapon_Pistol.Empty" )
self:SetNextPrimaryFire( CurTime() + 0.2 )
self:Reload()
return false
end
return true
end
--[[---------------------------------------------------------
Name: SWEP:CanSecondaryAttack()
Desc: Helper function for checking for no ammo
-----------------------------------------------------------]]
function SWEP:CanSecondaryAttack()
if ( self:Clip2() <= 0 ) then
self:EmitSound( "Weapon_Pistol.Empty" )
self:SetNextSecondaryFire( CurTime() + 0.2 )
return false
end
return true
end
--[[---------------------------------------------------------
Name: OnRemove
Desc: Called just before entity is deleted
-----------------------------------------------------------]]
function SWEP:OnRemove()
end
--[[---------------------------------------------------------
Name: OwnerChanged
Desc: When weapon is dropped or picked up by a new player
-----------------------------------------------------------]]
function SWEP:OwnerChanged()
end
--[[---------------------------------------------------------
Name: Ammo1
Desc: Returns how much of ammo1 the player has
-----------------------------------------------------------]]
function SWEP:Ammo1()
return self:GetOwner():GetAmmoCount( self:GetPrimaryAmmoType() )
end
--[[---------------------------------------------------------
Name: Ammo2
Desc: Returns how much of ammo2 the player has
-----------------------------------------------------------]]
function SWEP:Ammo2()
return self:GetOwner():GetAmmoCount( self:GetSecondaryAmmoType() )
end
--[[---------------------------------------------------------
Name: DoImpactEffect
Desc: Callback so the weapon can override the impact effects it makes
return true to not do the default thing - which is to call UTIL_ImpactTrace in c++
-----------------------------------------------------------]]
function SWEP:DoImpactEffect( tr, nDamageType )
return false
end