Is there any way to give this npc a unique story id ?
I have try this out, it is from amk mod for shoc.
local obj = alife():create("esc_bad_boy",vector():set(-120.48091125488,-9.0397319793701,-147.6286315918),137299,633)
params.custom="[logic]\ncfg = scripts\\bth\\bad_boy_script.ltx"
end ---END QUOTATION---
I have add the needed script parts from amk mod and the npc spawn and his logic script works also, but his story id doest work.
Your error gets invoked by task_objects.script iff _G.id_by_sid(3001) evaluates to nil. There are three possible ways this could come about, but in your case the only credible candidate seems to be that alife():story_object(3001) is nil. This happens when the game does not recognize that your spawned NPC has the relevant story ID. Maybe try setting the story ID in a different way, e.g.:
local sim = alife()
local position = vector():set(-120.48091125488, -9.0397319793701, -147.6286315918)
local obj = sim:create("esc_bad_boy", position, 137299, 633)
sim:object(obj.id).m_story_id = 3001
I have no idea if the above is a valid way of doing it or even if it differs from the way it's done in packet_utils, but it may be worth a try.