How can I make this code work if 2 NPCs occupy same space?

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

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

How can I make this code work if 2 NPCs occupy same space?

Post by sheamkennedy »

Code: Select all

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.
Last edited by sheamkennedy on Sat Dec 30, 2017 7:05 pm, edited 1 time in total.
⊕ 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
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Re: How can I make this code work if 2 NPCs occupy same spac

Post by Spoonweaver »

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: Select all

variable(spoon)
spoon:=0

 While &#40;spoon<6&#41; do,begin
    if&#40;getNPCID&#40; NPCatspot&#40;xtile,ytile,spoon&#41;  &#41;==1&#41;then&#40;
    write zone &#40;22, x tile, y tile&#41;
    &#41;
    Increment&#40;spoon&#41;
 End

Last edited by Spoonweaver on Sat Dec 30, 2017 11:42 pm, edited 1 time in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

The "increment(spoon)" is in the wrong place. (Edit: Spoonweaver edited and fixed his script)

Code: Select all

variable&#40;which&#41;
for &#40;which, 0, NPC at spot&#40;x tile, y tile, get count&#41; -- 1&#41; do &#40;
  if &#40;get NPC ID&#40;NPC at spot&#40;x tile, y tile, which&#41;&#41; == 1&#41; then&#40;
   write zone &#40;22, x tile, y tile&#41;
  &#41;
&#41;
Or you can use a while loop until "NPC at spot" returns false.
Last edited by TMC on Fri Jan 12, 2018 1:28 pm, edited 1 time in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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
Post Reply