こはね 发表于 2019-11-18 00:56:45

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

<p>通过自己编写触发程序,我们可以将地图上某种单位全部改变控制者,例如将玩家1的诸葛弩全部转变成玩家2的单位,将玩家5的鹰炮全部转变成大自然的单位。
<br/>但是有一点要注意,不要滥用该触发程序,因为这种触发程序要寻找地图上所有单位并作出判断,所以是非常占用内存的,滥用会造成游戏卡顿。
<br/>
<br/>以下为触发程序代码:
<style>
pre{white-space: pre-wrap;word-wrap: break-word;font-family:Calibri,宋体;}
</style>
<pre>
        xsSetContextPlayer(0);
        /*数值必须大于你的mod单位数量+263;用来统计单位数量*/
        for(UnitTypeID=1800;&gt;-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;&lt;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);
        }
        }

<h2 style="font-size:24px;">源代码:</h2>        xsSetContextPlayer(0);
        for(UnitTypeID=1800;&gt;-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;&lt;AllUC)
                {
                        if(kbUnitGetProtoUnitID(kbGetBlockID(""+u)) ==PorType)
                        {
                        trUnitSelectClear();
                        trUnitSelectByID(kbGetBlockID(""+u));
                        trUnitConvert(0);
                        }
                }
        }
        else
        {
                for(u=1;&lt;AllUC)
                {
                        if(kbUnitGetProtoUnitID(kbGetBlockID(""+u)) ==PorType)
                        {
                        trUnitSelectClear();
                        trUnitSelectByID(kbGetBlockID(""+u));
                        if(trUnitIsOwnedBy(2))
                                {
                                trUnitConvert(0);
                                }
                        }
                }
        }



<h2 style="font-size:24px;">地图触发代码,仅限圣典所提及的c++语法触发;请自行参考圣典的地图教程:<a href="Age_of_Empires_III_Modding_Tutorial/13-05Trigger.htm">https://www.aoebbs.net/Age_of_Empires_III_Modding_Tutorial/13-05Trigger.htm</a></h2>        aoebbs("rule _Debug44 active runImmediately { ");
        aoebbs("if((trTime()-cActivationTime) &gt;= 1.00000000){");
        aoebbs("xsSetContextPlayer(0);");
        aoebbs("for(UnitTypeID=1800;&gt;-1)");
        aoebbs("{");
        aoebbs("        if(kbGetUnitTypeName(UnitTypeID)==\"all\") break;");
        aoebbs("}");
        aoebbs("xsSetContextPlayer(0); float P0UC = kbUnitCount(0,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(1); float P1UC = kbUnitCount(1,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(2); float P2UC = kbUnitCount(2,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(3); float P3UC = kbUnitCount(3,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(4); float P4UC = kbUnitCount(4,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(5); float P5UC = kbUnitCount(5,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(6); float P6UC = kbUnitCount(6,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(7); float P7UC = kbUnitCount(7,UnitTypeID,255);");
        aoebbs("xsSetContextPlayer(8); float P8UC = kbUnitCount(8,UnitTypeID,255);");
        aoebbs("float AllUC = (P0UC+P1UC+P2UC+P3UC+P4UC+P5UC+P6UC+P7UC+P8UC)*cNumberPlayers;");
        aoebbs("float PorType = kbGetProtoUnitID(\"ypChuKoNu\");");
        aoebbs("bool allplayer = true;");
        aoebbs("if(allplayer == true)");
        aoebbs("{");
        aoebbs("        for(u=1;&lt;AllUC)");
        aoebbs("        {");
        aoebbs("                if(kbUnitGetProtoUnitID(kbGetBlockID(\"\"+u)) ==PorType)");
        aoebbs("                {");
        aoebbs("                trUnitSelectClear();");
        aoebbs("                trUnitSelectByID(kbGetBlockID(\"\"+u));");
        aoebbs("                trUnitConvert(0);");
        aoebbs("                }");
        aoebbs("        }");
        aoebbs("}");
        aoebbs("else");
        aoebbs("{");
        aoebbs("        for(u=1;&lt;AllUC)");
        aoebbs("        {");
        aoebbs("                if(kbUnitGetProtoUnitID(kbGetBlockID(\"\"+u)) ==PorType)");
        aoebbs("                {");
        aoebbs("                trUnitSelectClear();");
        aoebbs("                trUnitSelectByID(kbGetBlockID(\"\"+u));");
        aoebbs("                if(trUnitIsOwnedBy(2))");
        aoebbs("                        {");
        aoebbs("                        trUnitConvert(0);");
        aoebbs("                        }");
        aoebbs("                }");
        aoebbs("        }");
        aoebbs("}");
        aoebbs("xsDisableRule(\"_Debug44\");");
        aoebbsZ("}} /*");





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





