Rules FAQ Members List Search Register Login

 Raised This Month: \$10 Target: \$400 2%

Solved Math and and hook "say"

Author Message
chickez
Junior Member
Join Date: Jun 2020
Location: Slovakia
 07-03-2020 , 13:07   Math and and hook "say" #1 Hey. I was looking for plugin, which is - math examples, and who first write right sum *do something*. But I didn't find. Code: Spoiler PHP Code: ``` #include  #define PLUGIN "Math Examples" #define VERSION "0.1" #define AUTHOR "chick" public plugin_init() {     register_plugin ( PLUGIN, VERSION, AUTHOR )          set_task ( 60.0, "fRandomMath", _, _, _, "b" ) } public fRandomMath( id ) {     new iRandom = ( random_num(0,1) )          new a     new b     new sum = a+b          new name[ 32 ]     = get_user_name ( id )     new authid[ 32 ] = get_user_authid ( id )          if ( iRandom == 0 )         {             a = 2             b = 2                          client_print ( id, print_chat, "Math ex: %i + %i", a, b )                          /*If ANY PLAYER write right sum as first - in this its 4 -, then do this below*/             {                 client_print ( id, print_chat, "%s (%s) write first!", name, authid )                 return PLUGIN_HANDLED //End function ?             }         }     if ( iRandom == 1 )         {             a = 1             b = 1                          client_print ( id, print_chat, "Math ex: %i + %i", a, b )                          /*If ANY PLAYER write right sum as first - in this its 2 -, then do this below*/             {                 client_print ( id, print_chat, "%s (%s) write first!", name, authid )                 return PLUGIN_HANDLED //End function ?             }         }     return PLUGIN_HANDLED }  ``` I want to get from client right sum, then do something (in the comments of code explained) Can you explain me it please? Last edited by chickez; 07-06-2020 at 11:28. Reason: solved
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
 07-04-2020 , 04:00   Re: Math and get integer from clcmd "say" #2 Hook say(with register_clcmd), read the arguments(the chat message) and process it to get the sum. __________________
chickez
Junior Member
Join Date: Jun 2020
Location: Slovakia
 07-05-2020 , 04:58   Re: Math and get integer from clcmd "say" #3 I changed code a little. Spoiler PHP Code: ``` #include  #define PLUGIN "Math Examples" #define VERSION "0.1" #define AUTHOR "chick" public plugin_init ( ) {     register_plugin ( PLUGIN, VERSION, AUTHOR )              register_clcmd ( "say", "fMath" )     register_clcmd ( "say_team", "fMath" ) } public fMath ( id ) {     new a = random_num ( 0, 50 )     new b = random_num ( 0, 50 )     new sum = a+b          client_print ( id, print_chat, "Math example: %i + %i", a, b )          new Arg1 [ 4 ]     read_argv ( id, Arg1, charsmax(Arg1) )          str_to_num ( Arg1 )          if ( equali(Arg1, sum) )         client_print ( id, print_chat, "You're right!" )          return PLUGIN_HANDLED }  ``` This doesn't work. Error: Code: ```Error: Argument type mismatch (argument 2) on line 29 Warning: Symbol is assigned a value that is never used: "sum" on line 33``` What's wrong? Why it doesn't get the sum?
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
 07-05-2020 , 06:10   Re: Math and get integer from clcmd "say" #4 You have a lot of mistakes in that code. I suggest you dearch how to use read_argv, str_to_num, equal correctly and what they do. Give it one more try. If you can't figure it out I'll show you the correct way. __________________ Last edited by HamletEagle; 07-05-2020 at 06:10.
condoriano90
Member
Join Date: May 2020
 07-05-2020 , 06:53   Re: Math and get integer from clcmd "say" #5 nevermind Last edited by condoriano90; 07-05-2020 at 06:54.
