 |
|
ahenobarb
|
|
There's a small typo in line 4. It should say i=0 instead of i=o.
I tried the code in a saved game where there were lots of barbarians about, but the code had no effect. It's still a great idea though!
|
|
|  |
 |
|
ahenobarb
|
|
Does anyone have any idea why this code would not have an effect in the game? When I included it in the script.txt, it informed me about the typo, so I know that the game "read" the code, but it did not "excute" it.
|
|
|  |
 |
|
Peter Triggs
|
|
Gone Fishin, Canada
Jan 2000 time: 05:21
|
|
ahenobarb,
You should have got some 'wrong type of argument' errors because you can't use functions like GetArmyByIndex(int, int, armyVar) and GetCityByLocation(location, cityVar) with BuiltIn army or city variables: they must be user defined variables like 'tmpArmy' and 'tmpCity'. Make sure you've got DebugSlic=yes.
|
|
|  |
 |
|
ahenobarb
|
|
It looks like I am birthing Pedrunn's calf, but here is the revised code generated from the comments everyone included here. BTW, Immortal Wombat, I used your suggestion and changed EndTurn to BeginTurn and back again, but it still didn't do anything.
HandleEvent(EndTurn) 'CreateBarbarianCamp' pre { // When the player turn ends
int_t i;
army_t tmpArmy;
city_t tmpCity;
player[0] = g.player;
if(player[0] == 0) { //if player is barbarian
for(i=0; i <= player[0].armies; i = i + 1) {
GetArmyByIndex(player[0], i, tmpArmy); // In all its armies
CreateCity(0,tmpArmy.location, 0, tmpCity); // create a city in its location
if(CityIsValid(tmpCity)) { // if city was created
value[0] = GetUnitsAtLocation (tmpArmy.location);
value[1] = value[0] - 1; // The number of units
AddPops(city[0], value[1]); // becomes the size of the city
}
}
}
}
HandleEvent(MoveUnits) 'KillBarbarianCamp' pre { // When a army moves
int_t i;
army_t tmpArmy;
city_t tmpCity;
player[0] = g.player; // check army player owner
if(player[0] == 0) { // if player is barbarian
location[0] = tmpArmy.location; // Get its location
GetCityByLocation(location[0], tmpCity); // and check if there is a city
if(CityIsValid(tmpCity)) { // If there is
for (i = 0; i <= tmpCity.population; i=i+1){ //
Event: KillPop(tmpCity); // Kill City
}
}
}
}
I was looking over Pedrunn's other code regarding religion that he is working on with mapfi and others (you know the thread ) and he said he has concerns about the CreateCity function, which is also used here. perhaps it's the culprit?
|
|
|  |
 |
|
Pedrunn
|
 |
of Natal, Brazil
Jul 2001 time: 02:21
|
|
Try this one. I think it will work now.
Note: The part with // is to prevent the barbs to. mess up borders by creating city over them. If works with them. try without them.
Note2: I changed the MoveUnit event for BeginTurn. This mean that all barbarian cities are going to be destroyed every turn. This makes more sense since barbarians are supposed to be nomads.
code:
HandleEvent(EndTurn) 'CreateBarbarianCamp' pre { // When the player turn ends
int_t i;
int_t tmpPlayer;
int_t ArmyCount;
int_t CitySize;
army_t tmpArmy;
city_t tmpCity;
location_t tmpLoc;
player[0] = g.player;
if(player[0] == 0) {
ArmyCount = player[0].armies;
for(i=0; i <= ArmyCount; i = i + 1) {
tmpPlayer = player[0];
GetArmyByIndex(tmpPlayer, i, tmpArmy); // In all its armies
tmpLoc = tmpArmy.location;
// if(CellOwner(tmpLoc) == -1) { // if unit is in unclaimed land
CreateCity(0, tmpLoc, 0, tmpCity); // create a city in its location
if(CityIsValid(tmpCity)) { // if city was created
CitySize = GetUnitsAtLocation (tmpLoc) - 1; // The number of units
AddPops(tmpCity, CitySize); // becomes the size of the city
}
// }
}
}
}
HandleEvent(BeginTurn) 'KillBarbarianCamp' pre {
int_t i;
int_t tmpPlayer;
int_t CityCount;
int_t CitySize;
city_t tmpCity;
tmpPlayer = g.player;
if(tmpPlayer == 0) {
CityCount = PlayerCityCount(tmpPlayer);
for(i=0; i <= CityCount; i = i + 1) {
GetCityByIndex(tmpPlayer, i, tmpCity);
city[0] = tmpCity;
if(CityIsValid(city[0])) {
for (i = 0; i <= city[0].population; i=i+1) {
if(CityIsValid(city[0])) {
Event: KillPop(city[0]);
}
}
}
}
}
}
EDIT: Found a typo.
Last edited by Pedrunn on 14-08-2002 at 07:59
|
|
|  |
 |
|  |
 |
|  |
 |
|  |
 |
|
Pedrunn
|
 |
of Natal, Brazil
Jul 2001 time: 02:21
|
|
I fee such a jerk. I have finished this code but isntead of cities it is created Tile Improvements.
Add this in any .slc file of the mod you want to use it.
code:
//////////////////////////////////////////////////////////////////////////
// 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]);
}
}
and this in the bottom of the *_tileimp.txt of the same mod you want to use.
code:
##################################################
##########
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
}
}
You must have the Apolyton Tile File.
(* stands for the prefix of the mod and you will find these files to be changed in the
CTP2 base director/ctp2_data/default/gamedata).
|
|
|  |
 |
|
Dale
|
 |
Sir! Why do you keep clicking on me?
Dec 2000 time: 15:21
|
|
Pedrunn:
Just wanted to let you know that I can quite happily confirm that CreateCity() & CreateCoastalCity() work absolutely perfectly. 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.
CreateCity(player, location, distance[, holder]);
Where:
- player cannot be in the form: g.player, player[0].
- location cannot be an array element: army.location, city.location.
- distance is taken to me "somewhere between zero and X squares away".
- holder is not necessary, only if you want to do more with the city. Must be in form city_t.
- A city will not create within another city's radius. It puts it close to the location then.
Copy and paste the following code into scenario.slc, and start an original game. You should get a new city every couple of turns.
code:
// 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
}
}
}
}
|
|
|  |
All times are GMT. The time now is 05:21. Apolyton Time is 00:21. |
top of page
|
| archivepost |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|