收起左侧

[资料] 触发程序-将地图上某种单位全部改变控制者

[复制链接]
こはね发表于 2019-11-18 00:56:45

通过自己编写触发程序,我们可以将地图上某种单位全部改变控制者,例如将玩家1的诸葛弩全部转变成玩家2的单位,将玩家5的鹰炮全部转变成大自然的单位。

但是有一点要注意,不要滥用该触发程序,因为这种触发程序要寻找地图上所有单位并作出判断,所以是非常占用内存的,滥用会造成游戏卡顿。

以下为触发程序代码:


xsSetContextPlayer(0);
/*数值必须大于你的mod单位数量+263;用来统计单位数量*/
for(UnitTypeID=1800;>-1)
{
if(kbGetUnitTypeName(UnitTypeID)=="all") break;
}
/* 统计所有地图单位数量,255 = cUnitStateAny */
xsSetContextPlayer(0); float P0UC = kbUnitCount(0,UnitTypeID,255);
xsSetContextPlayer(1); float P1UC = kbUnitCount(1,UnitTypeID,255);
xsSetContextPlayer(2); float P2UC = kbUnitCount(2,UnitTypeID,255);
xsSetContextPlayer(3); float P3UC = kbUnitCount(3,UnitTypeID,255);
xsSetContextPlayer(4); float P4UC = kbUnitCount(4,UnitTypeID,255);
xsSetContextPlayer(5); float P5UC = kbUnitCount(5,UnitTypeID,255);
xsSetContextPlayer(6); float P6UC = kbUnitCount(6,UnitTypeID,255);
xsSetContextPlayer(7); float P7UC = kbUnitCount(7,UnitTypeID,255);
xsSetContextPlayer(8); float P8UC = kbUnitCount(8,UnitTypeID,255);
float AllUC = (P0UC+P1UC+P2UC+P3UC+P4UC+P5UC+P6UC+P7UC+P8UC)*cNumberPlayers;
/*因为kbUnitCount只能统计单位,不能准确获取最后一个剧情名(ScenarioName),所以 X cNumberPlayers倍,根据实际需求自己调整,否则会很占内存....*/

/*要转换的单位调用名,(kbGetProtoUnitID返回ProtoUnitID)*/
float PorType = kbGetProtoUnitID("Protoname");

/*循环AllUC次(地图所有单位*cNumberPlayers)
for(u=1;<AllUC){

/*如果某单位ID的ProtoUnitID == PorType (kbGetBlockID将剧情名(ScenarioName)转换成UnitID,注:kbGetBlockID的值带有双引号"";kbUnitGetProtoUnitID将UnitID转换成ProtoUnitID)*/
if(kbUnitGetProtoUnitID(kbGetBlockID(""+u)) == PorType)
/*剩下的你应该懂了,(trUnitSelectByID选取单位使用UnitID)*/
{trChatSend(0,""+u);trUnitSelectClear();trUnitSelectByID(kbGetBlockID(""+u));
trUnitConvert(2);
}
}

源代码:

	xsSetContextPlayer(0);
for(UnitTypeID=1800;>-1)
{
if(kbGetUnitTypeName(UnitTypeID)=="all") break;
}
xsSetContextPlayer(0); float P0UC = kbUnitCount(0,UnitTypeID,255);
xsSetContextPlayer(1); float P1UC = kbUnitCount(1,UnitTypeID,255);
xsSetContextPlayer(2); float P2UC = kbUnitCount(2,UnitTypeID,255);
xsSetContextPlayer(3); float P3UC = kbUnitCount(3,UnitTypeID,255);
xsSetContextPlayer(4); float P4UC = kbUnitCount(4,UnitTypeID,255);
xsSetContextPlayer(5); float P5UC = kbUnitCount(5,UnitTypeID,255);
xsSetContextPlayer(6); float P6UC = kbUnitCount(6,UnitTypeID,255);
xsSetContextPlayer(7); float P7UC = kbUnitCount(7,UnitTypeID,255);
xsSetContextPlayer(8); float P8UC = kbUnitCount(8,UnitTypeID,255);
float AllUC = (P0UC+P1UC+P2UC+P3UC+P4UC+P5UC+P6UC+P7UC+P8UC)*cNumberPlayers;
float PorType = kbGetProtoUnitID("Protoname");
bool allplayer = true;
if(allplayer == true)
{
for(u=1;<AllUC)
{
if(kbUnitGetProtoUnitID(kbGetBlockID(""+u)) == PorType)
{
trUnitSelectClear();
trUnitSelectByID(kbGetBlockID(""+u));
trUnitConvert(0);
}
}
}
else
{
for(u=1;<AllUC)
{
if(kbUnitGetProtoUnitID(kbGetBlockID(""+u)) == PorType)
{
trUnitSelectClear();
trUnitSelectByID(kbGetBlockID(""+u));
if(trUnitIsOwnedBy(2))
{
trUnitConvert(0);
}
}
}
}


地图触发代码,仅限圣典所提及的c++语法触发;请自行参考圣典的地图教程:https://www.aoebbs.net/Age_of_Empires_III_Modding_Tutorial/13-05Trigger.htm

	oxy("rule _Debug44 active runImmediately { ");
