diff --git a/scripting/include/srccoop/blackmesa/entitypatch.inc b/scripting/include/srccoop/blackmesa/entitypatch.inc index 7a084131..d77b2803 100644 --- a/scripting/include/srccoop/blackmesa/entitypatch.inc +++ b/scripting/include/srccoop/blackmesa/entitypatch.inc @@ -534,7 +534,7 @@ public MRESReturn Hook_WeaponSetModel(int _this, DHookParam hParams) { "models/weapons/w_rpg_mp.mdl", "models/weapons/w_rpg.mdl" }, }; - char szModelName[MAX_CLASSNAME]; + char szModelName[MAX_MODELNAME]; DHookGetParamString(hParams, 1, szModelName, sizeof(szModelName)); for (int i = 0; i < sizeof(szWeaponModel); i++) diff --git a/scripting/include/srccoop/blackmesa/idle_anims.inc b/scripting/include/srccoop/blackmesa/idle_anims.inc index b1aa9b1b..67bc3d06 100644 --- a/scripting/include/srccoop/blackmesa/idle_anims.inc +++ b/scripting/include/srccoop/blackmesa/idle_anims.inc @@ -27,38 +27,93 @@ enum struct IdleAnimEntry public IdleAnimEntry g_pIdle[MAXPLAYERS + 1]; -public Action IdleAnims_SetTransmit(const int iEntity, const int iClient) +public MRESReturn IdleAnims_Hook_PlayerSetModel(const int iPlayerIndex, DHookParam hParams) +{ + if (!DHookIsNullParam(hParams, 1) && g_pIdle[iPlayerIndex].m_pModel.IsValid()) + { + char szModelName[MAX_MODELNAME]; + DHookGetParamString(hParams, 1, szModelName, sizeof(szModelName)); + if (PrecacheModel(szModelName)) + { + g_pIdle[iPlayerIndex].m_pModel.SetModel(szModelName); + if (g_pIdle[iPlayerIndex].m_eIdleType == IdleNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("idle_noweapon"); + } + else if (g_pIdle[iPlayerIndex].m_eIdleType == SwimIdleNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("swimidle_noweapon"); + } + else if (g_pIdle[iPlayerIndex].m_eIdleType == SwimNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("swim_noweapon"); + } + else if (g_pIdle[iPlayerIndex].m_eIdleType == RunNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("run_noweapon"); + } + else if (g_pIdle[iPlayerIndex].m_eIdleType == LadderNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("ladder_noweapon"); + } + else if (g_pIdle[iPlayerIndex].m_eIdleType == JumpStartNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("jump_start_noweapon"); + } + else if (g_pIdle[iPlayerIndex].m_eIdleType == CIdleNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("cidle_noweapon"); + } + else if (g_pIdle[iPlayerIndex].m_eIdleType == CWalkNoWeapon) + { + g_pIdle[iPlayerIndex].m_pModel.SetAnimation("cwalk_noweapon"); + } + } + } + return MRES_Ignored; +} + +public Action IdleAnims_Hook_SetTransmit(const int iEntity, const int iClient) { CDynamicProp pDynamicProp = CDynamicProp(iEntity); CBasePlayer pPlayer = CBasePlayer(iClient); CBasePlayer pParentPlayer = view_as(pDynamicProp.GetParent()); - if (pParentPlayer == pPlayer) - { - // TODO: - // Thirdperson support + if (pParentPlayer == NULL_CBASEENTITY) return Plugin_Handled; + + Obs_Mode iObserverMode = pPlayer.GetObserverMode(); + + if (iObserverMode != OBS_MODE_NONE) + { + if (iObserverMode == OBS_MODE_IN_EYE) + { + return Plugin_Handled; + } } - if (pParentPlayer.IsValid() && pPlayer.GetObserverTarget() == pParentPlayer && pPlayer.GetObserverMode() == OBS_MODE_IN_EYE) + else if (pPlayer == pParentPlayer) { + // TODO: + // Add thirdperson support return Plugin_Handled; } return Plugin_Continue; } -public void IdleAnims_Player_PreThink(const int iClient) +public void IdleAnims_Hook_PlayerPreThinkPost(const int iClient) { CBasePlayer pPlayer = CBasePlayer(iClient); int iPlayerIndex = pPlayer.GetEntIndex(); - if (pPlayer.IsAlive() && !pPlayer.GetActiveWeapon().IsValid()) + bool bHasModel = g_pIdle[iPlayerIndex].m_pModel.IsValid(); + if (pPlayer.IsAlive() && pPlayer.GetActiveWeapon() == NULL_CBASEENTITY) { - if (!g_pIdle[iPlayerIndex].m_pModel.IsValid()) + if (!bHasModel) { char szModelName[MAX_MODELNAME]; if (pPlayer.GetModelName(szModelName, sizeof(szModelName))) { g_pIdle[iPlayerIndex].m_pModel = CDynamicProp.Create(szModelName); - if (g_pIdle[iPlayerIndex].m_pModel.IsValid()) + if (g_pIdle[iPlayerIndex].m_pModel != NULL_CBASEENTITY) { float vec3Pos[3]; pPlayer.GetAbsOrigin(vec3Pos); @@ -74,22 +129,26 @@ public void IdleAnims_Player_PreThink(const int iClient) g_pIdle[iPlayerIndex].m_pModel.SetAnimation("idle_noweapon"); g_pIdle[iPlayerIndex].m_eIdleType = IdleNoWeapon; - SDKHook(g_pIdle[iPlayerIndex].m_pModel.GetEntIndex(), SDKHook_SetTransmit, IdleAnims_SetTransmit); + SDKHook(g_pIdle[iPlayerIndex].m_pModel.GetEntIndex(), SDKHook_SetTransmit, IdleAnims_Hook_SetTransmit); + + bHasModel = true; } } } } else { - if (g_pIdle[iPlayerIndex].m_pModel.IsValid()) + if (bHasModel) { g_pIdle[iPlayerIndex].m_pModel.Kill(); g_pIdle[iPlayerIndex].m_pModel = NULL_CBASEENTITY; + bHasModel = false; } } - if (g_pIdle[iPlayerIndex].m_pModel.IsValid()) + if (bHasModel) { + bool bHasGroundEntity = pPlayer.GetGroundEntity() != NULL_CBASEENTITY; float vec3Velocity[3]; pPlayer.GetAbsVelocity(vec3Velocity); @@ -123,8 +182,8 @@ public void IdleAnims_Player_PreThink(const int iClient) } } } - else if ((!pPlayer.GetGroundEntity().IsValid() && g_pIdle[iPlayerIndex].m_eIdleType == JumpStartNoWeapon) || - (pPlayer.GetGroundEntity().IsValid() && !pPlayer.WasPressingButton(IN_JUMP) && pPlayer.IsPressingButton(IN_JUMP))) + else if ((!bHasGroundEntity && g_pIdle[iPlayerIndex].m_eIdleType == JumpStartNoWeapon) || + (bHasGroundEntity && !pPlayer.WasPressingButton(IN_JUMP) && pPlayer.IsPressingButton(IN_JUMP))) { if (g_pIdle[iPlayerIndex].m_eIdleType != JumpStartNoWeapon) { @@ -199,7 +258,7 @@ public void IdleAnims_Player_PreThink(const int iClient) int r, g, b, a; pPlayer.GetRenderColor(r, g, b, a); g_pIdle[iPlayerIndex].m_pModel.SetRenderColor(r, g, b, a); - + for (int i = 0; i < 24; ++i) { g_pIdle[iPlayerIndex].m_pModel.SetPoseParameter(i, pPlayer.GetPoseParameter(i)); diff --git a/scripting/include/srccoop/classdef.inc b/scripting/include/srccoop/classdef.inc index 1055e2a9..19cffc3b 100644 --- a/scripting/include/srccoop/classdef.inc +++ b/scripting/include/srccoop/classdef.inc @@ -337,7 +337,7 @@ stock void InitClassdef(GameData pGameConfig) methodmap CBaseEntity { - public CBaseEntity(const int iEntIndex = NULL_CBASEENTITY) + public CBaseEntity(const int iEntIndex = -1) { return view_as(iEntIndex > -1 ? EntIndexToEntRef(iEntIndex) : iEntIndex); } diff --git a/scripting/include/srccoop/playerpatch.inc b/scripting/include/srccoop/playerpatch.inc index 5b7045b7..ef9652fe 100644 --- a/scripting/include/srccoop/playerpatch.inc +++ b/scripting/include/srccoop/playerpatch.inc @@ -39,7 +39,7 @@ public void Hook_PlayerPreThinkPost(int iClient) return; #if defined SRCCOOP_BLACKMESA - IdleAnims_Player_PreThink(iClient); + IdleAnims_Hook_PlayerPreThinkPost(iClient); #endif CBasePlayer pPlayer = CBasePlayer(iClient); diff --git a/scripting/srccoop.sp b/scripting/srccoop.sp index d631532a..fc2872de 100644 --- a/scripting/srccoop.sp +++ b/scripting/srccoop.sp @@ -440,6 +440,10 @@ public void OnClientPutInServer(int client) DHookEntity(hkEvent_Killed, false, client, _, Hook_PlayerKilled); DHookEntity(hkEvent_Killed, true, client, _, Hook_PlayerKilledPost); + #if defined SRCCOOP_BLACKMESA + DHookEntity(hkSetModel, false, client, _, IdleAnims_Hook_PlayerSetModel); + #endif + #if defined PLAYERPATCH_RESTORE_MP_FORCERESPAWN DHookEntity(hkForceRespawn, false, client, _, Hook_PlayerForceRespawn); #endif