CounterStrikeSharp icon indicating copy to clipboard operation
CounterStrikeSharp copied to clipboard

[BUG?] Entity teleportation can only be activated once

Open ELDment opened this issue 10 months ago • 11 comments

Preface: Maybe This Is Not a Bug🥲

When the Alpha of CBaseModelEntity.Render Is Set to an Integer Between 1 and 255

The issue described in the title does not occur if the alpha value is set to an integer between 1 and 255.

Example (In CS2):
Image


When Alpha Is Set to 0

The unexpected behavior mentioned in the title occurs when alpha is set to 0.
Note: The title might not be fully accurate (details explained below).

Why set alpha to 0?
I aimed to make the entity glow without rendering its model/texture, similar to the prop_dynamic_glow effect in CS:GO.

Example (In CS2):
Image

Initially, I assumed the issue was caused by the entity not updating on the network when alpha=0. However, the m_lastNetworkChange property of the entity continuously increases, suggesting network updates are still occurring.


Key Observations

  1. After calling DispatchSpawn on an entity with alpha=0, only the first teleport takes effect. Subsequent teleports do not update the entity’s glow position (the glow remains static).
  2. The entity itself might still be teleporting (I dont know since it’s not rendered), but its glow does not follow.
  3. (Contradicts the title?) Printing the entity’s AbsOrigin after teleporting with alpha=0 confirms the coordinates match the target position.
  4. Tested CBaseModelEntity.RenderMode values:
    • kRenderTransColor
    • kRenderTransTexture
    • kRenderGlow
    • kRenderTransAlpha
    • kRenderTransAlphaAdd
    • kRenderWorldGlow
      All resulted in the same issue.
  5. Tested CBaseModelEntity.RenderFX values:
    • kRenderFxNone
    • kRenderFxFadeSlow
    • kRenderFxFadeIn
      No changes observed.
  6. Tested entity types:
    • prop_dynamic_override
    • prop_physics_override
    • CBaseModelEntity
      Issue persisted in all cases.

ELDment avatar Feb 07 '25 02:02 ELDment

Encountered a strange phenomenon: even if the Alpha of CBaseModelEntity.Render is set to an integer between 1 and 255, the healthshot model/texture will not be rendered, but it can be teleported multiple times!

Image

( actually this is what I expected 😅 ) Image

ELDment avatar Feb 07 '25 02:02 ELDment

Both the client and the server are Windows systems...

ELDment avatar Feb 07 '25 02:02 ELDment

What do you think @KillStr3aK 😭

ELDment avatar Feb 07 '25 03:02 ELDment

What if you set the follow entity input instead of teleporting around?

KillStr3aK avatar Feb 07 '25 04:02 KillStr3aK

What if you set the follow entity input instead of teleporting around?

Nothing happened (the glow remains static)

ELDment avatar Feb 07 '25 11:02 ELDment

mind sharing your glow code?

KillStr3aK avatar Feb 07 '25 20:02 KillStr3aK

mind sharing your glow code?


var buffer = Utilities.CreateEntityByName<CBaseModelEntity>("basemodelentity");

buffer!.DispatchSpawn();
buffer!.Spawnflags = 256U;
buffer!.SetModel("xxx");

buffer!.Collision.CollisionGroup = 0;
buffer!.ShadowStrength = 0.0f;
buffer!.AnimTime = 0.0f;

buffer!.RenderMode = RenderMode_t.kRenderWorldGlow;
buffer!.RenderFX = RenderFx_t.kRenderFxFadeSlow;
buffer!.Render = Color.FromArgb(1, 255, 255, 255);
buffer!.FadeMinDist = 100.0f;
buffer!.Glow.GlowRange = 5000;
buffer!.Glow.GlowTeam = -1;
buffer!.Glow.GlowType = 3;
buffer!.Glow.GlowRangeMin = 3;
buffer!.Glow.GlowColorOverride = Color.FromArgb(255, rand.Next(256), rand.Next(256), rand.Next(256));

Utilities.SetStateChanged(buffer!, "CBaseEntity", "m_CBodyComponent");
Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_nRenderMode");
Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_nRenderFX");
Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_clrRender");
buffer!.Teleport(new Vector(player.PlayerPawn.Value!.AbsOrigin!.X, player.PlayerPawn.Value!.AbsOrigin!.Y, player.PlayerPawn.Value!.AbsOrigin!.Z + player.PlayerPawn.Value!.ViewOffset.As<Vector>().Z + 40), new QAngle(0, 0, 0), new Vector(0, 0, 0));

My code is similar to this, but it will include more complex checks to ensure the entity is valid.

ELDment avatar Feb 08 '25 01:02 ELDment

mind sharing your glow code?

var buffer = Utilities.CreateEntityByName<CBaseModelEntity>("basemodelentity");

buffer!.DispatchSpawn(); buffer!.Spawnflags = 256U; buffer!.SetModel("xxx");

buffer!.Collision.CollisionGroup = 0; buffer!.ShadowStrength = 0.0f; buffer!.AnimTime = 0.0f;

buffer!.RenderMode = RenderMode_t.kRenderWorldGlow; buffer!.RenderFX = RenderFx_t.kRenderFxFadeSlow; buffer!.Render = Color.FromArgb(1, 255, 255, 255); buffer!.FadeMinDist = 100.0f; buffer!.Glow.GlowRange = 5000; buffer!.Glow.GlowTeam = -1; buffer!.Glow.GlowType = 3; buffer!.Glow.GlowRangeMin = 3; buffer!.Glow.GlowColorOverride = Color.FromArgb(255, rand.Next(256), rand.Next(256), rand.Next(256));

