[R&F] How to get civ unit at start?

Mikoto Misaka

Chieftain
Joined
Nov 11, 2019
Messages
4
I try it
Code:
INSERT INTO Types
    (Type,     Kind)
VALUES  ('MODIFIER_NEWLEADER_CAPITAL_CITY_GRANT_UNIT_IN_CITY', 'KIND_MODIFIER'),
        ('NEWLEADER_TRAIT_NEWUNIT', 'KIND_TRAIT') ;

INSERT INTO DynamicModifiers
        (ModifierType, CollectionType, EffectType)
VALUES   
        ('MODIFIER_NEWLEADER_CAPITAL_CITY_GRANT_UNIT_IN_CITY', 'COLLECTION_PLAYER_CAPITAL_CITY','EFFECT_GRANT_UNIT_IN_CITY'),

INSERT INTO Modifiers
        (ModifierId, ModifierType, RunOnce, Permanent, SubjectRequirementSetId)
VALUES   
        ('TRAIT_LEADER_NEWLEADER_SEND_NEWUNIT', 'MODIFIER_NEWLEADER_CAPITAL_CITY_GRANT_UNIT_IN_CITY', 0, 0, NULL) ,
INSERT INTO ModifierArguments
        (ModifierId, Name, Value)

VALUES   
        ('TRAIT_LEADER_NEWLEADER_SEND_NEWUNIT', 'UnitType', 'UNIT_NEWUNIT'),
        ('TRAIT_LEADER_NEWLEADER_SEND_NEWUNIT', 'Amount', 1),
and also try it
Code:
local numNEWUNIT   = 1  --------------------------------------------set number of extra starting scouts
local iNEWUNIT = GameInfo.Units["UNIT_NEWUNIT"].Index -----------------set unit

function OnPlayerTurnActivated( player, bIsFirstTime )

    local currentTurn = Game.GetCurrentGameTurn();
    local SpawnTurn = 0;
    local playerUnits;   
    local adjacentPlot;
    local unitPlot;
        if currentTurn == GameConfiguration.GetStartTurn() then
        local pPlayer = Players[player]
            if pPlayer:IsHuman() then
             playerUnits = pPlayer:GetUnits()
                for i, unit in playerUnits:Members() do
                    local unitTypeName = UnitManager.GetTypeName(unit)
                    if "LOC_UNIT_NEWUNIT_NAME" == unitTypeName then
                        SpawnTurn = 1;
                        unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());       
                    end
                end
            end       
            
            if SpawnTurn == 1 then
                local lastPlot = unitPlot;
                if numNEWUNIT> 0 then
                    for i = 1, numNEWUNIT do
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() + 1), lastPlot:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break       
                            end
                        end
                        pUnit = playerUnits:Create(iNEWUNIT, unitPlot:GetX(), unitPlot:GetY())
                        lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
                    end   
end
            


function Initialize()
Events.LocalPlayerChanged.Add( OnPlayerTurnActivated );
Events.PlayerTurnActivated.Add(OnPlayerTurnActivated);
end

Initialize();
but it is not working.
Can you give me some advice?
 
Both your SQL code and your lua code have syntax errors.

Your lua code has logical errors which would likely cause it to malfunction were it not for the syntax errors which would not allow the game to load the lua code.

Database.log will be showing an error for the SQL syntax issue
Lua.log will show a syntax error for the missing needed "end" commands the code does not contain. It will not necessarily display any errors related to the logic problems however.

Re your SQL:
Code:
INSERT INTO DynamicModifiers
        (ModifierType, CollectionType, EffectType)
VALUES   
        ('MODIFIER_NEWLEADER_CAPITAL_CITY_GRANT_UNIT_IN_CITY', 'COLLECTION_PLAYER_CAPITAL_CITY','EFFECT_GRANT_UNIT_IN_CITY'),
You did not terminate the code-chunk: , (comma) at the end of the code-chunk instead of ; (semi-colon). You made this error in all but the first code-chunk.
 
Last edited:
Back
Top Bottom