I'm trying to create wild animals for a mod. I'm at the point where I can have animals of different types spawn around the map by adding them to the Barbarian PlayerID 63. This works to a certain extent, but has the following problems:
Animals will sit on and fortify barbarian camps and refuse to move. (The main problem I'm trying to solve).
Barbarian spawning is reduced or stopped completely depending on the number of nearby animals.
Animals have their names prefixed with 'Barbarian', i.e "Barbarian Lion" (minor issue).
Barbarians and animals coordinate attacks (minor issue).
My first thought was to use some sort of promotion for animal units that makes Barbarian Camps impassable, but since Barbarian Camps are improvement, not features, it doesn't look like there's a good way of doing that.
I've tried creating a new player for animals under PlayerID 62. This would have the advantage of the animals having a different icon color, could be prefixed with "Wild", and could optionally be set to fight with barbarians. This seems like a good solution, but my initial tests are not going well - the main problem being that the game crashes when trying to process the new player's turn. I've searched for other cases where people have achieved something similar, but there don't seem to be any success stories so I'm not sure if it's even possible.
Here's the code I'm using:
So my first question - Is adding another barbarian-style player going to be achievable? If so, what do I need to do to prevent the player from crashing.
If not, can anyone think of some alternative options? The only other think I can think of is a script that swaps animals in barbarian camps with a human unit, but that's not a great solution and would look silly.
Animals will sit on and fortify barbarian camps and refuse to move. (The main problem I'm trying to solve).
Barbarian spawning is reduced or stopped completely depending on the number of nearby animals.
Animals have their names prefixed with 'Barbarian', i.e "Barbarian Lion" (minor issue).
Barbarians and animals coordinate attacks (minor issue).
My first thought was to use some sort of promotion for animal units that makes Barbarian Camps impassable, but since Barbarian Camps are improvement, not features, it doesn't look like there's a good way of doing that.
I've tried creating a new player for animals under PlayerID 62. This would have the advantage of the animals having a different icon color, could be prefixed with "Wild", and could optionally be set to fight with barbarians. This seems like a good solution, but my initial tests are not going well - the main problem being that the game crashes when trying to process the new player's turn. I've searched for other cases where people have achieved something similar, but there don't seem to be any success stories so I'm not sure if it's even possible.
Here's the code I'm using:
Code:
Game.AddPlayer(62, 3, 19);
print("Player 62 added");
local plot = Map.GetPlot( 5, 5 );
plot = plot:GetNearestLandPlot();
local unitId = GameInfo.Units.UNIT_BARBARIAN_WARRIOR.ID
Players[62]:InitUnit(unitId, plot:GetX(), plot:GetY());
print("unit added");
So my first question - Is adding another barbarian-style player going to be achievable? If so, what do I need to do to prevent the player from crashing.
If not, can anyone think of some alternative options? The only other think I can think of is a script that swaps animals in barbarian camps with a human unit, but that's not a great solution and would look silly.