Post new topic    
Red Slime
Send private message
Creating definite NPC layering 
 PostSat Dec 01, 2018 3:52 am
Send private message Reply with quote
I have a script that destroys a given NPC when the hero walks over it. I set the command "NPC at spot" to read the bottommost NPC of that tile, which is the one I want to destroy. However, sometimes there are multiple NPCs occupying that spot, because the NPCs move through each other with "Set NPC obstructs". In these cases, the layering of the NPCs seems random, and it will delete either, sometimes the one I don't want to destroy. So, is there a way to make sure an NPC is always above/below other NPCs?
Liquid Metal King Slime
Send private message
 
 PostSat Dec 01, 2018 4:25 am
Send private message Reply with quote
I would suggest that instead you detect the npc's ID or copy number.
If you only want to destroy 1 type of npc rather than another it would be a simply task.

here is example of what i generally do for collision. It checks the stacked npcs at a given pixel ( which is in the middle of the hero ) it checks up to a layer of 5 but can go higher if need be.

Code:


variable(THING), variable(k)

for (k,0,5,1) do, begin
  THING:=NPC at pixel ( HERO pixel X(0)+10 , HERO pixel Y(0)+10 , k )
  if ( get NPC ID (THING)==2 ) THEN (destroy npc (THING) )
end

Metal King Slime
Send private message
 
 PostSat Dec 01, 2018 9:16 am
Send private message Reply with quote
Yes, it seems you don't actually want to control how NPCs are layered, you want to select the right NPC when there are multiple ones.

The way Spoonweaver uses "npc at pixel" is better than "npc at spot" if some of the NPCs are in motion so that they are part-way between different tiles. "npc at spot" considers an NPC to be on the tile that its top-left corner is over, even if that's by just one pixel.

However, there's a bug in Spoonweaver's script: "npc at pixel" will return 0 if k is out of range, so if you were looking for NPC ID 0, you'd see it everywhere.
Instead:
Code:
for (k,0,5,1) do, begin
  THING:=NPC at pixel ( HERO pixel X(0)+10 , HERO pixel Y(0)+10 , k )
  if ( THING && get NPC ID (THING)==2 ) THEN (destroy npc (THING), k -= 1 )
end
Red Slime
Send private message
 
 PostSat Dec 01, 2018 4:01 pm
Send private message Reply with quote
TMC wrote:
Yes, it seems you don't actually want to control how NPCs are layered, you want to select the right NPC when there are multiple ones.

The way Spoonweaver uses "npc at pixel" is better than "npc at spot" if some of the NPCs are in motion so that they are part-way between different tiles. "npc at spot" considers an NPC to be on the tile that its top-left corner is over, even if that's by just one pixel.

However, there's a bug in Spoonweaver's script: "npc at pixel" will return 0 if k is out of range, so if you were looking for NPC ID 0, you'd see it everywhere.
Instead:
Code:
for (k,0,5,1) do, begin
  THING:=NPC at pixel ( HERO pixel X(0)+10 , HERO pixel Y(0)+10 , k )
  if ( THING && get NPC ID (THING)==2 ) THEN (destroy npc (THING), k -= 1 )
end


Thanks for the help, this seems to work perfectly.
Display posts from previous: