• 🏆 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!

Roaming Trader

Status
Not open for further replies.
Level 5
Joined
Jul 15, 2018
Messages
111
I am planning on creating a roaming trade unit on my rpg map. This unit will have unique items for sale, have a squad of caravan guards, and will be killable. There are a total of 9 towns, with regions associated with each, that the caravan would travel to. What is the best way to go about creating a system of triggers that:
  1. Checks if trade unit has been killed between point A and point B
  2. Waits 30 seconds in each town it stops in
  3. Spawns a new trading unit and guards should the unit be killed on its way to its destination.
  4. Increases the number of guards that spawn based on how much time has passed
Given the size of the map I am working on it might be beneficial to have 2 or 3 units going at a time.
 
Level 12
Joined
Nov 3, 2013
Messages
989
So are there 9 towns and 9 associated territories/regions, or 9 towns and multiple territories/regions for each town? I didn't quite get if the caravan travel around in the surroundings or if it go straight from town to town following some city connecting path or whatever.

Also, it would be useful to know whether or not there are more than one road, i.e. whether you can go from town A to down B, C, D, etc. or only from town A to town B, town B to town C, etc.


Anyway, for #1 it should be possible to simply have an integer variable, and have each number represent one of the 'paths'. e.g. caravan_path = 1 could be A to B, caravan_path = 2 -> B to C, and so on.


#2 would change a bit depending on #1, but I'm assuming you would just have placed some regions/rects in each town. When the caravan enters there's a 30 sec wait or timer, then you set the integer variable to the next path, and order it to move again. (Perhaps through a series of regions along the way I guess.)


#3 on kill, wait/timer, create caravan unit & guards. The number of guards could simply be another integer as well (Of course, you might have more than one unit type which means it could be slightly different.), ties in with #4. Where to respawn would depend on where the caravan was supposed to go I guess, so that integer variable from #1 and #2 would come in handy.


#4, either a periodic event or a timer loop, every HoweverLongYouWant seconds increase the guards integer by 1.

Maybe you want to add on to #2 that when the caravan enters town it checks how many guards it currently has and if it has fewer than "guardAmount" variable (or whatver you decide to call it) then spawn the necessary amount of guards and add them to the caravan unit group.

That would solve both the 'more guards as the game progress' aspect, but it would also refill the guards if some of them died on the way.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
Problem 1 is actually 2 different problems.
  • Detecting convoy death.
  • Determining convoy route.
Detecting death is pretty simple either count number of convoy units still alive using on death event to decrement the counter or every 5-10 seconds test the number of living units in a convoy unit group. If dead you select a suitable town to spawn at and then create the required number of units.

Determining convoy route is less simple. Each town needs a list of valid destination towns from which the convoy could visit. When at a town and the convoy is about to depart, a town from the list of destination towns for that town is chosen at random and this becomes the convoys destination. To prevent it cycling between 2 towns due to RNG an extra requirement could be made that it cannot depart for the town it immediately came from, which would be implemented by filtering the destination town list into a temporary list to select from.

Once a destination is set the convoy is ordered to move to a point in the destination town. Every 15 seconds an AI style think trigger is run for the convoy. This tests if its guard units stray too far from the caravan and if so orders the caravan to stop and the guards to move to the caravan. It also tests if it has arrived at its destination (near the selected town point) and if so then goes into its waiting state.

Problem 2 is the waiting state. After the AI think routine determines the caravan is in a town it goes into a waiting state. This could be implemented by turning off the AI think routine and then using a 30 second timer with timer expiry turning back on AI think and selecting a destination town as described above. Another way to implement it would be a state machine inside the AI think routine itself and have a variable to track state (traveling, at town) and then a counter which is incremented every time the think routine is run until it reaches a value representing 30 seconds in which case it selects destination and begins.

Problem 3 is part of problem 2. Once it detects arrival at a town it then determines what units it has left. These are compared with the desired unit numbers and any difference is created somewhere in the town and added to the convoy group. Remember to periodically flush dead units from unit groups to keep them performing well.

Problem 4 would be a separate periodic trigger which changes the desired guard stock used above. It could be implemented as a simple increase guard count counters by 1 every few minutes, however this approach could potentially end up spawning so many guard that it causes performance problems. A better approach would be a lookup table of sorts that at certain time milestones more guards or new types of guards are added. If old types of guard are removed for new types of guard one could either remove them at the next arrival, or simply ignore them and hope they eventually die.

Multiple caravans would be implemented by instancing. Each caravan is a separate instance (index) with members stored in a set of arrays. AI think and such would loop through all caravan instances. Possible staggering could be employed if there are performance concerns for the AI think so each convoy is updated at a separate time.
 
Status
Not open for further replies.
Top