Jobs (For Ai)

TyGamess

Member
So! I have my villagers on wonder. Witch I am going to set as a job called "Wonder" or "Jobless" and when they are jobless they wonder around. But if you set them to a job, they will wonder around an area, and occationaly pick up items and bring them over to the targeted location for storage. But here is the hard part:

So i have a grid pathfind that bascily makes a new point every so offen to witch a villager will wonder and this is told by the "obj_target" but I would like to know what if i put them in a location like in a large square called "obj_farm" and then their "Wondering points" will only spawn in obj_farm. (or obj farm areas). But also say i have 2 farms. I dont want him moving from one farm to the other, just staying stationary at the one farm he was set at.
(This part is a side of it)
There will be a timer set for every 10 secedns where the villager will decide weither or not to contiue the work. So after 10 secends a coin will flip if 1 then they stay if 0 then they stop and start wondering again after making a grunting noise or shacking their head.

Basicly saying. How the heck do I set an roaming "area". my current grid code is this: (I have it set to a global because there is only 1 room)
GML:
// Pathfinding Grid Setup

cell_width = 16
cell_height = 16

var hcell = room_width div cell_width
var vcell = room_height div cell_height

global.grid = mp_grid_create(0,0,hcell, vcell, cell_width, cell_height)

//Add Walls
mp_grid_add_instances(global.grid,obj_noNoZone,false)
this basicly says they cant collide with obj_noNoZone witch is basicly a wall. I wanna do the same thing with obj_farm. But they will stay inside it. It wont act as a wall when they dont have a job. Because if it did, then even if they decieded to stop working, they would be stuck inside the farm.

I have been working on this for hours and I keep getting errors or my game just decides to crash. I got it to work once but when i added another villager the game crashed. Please help
 

Alexx

Member
Look into state machines. Once set up, you can easily manage what characters can and can't do.
I can share an example of an automated system if it is of any use to you.

As for the walls, just add instances to the grid to keep them confined to that area.
 
Could you draw a mockup image to illustrate your concept? I'm more of a visual thinker, so it would be easier to understand what you're trying to do and the problems that you're having if I have a visual representation.

Also, make sure to write an exception handler so that any time the game tries to read a villager's job, and their job has not yet been set, then the handler will automatically set their current task to "Wandering" and write a message to console, rather than crashing the entire game. In addition to being a precaution to help out during development, though it can also be used to simulate villagers getting lost and forgetting what they're supposed to be doing (something that real people do quite often.)

If somebody already has a job, on the other hand, and they have a pathfinding error that causes them to get lost, then you could also write their current job to a temporary local variable, like "Task_On_Hold," and then set their new current job to "Wandering" until they are no longer lost/stuck, at which point they'll return to their original job.

Similarly, you could have a not-quite-global variable to automatically specify a default job (under the parameter Default_Job) based on their occupation. Upon loading the game, the local variable of Default_Job will initially shadow the global variable of the same name and thusly be set to "Wander", then once the villager's occupation is set, their Default_Job becomes whatever is specified by their Occupation.
 
Last edited:

TyGamess

Member
1588356885825.png
Alright here, This is the map, The wight is the "NoNoZone" or walls. And the gapes inbetween them is unacceable. so they will not pass throught the wall to get to the location if the location is on the other side of the wall, but look at the blue area, thats the water in the little map. Say i drag and drop one of the villagers onto the water, their job is now fishing. so they will stay around that water (With a obj around the water telling how far away they can go). But say a villagers decides to pass the river, i dont want their job being "Fisherman" even tho i didnt assain it useing my "Mouse Release" event.
 

TyGamess

Member
Something you might have forgot is that it is indead a area that would be dedicated to the ransom gen of the villagers moving to target.
 
You can add certain conditions to them being a fisherman, like whether or not they already have a job, and/or whether it conflicts with their occupation and whatnot.

If their previous job was not "Fisherman" before they became a wanderer, in other words:
GML:
if (Task_On_Hold != "Fisherman")
Then they will not automatically become a Fisherman.
 
Top