(Solved) Npc empty seat detection

Hello
SO i made this event in which NPCs search for the seat with the False boolean variable
But the problem is that if i remove the Distance Below condition the npcs go to the furthest seat and if i keep the Distance Below it only searches for 100px and then the npc doesn’t move

It uses a for each object so your NPC will always take the first empty seat. The for each object picks 1 object at a time in the order in which they were added to the scene. It only picks 1 object at a time so the pick a random object will always choose that seat.

Here is one way. It sets the seat as not vacant as soon as the object is added.

I set the purple object as a pathfinder obstacle object so the NPCs don’t walk through each other. This could be a table or you could hide it.
ScreenRecorderProject58

You could also use the seat as an obstacle. Just turn the obstacle behavior off before it calculates a path and then turn it back on afterwards.

I like the tables better. IDK if it needs both. The table would probably be enough.
ScreenRecorderProject60

The top looks like booths. I don’t know your concept but it might be interesting to have multiple people come in at a time. My graphics are placed close together so I could record it and save it as a small GIF. It looks like they’re sharing tables. It would be interesting to seat them in singles or pairs. You could even make it larger and put up to 4 people per table.

So just as you said the concept is to have 4 npc sit around a table and eat and then leave.


I tried doing it the way you did but there was a problem that my npc’s have animation according to direction but when i did the Random Seat part the animation went crazy and the npc were not able to pick a seat. So i changed it a little but now there is a new problem is that if a npc is already and a new one collides it also stops

Instead of the collision, you could use the pathfinding reached destination. That way they won’t stop at the wrong seat you can check the collision after the destination reached. You would need a for each object if multiple NPCs could reach their destination at the same time.

Edit: also set the seat as not vacant as soon as it’s picked. That removes it from the choice of other NPCs should a new one be added before the previous one has reached the destination

I’ve been playing around with the concept but time 100. This is a bit crazy. I’m amazed it works. It took some re-writing. I’m not sure if I’m going to continue playing around. I would like to optimize it instead of using infinite servers. One server should be able to handle a few tables in each direction.

Try me (there is no interaction, people come in, they go to a table and get a glass a water)
https://gd.games/keith_13579/unaccountable-arithmetic

Project (click the green [code] and select [download zip]
https://github.com/doug13579/gdevelop—restaurant-pathfinder-tables

I used a bunch of state variables and I linked everything. I added different size tables. I wasn’t sure at first how to pick a table to fit the number of guests. Then I realized that I had it backwards. It picks a table and then using a min and max object variable it picks the number of guests. So, the small table can have 1 or 2 NPCs. The 4-person table can have 1 to 4. The 6-person table 4 to 6 and the 8-person table can have 7 or 8. That way, I don’t have to find a table to fit the party. It creates a party to fit the table.

Events - click to open

There are also object variables but I didn’t feel like screenshotting everything.

Table is a tiled sprite so it can be resized. NPC and Service have the pathfinder.

I have been thinking about how to do this and the example that you have created is just what i have been trying
One issue i am having is i can’t get the npc to have the animation according to direction i tried giving instance variable to seats according to direction and change the animation of npc according to that

That seems like a good approach. This part could be intefering. It might need to be turned into a subevent of something that checks if it’s moving. Either check it’s pathfinding speed or one of the booleans.



So i tried this but still same

Did you remove the seat collision condition from the last event? If the seats are different, it needs something to pick the appropriate seat.

Yes i tried with it and without it and i even tried for each instance of seat but i still don’t understand what is causing the npc to not pick up the variable into animation…

Is the animation action being triggered? I would add another action to the event with the animation action just to test whether the animation action is being triggered. There are a lot of conditions that need to be true to get to that action. It can be any action like addng text to the debugger or to a text object. I’ll sometimes add an action to play a sound or rotate an object. In your case, I would add the value of the seat variable to either the debugger or to a text object. Then you could see if it’s both working and what the seat value is. If both are valid then maybe another event is also changing the animation.

I tested with text object when i transfer the seat variable to npc variable it shows that it is picking up but the animation is not changing

Then either something else is changing the animation afterwards to something else or the object doesn’t have that animation that’s in the seat variable or the seat value isn’t the right number.

So i fixed i don’t know why the animation wasn’t changing with string but when i turned it into number variable it started working
Now i am facing another problem is that i want to create a object that follows the npc but it just keeps creating copies and if i put trigger once it just creates one

You could use another object variable on the NPC like hasOrder to track it.

If NPC hasOrder is false add order object and link
If NPC hasOrder is true then get linked and move it

You would either need to link the order to the NPC and then repick the order to move it or you could use the sticker behavior and stick the order to the NPC. There’s a sticker condition that works similar to linking that would pick the order object stuck to the NPC.

I don’t know when the order gets created. You might need a another object variable or condition to track to trigger the adding of the note.

You could either add the order when the NPC is spawned or similar to how I add the water. You wait until the NPC is seated. It depends on your concept.

In my version I would create an order when the NPC reached the table or maybe a certain amount of time or after the water. The order would be linked to the table but probably also the NPCs. I guess the NPC might contain their individual orders while the order would contain the complete order.

That’s just my version of your concept. Yours can be as simple or complex as you want it to be. I prefer simple. Simple is good. It depends on your concept. My concept works with groups or tables. Yours might work with 1 customer at a time which would be fine.

So i figured it out!!!
But i got one more problem


i am trying to set the order animation for each of the npc when they reach the seat and it is changing but it just keeps going on and it is happening for all of the npc even for those who are not in collision i even tried number variable but still same result

I think the last event used to be a subevent of the previous event. It needs something to filter the NPC by table or arriving status. Right now, as long as there’s an arriving table, it’s checking all of the NPCs.

Either make it a sub-event or add a condition to only pick the ones that don’t have an order. Maybe, set the HasOrder to a default value of -1

if HasOrder of NPC = -1
----For each NPC (subevent)
------------NPC is in collision with seat
-------------------set HasOrder to Random(4)
-------------------change the animation to seat.Direction


So i tried as you mentioned and still it is changing for all of the npc.
I even tried as subevent of the above and without subevent

What keeps changing? The npc animation or order animation ? If it’s happening to all of the objects then I don’t think it can be from the events in the last picture. It might be from something else.

I was talking about npc order system it just keeps changing for all of the npc even though i have used the conditions as you said
The npc direction problem is solved.