• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Making a Unit Roam the Map and Pick Up Items it sees.

Status
Not open for further replies.
Level 5
Joined
Jul 8, 2007
Messages
146
Is there a trigger or ability/trigger combo I can use so that let's say given an ability "Gather" when it is used, the unit begins to roam the map aimlessly and randomly and if it sees any gold coins per say, it picks them up and if it sees an enemy of type chicken it kills it and picks up what it drops?

I hope that made sense but if anyone thinks they may be able to help but would like me to explain a bit better, I'd be happy to. Thank you.
 
Level 5
Joined
Jul 8, 2007
Messages
146
Well, the ability wander is kind of restricted to an immediate area right? I was thinking of trying that but that doesn't really roam around the whole map. :/ But I really appreciate the response =] If you could help me out with the triggering when you get a chance, that would be greatly appreciated but thanks for your help so far. :D
 
Level 10
Joined
Mar 16, 2009
Messages
354
Wandering Effect

Create an ability based off of Essence of Blight (Undead Unit Ability)
and give it to the unit you want to wander, also set it to the default active ability. Make sure it doesn't heal or have any mana cost

Divide the map into 4 regions, these should cover all playable area.

Events
-Generic Unit Event
-Unit begins casting an abillity

Condition
-Ability Comparison
-Ability type of ability being cast equal to Essence of Blight

Action
-If / Then / Else, Multiple Functions
-If, Boolean Comparison
-(North East Region) Contains (WanderingUnit) equal to true
-Then Set (IntergerVariable) equal to Random Number Between 1-3
-Else, -If / Then / Else, Multiple Functions
-If, Boolean Comparison
-(North West Region) Contains (WanderingUnit) equal to true
-Then Set (IntergerVariable) equal to Random Number Between 4-6
-Else, -If / Then / Else, Multiple Functions
-If, Boolean Comparison
-(South East Region) Contains (WanderingUnit) equal to true
-Then Set (IntergerVariable) equal to Random Number Between 7-9
-Else, -If / Then / Else, Multiple Functions
-If, Boolean Comparison
-(South West Region) Contains (WanderingUnit) equal to true
-Then Set (IntergerVariable) equal to Random Number Between 10-12
-Else Do Nothing
-If / then / else
-If Or Multiple Functions
-Integer Comparison
-(IntergerVariable) is equal to 1 equal to true
-Integer Comparison
-(IntergerVariable) is equal to 4 equal to true
-Integer Comparison
-(IntergerVariable) is equal to 7 equal to true
-then Order unit to move to random point in (SouthWestRegion)

Do a similar thing for the other variable numbers
(same Trigger)

this will create the wandering effect

to pick up the items I'm not positive on how exactly to do so effectively.
 
Level 7
Joined
Mar 28, 2009
Messages
210
U might have to have like a unit on top of the coins so that if a unit is near to that unit the it goes there then make the unit go to that unit and then get the gold coin I can't do the triggers ( since I'm no where NEAR my comp like 10000 miles away) so that's how I would do it or unless gold coins are considered units erase the idea about the invisable unit xD.
Hope I helped!
 
Level 10
Joined
Mar 16, 2009
Messages
354
I was experimenting with it, I was able to create the dummy unit at all the items in playable map area but the problem is how to pick up the nearest item, The wandering unit can be right on top but still a trigger would need to be initialized to label every item or something to that effect--seems like a simple concept but to make it 100% random instead of going directly to a random item is a weird task.

my posts = 123 :D
 
Level 5
Joined
Jul 8, 2007
Messages
146
thanks so much for the responses so far. Unfortunately I'm still unable to make it so when they see an item, they pick it up and if they see an enemy of a certain type, kill it. This is what's most important. If they are unable to wander the map but can do this that would be great. If anyone can help, of course I'll +rep you and give you a mention in my map. :D
 
Level 10
Joined
Mar 16, 2009
Messages
354
to kill certain enemies it sees basic trigger like

Event - unit comes in 500 range of (Wander)
Condition - Unit type of (EnteringUnit) equal to (TypeYouWantToKill)
Action - issue order to (WanderingUnit) to attack (EnteringUnit)

Of course in order for the WanderingUnit to not bounce back and forth between multiple targets a conjunction of order ques would not to be established shouldn't be too difficult, I would tell you a better trigger but I don't have access to Worldedit at the moment sorry. Getting it to register where the items are without using random item in playable map area is difficult but next time I post I should get a solution for you.
;)
 
Level 5
Joined
Jul 8, 2007
Messages
146
Yeah, but so far the system you sent me seems to work flawlessly haha. only thing would be changing them to units and then, is there a way to make the drop off point a building that would be created later? Not preplaced?
 
Level 9
Joined
Jul 20, 2009
Messages
427
Yeah, but so far the system you sent me seems to work flawlessly haha. only thing would be changing them to units and then, is there a way to make the drop off point a building that would be created later? Not preplaced?

I think that can be done by adding a few triggers I think..Good thing for my map I use a similar system..I double checked the triggers I gave you,I found some bugs..although I think it's caused by items that are randomly placed on areas that the units can't reach..

If you like you could send me a copy of your map so that I could try to do the triggers directly..Just tell me which units and what buildings should they give the items to..And you mentioned,the workers are to be trained,if so would you like it such that whenever a worker unit enters the map it would automatically search for worms to kill, or you want them to only roam if you ask them to?
 
