Getting this error in a script:
getnpcslice: invalid npc reference -3
(maybe the NPC was deleted?)
My question is, how do you get a true/false value for if an NPC reference is an existent NPC or not? "NPC reference" requires the NPC ID, which my scripts don't deal with, they use the reference. Is there another way to do this so I can check to make sure the NPC hasn't been killed/deleted before trying to run a script on it?
NPC reference is invalid error
Moderators: marionline, SDHawk
You can either use "npc is disabled" which returns true either if the npc doesn't exist or if it is hidden due to a tag condition, or you can use "get npc id", which returns -1 if the NPC doesn't exist. Strangely, "get npc id" even works if you give it an NPC ID, testing whether any NPCs with that ID exist.
However, beware! After an NPC is deleted another one might be created (with "create NPC") which has the same NPC reference! If this is a concern you could put a special value in one of the NPC extra data slots and test that. (However, if the NPC was created in the map editor its reference won't be reused unless you have close to 300 NPCs on the map).
Code: Select all
if (get npc id(npc) <> -1) then (stuff...)
Last edited by TMC on Mon Dec 12, 2016 5:00 am, edited 2 times in total.