Basic SNPC?

I’ve been trying to get a basic SNPC working, copied the code from:

Replaced:


self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_USE_SHOT_REGULATOR | CAP_AIM_GUN )

for:


self:CapabilitiesAdd(bit.bor( CAP_MOVE_GROUND, CAP_OPEN_DOORS, CAP_ANIMATEDFACE, CAP_TURN_HEAD, CAP_USE_SHOT_REGULATOR, CAP_AIM_GUN))

and I’m getting the following errors:


[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

Can someone point me in the right direction, I can’t find anything to help…

Garry removed snpc functions a while ago while he works on better alternatives. Who knows why he removed them before any were added…

Thanks, you have no idea how useful that is :stuck_out_tongue:

Wait, so there’s no way to have an SNPC anymore?

I found some SNPCs on the workshop, I’m gonna look at those to help me learn :stuck_out_tongue:

Use
[lua]self:CapabilitiesAdd( CAP_ANIMATEDFACE + CAP_TURN_HEAD )[/lua] in ENT:Initialize()

ENUMs are usually designed in such a way that they can be added together.

Scripted entities are still working and functional.

Garry kind of broke schedules I believe. When I was porting my gamemode to Gmod13 I made a workaround:


local schdStay = ai_schedule.New( "NPC Stay Sc" )
local NewTask = ai_task.New()
NewTask:InitEngine("TASK_WAIT_INDEFINITE", 0) NewTask.TaskID = 1
schdStay.TaskCount = table.insert(schdStay.Tasks, NewTask)
function ENT:SelectSchedule()
 
	self:StartSchedule( schdStay )
 
end

Ya, that’s what I was doing, because I know how to add binary numbers, and I know how the binary forms of these enums look, however, I wanted the function that was equivalent to |, and hence, why I’m using bit.bor

Thanks for the replies, very useful info :smiley:

The + operator is not equivalent to the bitwise inclusive OR operator and should not be used as such. In this case it would work, but it’s bad practice and may cause some unexpected behavior if you don’t know the difference between the two.
If you want to add flags, use bit.bor. (bit.bor(CAP_ANIMATEDFACE,CAP_TURN_HEAD))