<h2 style="font-size:14px;">如何将这个触发程序添加到编辑器里面?将上面的“编辑器触发程序代码”按照格式复制到你的帝国3目录任意xml文件里面即可。
或者下载以下文件,放到你的帝国3目录的trigger3文件夹里面即可:</h2></pre>

</p>

こはね 发表于 2025-6-3 00:41:31

以前代码耗内存,作废。请使用kbUnitQuery系列函数,可参考https://www.aoebbs.net/thread-2077-1-1.html

        <Effect name="*Advanced Convert by Unittype">
                <Param name="Unittype" dispName="Unittype" VarType="unittype"></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>int UnitTypeID = 0;</Command>
                <Command>while(kbGetUnitTypeName(UnitTypeID)!="all")</Command>
                <Command>{</Command>
                <Command>        UnitTypeID = UnitTypeID+1;</Command>
                <Command>}</Command>
                <Command>int SetUnitType = 0;</Command>
                <Command>while(kbGetUnitTypeName(SetUnitType)!="%Unittype%")</Command>
                <Command>{</Command>
                <Command>        SetUnitType = SetUnitType+1;</Command>
                <Command>}</Command>
                <command>bool allplayer = %AllPlayer%;</command>
                <command>int playerID = %FormPlayer%;</command>
                <command>int unitID = 0;</command>
                <command>int maxplayerID = cNumberPlayers;</command>
                <command>int queryID = 0;</command>
                <command>int resultCount = 0;</command>
                <command>if(allplayer == true)</command>
                <command>{</command>
                <command>        playerID = 0;</command>
                <command>}</command>
                <command>else</command>
                <command>{</command>
                <command>        maxplayerID = playerID;</command>
                <command>}</command>
                <command>for(p=playerID;<=maxplayerID)</command>
                <command>{</command>
                <command>        xsSetContextPlayer(p);</command>
                <command>        queryID = kbUnitQueryCreate("QueryAliveUnit"+p);</command>
                <command>        kbUnitQueryResetData(queryID);</command>
                <command>        kbUnitQueryResetResults(queryID);</command>
                <command>        kbUnitQuerySetUnitType(queryID,UnitTypeID);</command>
                <command>        kbUnitQuerySetState(queryID, cUnitStateAlive);</command>
                <command>        kbUnitQuerySetAscendingSort(queryID,true);</command>
                <command>        kbUnitQuerySetPlayerID(queryID, p,false);</command>
                <command>        resultCount = kbUnitQueryExecute(queryID);</command>
                <command>        for(i=0;<resultCount) </command>
                <command>        {</command>
                <command>                unitID = kbUnitQueryGetResult(queryID,i);</command>
                <command>                if(kbUnitIsType(unitID,SetUnitType) == true)</command>
                <command>                {</command>
                <command>                        trUnitSelectClear();</command>
                <command>                        trUnitSelectByID(unitID);</command>
                <command>                        trUnitConvert(%ToPlayer%);</command>
                <command>                }</command>
                <command>        }</command>
                <command>}</command>
        </Effect>


页: [1]
查看完整版本: 触发程序-将地图上某种单位全部改变控制者