过滤器应用指南

From Valve Developer Community
< Zh
Jump to navigation Jump to search
English (en)日本語 (ja)Русский (ru)中文 (zh)Translate (Translate)
Icon-callout-underlinked.png
This article needs more links to other pages (since January 2024). You can help improve navigation by adding links to related documentation, such as entities or tools.

过滤器应用场景

本教程讲解Source引擎基础实体类过滤器(Filters)的用途。这套强大的实体系统能基于目标名称(targetname)、类名(classname)、伤害类型(damagetype)或其组合条件来触发特定行为,在关卡设计中具有广泛用途。例如在设计夺旗模式(CTF)地图时,就需要用过滤器防止玩家通过夺取己方旗帜作弊得分;也可以确保只有npc_zombie能激活某机关,而npc_crow则不行。

假设您已具备实体、触发器和I/O系统的基础知识,本文将重点解析各类过滤器的使用方法。

目标名称(en)过滤

使用filter_activator_name实体进行目标名称过滤,需配置三个关键值: 1. targetname:过滤器自身的标识名 2. filtername:要匹配的目标名称 3. Negated:取反逻辑(0=仅允许匹配项,1=排除匹配项)

以《半条命2》车站地图的垃圾桶彩蛋为例: 1. 将可乐罐命名为can 2. 创建filter_activator_name并设置:

  - filtername = can
  - Negated = 1(仅允许可乐罐触发)

3. 将该过滤器应用于垃圾桶内的trigger_once 4. 配置触发器检测物理实体并播放警报音效

这样只有当命名为can的实体进入触发区域才会激活警报。

类名过滤

filter_activator_class通过filterclass键值指定类名(如npc_zombie)。典型应用场景:

假设需要僵尸冲锋触发警报: 1. 创建触发器并设置:

  - 检测NPC和物理实体
  - 输出警报音效

2. 添加filter_activator_class过滤器:

  - filterclass = npc_zombie

3. 测试时物理物品穿过触发器不会激活,仅僵尸可触发

伤害类型过滤

filter_damage_type通过damagetype键值过滤伤害类型(不可直接用于触发器激活)。常用值:

  • 0: GENERIC
  • 1: CRUSH
  • 2: BULLET
  • 4: SLASH
  • 8: BURN
  • 16: VEHICLE / (TRAIN 军团要塞2 之中)
  • 32: FALL
  • 64: BLAST
  • 128: CLUB
  • 256: SHOCK (Spawns particle with missing texture in 求生之路2 之中)
  • 512: SONIC
  • 1024: ENERGYBEAM
  • 16384: DROWN
  • 32768: PARALYSE
  • 65536: NERVEGAS / (SAWBLADE 军团要塞2 之中)
  • 131072: POISON
  • 262144: RADIATION
  • 524288: DROWNRECOVER
  • 1048576: ACID / (CRITICAL 军团要塞2 之中)
  • 2097152: SLOWBURN
  • 4194304: REMOVENORAGDOLL
  • 16777216: FULLGIB (存在于 求生之路系列求生之路系列 之中)
Note.png注意: Some damage types are named incorrectly by default in base.fgd, instead using their GoldSource names.
  • VEHICLE is named FREEZE
  • ACID is named CHEMICAL
  • REMOVENORAGDOLL is named SLOWFREEZE
Tip.png提示: 军团要塞2 军团要塞2: Fancy damage effects such as decapitation, disintegration or ice/gold statues on death can be applied via VScript. See TakeDamageCustom function or the trigger example.
Icon-Bug.png错误:In 军团要塞2 军团要塞2, REMOVENORAGDOLL/SLOWFREEZE will cause the killed player's cosmetics to appear floating above their observer target.  (tested in: 军团要塞2)


典型应用:

复合过滤

filter_multi支持AND/OR逻辑组合多个过滤器:

  • AND:需全部条件满足
  • OR:满足任一条件即可

配置示例: 1. 创建名称过滤器(过滤targetname) 2. 创建类名过滤器(过滤classname) 3. 用filter_multi组合两者并设置逻辑关系