public static BaseEntity FindEntityByString(BaseEntity entStartAfter, string key, string value) { for (var index = entStartAfter != null ? EntityDictionary.EntityIndex(entStartAfter.Edict()) + 1 : 0; index < EntityDictionary.Max;) { var entity = FirstEntityAtIndex(index); if (entity == null) { return(null); } if (EntityProperties.TryGetValue(key, out var prop)) { var propValue = prop.GetValue(entity); if (value == (string)propValue) { return(entity); } } index = EntityDictionary.EntityIndex(entity.Edict()) + 1; } return(null); }
public static void ShowMessage(string str, BaseEntity pPlayer) { if (pPlayer?.IsNetClient() != true) { return; } var message = NetMessage.Begin(MsgDest.One, "HudText", pPlayer.Edict()); message.WriteString(str); message.End(); }
public static void ScreenShake(Vector center, float amplitude, float frequency, float duration, float radius) { var shake = new ScreenShake { duration = TempEntity.FixedUnsigned16(duration, 1 << 12), // 4.12 fixed frequency = TempEntity.FixedUnsigned16(frequency, 1 << 8) // 8.8 fixed }; for (var i = 1; i <= Engine.Globals.MaxClients; ++i) { BaseEntity pPlayer = PlayerByIndex(i); if (pPlayer == null || (pPlayer.Flags & EntFlags.OnGround) == 0) // Don't shake if not onground { continue; } float localAmplitude = 0; if (radius <= 0) { localAmplitude = amplitude; } else { var delta = center - pPlayer.Origin; var distance = delta.Length(); // Had to get rid of this falloff - it didn't work well if (distance < radius) { localAmplitude = amplitude;//radius - distance; } } if (localAmplitude != 0) { shake.amplitude = TempEntity.FixedUnsigned16(localAmplitude, 1 << 12); // 4.12 fixed var message = NetMessage.Begin(MsgDest.One, "ScreenShake", pPlayer.Edict()); // use the magic #1 for "one client" message.WriteShort(shake.amplitude); // shake amount message.WriteShort(shake.duration); // shake lasts this long message.WriteShort(shake.frequency); // shake noise frequency message.End(); } } }
/* * This is a glorious hack to find free space when you've crouched into some solid space * Our crouching collisions do not work correctly for some reason and this is easier * than fixing the problem :( */ public static void FixPlayerCrouchStuck(BaseEntity pPlayer) { // Move up as many as 18 pixels if the player is stuck. var origin = pPlayer.Origin; for (int i = 0; i < 18; ++i) { Trace.Hull(origin, origin, TraceFlags.None, Hull.Head, pPlayer.Edict(), out var trace); if (!trace.StartSolid) { break; } origin.z++; } pPlayer.Origin = origin; }