单位引用:修订间差异
(创建页面,内容为“'''单位引用'''(Unit Reference)是铁锈战争1.15新加入的单位选择器,可引用符合条件的单位。 ==查询== {| class="wikitable" |+单位引用 |标记 |getAsMarker() getOffsetRelative() getOffsetAbsolute() createMarker() |- |局内 |thisActionTarget eventSource |- |全局 |attachment() transporting() attacking lastDamagedBy parent activeWaypointTarget nearestUnit() globalSearchForFirstUnit() |- |存储 |customTarget1 customTarget2…”) 标签:移动版编辑 移动版网页编辑 |
(→全局) 标签:移动版编辑 移动版网页编辑 |
||
| (未显示2个用户的17个中间版本) | |||
| 第1行: | 第1行: | ||
'''单位引用'''(Unit Reference)是铁锈战争[[1.15]]新加入的单位选择器,可引用符合条件的单位。 | '''单位引用'''(Unit Reference)是铁锈战争[[1.15]]新加入的单位选择器,可引用符合条件的单位。 | ||
| 第32行: | 第33行: | ||
|} | |} | ||
==标记== | ==标记== | ||
临时、快速地创建一个标记,可用来反映位置、朝向、高度、队伍编号,且不需要用到时会自动移除,不隶属任何单位也不受单位后续行为的影响。 | |||
标记可分为两种,照铁锈战争的说法,一种是'''获取'''(get...),另一种是'''创建'''(create...)。获取会在以单位的基础创建标记,而'''创建'''完全与创建它的单位无关。 | |||
===标记的格式=== | |||
<p>获取:<code>getAsMarker()</code></p> | |||
<p>相对:<code>getOffsetRelative([x], [y], [height], [dirOffset])</code></p> | |||
<p>绝对:<code>getOffsetAbsolute([x], [y], [height])</code></p> | |||
<p>创建:<code>createMarker(x, y, [height], [teamId], [dir])</code></p> | |||
===标记的用法=== | |||
想直接获取当前位置等信息可以使用<code>getAsMarker</code>。 | |||
铁锈战争为偏移提供了两种方案,一种是'''相对偏移''',不止受单位位置、高度,还受朝向影响。通俗易懂就是你坐在一辆车上,你当然可以移动、旋转(<code>dirOffset</code>),但车移动、旋转你也必须移动、旋转。 | |||
另一种是'''绝对偏移''',只受单位位置、高度影响,比如单位坐标(1000, 1000),向左偏移5个单位(995, 1000)。 | |||
'''创建标记'''是直接在地图上创建一个标记,队伍编号可由自己决定,可以注意的是创建标记的(x, y)必须要填,但铁锈战争允许省略<code>(x=, y=)</code>。 | |||
{{折叠|标记的例子|<pre> | |||
teleportTo: getOffsetRelative(y= 10, dirOffset= self.customTimer) | |||
fireXTurretAtGround_withTarget: createMarker(activeWaypointTarget.x, activeWaypointTarget.y, teamId= self.teamId).nearestUnit(withinRange= 1500, withTag= "outpost", relation= "own") | |||
</pre>}} | |||
==局内== | ==局内== | ||
局内只能在行动内使用,可用<code>alsoTriggerAction</code>或<code>alsoQueueAction</code>延长“寿命”,你也可以用内存将其存储。<code>thisActionTarget</code>在不同情况下所指代的单位不同,与<code>eventSource</code> | 局内只能在行动内使用,可用<code>alsoTriggerAction</code>或<code>alsoQueueAction</code>延长“寿命”,你也可以用内存将其存储。<code>thisActionTarget</code>在不同情况下所指代的单位不同,与<code>eventSource</code>不同,后者只与<code>autoTriggerOnEvent</code>绑定,触发的事件不同所指代的单位也不同。 | ||
===thisActionIndex的用法=== | |||
<code>thisActionIndex</code>能在遍历过程中同时知道每个元素的位置信息,<code>index</code>为其缩略形式。受<code>alsoTriggerActionRepeat</code>与<code>takeResources_triggerActionForEach</code>影响。值为int(整数)类型,从0开始,用于遍历数组。 | |||
<pre>eg: | |||
[hiddenAction_1] | |||
alsoTriggerAction:2 | |||
alsoTriggerActionRepeat:memory.array.size | |||
[hiddenAction_2] | |||
setUnitMemory:array[index]=select(memory.array[index]==0,0,memory.array[index]-1)</pre> | |||
===对应的情况=== | |||
{| class="wikitable" | {| class="wikitable" | ||
|+thisActionTarget用处 | |+thisActionTarget用处 | ||
| 第52行: | 第83行: | ||
|- | |- | ||
|addWaypoint_triggerActionIfMatched | |addWaypoint_triggerActionIfMatched | ||
| | |被添加路径点的单位(没明确指定某个单位时则为在那个位置的标记,如move等) | ||
|} | |} | ||
{| class="wikitable" | |||
|+eventSource用处 | |||
|tookDamage | |||
|攻击你的单位 | |||
|- | |||
|killedAnyUnit | |||
|杀死的单位 | |||
|- | |||
|transportingNewUnit | |||
|新装载的单位 | |||
|- | |||
|transportUnloadedOrRemovedUnit | |||
|刚卸载的单位 | |||
|- | |||
|queuedUnitFinished | |||
|刚生产的单位 | |||
|- | |||
|touchTargetSuccess | |||
|碰到的单位(需配合路径点) | |||
|- | |||
|newMessage | |||
|给这个单位发信的单位 | |||
|} | |||
{{折叠|thisActionTarget与eventSource的例子|<pre> | |||
[turret_super] | |||
onShoot_triggerActions: idol | |||
[hiddenAction_idol] | |||
showMessageToAllPlayers: %{thisActionTarget}的笑容。 | |||
[hiddenAction_tookDmg] | |||
autoTriggerOnEvent: tookDamage(withTag="APCR") | |||
showMessageToAllPlayers: 来自%{eventSource}的攻击! | |||
</pre>}} | |||
==全局== | ==全局== | ||
铁锈战争提供了一些常见情况可能用到的单位选择器,且所以节都能使用,与[[ | 铁锈战争提供了一些常见情况可能用到的单位选择器,且所以节都能使用,与'''局内'''相对。 | ||
===选填参数部分=== | |||
<p>附属:<code>attachment([slot], [withTag])</code></p> | |||
<p>运输:<code>transporting([slot])</code></p> | |||
<p>最近单位:<code>nearestUnit([withinRange], [withTag], [relation], [incompleteBuildings], [withoutTag])</code></p> | |||
<p>搜索首个单位<code>globalSearchForFirstUnit([withTag], [relation], [incompleteBuildings])</code></p> | |||
====参数都为选填,默认情况就很有趣了。==== | |||
*附属 | |||
不填参数则返回行数最高的单位。 | |||
*运输 | |||
不填参数则返回最近运输的单位。 | |||
*最近单位 | |||
不填参数则返回范围约为500内的单位。 | |||
*搜索首个单位 | |||
不填参数则返回该地图最小id的单位。 | |||
===无参数部分=== | |||
这些单位引用的特点很明显,都是指向具体的某个单位。 | |||
<code>attacking</code>为<code>activeWaypointTarget</code>为攻击时套上单位的快捷引用方式。<code>lastDamagedBy</code>在事件来源为tookDamage时的快捷引用方式。<code>parent</code>在单位自身为他人附属时可使用。<code>activeWaypointTarget</code>能够实时监控路径点情况,如果没明确指定某个单位则返回在那个位置的标记(Marker),但似乎不能获取该路径点的类型,路径点类型可[https://docs.google.com/spreadsheets/d/1aeP3pUic0IutZlgGix_cM8xR7LEH44gS4itAxETK954/htmlview 详见]代码<code>addWaypoint_type</code>。 | |||
{{折叠|全局单位引用的例子|<pre> | |||
isVisible: if parent.attachment(slot= 5) == self | |||
[hiddenAction_repair] | |||
autoTriggerOnEvent: newWaypointGivenByPlayer | |||
requireConditional: if self.hasActiveWaypoint(type= "repair") | |||
showMessageToPlayer: 你正在治疗%{activeWaypointTarget}。 | |||
</pre>}} | |||
==存储== | ==存储== | ||
与[[自定义内存]]相比,虽然<code>customTarget1</code>与<code>customTarget2</code>与<code>@memory x:unit</code>功能相当,但前者能实时清理使用不了的单位。 | |||
单位生产、产生出来时,它的'''自定义目标1'''默认为工厂(把你生成出来的单位),这很有用,工厂不必通过<code>queuedUnitFinished</code>事件配合<code>sendMessageTo</code>告诉产物''把你生产出来的是谁''。 | |||
==其他== | ==其他== | ||
<code>nullUnit</code>有另一种写法,也就是<code>null</code>,但后者更泛用且简略,前者更像是特指,特指'''空'''的是单位。 | |||
2025年7月20日 (日) 13:28的版本
单位引用(Unit Reference)是铁锈战争1.15新加入的单位选择器,可引用符合条件的单位。
查询
| 标记 | getAsMarker()
getOffsetRelative() getOffsetAbsolute() createMarker() |
| 局内 | thisActionTarget
eventSource |
| 全局 | attachment()
transporting() attacking lastDamagedBy parent activeWaypointTarget nearestUnit() globalSearchForFirstUnit() |
| 存储 | customTarget1
customTarget2 |
| 其他 | nullUnit |
标记
临时、快速地创建一个标记,可用来反映位置、朝向、高度、队伍编号,且不需要用到时会自动移除,不隶属任何单位也不受单位后续行为的影响。 标记可分为两种,照铁锈战争的说法,一种是获取(get...),另一种是创建(create...)。获取会在以单位的基础创建标记,而创建完全与创建它的单位无关。
标记的格式
获取:getAsMarker()
相对:getOffsetRelative([x], [y], [height], [dirOffset])
绝对:getOffsetAbsolute([x], [y], [height])
创建:createMarker(x, y, [height], [teamId], [dir])
标记的用法
想直接获取当前位置等信息可以使用getAsMarker。
铁锈战争为偏移提供了两种方案,一种是相对偏移,不止受单位位置、高度,还受朝向影响。通俗易懂就是你坐在一辆车上,你当然可以移动、旋转(dirOffset),但车移动、旋转你也必须移动、旋转。
另一种是绝对偏移,只受单位位置、高度影响,比如单位坐标(1000, 1000),向左偏移5个单位(995, 1000)。
创建标记是直接在地图上创建一个标记,队伍编号可由自己决定,可以注意的是创建标记的(x, y)必须要填,但铁锈战争允许省略(x=, y=)。
| 标记的例子 |
|---|
teleportTo: getOffsetRelative(y= 10, dirOffset= self.customTimer) fireXTurretAtGround_withTarget: createMarker(activeWaypointTarget.x, activeWaypointTarget.y, teamId= self.teamId).nearestUnit(withinRange= 1500, withTag= "outpost", relation= "own") |
局内
局内只能在行动内使用,可用alsoTriggerAction或alsoQueueAction延长“寿命”,你也可以用内存将其存储。thisActionTarget在不同情况下所指代的单位不同,与eventSource不同,后者只与autoTriggerOnEvent绑定,触发的事件不同所指代的单位也不同。
thisActionIndex的用法
thisActionIndex能在遍历过程中同时知道每个元素的位置信息,index为其缩略形式。受alsoTriggerActionRepeat与takeResources_triggerActionForEach影响。值为int(整数)类型,从0开始,用于遍历数组。
eg: [hiddenAction_1] alsoTriggerAction:2 alsoTriggerActionRepeat:memory.array.size [hiddenAction_2] setUnitMemory:array[index]=select(memory.array[index]==0,0,memory.array[index]-1)
对应的情况
| fireXTurretAtGround | 指向的位置 |
| alsoTriggerAction | 与原行动的thisActionTarget相同 |
| onShoot_triggerActions | 炮塔射击的单位 |
| takeResources_triggerActionIfAnyCollected | 提取到的单位 |
| takeResources_triggerActionForEach | 与上同理 |
| addWaypoint_triggerActionIfMatched | 被添加路径点的单位(没明确指定某个单位时则为在那个位置的标记,如move等) |
| tookDamage | 攻击你的单位 |
| killedAnyUnit | 杀死的单位 |
| transportingNewUnit | 新装载的单位 |
| transportUnloadedOrRemovedUnit | 刚卸载的单位 |
| queuedUnitFinished | 刚生产的单位 |
| touchTargetSuccess | 碰到的单位(需配合路径点) |
| newMessage | 给这个单位发信的单位 |
| thisActionTarget与eventSource的例子 |
|---|
[turret_super]
onShoot_triggerActions: idol
[hiddenAction_idol]
showMessageToAllPlayers: %{thisActionTarget}的笑容。
[hiddenAction_tookDmg]
autoTriggerOnEvent: tookDamage(withTag="APCR")
showMessageToAllPlayers: 来自%{eventSource}的攻击!
|
全局
铁锈战争提供了一些常见情况可能用到的单位选择器,且所以节都能使用,与局内相对。
选填参数部分
附属:attachment([slot], [withTag])
运输:transporting([slot])
最近单位:nearestUnit([withinRange], [withTag], [relation], [incompleteBuildings], [withoutTag])
搜索首个单位globalSearchForFirstUnit([withTag], [relation], [incompleteBuildings])
参数都为选填,默认情况就很有趣了。
- 附属
不填参数则返回行数最高的单位。
- 运输
不填参数则返回最近运输的单位。
- 最近单位
不填参数则返回范围约为500内的单位。
- 搜索首个单位
不填参数则返回该地图最小id的单位。
无参数部分
这些单位引用的特点很明显,都是指向具体的某个单位。
attacking为activeWaypointTarget为攻击时套上单位的快捷引用方式。lastDamagedBy在事件来源为tookDamage时的快捷引用方式。parent在单位自身为他人附属时可使用。activeWaypointTarget能够实时监控路径点情况,如果没明确指定某个单位则返回在那个位置的标记(Marker),但似乎不能获取该路径点的类型,路径点类型可详见代码addWaypoint_type。
| 全局单位引用的例子 |
|---|
isVisible: if parent.attachment(slot= 5) == self
[hiddenAction_repair]
autoTriggerOnEvent: newWaypointGivenByPlayer
requireConditional: if self.hasActiveWaypoint(type= "repair")
showMessageToPlayer: 你正在治疗%{activeWaypointTarget}。
|
存储
与自定义内存相比,虽然customTarget1与customTarget2与@memory x:unit功能相当,但前者能实时清理使用不了的单位。
单位生产、产生出来时,它的自定义目标1默认为工厂(把你生成出来的单位),这很有用,工厂不必通过queuedUnitFinished事件配合sendMessageTo告诉产物把你生产出来的是谁。
其他
nullUnit有另一种写法,也就是null,但后者更泛用且简略,前者更像是特指,特指空的是单位。