chickez
Junior Member
Join Date: Jun 2020
Location: Slovakia
 07-05-2020 , 07:32   Re: Math and get integer from clcmd "say" #6 Okey, i think, i know how to use read_argv(). So str_to_num doesn't know, if i'm right. What about equali? It is for compare two strings. So I must use num_to_str for equali? I tried this: Spoiler PHP Code: ``` public plugin_init ( ) {     register_plugin ( PLUGIN, VERSION, AUTHOR )              register_clcmd ( "say", "fMath" )     register_clcmd ( "say_team", "fMath" )          set_task ( 15.0, "fMath" ) } public fMath ( id ) {     new a = random_num ( 0, 50 )     new b = random_num ( 0, 50 )     new sum = a+b          client_print ( id, print_chat, "Math example: %i + %i", a, b )          new Arg1 [ 128 ]          read_argv ( 1, Arg1, charsmax(Arg1) )          new Arg2 [ 128 ]     num_to_str ( sum, Arg2, charsmax(Arg2) )          if ( equali (Arg1, Arg2) )         client_print ( id, print_chat, "You're right!" )          return PLUGIN_HANDLED }  ``` It's compiled without errors or warnings. I tried it on server, but when I wrote anything, it called func. When I predicted right sum, it's called "You're right!".
chickez
Junior Member
Join Date: Jun 2020
Location: Slovakia
 07-05-2020 , 11:55   Re: Math and get integer from clcmd "say" #7 Okey, I was coding all day long. I did it, i think. Spoiler PHP Code: ``` #include #define PLUGIN "math"#define VERSION "0.1"#define AUTHOR "chick"new bool:bExamplenew Result = 0public plugin_init ( ) {    register_plugin ( PLUGIN, VERSION, AUTHOR )        register_clcmd ( "say", "fHandle_say" )        set_task ( 60.0, "fExample", 0, _, _, "b" )}public fHandle_say ( id ){    new said [ 64 ], ResultString [ 64 ]    read_argv ( 1, said, charsmax(said) )    num_to_str ( Result, ResultString, 63 )        if ( equali(said, ResultString) )        {            if ( !bExample )                {                    return 0                }            else                {                    client_print ( id, print_chat, "You're right!" )                    bExample = false                }        }    return PLUGIN_CONTINUE}public fExampleNoOne ( id ){    if ( bExample )        {            client_print ( id, print_chat, "No one has answered the result! Example is out!" )            bExample = false        }    return PLUGIN_CONTINUE}public fExample ( ){    set_task ( 10.0, "fExampleNoOne" )    bExample = true        new a, b    a = random_num ( 1, 5 )    b = random_num ( 1, 5 )        client_print ( 0, print_chat, "Example: %i + %i", a, b )    Result = a+b        return PLUGIN_HANDLED}  ``` It's working. But, if something is wrong, can you tell me what? Thanks. Last edited by chickez; 07-06-2020 at 11:29. Reason: a

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Server Discussion     Source Servers (SRCDS)     HL1 Servers (HLDS) AMX Mod X     News     Bug Reports     General     Off-Topic     Plugins         Suggestions / Requests         Approved Plugins         New Plugin Submissions         Unapproved/Old Plugins         Translation Request         High-Traffic Plugins             GunGame             UAIO (Ultimate All-In-One Plugin)             xREDIRECT             CSDM             AMX Super             RuneMod             Zombie Plague Mod             SuperHero Mod                 News                 Tech Support                 Scripting Help                 Off-Topic / General Chat                 Heroes                     Suggestions / Requests                     Approved Heroes                     New Submissions                     Unapproved/Old Heroes                         Module Heroes                     SuperHero Mod Stats - By 123                 (OLD) Bug Reports     Scripting         Scripting Help         Code Snippets/Tutorials         Module Coding     Donor Access SourceMod     News     General     Plugins         Plugins         Unapproved Plugins         Plugin/Gameplay Ideas and Requests         High-Traffic Plugins             SourceMod Anti-Cheat             Zombie:Reloaded             SourceBans / SourceBans++             VSH / Freak Fortress             Store             SM_Hosties             HLstatsX:CE     Scripting     Extensions     Snippets and Tutorials     Donor Access     Metamod: Source         Metamod:Source Plugins         Metamod:Source Questions         Coding MM:S Plugins & SM Extensions Hosted Stuff     Asherkin's Plugins         TFDodgeball         TF2Items         SteamTools     Bail's Plugins         CSDM         CS:S DM Off-Topic & Trash     Off-Topic     Trash

All times are GMT -4. The time now is 05:33.

 DMCA - Archive - Top