Hey great, i hope this does work, i havent actually tested it as i dont know how
.
.
. Maybe tomorrow.
You can only trigger event handler by this event unfortunatly I get error index of bounce errors if I use this event to trigger my code and try to use a build in array with DebugSlic=Yes. If it is just saved in a user defined variable no problem, but if you try to use this variable no change. So you have to use the CreateImprovement event and have to trigger an event handler by this event that will execute the FinishImprovements function.//////////////////////////////////////////////////////////////////////////
// 5) Barbarian Camp
// by Pedrunn
//////////////////////////////////////////////////////////////////////////
int_t CampPlacement;
HandleEvent(EndTurn) 'CreateBarbarianCamp' pre { // When the player turn ends
int_t i;
int_t tmpPlayer;
int_t ArmyCount;
int_t CitySize;
army_t tmpArmy;
location_t tmpLoc;
player[0] = g.player;
if(player[0] == 0) {
ArmyCount = player[0].armies;
for(i=0; i <= ArmyCount; i = i + 1) {
GetArmyByIndex(0, i, tmpArmy); // In all its armies
tmpLoc = tmpArmy.location;
if(CellOwner(tmpLoc) == -1) { // if unit is in unclaimed land
CampPlacement = 1;
GrantAdvance(0, AdvanceDB(ADVANCE_SUBNEURAL_ADS));
Event:CreateImprovement(0, tmpLoc, TerrainImprovementDB(TILEIMP_BARBARIAN_CAMP), 0);
}
else{
tmpPlayer = CellOwner(tmpLoc);
CampPlacement = 1;
GrantAdvance(tmpPlayer, AdvanceDB(ADVANCE_SUBNEURAL_ADS));
Event:CreateImprovement(tmpPlayer, tmpLoc, TerrainImprovementDB(TILEIMP_BARBARIAN_CAMP), 0);
}
}
}
}
HandleEvent(CreateImprovement) 'BarbsCantHaveSubneuralAds' post {
if(CampPlacement == 1) {
CampPlacement = 0;
FinishImprovements(location[0]);
if (HasAdvance(player[0], ID_ADVANCE_SUBNEURAL_ADS)) {
RemoveAdvance(player[0], AdvanceDB(ADVANCE_SUBNEURAL_ADS));
}
}
}
HandleEvent(BeginTurn) 'DestroyBarbarianCamp' pre {
int_t i;
int_t j;
location_t tmpLoc;
player[0] = g.player;
if(player[0] == 0) {
for (i=0; i<=GetMapWidth()-1; i=i+1) {
for (j=0; j<=GetMapHeight()-1 ; j=j+1) {
MakeLocation(tmpLoc, i, j);
if(TileHasImprovement(tmpLoc, TerrainImprovementDB(TILEIMP_BARBARIAN_CAMP))) {
Event: CutImprovements(tmpLoc);
}
}
}
}
}
HandleEvent(BattleAftermath) 'Destroy2BarbarianCamp' pre {
if(TileHasImprovement(location[0], TerrainImprovementDB(TILEIMP_BARBARIAN_CAMP))){
Event:CutImprovements(location[0]);
}
}
############################################################
TILEIMP_BARBARIAN_CAMP {
Icon ICON_TILEIMP_FORTIFICATIONS
Tooltip TOOLTIP_TILEIMP_SELECT_FORT_BUTTON
Statusbar STATUSBAR_TILEIMP_SELECT_FORT_BUTTON
Level 4
Class:Structure1
ConstructionTiles 1
CantBuildOn TERRAIN_WATER_BEACH
CantBuildOn TERRAIN_WATER_DEEP
CantBuildOn TERRAIN_WATER_RIFT
CantBuildOn TERRAIN_WATER_SHALLOW
CantBuildOn TERRAIN_WATER_SHELF
CantBuildOn TERRAIN_WATER_TRENCH
CantBuildOn TERRAIN_WATER_VOLCANO
TerrainEffect {
Terrain TERRAIN_BROWN_HILL
Terrain TERRAIN_BROWN_MOUNTAIN
Terrain TERRAIN_DESERT
Terrain TERRAIN_FOREST
Terrain TERRAIN_GLACIER
Terrain TERRAIN_GRASSLAND
Terrain TERRAIN_HILL
Terrain TERRAIN_JUNGLE
Terrain TERRAIN_MOUNTAIN
Terrain TERRAIN_PLAINS
Terrain TERRAIN_SWAMP
Terrain TERRAIN_TUNDRA
Terrain TERRAIN_WHITE_HILL
Terrain TERRAIN_WHITE_MOUNTAIN
DefenseBonus 0.5
EnableAdvance ADVANCE_SUBNEURAL_ADS
ProductionCost 0
ProductionTime 1
TilesetIndex 695
}
}
There's nothing wrong with the call, just how you used the args. You've got the right amount of args, but not the right ones.// Example CreateCity() & CreateCoastalCity() functions
HandleEvent(BeginTurn) 'CreateCityTest' pre {
city_t tmpCity;
location_t tmpLoc;
int_t tmpPlayer;
int_t tmpDistance;
int_t tmpCounter;
city_t tmpCity;
tmpDistance = 5; // This is the distance from loc to build city
tmpPlayer = g.player; // Current player
if(IsHumanPlayer(tmpPlayer)) { // Only do for human
tmpCounter = random(4); // <1 = CreateCity, >=3 = CoastalCity
if(GetCityByIndex(tmpPlayer, 0, tmpCity)) {
tmpLoc = tmpCity.location;
if(tmpCounter < 1) {
if(!(CreateCity(tmpPlayer, tmpLoc, tmpDistance)) { // Create the actual city. You don't need a settler for this.
return STOP; // Error creating city
}
}
if(tmpCounter >= 3) { // Create coastal city
if(!(CreateCoastalCity(tmpPlayer, tmpLoc, tmpDistance)) { // Create the actual city. You don't need a settler for this.
return STOP; // Error creating city
}
}
}
}
Comment