Only one message can be shown in center text at a time via PrintCenterText().
PriorityCenterText() allows that space to be given different priority levels that prevent new messages from overwriting what's already there.
Center text sent via these functions have the following attributes:
Messages of higher priority cannot be overwritten by messages of lower priority.
Messages of equal priority can overwrite each other.
Priority reverts to the minimum value (-2147483648) after 5.0 seconds.
An example of where I use this:
Versus Saxton Hale constantly displays the boss's health to the last player by sending CenterText in a repeated timer. This prevents messages like "You were just backstabbed!" from appearing because the health center text immediately overwrites it. PriorityCenterText allows the backstab message to have higher priority and not be overwritten for the 5 seconds it lasts.
There is currently nothing to make the priority text work between separate plugins.
(For example, if a new version of CSAY was made and you wanted it to be compatible with VSH - priority won't be checked between different plugins).
PHP Code:
/**
* Prints a center text message to a specific client with a specific level of "priority"
*
* @param iClient Client ent index.
* @param iPriority Priority level of message.
* @param szFormat Message to send (and formatting rules).
* @noreturn
*/
stock PriorityCenterText(iClient, iPriority = MIN_INT, const String:szFormat[], any:...)
/**
* Prints a center text message to everyone with a specific level of "priority"
* This will set the priority of all clients and works in tandem with PriorityCenterText()
*
* @param iPriority Priority level of message.
* @param szFormat Message to send (and formatting rules).
* @noreturn
*/
stock PriorityCenterTextAll(iPriority = MIN_INT, const String:szFormat[], any:...)
/**
* Prints a center text message to everyone with a specific level of "priority"
* This will override the priority of the functions above by maxing out priority for all clients
* In other words, this version ignores priority and is guaranteed to overwrite messages sent from the functions above
* It does have its own internal priority though which can be used against itself
*
* @param iPriority Priority level of message.
* @param szFormat Message to send (and formatting rules).
* @noreturn
*/
stock PriorityCenterTextAllEx(iPriority = MIN_INT+1, const String:szFormat[], any:...)
Full source here (same as the attached .inc)
Spoiler
PHP Code:
#if defined __prioritycentertext_0_included
#endinput
#endif
#define __prioritycentertext_0_included
/*
PriorityCenterText (Version 0x06)
Only one message can be shown in center text at a time.
These stocks allow that space to be given different priority levels that prevent new messages from overwriting what's there.
/*
Send priority center text to everyone.
This will obey priority sent to via PriorityCenterText() and not overwrite if it's lower priority
PriorityCenterTextAll(_, "Message")
Is the proper way to send something that can be overwritten by everything.
*/
stock PriorityCenterTextAll(iPriority = MIN_INT, const String:szFormat[], any:...)
{
decl String:szBuffer[MAX_CENTER_TEXT];
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
SetGlobalTransTarget(i);
VFormat(szBuffer, sizeof(szBuffer), szFormat, 3);
PriorityCenterText(i, iPriority, "%s", szBuffer);
}
}
}
/*
Send priority center text to everyone.
This version bypasses the priority in PriorityCenterText() with its own internal counter.
This version will ALWAYS have higher priority than the functions above, so long as it has higher priority than 'itself'
The priority of all players will be completely maxed out to achieve this.
*/
stock PriorityCenterTextAllEx(iPriority = MIN_INT+1, const String:szFormat[], any:...)
{
if (iPriority == MIN_INT)
{
iPriority++;
}
if (s_iLastPriority[0] > iPriority)
{
if (GetEngineTime() >= s_flResetPriority[0])
{
s_iLastPriority[0] = MIN_INT;
for (new i = 1; i <= MaxClients; i++)
{
s_iLastPriority[i] = MIN_INT;
}
}
else
{
return;
}
}
if (iPriority > s_iLastPriority[0])
{
s_flResetPriority[0] = GetEngineTime() + 5.0;
s_iLastPriority[0] = iPriority;
for (new i = 1; i <= MaxClients; i++)
{
s_iLastPriority[i] = MAX_INT;
}
}
decl String:szBuffer[MAX_CENTER_TEXT];
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
SetGlobalTransTarget(i);
VFormat(szBuffer, sizeof(szBuffer), szFormat, 3);
PrintCenterText(i, "%s", szBuffer);
}
}
}
Centertext is a usermsg, priority is one of the vars. you could just se the priority to something using a static var, and compare the optional var to that, rather than calling printcentertext.
Atleast, i think priority is a var, it is for some of the other usermsgs, like the one in the upper left.
Chdata
01-24-2015 05:10
Re: [INC] PriorityCenterText (0x02)
Also note I'm aware of this bug in the timing of revertpriority: