g_offsCollisionGroup 碰撞检测参数详解 科普

我不当学长 管理员组 2022-10-31 1320

为什么要解释这个参数:

在一些插件中,设置碰撞属性,比如玩家之间是否可穿越,或者说物体和其他物体之间是否可穿越,它们是这样写的

SetEntData(entity, g_offsCollisionGroup, 2, 4, true);

这里面的24就很奇怪,到底代表什么含义呢?

经过查询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)

Parameters

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)

COLLISION_GROUP_NONE 0 Normal
COLLISION_GROUP_DEBRIS 1 Collides with nothing but world and static stuff
COLLISION_GROUP_DEBRIS_TRIGGER 2 Same as debris, but hits triggers. Useful for an item that can be shot, but doesn't collide.
COLLISION_GROUP_INTERACTIVE_DEBRIS 3 Collides with everything except other interactive debris or debris
COLLISION_GROUP_INTERACTIVE 4 Collides with everything except interactive debris or debris
COLLISION_GROUP_PLAYER 5  
COLLISION_GROUP_BREAKABLE_GLASS 6 NPCs can see straight through an Entity with this applied.
COLLISION_GROUP_VEHICLE 7  
COLLISION_GROUP_PLAYER_MOVEMENT 8 For HL2, same as Collision_Group_Player, for TF2, this filters out other players and CBaseObjects
COLLISION_GROUP_NPC 9  
COLLISION_GROUP_IN_VEHICLE 10 Doesn't collide with anything, no traces
COLLISION_GROUP_WEAPON 11 Doesn't collide with players and vehicles
COLLISION_GROUP_VEHICLE_CLIP 12 Only collides with vehicles
COLLISION_GROUP_PROJECTILE 13  
COLLISION_GROUP_DOOR_BLOCKER 14 Blocks entities not permitted to get near moving doors
COLLISION_GROUP_PASSABLE_DOOR 15 Lets the Player through, nothing else.
COLLISION_GROUP_DISSOLVING 16 Things that are dissolving are in this group
COLLISION_GROUP_PUSHAWAY 17 Nonsolid on client and server, pushaway in player code
COLLISION_GROUP_NPC_ACTOR 18  
COLLISION_GROUP_NPC_SCRIPTED 19  
COLLISION_GROUP_WORLD 20 Doesn't collide with players/props
LAST_SHARED_COLLISION_GROUP 21 Amount of COLLISION_GROUP_ enumerations

相关插件:

FF2-Library/improved_saxton.sp at edited · Batfoxkid/FF2-Library (github.com)

g_offsCollisionGroup - AlliedModders (alliedmods.net)


CSGO插件分享-申明 1、本网站名称:CSGO插件分享-中文站  网址:https://bbs.csgocn.net
2、本站的宗旨在于为CSGO玩家提供一个插件分享的中文资源平台,多数插件来源于SourceMod论坛,并配以中文介绍和安装教程。
3、欢迎有能力的朋友共享有趣的CSGO插件资源。
4、本站资源大多为百度网盘,如发现链接失效,可以点: 这里进行反馈,我们会第一时间更新。
最新回复 (3)
返回