UserMessage "VGUIMenu" "nav_progress"
Some of you sure recognize this. Especially when have add one bot in game and server start generate nav file if it not exist.
And that time you almost can't do anything, you see your mouse cursor on screen and this panel what show server progress.
You can close this panel ALT+F4 or go your menu with ESC.
Lets create this.
*tip
Can quick test in game, type in console
showpanel nav_progress
hidepanel nav_progress
Simple way, using
ShowVGUIPanel, we get it appear in player screen.
PHP Code:
ShowVGUIPanel(client, "nav_progress");
At this point if you get already some message and different load bar status, it's because there have been remaining some data last time when player seen this panel and have not been erased.
Yeah, this data are store in players.
As you can see my picture, it have not message and loading bar full (data empty).
Start customize our panel!
Need build proper keyvalue structure to get it work.
(I peek from sourcecode2007)
It looks like this!
nav_progress Keyvalue structure
Code:
"data"
{
"msg" "Sampling walkable space..."
"total" "100"
"current" "10"
}
You build like this
PHP Code:
new Handle:kv = CreateKeyValues("data");
KvSetString(kv, "msg", "My own message");
KvSetNum(kv, "total", 100);
KvSetNum(kv, "current", 33);
Then send it to player and close handel just make sure no leak appears.
PHP Code:
ShowVGUIPanel(client, "nav_progress", kv);
CloseHandle(kv);
Here example plugin, if you want test for fun
PHP Code:
new g_iProgress;
public OnPluginStart()
{
RegConsoleCmd("sm_test", test);
}
public Action:test(client, args)
{
g_iProgress = 0;
CreateTimer(3.0, msg_generate, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Handled;
}
public Action:msg_generate(Handle:timer, any:userid)
{
new client = GetClientOfUserId(userid);
if(client == 0 || !IsClientInGame(client))
{
return Plugin_Stop;
}
new Handle:kv = INVALID_HANDLE;
if(g_iProgress < 300)
{
// Using my poor stock Build_NAV_PROGRESS()
kv = Build_NAV_PROGRESS( "Uninstall in progress", 300, (g_iProgress = GetRandomInt(g_iProgress,300)), true );
ShowVGUIPanel(client, "nav_progress", kv, true);
CreateTimer(GetRandomFloat(0.5, 3.0), msg_generate, userid, TIMER_FLAG_NO_MAPCHANGE);
}
else
{
kv = CreateKeyValues("data"); // Clear player "nav_progress" data
ShowVGUIPanel(client, "nav_progress", kv, false);
}
CloseHandle(kv);
return Plugin_Continue;
}
/*
* Copy most from sourcecode2007 file.
* Will build keyvalue structure to panel "nav_progress"
*
* @param msg Message what will print to panel
* @param ticks Maximum loading bar ticks
* @param current Loading bar progress
* @param showPercent Add in message, progress in percent
*
*/
stock Handle:Build_NAV_PROGRESS( const String:msg[], ticks, current, bool:showPercent = true )
{
decl String:buffer[192];
buffer[0] = '\0';
if ( showPercent && ticks )
{
Format(buffer, sizeof(buffer), "%s %.1f%", msg, float(current)*100.0/float(ticks));
}
else
{
strcopy(buffer, sizeof(buffer), msg);
}
new Handle:kv = CreateKeyValues("data");
KvSetString(kv, "msg", buffer);
KvSetNum(kv, "total", ticks);
KvSetNum(kv, "current", current);
return kv;
}
When use UserMsg to send "nav_progress"
UserMessage
PHP Code:
new Handle:hBf = Handle:StartMessageOne("VGUIMenu", client);
BfWriteString(hBf, "nav_progress"); // Panel name
BfWriteChar(hBf, 0x01); // 0x01 (SOH) - Use normal color from this point forward
BfWriteChar(hBf, 0x03); // 0x03 (ETX) - Use team color from this point forward
BfWriteString(hBf, "msg"); // keyvalue name. Whole string would be "\x01\x03msg" in usermessage actually, thanks to above two characters.
BfWriteString(hBf, "My custom message"); // Message
BfWriteString(hBf, "total"); // keyvalue name
BfWriteString(hBf, "300"); // Max ticks in loading bar
BfWriteString(hBf, "current");// keyvalue name
BfWriteString(hBf, "30"); // Current loading bar status by ticks
EndMessage();