AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   say number motd number (https://forums.alliedmods.net/showthread.php?t=324348)

rx1983 05-13-2020 19:33

say number motd number
 
1 Attachment(s)
how I do to send a random number.

to a page with motd?

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <chatcolor>

public plugin_init() {

    
register_plugin("say top","1","mestre")
    
register_clcmd("say topY",  "topY",  0"zzz"); // Y = NUMBER
}

public 
top_Y(id,level,cid) {
    new 
szNome32 ];
    
get_user_nameidszNome31 )
    if (!
cmd_access(id,level,cid,1))
    return 
PLUGIN_CONTINUE
    show_motd
(id,"http://www.xxxx.com.xx/xxxx/xxx.php?top=Y""TOP Y ( Y = NUMBER ) ")
    
client_print_color0print_chat"^3%s ^4topY ^1 rank xxx"szNome);
    return 
PLUGIN_CONTINUE   



Attachment 181368



https://forums.alliedmods.net/attach...1&d=1589412649

fysiks 05-13-2020 21:57

Re: say number motd number
 
Read the argument string (read_args()) and then get the number from the string and use it for your URL.

Also, if you have a predefined number of commands that work, you need to register all of them to call that same function. If the number is fully arbitrary, then you need to hook "say" and then process the the arg string to first check that it matches your command (i.e. "top") and then call your MOTD if it does.

Also, you mean arbitrary number, not random number.

rx1983 02-21-2023 19:08

Re: say number motd number
 
bump, can someone do this

fysiks 02-22-2023 01:38

Re: say number motd number
 
Here ya go. Add as many register_clcmd() functions as needed with a different number and update with your URL.

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define MIN_VALUE 1
#define MAX_VALUE 2000

public plugin_init()
{
    
register_plugin("say top""1.0.0""mestre/fy")

    new 
szSayCmd[20]
    for( new 
MIN_VALUE<= MAX_VALUEi++ )
    {
        
formatex(szSayCmdcharsmax(szSayCmd), "say top%d"i);
        
register_clcmd(szSayCmd"showTopMOTD");
    }
}

public 
showTopMOTD(id)
{
    new 
szCmd[10], iValueszUrl[128];
    
read_argv(1szCmdcharsmax(szCmd));
    
iValue str_to_num(szCmd[3]);

    
formatex(szUrlcharsmax(szUrl), "http://www.xxxx.com.xx/xxxx/xxx.php?top=%d"iValue);
    
show_motd(idszUrl);

    new 
szName[32];
    
get_user_nameidszNamecharsmax(szName))
    
client_print(0print_chat"^3%s ^4topY ^1 rank xxx"szName);
    
    return 
PLUGIN_CONTINUE;



rx1983 02-22-2023 06:28

Re: say number motd number
 
I need this to be done with a loop, the rank can go from 1 to 2000...

it will be very difficult to declare 2000 register_clcmd ...

fysiks 02-24-2023 00:10

Re: say number motd number
 
Would have been nice to know. Updated above. I'm not sure if there is any limitations to registering commands like this, if it causes issues, we can switch how it's done to not require all the registered commands.

rx1983 02-27-2023 09:15

Re: say number motd number
 


https://www.youtube.com/embed/4h-kEsfcVNk

would you be able to do the same thing without registering so many commands?

bigdaddy424 02-27-2023 11:46

Re: say number motd number
 
https://i.imgur.com/TAJKm1x.png
Code:
#include <amxmodx> new command[] = "top" public plugin_init()     register_srvcmd("get", "hook_say") public hook_say(){     new text[32]     read_argv(1, text, charsmax(text))     server_print("said %s, number %d", text, str_to_num(fmt("%s", text[strlen(command)]))) }

bigdaddy424 02-27-2023 12:26

Re: say number motd number
 
in this case
Code:
#include <amxmodx> #define WEB_URL "https://google.com/search?q=" public plugin_init()     register_clcmd("say", "hook_say") public hook_say(id){     new text[8], command[8]     read_argv(1, text, charsmax(text))     formatex(command, charsmax(command), "%.3s", text)     if (equal(command, "top"))         show_motd(             id,             fmt("%s%d", WEB_URL, str_to_num(fmt("%s", text[3]))),             fmt("Top %d | %s", str_to_num(fmt("%s", text[3])), __DATE__)         )     return PLUGIN_HANDLED }

fysiks 02-28-2023 01:08

Re: say number motd number
 
You are doing way more formatting than you need to do, no formatting related to "text" is required. Should also validate the number before showing the MOTD. Also, returning PLUGIN_HANDLED unconditionally in a "say" hook will prevent all normal chat messages from showing.

PHP Code:

#include <amxmodx>

#define WEB_URL "https://google.com/search?q="

public plugin_init()
{
    
register_clcmd("say""hook_say")
}

public 
hook_say(id)
{
    new 
text[8]
    
read_argv(1textcharsmax(text))

    if( 
equal(text"top"3) )
    {
        new 
iValue str_to_num(text[3])
        if( 
iValue )
        {
            
show_motd(idfmt("%s%d"WEB_URLiValue), fmt("Top %d | %s"iValue__DATE__))
        }
        return 
PLUGIN_HANDLED
    
}




All times are GMT -4. The time now is 00:19.

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