Can someone explain the NPC at spot command

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Gigglyardo
Slime
Posts: 9
Joined: Sun Aug 16, 2015 1:20 am

Can someone explain the NPC at spot command

Post by Gigglyardo »

So basically I'm having trouble with the "NPC at spot" command. I've tried everything but to no avail. I want to be able to push an npc onto a certain tile then run a script that deletes the npc and plays a noise. hmhmhmhhmhhmh
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6461
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

Well there's a few things that could be causing you problems with this command.
First, let's look at it.
NPC at spot (x, y, number)
the first part is pretty self explanatory, but the number part can be tricky. The number part refers to the layer an npc is on in the stack of potential npcs on any given tile. This means that if more then one npc may or may not be on the tile you're reading at any given time, you could possibly read the wrong one.
Ideally, there would be only 1 npc on the tile, at which point you can leave the number part out or put 0.

Next, NPC at spot refers to an NPC reference. This is not the same thing as an NPC ID or the number of an npc created in the editor because you can place more than one of those on a map at the same time.
Instead, an npc reference refers to a specific number assigned secretly to every single npc on every map. In order to find this number you first have to run the NPC reference command:
NPC reference (ID, copy)
I normally store this secret number in an variable, but simply comparing NPC reference (ID, copy) to NPC at spot (x, y, number) should work too.

I hope this helps.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Rather than using "npc reference" to get a reference, you can also do the opposite and get the ID number from a reference. E.g. to check for any copy of NPC ID 5:

Code: Select all

variable (npcref)
npcref := npc at spot(X, Y)  # change this
if (npcref != 0 && get npc id(npcref) == 5) then (
 # NPC 5 is on the correct tile
)
Last edited by TMC on Sun Aug 16, 2015 4:40 pm, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Welcome!

It also matters where you are using the "NPC at spot" command.

How are you triggering the script?

Personally, I think the "each step" script trigger would be the easiest place.
Post Reply