こはね 发表于 2025-6-2 19:34:54

kbUnitQuery查询单位

kbUnitQuery系列函数可用于地图触发程序、剧情编辑器触发程序、AI文件

首先用kbUnitQueryCreate创建查询,然后kbUnitQueryResetResults清除之前的查询数据;kbUnitQuerySet系列函数 设定各种查询条件,但似乎必须含有kbUnitQuerySetPlayerID函数,否则查询失败。
除此之外,必须用xsSetContextPlayer指定对象玩家,不然连queryID都不存在;还有一点xsSetContextPlayer与kbUnitQuerySetPlayerID的对象玩家必须一致(意义不明,多此一举),否则查询结果为空。

以下是一个地图注入式触发程序查询例子
aoebbs("rule _Debug71 minInterval 2 active runImmediately {");
aoebbs("if((trTime()-cActivationTime) >= 5.00000000){");
aoebbs("int UnitTypeID = 0;");
aoebbs("while(kbGetUnitTypeName(UnitTypeID)!=\"unit\"){");
aoebbs("UnitTypeID = UnitTypeID+1;");
aoebbs("}");
aoebbs("xsSetContextPlayer(1);");
aoebbs("trChatSend(0,\"UnitTypeID:\"+UnitTypeID+\":\"+kbGetUnitTypeName(UnitTypeID));");
aoebbs("int queryID = kbUnitQueryCreate(\"QueryAliveUnit\");");
aoebbs("trChatSend(0,\"queryID:\"+queryID);");
aoebbs("kbUnitQueryResetData(queryID);");
aoebbs("kbUnitQueryResetResults(queryID);");
aoebbs("kbUnitQuerySetUnitType(queryID,UnitTypeID);");
aoebbs("kbUnitQuerySetState(queryID, cUnitStateAlive);");
aoebbs("kbUnitQuerySetAscendingSort(queryID,true);");
aoebbs("kbUnitQuerySetPlayerID(queryID, 1,false);");
aoebbs("int resultCount = kbUnitQueryExecute(queryID);");
aoebbs("resultCount = kbUnitQueryNumberResults(queryID);");
aoebbs("trChatSend(0,\"resultCount:\"+resultCount);");
aoebbs("int unitID = 0;");
aoebbs("for(i=0;<resultCount) {");
aoebbs("unitID = kbUnitQueryGetResult(queryID,i);");
aoebbs("trChatSend(0,\"unitID[\"+unitID+\"]:\"+kbGetProtoUnitName(kbUnitGetProtoUnitID(unitID)));");
aoebbs("}");
aoebbs("xsDisableSelf();");
aoebbs("}");
aoebbs("}");
aoebbsE("");











こはね 发表于 2025-6-3 00:34:04

用于剧情编辑器,将某个玩家或全部玩家的某种单位全部转换成指定玩家控制

      <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]
查看完整版本: kbUnitQuery查询单位