Raised This Month: $106 Target: $400
 26% 

[H3LP] Argument type | formatex chat random


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ultimatgold
Member
Join Date: Jan 2013
Location: In the Air
Old 11-19-2018 , 19:55   [H3LP] Argument type | formatex chat random
Reply With Quote #1

Hi!

What is the problem?
Error message: Error: Argument type mismatch (argument 1)
How do i fix it?

PHP Code:
new chat[128];
    switch (
num)
    {
        case 
1:
        {
            
formatex(chat127"%s"Bot_Chat[random("")][0][0]);
        }
        case 
2:
        {
            
formatex(chat127"%s"Halo_Chat[random("")][0][0]);
        }
        case 
3:
        {
            
formatex(chat127"%s"Bye_Chat[random(11)][0][0]);
        }
        default:
        {
        }
    }
    } 
__________________
Hungary's TOP1 server:
ultimatgold is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-19-2018 , 20:20   Re: [H3LP] Argument type | formatex chat random
Reply With Quote #2

random("") is your problem.

random expects a number, not a string. Input a number and it will return a random number between 0 and the number - 1. random(10) will give random between 0 to 9.
__________________

Last edited by Bugsy; 11-19-2018 at 20:21.
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Old 11-20-2018 , 07:58   Re: [H3LP] Argument type | formatex chat random
Reply With Quote #3

Also use charsmax(chat) instead of typing the max length manually.
__________________
Stuff I'm good at:
- Goldsource level designing
- Arty in World of Tanks

redivcram is offline
ultimatgold
Member
Join Date: Jan 2013
Location: In the Air
Old 11-20-2018 , 09:22   Re: [H3LP] Argument type | formatex chat random
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
random("") is your problem.

random expects a number, not a string. Input a number and it will return a random number between 0 and the number - 1. random(10) will give random between 0 to 9.
Thank you!

Quote:
Originally Posted by redivcram View Post
Also use charsmax(chat) instead of typing the max length manually.
Do you write an example?

_____________________________________________ ____________________
EDIT:

Okay, I just tried:
PHP Code:
{
    if (!
get_pcvar_num(bot_chat_cvar))
    {
        return 
1;
    }
    new 
chat[128];
    switch (
num)
    {
        case 
1:
        {
            
formatex(chat127"%s"Bot_Chat[random(205)][0][0]);
        }
        case 
2:
        {
            
formatex(chat127"%s"Halo_Chat[random(6)][0][0]);
        }
        case 
3:
        {
            
formatex(chat127"%s"Bye_Chat[random(11)][0][0]);
        }
        default:
        {
        }
    }
    return 
0;

Error:
Error: Expected token: ",", but found "[" on line ***
Error: Expected token: ";", but found "]" on line 762

But, this is work fine:
Why?
PHP Code:
{
    if (!
get_pcvar_num(bot_chat_cvar))
    {
        return 
1;
    }
    new 
chat[128];
    switch (
num)
    {
        case 
1:
        {
            
randomsizeofBot_Chat ) )
        }
        case 
2:
        {
            
randomsizeofHalo_Chat ) )
        }
        case 
3:
        {
            
randomsizeofBye_Chat ) )
        }
        default:
        {
        }
    }
    return 
0;

__________________
Hungary's TOP1 server:

Last edited by ultimatgold; 11-20-2018 at 09:34.
ultimatgold is offline
redivcram
Veteran Member
Join Date: Jul 2014
Old 11-20-2018 , 10:10   Re: [H3LP] Argument type | formatex chat random
Reply With Quote #5

Quote:
Originally Posted by ultimatgold View Post
Do you write an example?
PHP Code:
formatex(chat127"%s"Bot_Chat[random(205)][0][0]); 

PHP Code:
formatex(chatcharsmax(chat), "%s"Bot_Chat[random(205)][0][0]); 
It gets the max length of the "chat" string. Is safer and better.

