介绍:
- 此代码片段适用于Left 4 Dead2或者Left 4 Dead
- 生成了一个具有物理效果(可以被打中后运动)的实体Entity
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#define MODEL_PIPE "models/w_models/weapons/w_eq_pipebomb.mdl"
bool g_bLeft4Dead2;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if( test == Engine_Left4Dead ) g_bLeft4Dead2 = false;
else if( test == Engine_Left4Dead2 ) g_bLeft4Dead2 = true;
else
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 & 2.");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public void OnPluginStart()
{
RegAdminCmd("sm_pipe", CmdPipe, ADMFLAG_ROOT);
}
public void OnMapStart()
{
PrecacheModel(MODEL_PIPE);
}
Action CmdPipe(int client, int args)
{
float vPos[3], vAng[3];
if( SetTeleportEndPoint(client, vPos) )
{
int entity = CreateEntityByName("weapon_pipe_bomb");
vAng[0] = 90.0;
vPos[2] += 10;
TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
DispatchSpawn(entity);
// Block +USE
SDKHook(entity, SDKHook_Use, OnUse);
// Remove glow
if( g_bLeft4Dead2 )
{
SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
SetEntProp(entity, Prop_Send, "m_glowColorOverride", 1);
SetEntProp(entity, Prop_Send, "m_nGlowRange", 0);
}
}
return Plugin_Handled;
}
Action OnUse(int entity)
{
return Plugin_Handled;
}
bool SetTeleportEndPoint(int client, float vPos[3])
{
GetClientEyePosition(client, vPos);
float vAng[3];
GetClientEyeAngles(client, vAng);
Handle trace = TR_TraceRayFilterEx(vPos, vAng, MASK_SHOT, RayType_Infinite, ExcludeSelf_Filter, client);
if( TR_DidHit(trace) )
{
TR_GetEndPosition(vPos, trace);
}
else
{
delete trace;
return false;
}
delete trace;
return true;
}
bool ExcludeSelf_Filter(int entity, int contentsMask, any client)
{
if( entity == client )
return false;
return true;
}
参考: