Here is the code for the Coastraiders mod by (I believe) CouchCaptainCharles:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// ccc CR ->
void SetCoastTraffic(string islandstr)
{
ref Pchar, CurIsland, cr;
string chrstr;
int crnation;
string sFantomType;
Pchar = GetMainCharacter();
int i = 1;
int j;
CurIsland = GetIslandByIndex(FindIsland(islandstr));
chrstr = "Cr" + islandstr;
for( j = 1; j <7; j++) //Loop to reset relation BEFORE groupcreation
{
cr = CharacterFromID(chrstr + j );
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), RELATION_NEUTRAL);
}
while(i < 6-(REDUCE_CR*2 + (sti(CurIsland.smuggling_nation) == PIRATE)*2)) // 1st loop to create 3 groups for 2 ships each, NK to reduce at pirate islands
{
string crg = chrstr + i;
Group_DeleteGroup(crg); //to clear for SeaLogin
string pos = "Quest_Ship_" + (1 + rand(16)); //random position
Group_CreateGroup(crg);
Group_SetGroupCommander(crg, crg);
Group_SetAddress(crg, islandstr, "Quest_Ships", pos);
if (rand(100) < COASTRAIDER_CHANCE)
{
crnation= PIRATE;
}
else
{
crnation = sti(CurIsland.smuggling_nation);
// crg is string, not object - crg.nation = crnation; //nation for group
if (GetRMRelationType(GetRMRelation(GetMainCharacter(),crnation))) // NK change to use RM
{
Group_SetTaskRunAway(crg);
Group_LockTask(crg);
}
else
{
Group_SetTaskMove(crg, 10000.0, 10000.0);
}
}
for( j = 0; j <2; j++) // 2nd loop to create 2 ships for each group
{
cr = CharacterFromID(chrstr + (i+j));
cr.nation = crnation; //nation for character
SetRandomNameToCharacter(cr);
if (crnation== PIRATE)
{
cr.quest.officertype = OFFIC_TYPE_CAPPIRATE;
sFantomType = "pirate";
}
else
{
cr.quest.officertype = OFFIC_TYPE_CAPMERCHANT;
sFantomType = "trade";
}
cr.FantomType = sFantomType;
LAi_Create_Officer(0, cr);
//cr.rank = makeint(Pchar.rank) + Rand(5); //sets NEW rank! // NK, disabled, leads to weird XP bug...
int skip = -10 + sti(Pchar.rank) + GetDifficulty()*2;
if(skip > 30) skip = 30;
int crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
while(true)
{
if(crship < SHIP_TYPES_QUANTITY)
{
if(sti(ShipsTypes[crship].CanEncounter) && ShipsTypes[crship].id != "BlackPearl")
{
if(crnation != PIRATE) { break; }
if(sti(ShipsTypes[crship].class) >= MAXPIRATECLASS) { break; }
}
}
crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
}
/*int crship = makeint(cr.rank)*10 + 20 -Rand(30); //select shiptype
if (crship>167) crship = makeint(170+Rand(15) );*/
Ship_CreateForCharacter(cr, crship, "Coaster")
//equip ship
Ship_SetFantomData(cr);
Fantom_SetCannons(cr, sFantomType);
Fantom_SetBalls(cr, sFantomType);
Fantom_SetSails(cr, sFantomType);
Fantom_SetGoods(cr, sFantomType);
Fantom_SetRandomMoney(cr, sFantomType);
SetRandomNameToShip(cr);
if (crnation== PIRATE)
{
cr.perks.list.ShipSpeedUp = true;
cr.Ship.crew.quantity = MakeInt(GetMaxCrewQuantity(cr));
}
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), GetRMRelationType(GetRMRelation(GetMainCharacter(), sti(cr.nation)))); // NK set base relation to avoid gray icon
string crgm = chrstr + (i +j); //add to group
Group_addCharacter(crg, crgm);
// NK to convert shipname to nice string
if(LogsToggle) {
Log_SetStringToLog("A " + XI_ConvertString(ShipsTypes[crship].sname) + " with " + GetNationNameByType(sti(cr.nation)) + "'s flag sighted at " + islandstr); Log_SetStringToLog("-"); }
if (islandstr == "QuebradasCostillas") {setCharacterShipLocation(cr,"QC_port")}
if (islandstr == "IslaMuelle") {setCharacterShipLocation(cr,"Muelle_port")}
if (islandstr == "FalaiseDeFleur") {setCharacterShipLocation(cr, "Falaise_de_fleur_port_01")}
else setCharacterShipLocation(cr, islandstr + "_port"); //ships in port, just eyecandy
}
i=i+2 //doublestep for grouploop
}
}
// ccc CR <-<!--c2--></div><!--ec2-->
This is an overall great mod, but I'd like to make it possible for enemy naval vessels to also raid the coast, not just pirates. I think I generally know what to do but my knowledge of code is very small. I've tried this but it doesn't answer. Any assitance would be great.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// ccc CR ->
void SetCoastTraffic(string islandstr)
{
ref Pchar, CurIsland, cr;
string chrstr;
int crnation;
string sFantomType;
Pchar = GetMainCharacter();
int i = 1;
int j;
CurIsland = GetIslandByIndex(FindIsland(islandstr));
chrstr = "Cr" + islandstr;
for( j = 1; j <7; j++) //Loop to reset relation BEFORE groupcreation
{
cr = CharacterFromID(chrstr + j );
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), RELATION_NEUTRAL);
}
while(i < 6-(REDUCE_CR*2 + (sti(CurIsland.smuggling_nation) == PIRATE)*2)) // 1st loop to create 3 groups for 2 ships each, NK to reduce at pirate islands
{
string crg = chrstr + i;
Group_DeleteGroup(crg); //to clear for SeaLogin
string pos = "Quest_Ship_" + (1 + rand(16)); //random position
Group_CreateGroup(crg);
Group_SetGroupCommander(crg, crg);
Group_SetAddress(crg, islandstr, "Quest_Ships", pos);
if (rand(100) < COASTRAIDER_CHANCE)
{
if (sti(CurIsland.smuggling_nation) = ENGLAND
{
crnation= FRANCE;
}
if (sti(CurIsland.smuggling_nation) = FRANCE
{
crnation= ENGLAND;
}
if (sti(CurIsland.smuggling_nation) = SPAIN
{
crnation= ENGLAND;
}
if (sti(CurIsland.smuggling_nation) = HOLLAND
{
crnation = PIRATE;
}
if (sti(CurIsland.smuggling_nation) = PORTUGAL
{
crnation = PIRATE;
}
}
else
{
crnation = sti(CurIsland.smuggling_nation);
// crg is string, not object - crg.nation = crnation; //nation for group
if (GetRMRelationType(GetRMRelation(GetMainCharacter(),crnation))) // NK change to use RM
{
Group_SetTaskRunAway(crg);
Group_LockTask(crg);
}
else
{
Group_SetTaskMove(crg, 10000.0, 10000.0);
}
}
for( j = 0; j <2; j++) // 2nd loop to create 2 ships for each group
{
cr = CharacterFromID(chrstr + (i+j));
cr.nation = crnation; //nation for character
SetRandomNameToCharacter(cr);
if (crnation== PIRATE)
{
cr.quest.officertype = OFFIC_TYPE_CAPPIRATE;
sFantomType = "pirate";
}
else
{
cr.quest.officertype = OFFIC_TYPE_CAPMERCHANT;
sFantomType = "trade";
}
cr.FantomType = sFantomType;
LAi_Create_Officer(0, cr);
//cr.rank = makeint(Pchar.rank) + Rand(5); //sets NEW rank! // NK, disabled, leads to weird XP bug...
int skip = -10 + sti(Pchar.rank) + GetDifficulty()*2;
if(skip > 30) skip = 30;
int crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
while(true)
{
if(crship < SHIP_TYPES_QUANTITY)
{
if(sti(ShipsTypes[crship].CanEncounter) && ShipsTypes[crship].id != "BlackPearl")
{
if(crnation != PIRATE) { break; }
if(sti(ShipsTypes[crship].class) >= MAXPIRATECLASS) { break; }
}
}
crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
}
/*int crship = makeint(cr.rank)*10 + 20 -Rand(30); //select shiptype
if (crship>167) crship = makeint(170+Rand(15) );*/
Ship_CreateForCharacter(cr, crship, "Coaster")
//equip ship
Ship_SetFantomData(cr);
Fantom_SetCannons(cr, sFantomType);
Fantom_SetBalls(cr, sFantomType);
Fantom_SetSails(cr, sFantomType);
Fantom_SetGoods(cr, sFantomType);
Fantom_SetRandomMoney(cr, sFantomType);
SetRandomNameToShip(cr);
if (crnation== PIRATE)
{
cr.perks.list.ShipSpeedUp = true;
cr.Ship.crew.quantity = MakeInt(GetMaxCrewQuantity(cr));
}
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), GetRMRelationType(GetRMRelation(GetMainCharacter(), sti(cr.nation)))); // NK set base relation to avoid gray icon
string crgm = chrstr + (i +j); //add to group
Group_addCharacter(crg, crgm);
// NK to convert shipname to nice string
if(LogsToggle) {
Log_SetStringToLog("A " + XI_ConvertString(ShipsTypes[crship].sname) + " with " + GetNationNameByType(sti(cr.nation)) + "'s flag sighted at " + islandstr); Log_SetStringToLog("-"); }
if (islandstr == "QuebradasCostillas") {setCharacterShipLocation(cr,"QC_port")}
if (islandstr == "IslaMuelle") {setCharacterShipLocation(cr,"Muelle_port")}
if (islandstr == "FalaiseDeFleur") {setCharacterShipLocation(cr, "Falaise_de_fleur_port_01")}
else setCharacterShipLocation(cr, islandstr + "_port"); //ships in port, just eyecandy
}
i=i+2 //doublestep for grouploop
}
}
// ccc CR <-<!--c2--></div><!--ec2-->
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// ccc CR ->
void SetCoastTraffic(string islandstr)
{
ref Pchar, CurIsland, cr;
string chrstr;
int crnation;
string sFantomType;
Pchar = GetMainCharacter();
int i = 1;
int j;
CurIsland = GetIslandByIndex(FindIsland(islandstr));
chrstr = "Cr" + islandstr;
for( j = 1; j <7; j++) //Loop to reset relation BEFORE groupcreation
{
cr = CharacterFromID(chrstr + j );
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), RELATION_NEUTRAL);
}
while(i < 6-(REDUCE_CR*2 + (sti(CurIsland.smuggling_nation) == PIRATE)*2)) // 1st loop to create 3 groups for 2 ships each, NK to reduce at pirate islands
{
string crg = chrstr + i;
Group_DeleteGroup(crg); //to clear for SeaLogin
string pos = "Quest_Ship_" + (1 + rand(16)); //random position
Group_CreateGroup(crg);
Group_SetGroupCommander(crg, crg);
Group_SetAddress(crg, islandstr, "Quest_Ships", pos);
if (rand(100) < COASTRAIDER_CHANCE)
{
crnation= PIRATE;
}
else
{
crnation = sti(CurIsland.smuggling_nation);
// crg is string, not object - crg.nation = crnation; //nation for group
if (GetRMRelationType(GetRMRelation(GetMainCharacter(),crnation))) // NK change to use RM
{
Group_SetTaskRunAway(crg);
Group_LockTask(crg);
}
else
{
Group_SetTaskMove(crg, 10000.0, 10000.0);
}
}
for( j = 0; j <2; j++) // 2nd loop to create 2 ships for each group
{
cr = CharacterFromID(chrstr + (i+j));
cr.nation = crnation; //nation for character
SetRandomNameToCharacter(cr);
if (crnation== PIRATE)
{
cr.quest.officertype = OFFIC_TYPE_CAPPIRATE;
sFantomType = "pirate";
}
else
{
cr.quest.officertype = OFFIC_TYPE_CAPMERCHANT;
sFantomType = "trade";
}
cr.FantomType = sFantomType;
LAi_Create_Officer(0, cr);
//cr.rank = makeint(Pchar.rank) + Rand(5); //sets NEW rank! // NK, disabled, leads to weird XP bug...
int skip = -10 + sti(Pchar.rank) + GetDifficulty()*2;
if(skip > 30) skip = 30;
int crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
while(true)
{
if(crship < SHIP_TYPES_QUANTITY)
{
if(sti(ShipsTypes[crship].CanEncounter) && ShipsTypes[crship].id != "BlackPearl")
{
if(crnation != PIRATE) { break; }
if(sti(ShipsTypes[crship].class) >= MAXPIRATECLASS) { break; }
}
}
crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
}
/*int crship = makeint(cr.rank)*10 + 20 -Rand(30); //select shiptype
if (crship>167) crship = makeint(170+Rand(15) );*/
Ship_CreateForCharacter(cr, crship, "Coaster")
//equip ship
Ship_SetFantomData(cr);
Fantom_SetCannons(cr, sFantomType);
Fantom_SetBalls(cr, sFantomType);
Fantom_SetSails(cr, sFantomType);
Fantom_SetGoods(cr, sFantomType);
Fantom_SetRandomMoney(cr, sFantomType);
SetRandomNameToShip(cr);
if (crnation== PIRATE)
{
cr.perks.list.ShipSpeedUp = true;
cr.Ship.crew.quantity = MakeInt(GetMaxCrewQuantity(cr));
}
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), GetRMRelationType(GetRMRelation(GetMainCharacter(), sti(cr.nation)))); // NK set base relation to avoid gray icon
string crgm = chrstr + (i +j); //add to group
Group_addCharacter(crg, crgm);
// NK to convert shipname to nice string
if(LogsToggle) {
Log_SetStringToLog("A " + XI_ConvertString(ShipsTypes[crship].sname) + " with " + GetNationNameByType(sti(cr.nation)) + "'s flag sighted at " + islandstr); Log_SetStringToLog("-"); }
if (islandstr == "QuebradasCostillas") {setCharacterShipLocation(cr,"QC_port")}
if (islandstr == "IslaMuelle") {setCharacterShipLocation(cr,"Muelle_port")}
if (islandstr == "FalaiseDeFleur") {setCharacterShipLocation(cr, "Falaise_de_fleur_port_01")}
else setCharacterShipLocation(cr, islandstr + "_port"); //ships in port, just eyecandy
}
i=i+2 //doublestep for grouploop
}
}
// ccc CR <-<!--c2--></div><!--ec2-->
This is an overall great mod, but I'd like to make it possible for enemy naval vessels to also raid the coast, not just pirates. I think I generally know what to do but my knowledge of code is very small. I've tried this but it doesn't answer. Any assitance would be great.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// ccc CR ->
void SetCoastTraffic(string islandstr)
{
ref Pchar, CurIsland, cr;
string chrstr;
int crnation;
string sFantomType;
Pchar = GetMainCharacter();
int i = 1;
int j;
CurIsland = GetIslandByIndex(FindIsland(islandstr));
chrstr = "Cr" + islandstr;
for( j = 1; j <7; j++) //Loop to reset relation BEFORE groupcreation
{
cr = CharacterFromID(chrstr + j );
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), RELATION_NEUTRAL);
}
while(i < 6-(REDUCE_CR*2 + (sti(CurIsland.smuggling_nation) == PIRATE)*2)) // 1st loop to create 3 groups for 2 ships each, NK to reduce at pirate islands
{
string crg = chrstr + i;
Group_DeleteGroup(crg); //to clear for SeaLogin
string pos = "Quest_Ship_" + (1 + rand(16)); //random position
Group_CreateGroup(crg);
Group_SetGroupCommander(crg, crg);
Group_SetAddress(crg, islandstr, "Quest_Ships", pos);
if (rand(100) < COASTRAIDER_CHANCE)
{
if (sti(CurIsland.smuggling_nation) = ENGLAND
{
crnation= FRANCE;
}
if (sti(CurIsland.smuggling_nation) = FRANCE
{
crnation= ENGLAND;
}
if (sti(CurIsland.smuggling_nation) = SPAIN
{
crnation= ENGLAND;
}
if (sti(CurIsland.smuggling_nation) = HOLLAND
{
crnation = PIRATE;
}
if (sti(CurIsland.smuggling_nation) = PORTUGAL
{
crnation = PIRATE;
}
}
else
{
crnation = sti(CurIsland.smuggling_nation);
// crg is string, not object - crg.nation = crnation; //nation for group
if (GetRMRelationType(GetRMRelation(GetMainCharacter(),crnation))) // NK change to use RM
{
Group_SetTaskRunAway(crg);
Group_LockTask(crg);
}
else
{
Group_SetTaskMove(crg, 10000.0, 10000.0);
}
}
for( j = 0; j <2; j++) // 2nd loop to create 2 ships for each group
{
cr = CharacterFromID(chrstr + (i+j));
cr.nation = crnation; //nation for character
SetRandomNameToCharacter(cr);
if (crnation== PIRATE)
{
cr.quest.officertype = OFFIC_TYPE_CAPPIRATE;
sFantomType = "pirate";
}
else
{
cr.quest.officertype = OFFIC_TYPE_CAPMERCHANT;
sFantomType = "trade";
}
cr.FantomType = sFantomType;
LAi_Create_Officer(0, cr);
//cr.rank = makeint(Pchar.rank) + Rand(5); //sets NEW rank! // NK, disabled, leads to weird XP bug...
int skip = -10 + sti(Pchar.rank) + GetDifficulty()*2;
if(skip > 30) skip = 30;
int crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
while(true)
{
if(crship < SHIP_TYPES_QUANTITY)
{
if(sti(ShipsTypes[crship].CanEncounter) && ShipsTypes[crship].id != "BlackPearl")
{
if(crnation != PIRATE) { break; }
if(sti(ShipsTypes[crship].class) >= MAXPIRATECLASS) { break; }
}
}
crship = skip + Rand(70 + GetDifficulty()*5) + Rand(70 + GetDifficulty()*5); //select shiptype
if (crship>150) crship = 162 + Rand(30);
if(crship < 0) crship = 0;
}
/*int crship = makeint(cr.rank)*10 + 20 -Rand(30); //select shiptype
if (crship>167) crship = makeint(170+Rand(15) );*/
Ship_CreateForCharacter(cr, crship, "Coaster")
//equip ship
Ship_SetFantomData(cr);
Fantom_SetCannons(cr, sFantomType);
Fantom_SetBalls(cr, sFantomType);
Fantom_SetSails(cr, sFantomType);
Fantom_SetGoods(cr, sFantomType);
Fantom_SetRandomMoney(cr, sFantomType);
SetRandomNameToShip(cr);
if (crnation== PIRATE)
{
cr.perks.list.ShipSpeedUp = true;
cr.Ship.crew.quantity = MakeInt(GetMaxCrewQuantity(cr));
}
SetCharacterRelationBoth(sti(cr.index), GetMainCharacterIndex(), GetRMRelationType(GetRMRelation(GetMainCharacter(), sti(cr.nation)))); // NK set base relation to avoid gray icon
string crgm = chrstr + (i +j); //add to group
Group_addCharacter(crg, crgm);
// NK to convert shipname to nice string
if(LogsToggle) {
Log_SetStringToLog("A " + XI_ConvertString(ShipsTypes[crship].sname) + " with " + GetNationNameByType(sti(cr.nation)) + "'s flag sighted at " + islandstr); Log_SetStringToLog("-"); }
if (islandstr == "QuebradasCostillas") {setCharacterShipLocation(cr,"QC_port")}
if (islandstr == "IslaMuelle") {setCharacterShipLocation(cr,"Muelle_port")}
if (islandstr == "FalaiseDeFleur") {setCharacterShipLocation(cr, "Falaise_de_fleur_port_01")}
else setCharacterShipLocation(cr, islandstr + "_port"); //ships in port, just eyecandy
}
i=i+2 //doublestep for grouploop
}
}
// ccc CR <-<!--c2--></div><!--ec2-->