Hi all,
I am trying to create a scenario involving only units (no cities at all) with the victory conditions of either eliminate all enemy units or elimination of a specific enemy unit (kind of like if you killed the enemy's general, the army disbands). I haven't touched lua before and after looking at some of the tutorials, I was still completely lost.
If there is a way to implement this through lua, I would like some guidance.
Thank you.
Korea receives a trait in the "Samurai Invasion of Korea"-scenario which makes it so that it can never be eliminated from the game (meaning that the civ survives with no cities whatsoever!). Implementing this trait requires XML (or SQL if you prefer that) only!
(IIRC there is a bug though that if you try to find the World Congress with 0 cities the game will CTD, though I guess that won't be applicable in a scenario)
Now, I'm not sure how to make a player win a victory, though I guess that the scenario's might offer a solution to that
Regarding the specific 'General', you can just give it a special promotion (E.g. 'Almighty Commander - When this unit dies you lose the game'), and you detect its death using the
UnitPrekill GameEvent. You'll still be able to read it's promotions, strength, etc. that way (just don't try to change any of those in that event since that will cause a CTD!). Once you know that the unit with the special promotion has died, push the victory for the other player.
You can use
GetMilitaryMight to check the 'strength of the army', which will be 0 if you don't have any units left! (This is used in the 'Demographics' of the main game as well)
Here's some simple sample code (for a general idea):
Code:
function CheckMilitarySize(iPlayer)
local pPlayer = Players[iPlayer];
if pPlayer:GetMilitaryMight() == 0 then
--push the victory condition for the other player here
end
end
GameEvents.PlayerDoTurn.Add(CheckMilitarySize)
local iGeneralPromotion = GameInfoTypes.PROMOTION_IM_THE_ALLMIGHTY_COMMANDER;
function CheckGeneralDeath(iPlayer,iUnit)
local pPlayer = Players[iPlayer];
local pUnit = pPlayer:GetUnitByID(iUnit);
if pUnit:IsHasPromotion(iGeneralPromotion) then
--push the victory condition for the other player here
end
end
GameEvents.UnitPrekill.Add(CheckGeneralDeath)
Personally, I think the best way to starting out with a new coding language is looking at applications of that language (in this case, at other mods or the Firaxis Scenarios!) and to check how certain things were achieved. Trying things out yourself also helps a lot too. (All of this is said from personal experience; Even though I'm not a lua-master (and will probably not become one soon), I'm getting better at it every day!)