Level 9
Joined
Jul 20, 2009
Messages
427
Both those systems leak a lot.

Maker.yey..He could help you he's good on this kind of things..Maker please help us on this,I also need this one for my map..The triggers I gave is what I have,please make a leakless version..:thumbs_up:
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I added some code. The unit remembers four last items it has been ordered to pick up. If the closest item check returns one of the last four items, it won't get picked up.

You can test in in the map, I added some items on top of cliffs and behind trees.

However this has a flaw. If the item is reachable but the unit does not get to it during the loop interval, it gets marked as "not being able to be picked up". Or if the unit is issued to pick up the item, but it is ordered byt the player to do something else before it picks up the item, the same happens.

But I have an idea how to prevent that.

http://www.hiveworkshop.com/forums/pastebin.php?id=wrm7p4
 
Level 5
Joined
Jul 8, 2007
Messages
146
I added some code. The unit remembers four last items it has been ordered to pick up. If the closest item check returns one of the last four items, it won't get picked up.

I'm not really understanding this. So let's say my map only has 3 possible items it can pick up, it wouldn't pick them up anymore after it got the third because any item it sees would be one of the last four he picked up right? :/

Maybe I misunderstood it but if I didn't, is there a way to remove that check?

By the way, once again thank you so much to you, pangahas and everyone else for all your help so far. I truly appreciate it. :grin:
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I'm not really understanding this. So let's say my map only has 3 possible items it can pick up, it wouldn't pick them up anymore after it got the third because any item it sees would be one of the last four he picked up right? :/

Are you talking about item types? It will pick all three if he can reach them under 3 seconds after it has been ordered to pick them.
 
Level 9
Joined
Jul 20, 2009
Messages
427
ok,But if you can do it ASAP I would really appreciate it..I'm currently stuck with that trigger..I can't go on with my map unless I have a lagless version of that..:cry:
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Ok the AI for this is rather simple...

Start by breaking it down into different parts as there will logically not be such complex natives to let you program this that easily.

Ok firstly our unit has to wander... I wonder how we will do that, hehe...
Ok so logically it must be in motion to wander around and it must be repetitive as all motions will come to an end (hopefully) and so new motions will have to be made.

The first problem to be solved is how the damn AI code will run, as all code has to have some activator otherwise it is a usless block of data in memory. You need something that is perodic (so it can be issued new movements when it stops) and infinite (so that it never stops).
I would say a good old infinite loop would solve this using TriggerSleepAction as a delay but as the AI may be dynamically created and destroyed (more than one unit or the unit may not be needed all the time or the AI may have to be paused) just use a timer with the AI code function as the function to run and run it in pereodic mode (never ending).
This leaves one last question, what update interval? Well for best results small numbers would be best but as AI can be demanding and is meant to be a background process, 1 second would do.

Next, what units does the AI affect, if it is only 1, use a variable, otherwise if many a group which you enum through.

Ok now for the first AI task, moving them randomly around the map.
First problem is when should a new move order be issued, as random movement every 1 second will result in a unit being stuck only in the middle are of a map due to chances. I would advise only to order it if its current order is equal to stop as then it is logically not moving and so needs a new order.

As for the actual movement, this can be incrediably easy if your map is like the ancient continent of pangea where every point can be walked to from every other point. However, if your map is like the world we live in, islands and unwalkable areas can pose a major problem, as issuing a move order to them is a waste of time as the unit will never be able to walk there. If that is the case then you will have to break the world up into movable areas and eithor provide an ability to bridge between them where the AI goes to if it has to change or keep them isolated on each island.
Ok so where can the unit go? Well that is a question which plagues AI writers of even the lattest games as you do not want it trying to walk into walls. The solution is to eithor try and pick a new random point a few times until one that is pathable is found (even if it is surrounded by unpathable terrain) and if that fails use one of a few preset pathable areas or use a preset pathable point map.
Depending on the ammount of unpathable area in your map, I would generally go with the second idea for more complex maps as it allows a garunteed pathable location always and also will mimic human behaviour more. Ofcourse you add some random offsets to these points every time it is moved to them so it seems more human like and less preset. This however can take a lot of time to set as each point relies on your AI (the intelligence driving you) to choose where it should be and in big maps you could end up with hundreds of points.

Now movement is done, what about your gold coins? Well, run a separate process next to the movement on in the same AI function for the same unit that checks all items in an area and if one is found to be a gold coin, it sets a global variable to this item and then issues the unit the order to pick up the item (ignoring any current move orders).

For efficency, you can irradicate overlap between the two areas as you logically will not have the current order as stop if you have found an item to pick up and equally if there is an item to pick up nearby, it is pointless to issue a movement order around the map as it should instantly go and pick it up.

I hope this helps you.
 
Level 5
Joined
Jul 8, 2007
Messages
146
So after thoroughly testing the system you made, Maker, I realized it all pretty much works flawlessly but the one thing I did notice is that sometimes the gatherer doesn't pick up an item, even when it's right next to it. It just stops millimeters from it, turns and keeps walking. Any particular bug that causes this?

Also, another problem I'm having which I know isn't because of your system since it worked on the test map. When I implemented the system into my map, the Gatherers do not do any damage to the enemies they find while gathering. They play the animation but deal no damage. Only when I then stop Gathering and order them to attack do they actually deal damage... Any ideas as to what could cause this?
 
Last edited:
Status
Not open for further replies.
Top