So I started working on a new map. In this map enemy units will spawn in rooms near players in the game and after a few hours of trying different methods of doing this, nothing is working efficiently. Can anyone give me some more ideas?
My current setup:
I have a record containing the vars:
• Region
• Open
• numPoints
• Points[numPoints]
So each room has a region, a bool for if the room is open or closed, a number of spawn points in the room, and an array holding the points.
• If a player opens the door to a room or is in a room with a closed door, the room is marked as open.
• Every time a player enters a room (region) the regions index id is added to an array (viablespawns[20]). This adds the id to next empty index in the array.
• Every time a player leaves a room (region) and there are no other players in it the regions index id is removed from the array (viablespawns[20]). This rebuilds the array without the removed id.
• Every 2 seconds the game counts the number of integers in the array, then does a random 1-count to get a random region from the current viable spawns, it checks if the room is open and if not rerolls until it has an open room.
• Then it randoms 1-numPoints for that region and spawns an enemy in the random region at the random point in the region.
In the end, I want to spawn enemies at random points in random regions and adjacent regions to the ones the players are located in. The current hacked "dynamic" array is very inefficient. Does anyone have any other ideas on how I could do this?
And WTF is there seriously no way to do line breaks on this forum?
And WTF is there seriously no way to do line breaks on this forum?
// = line break in WikiCreole, or you could just select a different markup like BBCode.
As for your problem, I am not sure, if I understand correctly. You want to spawn units randomly in all active areas; "active" meaning, that a player is in that room or any adjacent room. Am I correct in assuming, that your main problem would be to get a reference to the according record instance from the region activating the trigger?
Quote:
Every 2 seconds the game counts the number of integers in the array, then does a random 1-count to get a random region from the current viable spawns, it checks if the room is open and if not rerolls until it has an open room.
So you want to spawn in one of the opened rooms at a time. Why not add an array to keep track of all currently open rooms? Whenever a room is opened, add the room to the array and increment a counter variable. When a room is closed, remove the room from the array, add the last room in the array to the position of the removed one and decrement the counter. Then on spawning, spawn in a random room of this array from 1 to counter. Size of the array would need to cover the biggest possible number of open rooms, or just the maximum room count.
= line break in WikiCreole, or you could just select a different markup like BBCode.
So you want to spawn in one of the opened rooms at a time. Why not add an array to keep track of all currently open rooms? Whenever a room is opened, add the room to the array and increment a counter variable. When a room is closed, remove the room from the array, add the last room in the array to the position of the removed one and decrement the counter. Then on spawning, spawn in a random room of this array from 1 to counter. Size of the array would need to cover the biggest possible number of open rooms, or just the maximum room count.
First: Thanks, and where do I change it to bbcode?
Second: That's exactly what I'm already doing. The problem is that rebuilding the array every time someone leaves a region is very inefficient. It's also very inefficient to rely on enter/exit region events, but I don't think there is a way around that.
Just beneath the text you are writing for a new post, there is a dropdown menu. By default, WikiCreole is selected.
Quote:
That's exactly what I'm already doing. The problem is that rebuilding the array every time someone leaves a region is very inefficient. It's also very inefficient to rely on enter/exit region events, but I don't think there is a way around that.
You don't need to rebuild the entire array. You can simply put the last array member to the position of the removed member and leave the rest of the array as it is.
As for the enter/exit events, you could check the regions periodically, but that would probably not be more efficient. You could make the units having to open a door or activate a teleporter or whatever, in this case you could catch that instead of a region event.
Quote:
You don't need to rebuild the entire array. You can simply put the last array member to the position of the removed member and leave the rest of the array as it is.
There is no way to take the highest non null(or in this case non 0) value from the array without running a loop to find it, then I will have to run a second loop to find the index needing to be replaced and overwrite it and then erase the highest.
Currently this seems better than what your suggesting:
Run a counter variable to keep track of the currently highest index. Also, you don't need to clear the higher non-used array members, they will be overwritten anyway, once you add new active rooms again. Somewhat like this:
//add active roomViableSpawnCounter=ViableSpawnCounter+1ViableSpawnArray[ViableSpawnCounter]=(openedroom)//remove active roomViableSpawnArray[RoomToRemoveIndex]=ViableSpawnArray[ViableSpawnCounter]ViableSpawnCounter=ViableSpawnCounter-1
To get the index of the room, store the index in the room when activating it, maybe using another array or your record, depending on your setup. Could also use the data table for this.
Run a counter variable to keep track of the currently highest index. Also, you don't need to clear the higher non-used array members, they will be overwritten anyway, once you add new active rooms again. Somewhat like this:
<<code galaxy>>add active room
ViableSpawnCounter = ViableSpawnCounter + 1
ViableSpawnArray[ViableSpawnCounter] = (opened room)remove active room
ViableSpawnArray[RoomToRemoveIndex] = ViableSpawnArray[ViableSpawnCounter]
ViableSpawnCounter = ViableSpawnCounter - 1
<</code>>
I already have a counter setup this way.
Quote from Kueken531: GoTo get the index of the room, store the index in the room when activating it, maybe using another array or your record, depending on your setup.
I'm not sure what you mean here. Could you elaborate?
Quote from Kueken531: GoCould also use the data table for this.
I thought of doing this, but I don't know how to use data tables or how well it would work so I decided not to. Could you explain what these are used for, what an obvious use would be, and maybe how to do something with it so I can understand better? Or just link me to a tutorial :)
So I started working on a new map. In this map enemy units will spawn in rooms near players in the game and after a few hours of trying different methods of doing this, nothing is working efficiently. Can anyone give me some more ideas?
My current setup:
I have a record containing the vars:
• Region
• Open
• numPoints
• Points[numPoints]
So each room has a region, a bool for if the room is open or closed, a number of spawn points in the room, and an array holding the points.
• If a player opens the door to a room or is in a room with a closed door, the room is marked as open.
• Every time a player enters a room (region) the regions index id is added to an array (viablespawns[20]). This adds the id to next empty index in the array.
• Every time a player leaves a room (region) and there are no other players in it the regions index id is removed from the array (viablespawns[20]). This rebuilds the array without the removed id.
• Every 2 seconds the game counts the number of integers in the array, then does a random 1-count to get a random region from the current viable spawns, it checks if the room is open and if not rerolls until it has an open room.
• Then it randoms 1-numPoints for that region and spawns an enemy in the random region at the random point in the region.
In the end, I want to spawn enemies at random points in random regions and adjacent regions to the ones the players are located in. The current hacked "dynamic" array is very inefficient. Does anyone have any other ideas on how I could do this?
And WTF is there seriously no way to do line breaks on this forum?
//
= line break in WikiCreole, or you could just select a different markup like BBCode.As for your problem, I am not sure, if I understand correctly. You want to spawn units randomly in all active areas; "active" meaning, that a player is in that room or any adjacent room. Am I correct in assuming, that your main problem would be to get a reference to the according record instance from the region activating the trigger?
So you want to spawn in one of the opened rooms at a time. Why not add an array to keep track of all currently open rooms? Whenever a room is opened, add the room to the array and increment a counter variable. When a room is closed, remove the room from the array, add the last room in the array to the position of the removed one and decrement the counter. Then on spawning, spawn in a random room of this array from 1 to counter. Size of the array would need to cover the biggest possible number of open rooms, or just the maximum room count.
First: Thanks, and where do I change it to bbcode?
Second: That's exactly what I'm already doing. The problem is that rebuilding the array every time someone leaves a region is very inefficient. It's also very inefficient to rely on enter/exit region events, but I don't think there is a way around that.
Just beneath the text you are writing for a new post, there is a dropdown menu. By default, WikiCreole is selected.
You don't need to rebuild the entire array. You can simply put the last array member to the position of the removed member and leave the rest of the array as it is.
As for the enter/exit events, you could check the regions periodically, but that would probably not be more efficient. You could make the units having to open a door or activate a teleporter or whatever, in this case you could catch that instead of a region event.
There is no way to take the highest non null(or in this case non 0) value from the array without running a loop to find it, then I will have to run a second loop to find the index needing to be replaced and overwrite it and then erase the highest.
Currently this seems better than what your suggesting:
Run a counter variable to keep track of the currently highest index. Also, you don't need to clear the higher non-used array members, they will be overwritten anyway, once you add new active rooms again. Somewhat like this:
To get the index of the room, store the index in the room when activating it, maybe using another array or your record, depending on your setup. Could also use the data table for this.