oxy("if((trTime()-cActivationTime) >= 1.00000000){");
oxy("xsSetContextPlayer(0);");
oxy("for(UnitTypeID=1800;>-1)");
oxy("{");
oxy(" if(kbGetUnitTypeName(UnitTypeID)==\"all\") break;");
oxy("}");
oxy("xsSetContextPlayer(0); float P0UC = kbUnitCount(0,UnitTypeID,255);");
oxy("xsSetContextPlayer(1); float P1UC = kbUnitCount(1,UnitTypeID,255);");
oxy("xsSetContextPlayer(2); float P2UC = kbUnitCount(2,UnitTypeID,255);");
oxy("xsSetContextPlayer(3); float P3UC = kbUnitCount(3,UnitTypeID,255);");
oxy("xsSetContextPlayer(4); float P4UC = kbUnitCount(4,UnitTypeID,255);");
oxy("xsSetContextPlayer(5); float P5UC = kbUnitCount(5,UnitTypeID,255);");
oxy("xsSetContextPlayer(6); float P6UC = kbUnitCount(6,UnitTypeID,255);");
oxy("xsSetContextPlayer(7); float P7UC = kbUnitCount(7,UnitTypeID,255);");
oxy("xsSetContextPlayer(8); float P8UC = kbUnitCount(8,UnitTypeID,255);");
oxy("float AllUC = (P0UC+P1UC+P2UC+P3UC+P4UC+P5UC+P6UC+P7UC+P8UC)*cNumberPlayers;");
oxy("float PorType = kbGetProtoUnitID(\"ypChuKoNu\");");
oxy("bool allplayer = true;");
oxy("if(allplayer == true)");
oxy("{");
oxy(" for(u=1;<AllUC)");
oxy(" {");
oxy(" if(kbUnitGetProtoUnitID(kbGetBlockID(\"\"+u)) == PorType)");
oxy(" {");
oxy(" trUnitSelectClear();");
oxy(" trUnitSelectByID(kbGetBlockID(\"\"+u));");
oxy(" trUnitConvert(0);");
oxy(" }");
oxy(" }");
oxy("}");
oxy("else");
oxy("{");
oxy(" for(u=1;<AllUC)");
oxy(" {");
oxy(" if(kbUnitGetProtoUnitID(kbGetBlockID(\"\"+u)) == PorType)");
oxy(" {");
oxy(" trUnitSelectClear();");
oxy(" trUnitSelectByID(kbGetBlockID(\"\"+u));");
oxy(" if(trUnitIsOwnedBy(2))");
oxy(" {");
oxy(" trUnitConvert(0);");
oxy(" }");
oxy(" }");
oxy(" }");
oxy("}");
oxy("xsDisableRule(\"_Debug44\");");
oxyZ("}} /*");


编辑器触发程序代码:

	<Effect name="*Advanced Convert by Protoname">
<Param name="Unitcount" dispName=">=Your MOD all Unit Count+263" VarType="string">1665</Param>
<Param name="Protounit" dispName="Protounit" VarType="protounit"></Param>
<Param name="ToPlayer" dispName="Convert To" VarType="player">1</Param>
<Param name="AllPlayer" dispName="Is all Player?" VarType="bool">false</Param>
<Param name="FormPlayer" dispName="Form Player" VarType="player">2</Param>
<command>xsSetContextPlayer(0);</command>
<command>for(UnitTypeID=%Unitcount%;>-1)</command>
<command>{</command>
<command> if(kbGetUnitTypeName(UnitTypeID)=="all") break;</command>
<command>}</command>
<command>xsSetContextPlayer(0); float P0UC = kbUnitCount(0,UnitTypeID,255);</command>
<command>xsSetContextPlayer(1); float P1UC = kbUnitCount(1,UnitTypeID,255);</command>
<command>xsSetContextPlayer(2); float P2UC = kbUnitCount(2,UnitTypeID,255);</command>
<command>xsSetContextPlayer(3); float P3UC = kbUnitCount(3,UnitTypeID,255);</command>
<command>xsSetContextPlayer(4); float P4UC = kbUnitCount(4,UnitTypeID,255);</command>
<command>xsSetContextPlayer(5); float P5UC = kbUnitCount(5,UnitTypeID,255);</command>
<command>xsSetContextPlayer(6); float P6UC = kbUnitCount(6,UnitTypeID,255);</command>
<command>xsSetContextPlayer(7); float P7UC = kbUnitCount(7,UnitTypeID,255);</command>
<command>xsSetContextPlayer(8); float P8UC = kbUnitCount(8,UnitTypeID,255);</command>
<command>float AllUC = (P0UC+P1UC+P2UC+P3UC+P4UC+P5UC+P6UC+P7UC+P8UC)*cNumberPlayers;</command>
<command>float PorType = kbGetProtoUnitID("%Protounit%");</command>
<command>bool allplayer = %AllPlayer%;</command>
<command>if(allplayer == true)</command>
<command>{</command>
<command> for(u=1;<AllUC)</command>
<command> {</command>
<command> if(kbUnitGetProtoUnitID(kbGetBlockID(""+u)) == PorType)</command>
<command> {</command>
<command> trUnitSelectClear();</command>
<command> trUnitSelectByID(kbGetBlockID(""+u));</command>
<command> trUnitConvert(%ToPlayer%);</command>
<command> }</command>
<command> }</command>
<command>}</command>
<command>else</command>
<command>{</command>
<command> for(u=1;<AllUC)</command>
<command> {</command>
<command> if(kbUnitGetProtoUnitID(kbGetBlockID(""+u)) == PorType)</command>
<command> {</command>
<command> trUnitSelectClear();</command>
<command> trUnitSelectByID(kbGetBlockID(""+u));</command>
<command> if(trUnitIsOwnedBy(%FormPlayer%))</command>
<command> {</command>
<command> trUnitConvert(%ToPlayer%);</command>
<command> }</command>
<command> }</command>
<command> }</command>
<command>}</command>
</Effect>


)R3(PH@}[ZNM9T4S6)U}VZS.jpg

如何将这个触发程序添加到编辑器里面?将上面的“编辑器触发程序代码”按照格式复制到你的帝国3目录任意xml文件里面即可。
或者下载以下文件,放到你的帝国3目录的trigger3文件夹里面即可:


advanceconvert.xml


跳转到