以下代码整合了所有玩家的胜利以及失败,首先是先算出有效玩家总数用于减少游戏运行内存,然后设定一个EnemyAlive用于判断敌人存活状态(是否输掉游戏),初始状态设定为0;用for循环判断所有非自己的玩家,如果为敌人并且存活EnemyAlive变成1;当没有任何存活的敌人,EnemyAlive保持0不变,然后你获胜了。输掉游戏的设定则是判断LogicalTypeNeededForVictory的数量,如果LogicalTypeNeededForVictory数量少于1,你战败,输掉游戏。
float TypeID = 0; while(kbGetUnitTypeName(TypeID)!="LogicalTypeNeededForVictory") { TypeID = TypeID+1; } bool whilebool = true; int PlayerCount = 1; while(whilebool) { if(kbIsPlayerValid(PlayerCount)) { PlayerCount = PlayerCount + 1; } else { whilebool = false; } } PlayerCount = PlayerCount - 1; for(PlayerID=1;<=PlayerCount) { xsSetContextPlayer(PlayerID); int EnemyAlive=0; for(i=1;<=PlayerCount) { xsSetContextPlayer(PlayerID); if(i != PlayerID && kbIsPlayerEnemy(i)) { if(trPlayerActive(i)) { EnemyAlive = 1; } } } if(EnemyAlive == 0) { if(trCurrentPlayer() == PlayerID && trPlayerActive(trCurrentPlayer())) { xsDisableSelf(); } trSetPlayerWon(PlayerID); trEndGame(); } if(trPlayerActive(PlayerID)) { if(kbUnitCount(PlayerID,TypeID,cUnitStateAlive) < 1) { if(trCurrentPlayer() == PlayerID && trPlayerActive(trCurrentPlayer())) { xsDisableSelf(); }
trSetPlayerDefeated(PlayerID); } } }
以下是让chatgpt写上注释的版本
float TypeID = 0; // 初始化 TypeID 变量为 0
// 找到目标类型 "LogicalTypeNeededForVictory" 对应的 TypeID while(kbGetUnitTypeName(TypeID) != "LogicalTypeNeededForVictory") { TypeID = TypeID + 1; // 遍历类型 ID,直到找到目标类型名称 }
bool whilebool = true; // 控制循环的布尔变量 int PlayerCount = 1; // 初始化玩家计数器
// 计算有效玩家的总数 while(whilebool) { if(kbIsPlayerValid(PlayerCount)) { // 检查当前玩家是否有效 PlayerCount = PlayerCount + 1; // 增加玩家计数器 } else { whilebool = false; // 如果无效玩家,结束循环 } }
PlayerCount = PlayerCount - 1; // 玩家总数应为最后一个有效玩家的编号
// 遍历每个玩家,检查游戏状态 for(PlayerID = 1; PlayerID <= PlayerCount; PlayerID++) { xsSetContextPlayer(PlayerID); // 设置当前上下文为当前玩家 int EnemyAlive = 0; // 初始化敌人生存标志为 0
// 检查是否有敌人存活 for(i = 1; i <= PlayerCount; i++) { xsSetContextPlayer(PlayerID); // 设置当前上下文为当前玩家 if(i != PlayerID && kbIsPlayerEnemy(i)) { // 如果 i 是敌人 if(trPlayerActive(i)) { // 如果敌人 i 仍然存活 EnemyAlive = 1; // 设置敌人生存标志为 1 } } }
// 如果没有敌人存活 if(EnemyAlive == 0) { // 检查当前玩家是否是本地玩家,并且仍然存活 if(trCurrentPlayer() == PlayerID && trPlayerActive(trCurrentPlayer())) { xsDisableSelf(); // 禁用当前规则 } trSetPlayerWon(PlayerID); // 设置当前玩家获胜 trEndGame(); // 结束游戏 }
// 检查当前玩家是否仍然存活 if(trPlayerActive(PlayerID)) { // 检查当前玩家是否有指定类型的单位存活 if(kbUnitCount(PlayerID, TypeID, cUnitStateAlive) < 1) { // 如果本地玩家是当前玩家且仍存活 if(trCurrentPlayer() == PlayerID && trPlayerActive(trCurrentPlayer())) { xsDisableSelf(); // 禁用当前规则 } trSetPlayerDefeated(PlayerID); // 设置当前玩家失败 } } }
以下是xml格式。(注:因为discuz会自动还原转义字符,直接复制到xml文件可能会出错)
<Effect name="*Advanced Standard Win"> <command>float TypeID = 0;</command> <command>while(kbGetUnitTypeName(TypeID)!="LogicalTypeNeededForVictory")</command> <command>{</command> <command> TypeID = TypeID+1;</command> <command>}</command> <command>bool whilebool = true;</command> <command>int PlayerCount = 1;</command> <command>while(whilebool)</command> <command>{</command> <command> if(kbIsPlayerValid(PlayerCount))</command> <command> {</command> <command> PlayerCount = PlayerCount + 1;</command> <command> }</command> <command> else</command> <command> {</command> <command> whilebool = false;</command> <command> }</command> <command>}</command> <command>PlayerCount = PlayerCount - 1;</command> <command>for(PlayerID=1;<=PlayerCount)</command> <command>{</command> <command> xsSetContextPlayer(PlayerID);</command> <command> int EnemyAlive=0;</command> <command> for(i=1;<=PlayerCount)</command> <command> {</command> <command> xsSetContextPlayer(PlayerID);</command> <command> if(i != PlayerID && kbIsPlayerEnemy(i))</command> <command> {</command> <command> if(trPlayerActive(i))</command> <command> {</command> <command> EnemyAlive = 1;</command> <command> }</command> <command> }</command> <command> }</command> <command> if(EnemyAlive == 0)</command> <command> {</command> <command> if(trCurrentPlayer() == PlayerID && trPlayerActive(trCurrentPlayer()))</command> <command> {</command> <command> xsDisableSelf();</command> <command> }</command> <command> trSetPlayerWon(PlayerID);</command> <command> trEndGame();</command> <command> }</command> <command> if(trPlayerActive(PlayerID))</command> <command> {</command> <command> if(kbUnitCount(PlayerID,TypeID,cUnitStateAlive) < 1)</command> <command> {</command> <command> if(trCurrentPlayer() == PlayerID && trPlayerActive(trCurrentPlayer()))</command> <command> {</command> <command> xsDisableSelf();</command> <command> }</command>
<command> trSetPlayerDefeated(PlayerID);</command> <command> }</command> <command> }</command> <command>}</command> </Effect>
假如拆开成多个触发程序,如果以8个玩家为例,那么就是插入8*2个触发程序,然后每个子项有7个条件以及1个效果;足够按到你手软。 首先判断玩家2-7是否存活(条件是Player Active),然后设定你获得胜利(效果用Set Player Won)。假如只使用游戏自带的触发程序你只能做到其他玩家是否存活,不能识别其他玩家是否是盟友,就算是盟友也必需非存活状态才能获胜;当玩家2-7都不存活(战败),你就获胜。 <Condition name="Player Active"> <Param name="PlayerID" dispname="$$22301$$Player" vartype="player">1</Param> <Expression>trPlayerActive(%PlayerID%)</Expression> </Condition>
<Effect name="Set Player Won"> <Param name="Player" dispname="$$22301$$Player" vartype="player">1</Param> <Command>trSetPlayerWon(%Player%);</Command> </Effect> 弄完获胜的触发程序,下面就是失败的触发程序了 判断自己的单位以及建筑状态,只使用游戏自带的触发程序你只能用All Units Dead、All buildings dead或All Units And Buildings Dead来判断玩家是否已经输掉游戏;All Units And Buildings Dead有一个缺点,就是哪怕存留一个住房你也不会输掉。 <Condition name="All Units Dead"> <Param name="PlayerID" dispname="$$22301$$Player" vartype="player">1</Param> <Expression>trPlayerUnitCount(%PlayerID%)==0</Expression> </Condition> <Condition name="All Buildings Dead"> <Param name="PlayerID" dispname="$$22301$$Player" vartype="player">1</Param> <Expression>trPlayerBuildingCount(%PlayerID%)==0</Expression> </Condition> <Condition name="All Units And Buildings Dead"> <Param name="PlayerID" dispname="$$22301$$Player" vartype="player">1</Param> <Expression>trPlayerUnitAndBuildingCount(%PlayerID%)==0</Expression> </Condition>
|