AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [H3LP] Argument type | formatex chat random (https://forums.alliedmods.net/showthread.php?t=312187)

ultimatgold 11-19-2018 18:55

[H3LP] Argument type | formatex chat random
 
Hi! :wink:

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:
        {
        }
    }
    } 


Bugsy 11-19-2018 19:20

Re: [H3LP] Argument type | formatex chat random
 
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.

redivcram 11-20-2018 06:58

Re: [H3LP] Argument type | formatex chat random
 
Also use charsmax(chat) instead of typing the max length manually.

ultimatgold 11-20-2018 08:22

Re: [H3LP] Argument type | formatex chat random
 
Quote:

Originally Posted by Bugsy (Post 2624820)
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 (Post 2624868)
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;



redivcram 11-20-2018 09:10

Re: [H3LP] Argument type | formatex chat random
 
Quote:

Originally Posted by ultimatgold (Post 2624874)
Do you write an example?

PHP Code:

formatex(chat127"%s"Bot_Chat[random(205)][0][0]); 

:arrow:
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 (Post 2624874)
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 (Post 2624874)
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.

Bugsy 11-20-2018 10:28

Re: [H3LP] Argument type | formatex chat random
 
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



ultimatgold 11-22-2018 17:55

Re: [H3LP] Argument type | formatex chat random
 
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 ) ) ] ); 



All times are GMT -4. The time now is 06:26.

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