AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   random_num issue (https://forums.alliedmods.net/showthread.php?t=220568)

Mofforg 07-12-2013 00:23

random_num issue
 
Here's a part of my little plugin to filter player nicknames.

PHP Code:

public client_connect(id)
{
...
static 
pName[25];
get_user_name idpName24 );
if (
strlen(pName) < 4)
{
    
set_user_info(id"name""Short name!%d",random_num(1,999999))
    return 
PLUGIN_HANDLED
}
...


returns:

PHP Code:

error 088number of arguments does not match definition 

What's wrong?

zi443r 07-12-2013 01:09

Re: random_num issue
 
PHP Code:

set_user_info index, const info[], const value[] ) 


ConnorMcLeod 07-12-2013 01:12

Re: random_num issue
 
Also, as most of amxx natives, get_user_name is already returning the string len, so you can do :

if( get_user_name(id, szName, charsmax(szName)) < 4 )

Mofforg 07-12-2013 09:14

Re: random_num issue
 
Quote:

Originally Posted by zi443r (Post 1989118)
PHP Code:

set_user_info index, const info[], const value[] ) 


I know that, but i want to do %d in the const value[].

YamiKaitou 07-12-2013 09:18

Re: random_num issue
 
Quote:

Originally Posted by Mofforg (Post 1989299)
I know that, but i want to do %d in the const value[].

You can't. Format it first

Mofforg 07-12-2013 10:09

Re: random_num issue
 
Quote:

Originally Posted by YamiKaitou (Post 1989307)
You can't. Format it first

Is that correct?
PHP Code:

static shortname[25];
format(shortname24"Short name!%d"random_num(1,999999))
set_user_info(id"name"shortname


claudiuhks 07-12-2013 10:36

Re: random_num issue
 
Quote:

Originally Posted by Mofforg (Post 1989347)
Is that correct?
PHP Code:

static shortname[25];
format(shortname24"Short name!%d"random_num(1,999999))
set_user_info(id"name"shortname


It's alright, but you should use formatex for more efficiency. Check that: http://docs.sourcemod.net/api/

First, check for Format and then for FormatEx to see the difference. They'll make you understand better than me. This is for Source Mod, but the documentation seems better and the natives are approximately same.

An example:

PHP Code:

static AString[32];
AString "claudiuhks";
format(AString31"hattrick_%s"AString);
//result: hattrick_claudiuhks

static BString[32];
BString "claudiuhks";
formatex(BString31"hattrick_claudiuhks" /* can't use argument BString since you format it */);
//result: hattrick_claudiuhks 


Mofforg 07-12-2013 10:54

Re: random_num issue
 
Quote:

Originally Posted by claudiuhks (Post 1989363)
It's alright, but you should use formatex for more efficiency. Check that: http://docs.sourcemod.net/api/

First, check for Format and then for FormatEx to see the difference. They'll make you understand better than me. This is for Source Mod, but the documentation seems better and the natives are approximately same.

An example:

PHP Code:

static AString[32];
AString "claudiuhks";
format(AString31"hattrick_%s"AString);
//result: hattrick_claudiuhks

static BString[32];
BString "claudiuhks";
formatex(BString31"hattrick_claudiuhks" /* can't use argument BString since you format it */);
//result: hattrick_claudiuhks 


Thanks. Changed format( to fomated( in all my plugins =)

fysiks 07-15-2013 18:22

Re: random_num issue
 
Quote:

Originally Posted by Mofforg (Post 1989377)
Thanks. Changed format( to fomated( in all my plugins =)

I hope you checked for the validity of changing it.

Mofforg 07-16-2013 05:47

Re: random_num issue
 
Quote:

Originally Posted by fysiks (Post 1991686)
I hope you checked for the validity of changing it.

As i can see here's nothing needed to be changed in syntax. Am i wrong?


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

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