AddCSLuaFile()
ENT.Type
= "nextbot"
ENT.Base
= "base_nextbot"
if CLIENT
then
return
end
util.
PrecacheModel(
"models/police.mdl" )
util.
PrecacheModel(
"models/combine_soldier.mdl" )
function ENT:
Initialize()
self.BotTeam
= math.
random(
1,
2 )
self:
SetCollisionGroup( COLLISION_GROUP_WORLD )
self:
SetHealth(
100 )
self:
AddFlags( FL_OBJECT )
self:
SetNWInt(
"BotTeam", self.BotTeam )
if self.BotTeam
== 1 then
self:
SetModel(
"models/police.mdl" )
else
self:
SetModel(
"models/combine_soldier.mdl" )
end
self.WeaponMount
= self:
LookupAttachment(
"anim_attachment_RH" )
self.WeaponPosition
= self:
GetAttachment( self.WeaponMount )
self.Weapon
= ents.
Create(
"prop_dynamic" )
self.
Weapon:
SetPos( self.WeaponPosition.Pos )
self.
Weapon:
SetAngles( self.WeaponPosition.Ang )
self.
Weapon:
SetModel(
"models/weapons/w_smg1.mdl" )
self.
Weapon:
Spawn()
self.
Weapon:
SetParent( self, self.WeaponMount )
self:
StartActivity( ACT_IDLE_SMG1 )
self.head
= self:
LookupBone(
"ValveBiped.Bip01_Head1" )
self.Active
= true
self.
loco:
SetDesiredSpeed(
100 )
end
function ENT:
Think()
self.targetLocation
= Entity(
1 )
self.targetEnemy
= Entity(
2 )
if self.targetLocation
then
self.
loco:
Approach( self.
targetLocation:
GetPos(),
1 )
end
if IsValid( self.targetEnemy )
then
self.faceDir
= self:
GetForward()
self.moveDir
= self:
WorldToLocal( self.
targetEnemy:
GetBonePosition( self.head ) )
self.yaw
= self.
moveDir:
AngleEx( self.faceDir )
self:
SetPoseParameter(
"move_yaw", self.yaw.yaw )
self:
SetPoseParameter(
"aim_pitch", self.yaw.pitch )
self:
SetPoseParameter(
"aim_yaw", self.yaw.yaw )
self.
Weapon:
FireBullets(
{
Attacker
= self,
Callback
= DisplayTurretDamageInfo,
Damage
= 5,
Force
= 1,
Distance
= 2400,
HullSize
= 1,
Num
= 2,
Tracer
= 4,
AmmoType
= "smg1",
TracerName
= "MuzzleEffect",
Dir
= self.
Weapon:
GetForward(),
Spread
= vector_origin,
Src
= self.
Weapon:
GetPos(),
IgnoreEntity
= self
},
true )
else
self.faceDir
= self:
GetForward()
self.moveDir
= self:
WorldToLocal( self.
targetLocation:
GetPos() )
self.yaw
= self.
moveDir:
AngleEx( self.faceDir )
self:
SetPoseParameter(
"move_yaw", self.yaw.yaw )
end
end
function ENT:
RunBehaviour()
repeat
if self.targetLocation
&& self:
GetActivity()
!= ACT_RUN_RIFLE
then
self:
StartActivity( ACT_RUN_RIFLE )
elseif !self.targetLocation
&& self:
GetActivity()
!= ACT_IDLE_SMG1
then
self:
StartActivity( ACT_IDLE_SMG1 )
end
if IsValid( self.targetEnemy )
then
self.
loco:
FaceTowards( self.
targetEnemy:
GetPos() )
else
self.
loco:
FaceTowards( self.
targetLocation:
GetPos() )
end
coroutine.
wait(
0.1 )
until ( !self.Active )
end
function ENT:
OnKilled()
self:
StartActivity( ACT_DIERAGDOLL )
local drop
= ents.
Create(
"weapon_smg1" )
drop:
SetPos( self.
Weapon:
GetPos() )
drop:
Spawn()
self.Active
= false
self:
AddFlags( FL_KILLME )
self.
Weapon:
Remove()
self:
Remove()
end