为什么要解释这个参数:
在一些插件中,设置碰撞属性,比如玩家之间是否可穿越,或者说物体和其他物体之间是否可穿越,它们是这样写的
SetEntData(entity, g_offsCollisionGroup, 2, 4, true);
这里面的2,4就很奇怪,到底代表什么含义呢?
经过查询SetEntData API介绍知道:
/**
* Peeks into an entity's object data and sets the integer value at
* the given offset.
*
* @param entity Edict index.
* @param offset Offset to use.
* @param value Value to set.
* @param size Number of bytes to write (valid values are 1, 2, or 4).
* @param changeState If true, change will be sent over the network.
* @error Invalid entity or offset out of reasonable bounds.
*/
native void SetEntData(int entity, int offset, any value, int size=4, bool changeState=false);
其中的数字2代表的是一个表示可以被设置的属性数值,数字4是表示这个数据的字节大小。那么问题来了,我们怎么知道到底设置什么数值?有哪些数值呢?
下面的官方源码中的enum值,给了我们最详细的解答:
官方源码:
hl2sdk-ob: public/const.h@2e2ec01be7aa (alliedmods.net)
碰撞组 - Valve 开发者社区 (valvesoftware.com)
enum Collision_Group_t
// from this website:https://hg.alliedmods.net/hl2sdks/hl2sdk-ob/file/2e2ec01be7aa/public/const.h
{
COLLISION_GROUP_NONE = 0,
COLLISION_GROUP_DEBRIS, // Collides with nothing but world and static stuff
COLLISION_GROUP_DEBRIS_TRIGGER, // Same as debris, but hits triggers
COLLISION_GROUP_INTERACTIVE_DEBRIS, // Collides with everything except other interactive debris or debris
COLLISION_GROUP_INTERACTIVE, // Collides with everything except interactive debris or debris
COLLISION_GROUP_PLAYER,
COLLISION_GROUP_BREAKABLE_GLASS,
COLLISION_GROUP_VEHICLE,
COLLISION_GROUP_PLAYER_MOVEMENT, // For HL2, same as Collision_Group_Player, for
// TF2, this filters out other players and CBaseObjects
COLLISION_GROUP_NPC, // Generic NPC group
COLLISION_GROUP_IN_VEHICLE, // for any entity inside a vehicle
COLLISION_GROUP_WEAPON, // for any weapons that need collision detection
COLLISION_GROUP_VEHICLE_CLIP, // vehicle clip brush to restrict vehicle movement
COLLISION_GROUP_PROJECTILE, // Projectiles!
COLLISION_GROUP_DOOR_BLOCKER, // Blocks entities not permitted to get near moving doors
COLLISION_GROUP_PASSABLE_DOOR, // Doors that the player shouldn't collide with
COLLISION_GROUP_DISSOLVING, // Things that are dissolving are in this group
COLLISION_GROUP_PUSHAWAY, // Nonsolid on client and server, pushaway in player code
COLLISION_GROUP_NPC_ACTOR, // Used so NPCs in scripts ignore the player.
COLLISION_GROUP_NPC_SCRIPTED, // USed for NPCs in scripts that should not collide with each other
LAST_SHARED_COLLISION_GROUP
};
在SourceMod 1.11+引入了:
SetEntityCollisionGroup · sdktools_functions · SourceMod Scripting API Reference
void SetEntityCollisionGroup(int entity, int collisionGroup)
- int entity
-
The entity index.
- int collisionGroup
-
Collision group to use.
也是可以达到同样的效果,函数更直观了!
参考:sdktools_functions · SourceMod Scripting API Reference
第三方WiKi介绍:
COLLISION_GROUP - Garry's Mod Wiki (facepunch.com)
相关插件:
FF2-Library/improved_saxton.sp at edited · Batfoxkid/FF2-Library (github.com)
g_offsCollisionGroup - AlliedModders (alliedmods.net)