Raised This Month: $32 Target: $400
 8% 

some answers about return 0/1 etc


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 03-25-2021 , 14:13   some answers about return 0/1 etc
Reply With Quote #1

i've tried to rewrite some admin commands (from default), for making an all in one mod for my server.

No matter what admin command i write, console return me:

Code:
amx_kick id
Command amx_kick not found
How can i avoid 'not found'?

Some example of code:

Code:
public AdminKick ( iEntity, iLevel, iCID ) {
	if ( !cmd_access ( iEntity, iLevel, iCID, 2 ) ) {
		console_print ( iEntity, "[MIX] You have no access." );
		return;
	}

	new iEntityArgument [ 32 ], iEntityReason [ 16 ];
	read_argv ( 1, iEntityArgument, charsmax ( iEntityArgument ) );
	read_argv ( 2, iEntityReason, charsmax ( iEntityReason ) );

	if ( !strlen ( iEntityArgument ) || !strlen ( iEntityReason ) )
		return;

	new iEntityTarget = cmd_target ( iEntity, iEntityArgument, 9 );

	if ( !iEntityTarget )
		return;

	if ( !is_user_connected ( iEntityTarget ) )
		return;

	new iStatement [ 256 ];
	formatex ( iStatement, charsmax ( iStatement ), "INSERT INTO `admincmd_last` ( `admin_name`, `command_used`, `target_name`, `timestamp` ) VALUES ( '%s', 'kick', '%s', '%0.2f' )", gPlayerName [ iEntity ], gPlayerName [ iEntityTarget ], get_systime ( ) );
	SQL_ThreadQuery ( gSQLTuple, "SQL_Ignore", iStatement );

	server_cmd ( "kick #%d ^"%s^"", get_user_userid ( iEntityTarget ), iEntityReason );
        return 1;
}
no matter what return i use (HANDLED, HANDLED_MAIN, CONTINUE) it throws me this error.
__________________
LondoN is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-25-2021 , 14:53   Re: some answers about return 0/1 etc
Reply With Quote #2

Wut? AMXX says "uknown command" if the command doesn't exist, not "not found".
Show how you're registering it.

------------------------

Code:
console_print ( iEntity, "[MIX] You have no access." );

This message is already printed by "cmd_access" by default.

------------------------

Code:
if ( !strlen ( iEntityArgument ) || !strlen ( iEntityReason ) )         return;

This is also automatically checked by "cmd_access" but you should set the number of arguments to 3 instead of 2 because the command itself is also counted.

------------------------

Code:
new iEntityTarget = cmd_target ( iEntity, iEntityArgument, 9 );

What is 9? Why use magic numbers?

------------------------

Code:
if ( !is_user_connected ( iEntityTarget ) )         return;

This can never happen.

------------------------

Code:
'%.02f' get_systime()

get_systime() doesn't return a float.

------------------------

Code:
return 1;

Again, magic numbers. PLUGIN_HANDLED exists for a reason.

PS: iEntityArgument, iEntityReason, iStatement. The "i" stands for integer. None of these are integers.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-25-2021 , 23:43   Re: some answers about return 0/1 etc
Reply With Quote #3

You should always use pre-defined variable/defines when available for return codes and flags. For example, the flags for cmd_target() should be using the defined names for the flags (defined in amxmisc.inc just above where the function itself is defined). For this type of flag (bitwise), you can use the bitwise OR (the pipe character, "|") to combine them. Return codes for the register_*() functions are defined in amxconst.inc.

Is your space bar about to wear out? Can you use any more spaces in your code?
__________________
fysiks is offline
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 23:02.


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