First off, ActivePlayerTurnEnd only fires for the person playing the game (AKA you), not for AIs.
You'll probably want to use GameEvents.PlayerDoTurn (although that fires at the start of a turn, rather than the end of the turn. I'm not sure what to use if you specifically want it to fire at the end of the turn).
Anyways, on the assumption that PlayerDoTurn will work for what you want to do, then look at the wiki. You'll notice that it takes 1 argument: a PlayerID.
So, first line:
function SpawnUnits(playerID)
Now, in my post earlier, I said you needed a player OBJECT, not a player ID. So, we have to get the player object from just the ID. Luckily, there is a Players array! The index you'll be looking for is the playerID that is passed to your function. So your next line would be something like:
local pPlayer = Players[playerID]
So now we have the player object that we need. So now we need to figure out which unit to spawn. In your example you hardcoded a "1" in there for the unit type to spawn. In an unmodded game, the unit with unitID of 1 is a Worker, so I'm going to use that for this example. Next line would be something like this:
local unitID = GameInfoTypes.UNIT_WORKER
As a note, you could skip this step and just put the GameInfoTypes.UNIT_WORKER part inside your InitUnit call, but its good practice to store that kind of stuff into localized variables. When your lua scripts start getting more complex, every time you use GameInfoTypes/etc, you are doing a database lookup. They take more time to process than just reading a variable, and can really slow down the turn times if you're using a lot of them. Also, its a bad idea to just put a '1' in there like you did. What if someone else using your mod has another mod installed, and '1' is no longer a worker? Then you would be spawning a completely different unit.
Anyways, moving on. Now we need to know WHERE to spawn the unit. I'm not really sure where you got the 13,13 from. If you are including a scenario map with fixed spawn points, and you will always want it to be spawned there, that will work. For the sake of simplicity, I will assume you are right and spawning in hex 13,13 every game will work just fine.
So what do we have so far?
Code:
function SpawnUnits(playerID)
local pPlayer = Players[playerID]
local unitID = GameInfoTypes.UNIT_WORKER
pPlayer:InitUnit(unitID, 13, 13)
end
GameEvents.PlayerDoTurn.Add(SpawnUnits)
Now, what's wrong with this script? It will spawn a worker every turn, for every civ in the game! We haven't done any logic checks to see if the player is the civ you want to add the unit to, or to check what turn it is.
To check what turn it is, we'll do something like:
local currentTurn = Game.GetGameTurn()
Then check it in an if statement, like so:
if (currentTurn == 50) then
----stuff
end
Now, since you only want to add the unit to a single, specific civ, we'll also have to check what civ the player is using. From the wiki, we can see that there is another Player function called GetCivilizationType, which returns something along the lines of CIVILIZATION_AMERICA. So you will need something like:
local playerCiv = pPlayer:GetCivilizationType()
Then check that in an if statement as well!
if (playerCiv == CIVILIZATION_AMERICA) then
---stuff
end
Now, we're checking what turn it is, checking what civ the player is so we aren't spawning the unit for EVERY civ, and then we're actually spawning the unit. All put together, your function would look something like:
Code:
function SpawnUnits(playerID)
local pPlayer = Players[playerID]
local unitID = GameInfoTypes.UNIT_WORKER
local currentTurn = Game.GetGameTurn()
local playerCiv = pPlayer:GetCivilizationType()
if (currentTurn == 50) then
if (playerCiv == CIVILIZATION_AMERICA) then
pPlayer:InitUnit(unitID, 13, 13)
end
end
end
GameEvents.PlayerDoTurn.Add(SpawnUnits)
That code, as written, should spawn a worker for America on turn 50 in plot 13,13. Hopefully this helps!