Quote:
Originally Posted by ultimatgold View Post
Okay, I just tried:
PHP Code:
{
    if (!
get_pcvar_num(bot_chat_cvar))
    {
        return 
1;
    }
    new 
chat[128];
    switch (
num)
    {
        case 
1:
        {
            
formatex(chat127"%s"Bot_Chat[random(205)][0][0]);
        }
        case 
2:
        {
            
formatex(chat127"%s"Halo_Chat[random(6)][0][0]);
        }
        case 
3:
        {
            
formatex(chat127"%s"Bye_Chat[random(11)][0][0]);
        }
        default:
        {
        }
    }
    return 
0;

Error:
Error: Expected token: ",", but found "[" on line ***
Error: Expected token: ";", but found "]" on line 762
Posting the full code would help.

Quote:
Originally Posted by ultimatgold View Post
But, this is work fine:
Why?
PHP Code:
{
    if (!
get_pcvar_num(bot_chat_cvar))
    {
        return 
1;
    }
    new 
chat[128];
    switch (
num)
    {
        case 
1:
        {
            
randomsizeofBot_Chat ) )
        }
        case 
2:
        {
            
randomsizeofHalo_Chat ) )
        }
        case 
3:
        {
            
randomsizeofBye_Chat ) )
        }
        default:
        {
        }
    }
    return 
0;

That code makes no sense at all.
I'd still suggest posting the full code if you want to help us help you solve the issue.
__________________
Stuff I'm good at:
- Goldsource level designing
- Arty in World of Tanks

redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-20-2018 , 11:28   Re: [H3LP] Argument type | formatex chat random
Reply With Quote #6

You need to provide more code for us to fully help you. You may not need to use formatex() at all--without providing your string arrays we cannot tell what the purpose of formatex() is. Also, if you plan to print these to chat, client_print() includes its own formatting so formatex() would not be needed. If you do not need to format the chat message, just print the messages directly from the chat array and remove the szChat[] variable.

PHP Code:

#include <amxmodx>

new bot_chat_cvar;

new 
Bot_Chat[][] =
{
    
"String 1",
    
"String 2",
    
"String 3",
    
"String 4",
    
"String 5",
    
"String 6",
    
"String 7",
};
    
new 
Halo_Chat[][] =
{
    
"String 1",
    
"String 2",
    
"String 3",
    
"String 4",
    
"String 5",
    
"String 6",
    
"String 7",
};

new 
Bye_Chat[][] =
{
    
"String 1",
    
"String 2",
    
"String 3",
    
"String 4",
    
"String 5",
    
"String 6",
    
"String 7",
};

public 
ChatFuncnum 
{
    if ( !
get_pcvar_numbot_chat_cvar ) ) 
    { 
        return 
1
    } 
    
    new 
szChat128 ];
    
    switch ( 
num 
    { 
        case 
1
        { 
            
formatexszChatcharsmaxszChat ) , "%s" Bot_ChatrandomsizeofBot_Chat ) ) ] ); 
            
//or
            
client_printprint_chat Bot_ChatrandomsizeofBot_Chat ) ) ] );
        } 
        case 
2
        { 
            
formatexszChat charsmaxszChat ) , "%s" Halo_ChatrandomsizeofHalo_Chat ) ) ] ); 
            
//or
            
client_printprint_chat Halo_ChatrandomsizeofHalo_Chat ) ) ] );
        } 
        case 
3
        { 
            
formatexszChat charsmaxszChat ) , "%s" Bye_ChatrandomsizeofBye_Chat  ) ) ] );
            
//or
            
client_printprint_chat Bye_ChatrandomsizeofBye_Chat ) ) ] );
        } 
        default: 
        {
            
        } 
    } 
    
    return 
0

__________________
Bugsy is offline
ultimatgold
Member
Join Date: Jan 2013
Location: In the Air
Old 11-22-2018 , 18:55   Re: [H3LP] Argument type | formatex chat random
Reply With Quote #7

Hi!

I'm sorry to write you so late, I worked.
Okay, now not work:
PHP Code:
formatex(chatcharsmax(chat), "%s"Bot_Chat[random(205)][0][0]); 
But... This is work perfect!
PHP Code:
client_printprint_chat Bot_ChatrandomsizeofBot_Chat ) ) ] ); 
__________________
Hungary's TOP1 server:
ultimatgold is offline
Reply


Thread Tools
Display Modes

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 Jump


All times are GMT -4. The time now is 18:23.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode