Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
fix: preview model and transmit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kxnrl committed Aug 29, 2023
1 parent ebfb468 commit 1a64cc1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 40 deletions.
3 changes: 2 additions & 1 deletion include/TransmitManager.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define _TransmitManager_included

#define TRANSMIT_MAX_CHANNEL 5
#define TRANSMIT_ALL_CHANNEL -1

/**
* Adds entity hooks for the given entity to the Transmit Manager.
Expand Down Expand Up @@ -83,7 +84,7 @@ native bool TransmitManager_IsEntityHooked(int entity);
/**
* _________________Do not edit below this line!_______________________
*/
public Extension __ext_transmit =
public Extension __ext_transmit =
{
name = "TransmitManager",
file = "TransmitManager.ext",
Expand Down
69 changes: 39 additions & 30 deletions store/modules/skin.sp
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,14 @@ void Skin_PreviewSkin(int client, int itemid)
return;
}

int m_iViewModel = CreateEntityByName("prop_dynamic_override"); // prop_physics_multiplayer
DispatchKeyValue(m_iViewModel, "spawnflags", "64");
if (GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") == -1)
{
tPrintToChat(client, "%T", "must on ground", client);
return;
}

int m_iViewModel = CreateEntityByName("prop_dynamic_override");
DispatchKeyValue(m_iViewModel, "spawnflags", "320");
DispatchKeyValue(m_iViewModel, "model", g_ePlayerSkins[g_Items[itemid].iData].szModel);
DispatchKeyValue(m_iViewModel, "rendermode", "0");
DispatchKeyValue(m_iViewModel, "renderfx", "0");
Expand All @@ -540,8 +546,10 @@ void Skin_PreviewSkin(int client, int itemid)
}

SetEntProp(m_iViewModel, Prop_Send, "m_CollisionGroup", 11);
SetEntPropEnt(m_iViewModel, Prop_Send, "m_hOwnerEntity", client);

AcceptEntityInput(m_iViewModel, "Enable");
SetEntityMoveType(m_iViewModel, MOVETYPE_NOCLIP);

int offset = GetEntSendPropOffs(m_iViewModel, "m_clrGlow");
SetEntProp(m_iViewModel, Prop_Send, "m_bShouldGlow", true, true);
Expand All @@ -557,7 +565,7 @@ void Skin_PreviewSkin(int client, int itemid)
float m_fOrigin[3], m_fAngles[3], m_fRadians[2], m_fPosition[3];

GetClientAbsOrigin(client, m_fOrigin);
GetClientAbsAngles(client, m_fAngles);
GetClientEyeAngles(client, m_fAngles);

m_fRadians[0] = DegToRad(m_fAngles[0]);
m_fRadians[1] = DegToRad(m_fAngles[1]);
Expand All @@ -566,8 +574,11 @@ void Skin_PreviewSkin(int client, int itemid)
m_fPosition[1] = m_fOrigin[1] + 64 * Cosine(m_fRadians[0]) * Sine(m_fRadians[1]);
m_fPosition[2] = m_fOrigin[2] + 4 * Sine(m_fRadians[0]);

m_fAngles[0] *= -1.0;
m_fAngles[1] *= -1.0;
m_fAngles[0] = 0.0;
m_fAngles[1] -= 180.0;
m_fAngles[2] = 0.0;

m_fPosition[2] += 1.0;

TeleportEntity(m_iViewModel, m_fPosition, m_fAngles, NULL_VECTOR);

Expand All @@ -576,24 +587,15 @@ void Skin_PreviewSkin(int client, int itemid)

