Hy
Ich versuche seit guten 4 Stunden einen SNPC zu erstellen, der erstmal nur zu random nodes rennen soll.
Also wie erkennbar nur das einfachste. Trotzdem will es einfach nicht hinhauen.
Init
Spoiler:
Spoiler anzeigen
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
include('spawnnpc.lua')
local schdChase = ai_schedule.New( "Dadada" ) //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
schdChase:EngTask( TASK_GET_PATH_TO_RANDOM_NODE, 128 )
schdChase:EngTask( TASK_RUN_PATH, 0 )
schdChase:EngTask( TASK_WAIT_FOR_MOVEMENT, 0 )
schdChase:EngTask( TASK_RELOAD, 0 )
function ENT:Task_TASK_HELLO(data) //Called every think until the task is completed
print(data.." Again")
end
function ENT:TaskStart_TASK_HELLO(data) //Called when the task is initiated (started)
print(data)
end
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 )
self:CapabilitiesAdd( CAP_OPEN_DOORS )
self:CapabilitiesAdd( CAP_ANIMATEDFACE )
self:CapabilitiesAdd( CAP_TURN_HEAD )
self:CapabilitiesAdd( CAP_USE_SHOT_REGULATOR )
self:CapabilitiesAdd( 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
//PrintTable( schdChase )
end
Shared
Spoiler:
Spoiler anzeigen
ENT.Base = "base_ai"
ENT.Type = "ai"
ENT.PrintName = "Test"
ENT.Author = "Test"
ENT.Contact = "Test" //fill in these if you want it to be in the spawn menu
ENT.Purpose = "Test"
ENT.Instructions = "Test"
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
cl
Spoiler:
Spoiler anzeigen
include('shared.lua')
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
Das ist fast 1zu1 der Code vom neuen und alten Wiki...
Zustande gebracht habe ich diesen Fehler
Spoiler:
Spoiler anzeigen
[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
Code ist
Code:
-- If we're currently running a schedule then run it.
if ( self.CurrentSchedule ) then
self:DoSchedule( self.CurrentSchedule )
end
und
function ENT:DoSchedule( schedule )
if ( self.CurrentTask ) then
self:RunTask( self.CurrentTask )
end
if ( self:TaskFinished() ) then
self:NextTask( schedule )
end
end
Problem scheint also zu sein, dass das Entity keine Schedule hat. Habe ich jedoch mit PrintTable wiederlegt. Alles ist io.
Die einzelnen Tasks habe ich auch mit "" getestet.
Ich würde ungern bei 0 anfangen...
Danke für jegliche Einsicht in das AI scripting ;D