Raised This Month: $ Target: $400
 0% 

Problem with agrument reading


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vbSteve
Junior Member
Join Date: Jun 2006
Old 06-05-2007 , 06:09   Problem with agrument reading
Reply With Quote #1

Hi,

I'm making a plugin that will work as a clan chat (a private chat system for clan members only)

I'm having problems with reading the first argument of the command amx_clansay <Message>, which I bound to "messagemode amx_clansay". Everytime I use it, it keeps resulting in the same error:
Usage: amx_clansay <Message>

I'm desperate (Ive been looking for hours and hours), and I can't find where I'm wrong; maybe you guys can find it. I'm guessing it's something to do with "read_argv(1, argSay, 255);"

Here's a the part of the code that needs attention:

Code:
#include <amxmodx>

#define ADM_LEVEL ADMIN_LEVEL_H
#define msgPrefix "[Clan]"
#define Color "^x04" 		// Green

public plugin_init(){
	register_plugin("Clan Chat", "1.0.7", "mCoDev Systems");
	
	register_concmd("amx_clansay", "do_clansay", ADM_LEVEL, " <Message>");

	return PLUGIN_HANDLED;
}

public do_clansay(id, level, cid){
	new argSay[256];  // Hold command argument
	new tMsg[256];   // Hold Message
	new pName[33];    // Hold playername
	new p = get_maxplayers(); // Max players.
	new pid;  // Hold player id

	read_argv(1, argSay, 255);
	
	if (!cmd_access(id, level, cid, 3)) return PLUGIN_HANDLED;
	
	get_user_name(id, pName, 32);
	format(tMsg, 255, "%s %s %s: %s", Color, msgPrefix, pName, argSay);
	
	for(pid=1; pid <= p; ++pid){
		if(get_user_flags(pid) & ADM_LEVEL){
			if(is_user_connected(pid)){
				print_message(pid, tMsg); // Subroutine print_message.
			}
		}
	}
	
	return PLUGIN_HANDLED;
}


Many thanks in advance.
Steve
vbSteve is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-05-2007 , 06:25   Re: Problem with agrument reading
Reply With Quote #2

I think you have to write the message in "" with this way...
You could try to do a for-loop and get all the arguments(the single words of the message)
This let you get the number of arguments (words)
Code:
get_msg_args()
greetz regalis
__________________
regalis is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-05-2007 , 06:50   Re: Problem with agrument reading
Reply With Quote #3

1) use get_players(). NEVER use get_maxplayers() like that again.
2) use read_args(). read_argv(1, ...) gets the first argument.
_Master_ is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-05-2007 , 06:54   Re: Problem with agrument reading
Reply With Quote #4

Quote:
Originally Posted by _Master_ View Post
1) use get_players(). NEVER use get_maxplayers() like that again.
2) use read_args(). read_argv(1, ...) gets the first argument.
You are the master!
You won the thread
__________________
regalis is offline
vbSteve
Junior Member
Join Date: Jun 2006
Old 06-05-2007 , 07:39   Re: Problem with agrument reading
Reply With Quote #5

Hi,

Still didn't work.
It works when I use it with more than 1 parameters, but it has to work with only 1 too. I copied a part from my console (client side):
Code:
Type 'amx_help' in the console to see available commands
Time Left: 29:10 min. Next Map: cs_militia_cz
Usage:  amx_clansay  <Message>       -----> Used this with "messagemode amx_clansay"
] amx_clansay yo
Usage:  amx_clansay  <Message>
] amx_clansay "yo"
Usage:  amx_clansay  <Message>
] amx_clansay yo yo 
[Clan] ``TeamDW| Lumos: yo yo 
] amx_clansay "yo" 0
[Clan] ``TeamDW| Lumos: "yo" 0
] amx_clansay "yo yo"
Usage:  amx_clansay  <Message>
Tried with get_msg_args, but then resulted in compile err "undefined symbol"
Now changed code code to:

Code:
#include <amxmodx>
#include <amxmisc>

#define ADM_LEVEL ADMIN_LEVEL_H
#define msgPrefix "[Clan]"
#define Color "^x04" 		// Green

new gSayText;

public plugin_init(){
	register_plugin("Clan Chat", "1.0.23", "mCoDev Systems");
	
	register_concmd("amx_clansay", "do_clansay", ADM_LEVEL, " <Message>");
	//register_concmd("amx_clantsay", "do_clantsay", ADM_LEVEL, " <Message>");
	//register_concmd("amx_clansayall", "do_clansayall", ADM_LEVEL, " <Message>");

	gSayText = get_user_msgid("SayText");
	
	return PLUGIN_HANDLED;
}

public do_clansay(id, level, cid){
	new argSay[255];		// Hold argument
	new tMsg[256];			// Hold new message
	new pName[33];			// Hold playername
	new pid;			// Hold player ID, Hold counter
	new p = get_maxplayers();
	
	if (!cmd_access(id, level, cid, 3)) return PLUGIN_HANDLED;
		
	read_args(argSay, 254);
	
	get_user_name(id, pName, 32);
	format(tMsg, 255, "%s %s %s: %s", Color, msgPrefix, pName, argSay);
	
	for(pid=1; pid <= p; ++pid){
		if(get_user_flags(pid) & ADM_LEVEL){
			if(is_user_connected(pid)){
				server_print("(%i) %s %s: %s", pid, msgPrefix, pName, argSay);
				client_print(pid, print_console, "%s %s: %s", msgPrefix, pName, argSay);
				
				message_begin(MSG_ONE, gSayText, {0,0,0}, pid);
				write_byte(pid);
				write_string(tMsg);
				message_end();
			}
		}
	}
	
	return PLUGIN_HANDLED;
}
Thanks.

Last edited by vbSteve; 06-05-2007 at 07:44.
vbSteve is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-05-2007 , 07:51   Re: Problem with agrument reading
Reply With Quote #6

Actually it ONLY works when you use it with more than (or equal to) 2 arguments.
PHP Code:
if (!cmd_access(idlevelcid3)) return PLUGIN_HANDLED
http://forums.alliedmods.net/showthread.php?t=55149

Last edited by _Master_; 06-05-2007 at 08:02. Reason: messed up args no.
_Master_ is offline
vbSteve
Junior Member
Join Date: Jun 2006
Old 06-05-2007 , 08:01   Re: Problem with agrument reading
Reply With Quote #7

lol. Yeah that makes sens, in fact it works now perfect =) Thanks loads
vbSteve 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 10:33.


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