AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   error 035: argument type mismatch (argument 1) (https://forums.alliedmods.net/showthread.php?t=252450)

Mofforg 12-02-2014 21:37

error 035: argument type mismatch (argument 1)
 
Hi.


Can not beat that error
PHP Code:

error 035argument type mismatch (argument 1

I've searched a lot but all i find in posts is easy errors (like adding 'id' when it don't need to be added or words mispell), but i can not find any mistakes in my code..

Guide me please what's wrong...

PHP Code:

#include <amxmodx>
#define MAX_ARG_LEN    128
#define MAX_ARGS_NUM 50

static command[MAX_ARGS_NUM][MAX_ARG_LEN]
new 
len

public client_command(id)
{
    new 
args read_argc()-// get number of client command arguments
    
    
for(new i;i<=args;i++)
        
read_argv(icommand[i], MAX_ARG_LEN// read all arguments to array "command"

    
if(equal(command[0],"amx_internalbancommand",22)) // if it is internal ban command
    
{
        
// command syntax "amx_internalbancommand" "#playerindex" *others not important*
        
for(new i;i<=31;i++) // loop until we find player index (if any), 31 is the last player index 
        
{
            
len strlen(i) + 1; <<<<<<<<<<< error 035argument type mismatch (argument 1)     // here we define a length of int "i" (i am using strlen, because there are no native function intlen and i have no idea how to convert int to string) plus one
            
if( equal(command[1],"#" i,len) ) <<<<<<<<<<< error 033: array must be indexed (variable "-unknown-")   // and here we check is our command argument matches the string, e.g. "#1"
            
{
                ...
                break
            }
        }
    }



Bugsy 12-02-2014 21:43

Re: error 035: argument type mismatch (argument 1)
 
You are checking strlen of an integer, it expects a string (array). And "#" + i just makes no sense.

Mofforg 12-02-2014 21:46

Re: error 035: argument type mismatch (argument 1)
 
Quote:

Originally Posted by Bugsy (Post 2230612)
You are checking strlen of an integer, it expects a string (array). And "#" + i just makes no sense.

Ok, but how to convert integer to string?

Bugsy 12-02-2014 21:48

Re: error 035: argument type mismatch (argument 1)
 
What exactly is this code supposed to do? Give me what is inputted and what you expect it to do.

Mofforg 12-02-2014 22:11

Re: error 035: argument type mismatch (argument 1)
 
Quote:

Originally Posted by Bugsy (Post 2230615)
What exactly is this code supposed to do? Give me what is inputted and what you expect it to do.

It listen to commands and if it finds a command "amx_internalbancommand" it make some actions (well, it just logs it, but not important here).

Example command: amx_internalbancommand #31

Where #31 is an index of a player in game.


Found how to convert, but does not work...ooh.

PHP Code:

new len;
num_to_str(ilen3); <<<<<<<< error 035argument type mismatch (argument 2)
len strlen(len) + 1;
len str_to_num(len); 

Why "len" errors here? It's just a buffer, so a string. As it's not defined what type is it, it should be automatically become a string, is it?

YamiKaitou 12-02-2014 22:14

Re: error 035: argument type mismatch (argument 1)
 
A string is an array. Len is not an array

Bugsy 12-02-2014 22:20

Re: error 035: argument type mismatch (argument 1)
 
I don't see what your loop is even doing. It's looping from 0 to 31 (when it should be 1 to 32 if its an actual player id, and #1-#XXX if it's a userid) and stopping when the arg matches the loop index value. Why don't you just skip this part? Maybe use cmd_target() instead to validate it hit a valid, and acceptable, player index.

Bugsy 12-02-2014 22:26

Re: error 035: argument type mismatch (argument 1)
 
Quote:

Originally Posted by Mofforg (Post 2230625)
Why "len" errors here? It's just a buffer, so a string. As it's not defined what type is it, it should be automatically become a string, is it?

No, this isn't Visual Basic.

Why don't you try something like this. It accepts all or part of the users name, or the userid number (#12).
- amx_internalbancommand bugs
- amx_internalbancommand #12

PHP Code:

public plugin_init() 
{
    
register_clcmd"amx_internalbancommand" "BanCmd" );
}

public 
BanCmdid )
{
    new 
szArg33 ] , idTarget szName33 ];
    
    
read_argvszArg charsmaxszArg ) );
    
idTarget cmd_targetid szArg ); //3rd param has flags to control who can be selected, see below

    
if ( idTarget )
    {
        
get_user_nameidTarget szName charsmaxszName ) );
        
client_printid print_chat "You used ban cmd on '%s'" szName );
    }
    
    return 
PLUGIN_HANDLED;


Flags for cmd_target (already defined by default), just use flag(s)
#define CMDTARGET_OBEY_IMMUNITY (1<<0)
#define CMDTARGET_ALLOW_SELF (1<<1)
#define CMDTARGET_ONLY_ALIVE (1<<2)
#define CMDTARGET_NO_BOTS (1<<3)

To use multiple, use bit-wise OR
CMDTARGET_NO_BOTS | CMDTARGET_OBEY_IMMUNITY

Mofforg 12-02-2014 23:38

Re: error 035: argument type mismatch (argument 1)
 
Quote:

Originally Posted by Bugsy (Post 2230630)
Why don't you try something like this. It accepts all or part of the users name, or the userid number (#12).
- amx_internalbancommand bugs
- amx_internalbancommand #12

PHP Code:

public plugin_init() 
{
    
register_clcmd"amx_internalbancommand" "BanCmd" );
}

public 
BanCmdid )
{
    new 
szArg33 ] , idTarget szName33 ];
    
    
read_argvszArg charsmaxszArg ) );
    
idTarget cmd_targetid szArg ); //3rd param has flags to control who can be selected, see below

    
if ( idTarget )
    {
        
get_user_nameidTarget szName charsmaxszName ) );
        
client_printid print_chat "You used ban cmd on '%s'" szName );
    }
    
    return 
PLUGIN_HANDLED;


Flags for cmd_target (already defined by default), just use flag(s)
#define CMDTARGET_OBEY_IMMUNITY (1<<0)
#define CMDTARGET_ALLOW_SELF (1<<1)
#define CMDTARGET_ONLY_ALIVE (1<<2)
#define CMDTARGET_NO_BOTS (1<<3)

To use multiple, use bit-wise OR
CMDTARGET_NO_BOTS | CMDTARGET_OBEY_IMMUNITY

Thanks, that's an ideal of accepting both userid and username. I made your way, now works! I can use only client_command through (can not BanCmd) because bansystem is closed-source and i can not edit it. And bansystem have no forward functions.

I did not consider to use cmd_target because i can not find full documentation on it (i even did not know that function before you told me about it). I am not sure what exactly does it do, what for does here the first argument and what does it mean.

PHP Code:

    if(equal(command[0],"amx_internalbancommand",22))
    {
        new 
idTarget;
        
idTarget cmd_targetid command[1] , CMDTARGET_ALLOW_SELF );
        
        if ( 
idTarget )
        {
            ...
        }
    } 


Bugsy 12-03-2014 09:06

Re: error 035: argument type mismatch (argument 1)
 
Ok, I wasn't sure what you were doing but it looks like you figured it out. The first arg (id) is the player who used the command.


All times are GMT -4. The time now is 15:24.

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