How to init unit?

local player = Players[ NUM ];
local plot = Map.GetPlot( X, Y );
local unit = player:InitUnit( UNITS.ID, plot:GetX(), plot:GetY());
 
How to check barbarians ID, i have tried this:
local id1 = GameInfo.Units.UNIT_BARBARIAN_WARRIOR.ID
local id1 = GameInfo.Civilizations.CIVILIZATION_BARBARIAN.ID
print("NEF: >>>>>>> unit id:",id1);
print("NEF: >>>>>>> civ id:",id2);

but it works only for units.
 
now it works :)

local id1 = GameInfo.Units.UNIT_BARBARIAN_WARRIOR.ID
local id2 = GameInfo.Units.UNIT_WARRIOR.ID
local id3 = GameInfo.Civilizations.CIVILIZATION_BARBARIAN.ID
print("NEF: >>>>>>> unit id:",id1);
print("NEF: >>>>>>> unit2 id:",id2);
print("NEF: >>>>>>> civ id:",id3);


Map Script: NEF: >>>>>>> unit id: 85
Map Script: NEF: >>>>>>> unit2 id: 83
Map Script: NEF: >>>>>>> civ id: 19

thank you
 
if ( plot:HasBarbarianCamp() ) then
local barbplayer = Players[19];
local barbunit = 85;
local plotX = Plot:GetX();
local plotX = Plot:GetX();
local unit = barbplayer:InitUnit( barbunit, plotX, plotY); --add unit
end

Why it results with civ crash?
If I change Players index to 0 or 1 it works without crash?
 
i dont think you can. even the civ's settlers, scouts, warriors are generated after the map and game init
 
I have checked if barbs is a player and:

code from newturn.lua:

print("------------------------------- TURN START");
for i = 0, GameDefines.MAX_MAJOR_CIVS + GameDefines.MAX_MINOR_CIVS - 1 do -- add CS to LD mirror
local player = Players;
if player:IsEverAlive() then

local civilizationType = player:GetCivilizationType();
local civid = player:GetID();
local LeaderType = player:GetLeaderType();
local MinorCivTrait = player:GetMinorCivTrait();
local CivName = player:GetName();
local CivNameKey = player:GetNameKey();
local Team= player:GetTeam();
local Personality= player:GetPersonality();
local PersonalityType= player:GetPersonalityType();
local Playable =0;
if ( player:IsPlayable() ) then
Playable = 1;
end
print("NEF: CivilizationType:",CivilizationType,", GetID():", civid ,", GetLeaderType():", LeaderType ,", GetMinorCivTrait():", MinorCivTrait ,", GetName():", CivName,"Team:", Team ,"Personality:", Personality ,"PersonalityType:", PersonalityType , "Playable:", Playable);
end
end
local barbplayer = Players[19];
local barbunit = 85;
if ( barbplayer:IsAlive() ) then
--local unit = barbplayer:InitUnit( barbunit, x, y); --add unit
print("NEF: Add Barbs unit at plot");
else print("NEF: Barbs is not alive");
end

Result:

NewTurn: ------------------------------- TURN START
NewTurn: NEF: CivilizationType: nil , GetID(): 0 , GetLeaderType(): 2 , GetMinorCivTrait(): -1 , GetName(): Augustus Caesar Team: 0 Personality: -1 PersonalityType: 2 Playable: 1
NewTurn: NEF: CivilizationType: nil , GetID(): 1 , GetLeaderType(): 20 , GetMinorCivTrait(): -1 , GetName(): Genghis Khan Team: 1 Personality: -1 PersonalityType: 20 Playable: 1
NewTurn: NEF: CivilizationType: nil , GetID(): 22 , GetLeaderType(): 3 , GetMinorCivTrait(): 2 , GetName(): Oslo Team: 22 Personality: 2 PersonalityType: 3 Playable: 0
NewTurn: NEF: CivilizationType: nil , GetID(): 23 , GetLeaderType(): 3 , GetMinorCivTrait(): 0 , GetName(): Florence Team: 23 Personality: 0 PersonalityType: 3 Playable: 0
NewTurn: NEF: CivilizationType: nil , GetID(): 24 , GetLeaderType(): 3 , GetMinorCivTrait(): 2 , GetName(): Helsinki Team: 24 Personality: 3 PersonalityType: 3 Playable: 0
NewTurn: NEF: CivilizationType: nil , GetID(): 25 , GetLeaderType(): 3 , GetMinorCivTrait(): 2 , GetName(): Venice Team: 25 Personality: 2 PersonalityType: 3 Playable: 0
NewTurn: NEF: Barbs is not alive
NewTurn: -------------------------------

It is turn 10 with barbs at the map. Barbs is not a player, so I don't need to active it. It just work as separate unit I think but I don't know how to add it.
 
Players[63] is barbarians

edit:

quick test in tuner

Players[63]:InitUnit( 1, 11, 14); Players[63]:InitUnit( 1, 11, 14);

plops a barb worker and spearman at x 11 y 14

player 60 crashes game ;)
 
Back
Top Bottom