You must be logged in to post messages.
Please login or register

AI & RM Scripting
Moderated by Sebastien, Leif Ericson

Hop to:    
Welcome! You are not logged in. Please Login or Register.1 reply
Age of Kings Heaven » Forums » AI & RM Scripting » How to give villagers a specific task
Bottom
Topic Subject:How to give villagers a specific task
Khan Ivayl
Squire
posted 07-03-20 11:10 AM CT (US)         
An example close to my actual problem: A unique villager type that can only mine. Can I use the unit ID to teach the AI to only use that unit for mining and nothing else? How would that look?

Thank you dearly in advance
AuthorReplies:
Leif Ericson
Seraph Emeritus
posted 07-07-20 08:28 PM CT (US)     1 / 1       
This is for a mod, right? If the mod uses Userpatch there some ways you can do it, although it can be complicated. This code will find one of the special villager units and directly task them to the resource, like how a human selects a villager and right clicks on a resource to tell them to gather it.

Assume the unit ID is 1001. First, find one of the special villagers.

(defrule
(unit-type-count 1001 > 0) ;we have at least one of the special villagers
=>
(up-full-reset-search) ;search for the unit from scratch
(up-find-local c: 1001 c: 1) ;find 1 unit owned by the AI player that has the unit ID 1001
)

Then, find a gold mine.

(defrule
(up-set-target-object search-local c: 0) ;we can set the unit we found as the target object, meaning the search was successful
(up-gaia-type-count c: gold > 0) ;we have found a gold mine
=>
(up-reset-search 0 0 1 1) ;start our search for resources over again
(up-filter-status c: status-resource c: list-active) ;tell our next search to search for resources
(up-find-resource c: gold c: 1) ;find a gold mine
)

(defrule
(up-set-target-object search-local c: 0) ;we found a special villager
(up-set-target-object search-remote c: 0) ;we found a gold mine
=>
(up-target-objects 1 action-default -1 -1) ;tell the special villager we found to target the gold mine
(disable-self)
)

This code would have to be modified further to really work as intended. But it's a starting point. Telling specific units to do specific things unfortunately requires more advanced scripting. It's much easier to tell the AI to do general things.

~`o~|\  Join the fresh and exciting AI Ladder for its fourth season!
 `  |_\
       |    Learn the joy of AI scripting in my guide: The World of AI Scripting
______|______
 \        /
   .....Hinga Dinga Durgen! - SpongeBob
  `-=<.__.>=-
You must be logged in to post messages.
Please login or register

Hop to:    

Age of Kings Heaven | HeavenGames