• Need help fixing up Garry's old fighter NPC
    2 replies, posted
This is from the mirror of the old wiki: [URL]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexde03.html[/URL] [code] ENT.Base = "base_ai" ENT.Type = "ai" ENT.PrintName = "" ENT.Author = "" ENT.Contact = "" //fill in these if you want it to be in the spawn menu ENT.Purpose = "" ENT.Instructions = "" ENT.AutomaticFrameAdvance = true /*--------------------------------------------------------- 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 if SERVER then local schdChase = ai_schedule.New( "AIFighter Chase" ) //creates the schedule used for this npc // Run away randomly (first objective in task) schdChase:EngTask( "TASK_GET_PATH_TO_RANDOM_NODE", 128 ) schdChase:EngTask( "TASK_RUN_PATH", 0 ) schdChase:EngTask( "TASK_WAIT_FOR_MOVEMENT", 0 ) schdChase:AddTask( "PlaySequence", { Name = "cheer1", Speed = 1 } ) // Find an enemy and run to it (second objectives in task) schdChase:AddTask( "FindEnemy", { Class = "player", Radius = 2000 } ) schdChase:EngTask( "TASK_GET_PATH_TO_RANGE_ENEMY_LKP_LOS", 0 ) schdChase:EngTask( "TASK_RUN_PATH", 0 ) schdChase:EngTask( "TASK_WAIT_FOR_MOVEMENT", 0 ) // Shoot it (third objective in task) schdChase:EngTask( "TASK_STOP_MOVING", 0 ) schdChase:EngTask( "TASK_FACE_ENEMY", 0 ) schdChase:EngTask( "TASK_ANNOUNCE_ATTACK", 0 ) schdChase:EngTask( "TASK_RANGE_ATTACK1", 0 ) schdChase:EngTask( "TASK_RELOAD", 0 ) //schedule is looped till you give it a different schedule function ENT:Initialize() self:SetModel( "models/Humans/Group01/Female_01.mdl" ) self:SetHullType( HULL_HUMAN ); self:SetHullSizeNormal(); self:SetSolid( SOLID_BBOX ) self:SetMoveType( MOVETYPE_STEP ) self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_USE_SHOT_REGULATOR | CAP_AIM_GUN ) self:SetMaxYawSpeed( 5000 ) //don't touch stuff above here self:SetHealth(100) self:Give( "weapon_ak47" ) //Can be given sweps. end function ENT:OnTakeDamage(dmg) self:SetHealth(self:Health() - dmg:GetDamage()) if self:Health() <= 0 then //run on death self:SetSchedule( SCHED_FALL_TO_GROUND ) //because it's given a new schedule, the old one will end. end end /*--------------------------------------------------------- Name: SelectSchedule ---------------------------------------------------------*/ function ENT:SelectSchedule() self:StartSchedule( schdChase ) //run the schedule we created earlier end end if CLIENT then ENT.RenderGroup = RENDERGROUP_BOTH /*--------------------------------------------------------- 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: BuildBonePositions Desc: ---------------------------------------------------------*/ function ENT:BuildBonePositions( NumBones, NumPhysBones ) // You can use this section to position the bones of // any animated model using self:SetBonePosition( BoneNum, Pos, Angle ) // This will override any animation data and isn't meant as a // replacement for animations. We're using this to position the limbs // of ragdolls. end /*--------------------------------------------------------- Name: SetRagdollBones Desc: ---------------------------------------------------------*/ function ENT:SetRagdollBones( bIn ) // If this is set to true then the engine will call // DoRagdollBone (below) for each ragdoll bone. // It will then automatically fill in the rest of the bones self.m_bRagdollSetup = bIn end /*--------------------------------------------------------- Name: DoRagdollBone Desc: ---------------------------------------------------------*/ function ENT:DoRagdollBone( PhysBoneNum, BoneNum ) // self:SetBonePosition( BoneNum, Pos, Angle ) end [/code] I get an error regarding engine tasks upon trying to use this bot. What went wrong? [editline]22nd July 2015[/editline] [ERROR] lua/includes/modules/ai_task.lua:117: bad argument #1 to 'RunEngineTask' (number expected, got nil) 1. RunEngineTask - [C]:-1 2. Run - lua/includes/modules/ai_task.lua:117 3. RunTask - gamemodes/base/entities/entities/base_ai/schedules.lua:148 4. DoSchedule - gamemodes/base/entities/entities/base_ai/schedules.lua:71 5. unknown - gamemodes/base/entities/entities/base_ai/schedules.lua:22 [editline]22nd July 2015[/editline] NOTE: Sorry for forgetting an end in the code, I quickly put it together due to how impatient I am right now >_<, but in the actual code there's the necessary end. I can't edit it due to the text not showing up in the edit mode, too. Sucks. [editline]22nd July 2015[/editline] EXTRA NOTE: For some reason the | operator doesn't work in the CapabilitiesAdd func, after I replaced them with "or" they worked fine, but I still get the error revolving around engine tasks on the bot being spawned.
Oh god... There is just so many things wrong. For a start, you need to recreate the animation system which is ran from the task.
You shouldn't have replaced | with "or". That was a binary operator. Use bit.bor(arg1,arg2) instead. As for your other issues.... Good luck, man.
Sorry, you need to Log In to post a reply to this thread.