Utilities.SetStateChanged(buffer!, "CBaseEntity", "m_CBodyComponent"); Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_nRenderMode"); Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_nRenderFX"); Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_clrRender"); buffer!.Teleport(new Vector(player.PlayerPawn.Value!.AbsOrigin!.X, player.PlayerPawn.Value!.AbsOrigin!.Y, player.PlayerPawn.Value!.AbsOrigin!.Z + player.PlayerPawn.Value!.ViewOffset.As<Vector>().Z + 40), new QAngle(0, 0, 0), new Vector(0, 0, 0)); My code is similar to this, but it will include more complex checks to ensure the entity is valid.

This doesn't set the weapon as a parent or follow it, you need to try with either solutions as @KillStr3aK said 👍

Dliix66 avatar Feb 08 '25 11:02 Dliix66

mind sharing your glow code?

var buffer = Utilities.CreateEntityByName("basemodelentity"); buffer!.DispatchSpawn(); buffer!.Spawnflags = 256U; buffer!.SetModel("xxx"); buffer!.Collision.CollisionGroup = 0; buffer!.ShadowStrength = 0.0f; buffer!.AnimTime = 0.0f; buffer!.RenderMode = RenderMode_t.kRenderWorldGlow; buffer!.RenderFX = RenderFx_t.kRenderFxFadeSlow; buffer!.Render = Color.FromArgb(1, 255, 255, 255); buffer!.FadeMinDist = 100.0f; buffer!.Glow.GlowRange = 5000; buffer!.Glow.GlowTeam = -1; buffer!.Glow.GlowType = 3; buffer!.Glow.GlowRangeMin = 3; buffer!.Glow.GlowColorOverride = Color.FromArgb(255, rand.Next(256), rand.Next(256), rand.Next(256)); Utilities.SetStateChanged(buffer!, "CBaseEntity", "m_CBodyComponent"); Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_nRenderMode"); Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_nRenderFX"); Utilities.SetStateChanged(buffer!, "CBaseModelEntity", "m_clrRender"); buffer!.Teleport(new Vector(player.PlayerPawn.Value!.AbsOrigin!.X, player.PlayerPawn.Value!.AbsOrigin!.Y, player.PlayerPawn.Value!.AbsOrigin!.Z + player.PlayerPawn.Value!.ViewOffset.As().Z + 40), new QAngle(0, 0, 0), new Vector(0, 0, 0)); My code is similar to this, but it will include more complex checks to ensure the entity is valid.

This doesn't set the weapon as a parent or follow it, you need to try with either solutions as @KillStr3aK said 👍

I actually tried the method he mentioned and the glow stayed where it teleported. (I removed it because setting the parent didn't solve the problem)

ELDment avatar Feb 08 '25 11:02 ELDment

Try this, it works on pawn, it should work on a weapon (I didn't test it though)

public static void SetGlow(this CBaseEntity entity)
{
	CBaseModelEntity? modelGlow = Utilities.CreateEntityByName<CBaseModelEntity>("prop_dynamic");
	CBaseModelEntity? modelRelay = Utilities.CreateEntityByName<CBaseModelEntity>("prop_dynamic");
	if (modelGlow == null || modelRelay == null)
		return;

	string modelName = entity.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.ModelName;

	modelRelay.SetModel(modelName);
	modelRelay.Spawnflags = 256u;
	modelRelay.RenderMode = RenderMode_t.kRenderNone;
	modelRelay.DispatchSpawn();

	modelGlow.SetModel(modelName);
	modelGlow.Spawnflags = 256u;
	modelGlow.DispatchSpawn();

	modelGlow.Glow.GlowColorOverride = Color.Magenta;
	modelGlow.Glow.GlowRange = 5000;
	modelGlow.Glow.GlowTeam = -1;
	modelGlow.Glow.GlowType = 3;
	modelGlow.Glow.GlowRangeMin = 100;

	modelRelay.AcceptInput("FollowEntity", entity, modelRelay, "!activator");
	modelGlow.AcceptInput("FollowEntity", modelRelay, modelGlow, "!activator");
}

Dliix66 avatar Feb 08 '25 11:02 Dliix66

Try this, it works on pawn, it should work on a weapon (I didn't test it though)

public static void SetGlow(this CBaseEntity entity) { CBaseModelEntity? modelGlow = Utilities.CreateEntityByName<CBaseModelEntity>("prop_dynamic"); CBaseModelEntity? modelRelay = Utilities.CreateEntityByName<CBaseModelEntity>("prop_dynamic"); if (modelGlow == null || modelRelay == null) return;

string modelName = entity.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.ModelName;

modelRelay.SetModel(modelName); modelRelay.Spawnflags = 256u; modelRelay.RenderMode = RenderMode_t.kRenderNone; modelRelay.DispatchSpawn();

modelGlow.SetModel(modelName); modelGlow.Spawnflags = 256u; modelGlow.DispatchSpawn();

modelGlow.Glow.GlowColorOverride = Color.Magenta; modelGlow.Glow.GlowRange = 5000; modelGlow.Glow.GlowTeam = -1; modelGlow.Glow.GlowType = 3; modelGlow.Glow.GlowRangeMin = 100;

modelRelay.AcceptInput("FollowEntity", entity, modelRelay, "!activator"); modelGlow.AcceptInput("FollowEntity", modelRelay, modelGlow, "!activator"); }

Actually, I have already solved the model glowing. The purpose of opening this issue is to understand why the teleportation only works the first time when alpha = 0. Or is there a way to hide the model's texture?

ELDment avatar Feb 08 '25 17:02 ELDment