if (g_pTransmit)
{
if (GetFeatureStatus(FeatureType_Native, "TransmitManager_SetEntityBlock") == FeatureStatus_Available)
{
TransmitManager_AddEntityHooks(m_iViewModel, false);
TransmitManager_SetEntityBlock(m_iViewModel, true);
PrintToServer("[Store] Spawn preview model<%d> in block mode.", m_iViewModel);
}
// TODO switch to old mode
else
{
TransmitManager_AddEntityHooks(m_iViewModel);
TransmitManager_AddEntityHooks(m_iViewModel, false);
TransmitManager_SetEntityBlock(m_iViewModel, true);
TransmitManager_SetEntityOwner(m_iViewModel, client);
TransmitManager_SetEntityState(m_iViewModel, client, true, TRANSMIT_ALL_CHANNEL);

SetEntPropEnt(m_iViewModel, Prop_Send, "m_hOwnerEntity", client);
CreateTimer(0.1, UpdatePreviewTransmitState, EntIndexToEntRef(m_iViewModel), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
PrintToServer("[Store] Spawn preview model<%d> in normal mode.", m_iViewModel);
}
PrintToServer("[Store] Spawn preview model<%d> in block mode.", m_iViewModel);

TransmitManager_SetEntityOwner(m_iViewModel, client);
TransmitManager_SetEntityState(m_iViewModel, client, true, STORE_TRANSMIT_CHANNEL);
// occlusion
CreateTimer(0.1, CheckPreviewOcclusion, EntIndexToEntRef(m_iViewModel), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
else if (!IsParallelMode())
{
Expand All @@ -606,7 +608,7 @@ void Skin_PreviewSkin(int client, int itemid)
tPrintToChat(client, "%T", "Chat Preview", client);
}

static Action UpdatePreviewTransmitState(Handle timer, int ref)
static Action CheckPreviewOcclusion(Handle timer, int ref)
{
int entity = EntRefToEntIndex(ref);
if (entity < MaxClients)
Expand All @@ -619,17 +621,24 @@ static Action UpdatePreviewTransmitState(Handle timer, int ref)
return Plugin_Stop;
}

PrintToServer("[Store] Update preview model<%d> in normal mode.", entity);

for (int target = 1; target <= MaxClients; ++target)
float vPosEntity[3], vPosClient[3];
GetClientAbsOrigin(client, vPosClient);
GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", vPosEntity);
if (vPosClient[2] < vPosEntity[2] - 40.0)
{
if (client != target && IsClientInGame(target))
{
TransmitManager_SetEntityState(entity, client, false, STORE_TRANSMIT_CHANNEL);
}
SafeKillPreview(client, entity);
PrintToServer("[Store] CheckPreviewOcclusion(%N, %d) --3D-> %f :: %f", client, entity, vPosClient[2], vPosEntity[2] - 40.0);
return Plugin_Stop;
}
vPosClient[2] = 0.0;
vPosEntity[2] = 0.0;

TransmitManager_SetEntityState(entity, client, true, STORE_TRANSMIT_CHANNEL);
if (GetVectorDistance(vPosEntity, vPosClient) < 32.0)
{
SafeKillPreview(client, entity);
PrintToServer("[Store] CheckPreviewOcclusion(%N, %d) --2D-> %f", client, entity, GetVectorDistance(vPosEntity, vPosClient));
return Plugin_Stop;
}

return Plugin_Continue;
}
Expand Down
12 changes: 3 additions & 9 deletions store/sounds.sp
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,9 @@ static void StartSoundToAll(int client)
int speaker = SpawnSpeakerEntity(fPos, fAgl, 3.5);
if (g_pTransmit)
{
TransmitManager_AddEntityHooks(speaker);
TransmitManager_AddEntityHooks(speaker, false);
TransmitManager_SetEntityOwner(speaker, client);
// PrintToChatAll("transmit speaker %d :: %N", speaker, client);

for (int i = 1; i <= MaxClients; i++)
if (IsClientInGame(i) && i != client)
{
TransmitManager_SetEntityState(speaker, i, false, STORE_TRANSMIT_CHANNEL);
}
}

SetVariantString("!activator");
Expand All @@ -293,10 +287,10 @@ static void StartSoundToAll(int client)

if (g_pTransmit)
{
if (TransmitManager_GetEntityState(client, i))
if (TransmitManager_GetEntityState(client, i, TRANSMIT_ALL_CHANNEL))
{
// don't transmit
TransmitManager_SetEntityState(speaker, i, true, STORE_TRANSMIT_CHANNEL);
TransmitManager_SetEntityState(speaker, i, true, TRANSMIT_ALL_CHANNEL);
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions translations/store.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -980,4 +980,10 @@
"en" "Anti Collision..."
"chi" "反和谐, 请使用正常视角进行预览..."
}

"must on ground"
{
"en" "You must be on ground to use this feature."
"chi" "你必须站在地上才能使用该功能."
}
}

0 comments on commit 1a64cc1

Please sign in to comment.