Raised This Month: $51 Target: $400
 12% 

random_num issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 07-12-2013 , 00:23   random_num issue
Reply With Quote #1

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?

Last edited by Mofforg; 07-12-2013 at 00:25.
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
zi443r
Senior Member
Join Date: Mar 2009
Location: Braila,Romania
Old 07-12-2013 , 01:09   Re: random_num issue
Reply With Quote #2

PHP Code:
set_user_info index, const info[], const value[] ) 
__________________

Last edited by zi443r; 07-12-2013 at 01:09.
zi443r is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-12-2013 , 01:12   Re: random_num issue
Reply With Quote #3

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 )
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 07-12-2013 , 09:14   Re: random_num issue
Reply With Quote #4

Quote:
Originally Posted by zi443r View Post
PHP Code:
set_user_info index, const info[], const value[] ) 
I know that, but i want to do %d in the const value[].
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-12-2013 , 09:18   Re: random_num issue
Reply With Quote #5

Quote:
Originally Posted by Mofforg View Post
I know that, but i want to do %d in the const value[].
You can't. Format it first
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 07-12-2013 , 10:09   Re: random_num issue
Reply With Quote #6

Quote:
Originally Posted by YamiKaitou View Post
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
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 07-12-2013 , 10:36   Re: random_num issue
Reply With Quote #7

Quote:
Originally Posted by Mofforg View Post
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 
__________________

Last edited by claudiuhks; 07-12-2013 at 10:45.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 07-12-2013 , 10:54   Re: random_num issue
Reply With Quote #8

Quote:
Originally Posted by claudiuhks View Post
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 =)
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-15-2013 , 18:22   Re: random_num issue
Reply With Quote #9

Quote:
Originally Posted by Mofforg View Post
Thanks. Changed format( to fomated( in all my plugins =)
I hope you checked for the validity of changing it.
__________________
fysiks is offline
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 07-16-2013 , 05:47   Re: random_num issue
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
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?
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
Reply



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 17:17.


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