Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.36 KB | None | 0 0
  1. AddCSLuaFile("shared.lua")
  2.  
  3. ENT.Base = "base_nextbot"
  4. ENT.Type = "nextbot"
  5. ENT.Spawnable = true
  6.  
  7. ENT.PrintName = "Super Metropolice"
  8. ENT.Author = "Oploz"
  9. ENT.Contact = ""
  10. ENT.Instruction = ""
  11.  
  12. ENT.Idle = ACT_IDLE
  13. ENT.Walk = ACT_WALK
  14. ENT.Run = ACT_RUN
  15. ENT.StandRifle = ACT_IDLE_ANGRY_SMG1
  16. ENT.StandPistol = ACT_IDLE_ANGRY_PISTOL
  17.  
  18. ENT.Primary = {} --Weapon for long distance
  19.  
  20. ENT.Primary.Sound1 = "Weapon_357.Single"
  21. ENT.Primary.Sound2 = "Weapon_Pistol.NPC_Single"
  22. ENT.Primary.Reload1 = "Weapon_357.Spin"
  23. ENT.Primary.Reload2 = "Weapon_Pistol.Reload"
  24. ENT.Primary.ReloadSequence = "reload_pistol"
  25. ENT.Primary.Act = ACT_GESTURE_RANGE_ATTACK_PISTOL
  26. ENT.Primary.ReloadAct = ACT_GESTURE_RELOAD_PISTOL
  27.  
  28. util.PrecacheSound(ENT.Primary.Sound1)
  29. util.PrecacheSound(ENT.Primary.Reload1)
  30.  
  31. util.PrecacheSound(ENT.Primary.Sound2)
  32. util.PrecacheSound(ENT.Primary.Reload2)
  33.  
  34. function ENT:SetWeaponInfo()
  35. self.Primary.Name = "weapon_357" --Weapon classname
  36. self.Primary.Clip = 18 --Clip size
  37. self.Primary.Num = 1 --Amount of bullets per shot
  38. self.Primary.Spread = 5 --Spread
  39. self.Primary.Damage = 5 --Damage per bullets
  40. self.Primary.AmmoType = "357" --Ammo type
  41. self.Primary.Delay = 0.4 --Fire rate
  42. self.Primary.ReloadSoundDelay = 0.8 --Reloading sound delay
  43. self.Primary.MuzzleProbability = 0.5 --Probability of emitting muzzle flash
  44. self.Primary.MuzzleScale = 1 or 0.6 --Scale of muzzle flash
  45. self.Primary.Sound = self.Primary.Sound1 or self.Primary.Sound2 --Shooting sound
  46. self.Primary.Reload = self.Primary.Reload1 or self.Primary.Reload2 --Reloading sound
  47. self.Primary.Ammo = 200 --Ammo that the weapon now has
  48. end
  49.  
  50. function ENT:Initialize()
  51. self:SetModel( "models/player/jesus/jesus.mdl" ) -- Remember
  52. self:SetHealth(125)
  53. self:SetWeaponInfo() -- Give Jesus his weapon
  54. self:ClearUserStuck()
  55.  
  56. self.LoseTargetDist = 2000 -- How far the enemy has to be before we lose them
  57. self.SearchRadius = 1000 -- How far to search for enemies
  58. end
  59.  
  60. -- Called when NPC thinks it is stuck
  61. function ENT:OnStuck()
  62. print(self, "OnStuck" )
  63. end
  64.  
  65. -- Clears stuck
  66. function ENT:HandleStuck()
  67. self.loco:ClearStuck()
  68. print("No longer stuck")
  69. end
  70.  
  71. -- Saves enemy as entity
  72. function ENT:SetEnemy( ent )
  73. self.Enemy = ent
  74. end
  75.  
  76. -- Retrieve saved enemy
  77. function ENT:GetEnemy()
  78. return self.Enemy
  79. end
  80.  
  81. -- Ensures we have an enemy
  82. function ENT:HaveEnemy()
  83. if ( self:GetEnemy() and IsValid( self:GetEnemy() ) ) then -- If our current enemy is valid
  84. if ( self:GetRangeTo( self:GetEnemy():GetPos() ) > self.LoseTargetDist ) then -- If the enemy is too far
  85. -- If the enemy is lost then call FindEnemy() to look for a new one
  86. -- FindEnemy() will return true if an enemy is found, making this function return true
  87. return self:FindEnemy()
  88. -- If the enemy is dead( we have to check if its a player before we use Alive() )
  89. elseif ( self:GetEnemy():IsPlayer() and !self:GetEnemy():Alive() ) then
  90. return self:FindEnemy() -- Return false if the search finds nothing
  91. end
  92. -- The enemy is neither too far nor too dead so we can return true
  93. return true
  94. else
  95. -- The enemy isn't valid so lets look for a new one
  96. return self:FindEnemy()
  97. end
  98. end
  99.  
  100. -- Returns true and sets our enemy if we find one
  101. function ENT:FindEnemy()
  102. -- Search around us for entities
  103. local _ents = ents.FindInSphere( self:GetPos(), self.SearchRadius )
  104. if _ents != nil then
  105. for k, v in pairs( _ents ) do -- Here we loop through every entity the above search finds and see if it's the one we want
  106. if ( v:IsPlayer() and self:IsLineOfSightClear(v) and false ~= v:IsTraitor()) then
  107. -- We found a non traitor we can see so lets set it as our enemy and return true
  108. local lastdis = 2000
  109. local vdis = GetRangeTo(v)
  110.  
  111. if vdis < lastdis then -- Ensures Jesus shoots at the closest target to him
  112. lastdis = vdis
  113. self:SetEnemy( v )
  114. end
  115. end
  116. end
  117. return true
  118. end
  119.  
  120. self:SetEnemy( nil ) -- We found nothing so we will set our enemy as nil ( nothing ) and return false
  121. return false
  122. end
  123.  
  124. --Gets a position for aiming at the enemy
  125. function ENT:GetTargetPos(aiming, target)
  126. -- for k, v in pairs(ents.FindInSphere(self:GetPos(), 200)) do
  127. -- if v:GetClass() == "npc_grenade_frag" then
  128. -- return v:GetPos()
  129. -- end
  130. -- end
  131.  
  132. local e = target
  133. if not IsValid(e) then e = self:GetEnemy() end
  134. if not IsValid(e) then
  135. return self:GetEye().Pos + self:GetForward() * self.NearDistance
  136. end
  137. local dir, attach, bone = e:GetPos(), 0, nil
  138.  
  139. if e:GetClass():find("headcrab") then
  140. return e:GetPos() + Vector(0, 0, 8)
  141. end
  142.  
  143. if e:LookupBone("ValveBiped.Bip01_Head1") then
  144. attach = nil
  145. bone = e:LookupBone("ValveBiped.Bip01_Head1")
  146. dir = e:GetBonePosition(bone)
  147. elseif e:LookupBone("ValveBiped.Bip01_Neck1") then
  148. attach = nil
  149. bone = e:LookupBone("ValveBiped.Bip01_Neck1")
  150. dir = e:GetBonePosition(bone)
  151. elseif e:LookupBone("Bip01 Head") then --for Half-Life Source NPCs
  152. attach = nil
  153. bone = e:LookupBone("Bip01 Head")
  154. dir = e:GetBonePosition(bone)
  155. elseif e:LookupBone("Bip01 Neck") then --for Half-Life Source NPCs
  156. attach = nil
  157. bone = e:LookupBone("Bip01 Neck")
  158. dir = e:GetBonePosition(bone)
  159. elseif e:LookupBone("TorSkel Head") then --for Half-Life: Renaissance Tor
  160. attach = nil
  161. bone = e:LookupBone("TorSkel Head")
  162. dir = e:GetBonePosition(bone)
  163. elseif e:LookupAttachment("eyes") and e:LookupAttachment("eyes") > 0 then --for most human
  164. attach = e:LookupAttachment("eyes")
  165. dir = e:GetAttachment(attach).Pos
  166. elseif e:LookupAttachment("light") and e:LookupAttachment("light") > 0 then --for manhack
  167. attach = e:LookupAttachment("light")
  168. dir = e:GetAttachment(attach).Pos
  169. elseif e:GetAttachments() and #e:GetAttachments() > 0 then
  170. if aiming then
  171. self.aimattach = self.aimattach + 1
  172. if self.aimattach > #e:GetAttachments() then
  173. self.aimattach = 1
  174. end
  175. end
  176. attach = self.aimattach
  177. dir = e:GetAttachment(attach or 1).Pos
  178. end
  179. return dir
  180. end
  181.  
  182. function ENT:FireWeapon(smg)
  183. if not (IsValid(self:GetEnemy()) or IsValid(self.Weapon)) then return end
  184. if not self.shoot then return end
  185. if self.Weapon:GetForward():Dot(self:GetAimVector()) < 0.9 then
  186. .loco:FaceTowards(self.lastsaw) return
  187. end
  188.  
  189. if self.Weapon:GetNoDraw() then
  190. .Weapon:SetNoDraw(false)
  191. end
  192.  
  193. local wep = self.Weapon
  194. local shootPos = self:GetMuzzle().Pos
  195. local WeaponInfo = self.havepistol and self.Primary or self.Secondary
  196. local delay = math.Clamp(WeaponInfo.Delay + self:XorRand(-0.1, 0.1), 0.05, 3)
  197.  
  198. if WeaponInfo.Ammo <= 0 then
  199. return
  200. end
  201.  
  202. if CurTime() < self.Time.Fired then
  203. return
  204. end
  205.  
  206. self:AddGesture(WeaponInfo.Act)
  207.  
  208. WeaponInfo.Ammo = WeaponInfo.Ammo - 1
  209. wep:EmitSound(WeaponInfo.Sound)
  210.  
  211. local dir = self:GetTargetPos(true)
  212. -- local t = util.TraceLine({start = shootPos, endpos = dir, filter = {self, wep}})
  213. -- debugoverlay.Line(t.StartPos, t.HitPos, 1, Color(0, 255, 0, 255), false)
  214.  
  215. local bullet = {
  216. Attacker = self,
  217. Num = WeaponInfo.Num,
  218. Src = shootPos,
  219. Dir = dir - shootPos,
  220. Spread = Vector(WeaponInfo.Spread, WeaponInfo.Spread, 0),
  221. Force = 10000,
  222. Tracer = 1,
  223. TracerName = "Tracer",
  224. Damage = WeaponInfo.Damage,
  225. AmmoType = WeaponInfo.AmmoType,
  226. Callback = function(attacker, tr, dmginfo)
  227. if not IsValid(attacker:GetEnemy()) then return end
  228. if not IsValid(tr.Entity) then return end
  229. if tr.Entity ~= attacker:GetEnemy() then return end
  230.  
  231. dmginfo:SetInflictor(wep)
  232. local c = tr.Entity:GetClass()
  233. local health, maxhealth = tr.Entity:Health(), tr.Entity:GetMaxHealth()
  234. if health <= 0 then health = 1 end
  235. if maxhealth <= 0 then maxhealth = 1 end
  236. local speak_flag = health / maxhealth < 0.25
  237.  
  238. if c == "npc_turret_floor" then
  239. -- tr.Entity:Fire("SelfDestruct")
  240. speak_flag = false
  241. elseif c == "npc_rollermine" then
  242. util.BlastDamage(wep, self, tr.Entity:GetPos(), 1, 1)
  243. speak_flag = false
  244. end
  245.  
  246. if speak_flag then
  247. self:Speak(self.Sentence.EnemyHurt, self:CanSpeak())
  248. end
  249. end
  250. }
  251. self:FireBullets(bullet)
  252.  
  253. self:MuzzleFlash()
  254. wep:MuzzleFlash()
  255. self.Time.Fired = CurTime() + delay
  256. self.Time.Moved = CurTime() + delay / 5
  257.  
  258. local ef = EffectData()
  259. ef:SetOrigin( shootPos )
  260. ef:SetAngles( self:GetMuzzle().Ang )
  261. ef:SetScale( WeaponInfo.MuzzleScale )
  262. ef:SetEntity( wep )
  263. ef:SetEntIndex( wep:EntIndex() )
  264. ef:SetAttachment( wep:LookupAttachment( "muzzle" ) )
  265. if self:XorRand() < WeaponInfo.MuzzleProbability then
  266. util.Effect("MuzzleEffect", ef)
  267. end
  268.  
  269. ef:SetAngles(self:GetMuzzle().Ang - Angle(0, 90, 0))
  270. ef:SetOrigin( shootPos - self:GetMuzzle().Ang:Forward() * 8 )
  271. ef:SetStart(self:GetRight())
  272. if eject then
  273. util.Effect("RifleShellEject", ef)
  274. end
  275. end
  276.  
  277. function ENT:RunBehaviour()
  278. while ( true ) do
  279. if self:HaveEnemy() then -- Find or remember an enemy
  280. self.lastSeen = GetEnemy()
  281. else
  282. self.lastSeen = FindEnemy()
  283. end
  284.  
  285. if IsValid( self.lastSeen ) and GetRangeTo( self.lastSeen ) < self.LoseTargetDist and self:IsLineOfSightClear( self.lastSeen ) then
  286. self.loco:FaceTowards(self.lastSeen)
  287. self:Aim(self.lastSeen)
  288. self:FireWeapon()
  289. end
  290.  
  291.  
  292. coroutine.yield() -- The function is done here
  293. end
  294. end
  295.  
  296. list.Set( "NPC", "jesus_nextbot", {
  297. Name = "Simple bot",
  298. Class = "jesus_nextbot",
  299. Category = "NextBot"
  300. } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement