AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [HOWTO] Ingame Browser (https://forums.alliedmods.net/showthread.php?t=54976)

Tobi17 05-09-2007 18:33

[HOWTO] Ingame Browser
 
Hello,

to display external urls for clients within the ingame browser you have to execute the following code:

Code:

public OnPluginStart()
{
        RegServerCmd("my_browse", my_browse);
}


public Action:my_browse(args)
{
        if (args < 2) {
                PrintToServer("Usage: my_browse <userid><url> - open client ingame browser");
                return Plugin_Handled;
        }

        decl String:client_id[32];
        GetCmdArg(1, client_id, 32);

        new String:client_url[192];
        decl String:argument_string[512];
        GetCmdArgString(argument_string, 512);
        new find_pos = StrContains(argument_string, "http://", true);
        if (find_pos == -1) {
                new argument_count = GetCmdArgs();
                for(new i = 1; i < argument_count; i++) {
                        decl String:temp_argument[192];
                        GetCmdArg(i+1, temp_argument, 192);
                        if ((192 - strlen(client_url)) > strlen(temp_argument)) {
                                strcopy(client_url[strlen(client_url)], 192, temp_argument);
                        }
                }
        } else {
                strcopy(client_url, 192, argument_string[find_pos]);
        }

        new client = StringToInt(client_id);
        if (client > 0) {
                new player_index = GetClientOfUserId(client);
                if ((player_index > 0) && (!IsFakeClient(player_index)) && (IsClientConnected(player_index))) {
                        decl Handle:hBf;
                        hBf = StartMessageOne("VGUIMenu", player_index);
                        if (hBf != INVALID_HANDLE) {
                                BfWriteString(hBf, "info");
                                BfWriteByte(hBf,  1);
                                BfWriteByte(hBf,  3);
                                BfWriteString(hBf, "title");
                                BfWriteString(hBf, "MyTitle");
                                BfWriteString(hBf, "type");
                                BfWriteString(hBf, "2");
                                BfWriteString(hBf, "msg");
                                BfWriteString(hBf, client_url);
                                BfWriteString(hBf, "cmd");
                                BfWriteString(hBf, "");
                                EndMessage();
                        }
                }       
        }               
                       
        return Plugin_Handled;
}

This could be maybe useful for anyone.

Bye
Tobi

BAILOPAN 05-09-2007 19:04

Re: [HOWTO] Ingame Browser
 
Just an FYI on this one: The message can't exceed 255 bytes (including ~1-3 bytes for the header). I ran into this trying to send a long URL. Unlike HL1, you can't break up the message.

EDIT: I didn't mean the above code doesn't work, just that looking for the same HL1 functionality won't work.

Tobi17 05-09-2007 19:07

Re: [HOWTO] Ingame Browser
 
Hello,

the client url is limited to 192 characters. The code above should work without any problems.

Bye
Tobi

API 05-10-2007 09:57

Re: [HOWTO] Ingame Browser
 
I didn't realize a MOTD window could already be made... nice.


All times are GMT -4. The time now is 12:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.