Post new topic    
Liquid Metal Slime
Send private message
How can I make this code work if 2 NPCs occupy same space? 
 PostSat Dec 30, 2017 7:04 pm
Send private message Reply with quote
Code:

if(get NPC ID(NPC at spot(x tile, y tile)) == 1) then(
   write zone (22, x tile, y tile)
)


Right now I have a loop that places zone #22 wherever NPC ID #1 is and if NPC #1 is not there then it erases the zone. The only problem is I have some non-obstruct NPCs that wander the map and anytime they occupy the same space as NPC #1 it causes zone #22 not to be written to NPC #1. Is there a way I can account for this? Keeping in mind there could be scenarios where up to 3 NPCs occupy the same space.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Liquid Metal King Slime
Send private message
Re: How can I make this code work if 2 NPCs occupy same spac 
 PostSat Dec 30, 2017 8:07 pm
Send private message Reply with quote
You just have to read the npc layer.
I suggest setting up a for command to run through 5 or 6 layers checking for the npc


Code:

variable(spoon)
spoon:=0

 While (spoon<6) do,begin
    if(getNPCID( NPCatspot(xtile,ytile,spoon)  )==1)then(
    write zone (22, x tile, y tile)
    )
    Increment(spoon)
 End

Metal King Slime
Send private message
 
 PostSat Dec 30, 2017 11:25 pm
Send private message Reply with quote
The "increment(spoon)" is in the wrong place. (Edit: Spoonweaver edited and fixed his script)

Code:
variable(which)
for (which, 0, NPC at spot(x tile, y tile, get count) -- 1) do (
  if (get NPC ID(NPC at spot(x tile, y tile, which)) == 1) then(
   write zone (22, x tile, y tile)
  )
)


Or you can use a while loop until "NPC at spot" returns false.
Liquid Metal Slime
Send private message
 
 PostFri Jan 12, 2018 1:17 pm
Send private message Reply with quote
Thanks I got it figured out!
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Display posts from previous: