Throw error in ShowHudText or ShowSyncHudText if HudText params not yet set (#1890)

This commit is contained in:
Nicholas Hastings
2022-12-20 01:26:38 +00:00
committed by GitHub
parent c5e69900f9
commit 515df38b72
+13
View File
@@ -70,6 +70,7 @@ struct hud_text_parms
float holdTime;
float fxTime;
int channel;
bool isSet = false;
};
class HudMsgHelpers :
@@ -282,6 +283,7 @@ static cell_t SetHudTextParams(IPluginContext *pContext, const cell_t *params)
g_hud_params.g2 = 255;
g_hud_params.b2 = 250;
g_hud_params.a2 = 0;
g_hud_params.isSet = true;
return 1;
}
@@ -308,6 +310,7 @@ static cell_t SetHudTextParamsEx(IPluginContext *pContext, const cell_t *params)
g_hud_params.g2 = static_cast<byte>(color2[1]);
g_hud_params.b2 = static_cast<byte>(color2[2]);
g_hud_params.a2 = static_cast<byte>(color2[3]);
g_hud_params.isSet = true;
return 1;
}
@@ -384,6 +387,11 @@ static cell_t ShowSyncHudText(IPluginContext *pContext, const cell_t *params)
return -1;
}
if (!g_hud_params.isSet)
{
return pContext->ThrowNativeError("ShowSyncHudText first requires a call to SetHudTextParams or SetHudTextParamsEx");
}
if ((err = s_HudMsgHelpers.ReadHudSyncObj(params[2], pContext->GetIdentity(), &obj)) != HandleError_None)
{
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err);
@@ -468,6 +476,11 @@ static cell_t ShowHudText(IPluginContext *pContext, const cell_t *params)
return -1;
}
if (!g_hud_params.isSet)
{
return pContext->ThrowNativeError("ShowHudText first requires a call to SetHudTextParams or SetHudTextParamsEx");
}
client = params[1];
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
{