Chat Commands
#1

Hello everyone. I made some chat commands, but i have some problems with them! Here i'll show you screenshots of the issue, and i'll post the pawno codes for those who might be able to fix it

Problem Screenshots:



Problem Codes:

1. /do

Код:
	if (strcmp("/do", cmdtext, true, 10) == 0)
	{
    	new str[128];
    	if(sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /do [TEXT]");
    	new name[20];
    	GetPlayerName(playerid,name,20);
    	format(str,sizeof(str),"** %s ((%s))",str,name);
		new Float:X,Float:Y,Float:Z;
    	GetPlayerPos(playerid,X,Y,Z);
    	for(new i = 0;i<MAX_PLAYERS;++i)
    	{
			if(IsPlayerInRangeOfPoint(i,5,X,Y,Z)) SendClientMessage(i,-1,str);
			return 0;
		}
    	return 1;
	}
2. /me

Код:
 	if (strcmp("/me", cmdtext, true, 10) == 0)
	{
    	new str[128];
    	if(sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /me [TEXT]");
    	new name[20];
    	GetPlayerName(playerid,name,20);
    	format(str,sizeof(str),"** %s %s **",name,str);
		new Float:X,Float:Y,Float:Z;
    	GetPlayerPos(playerid,X,Y,Z);
    	for(new i = 0;i<MAX_PLAYERS;++i)
    	{
        	if(IsPlayerInRangeOfPoint(i,5,X,Y,Z)) SendClientMessage(i,-1,str);
        	return 0;
    	}
    	return 1;
	}
3. /b

Код:
	if (strcmp("/b", cmdtext, true, 10) == 0)
	{
    	new str[128];
    	if(sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /b [TEXT]");
    	new name[20];
    	GetPlayerName(playerid,name,20);
    	format(str,sizeof(str),"((%s: %s))",name,str);
		new Float:X,Float:Y,Float:Z;
    	GetPlayerPos(playerid,X,Y,Z);
    	for(new i = 0;i<MAX_PLAYERS;++i)
    	{
			if(IsPlayerInRangeOfPoint(i,5,X,Y,Z)) SendClientMessage(i,-1,str);
			return 0;
		}
    	return 1;
	}
4. /o

Код:
	if (strcmp("/o", cmdtext, true, 10) == 0)
	{
    	new str[128];
    	if(sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /o [TEXT]");
    	new name[20];
    	GetPlayerName(playerid,name,20);
    	format(str,sizeof(str),"[OOC] %s[%d]: %s",name,playerid,str);
    	SendClientMessageToAll(-1,str);
    	return 1;
	}
I hope someone is able to fix it !

Greetings, CrazyManiac.

NOTE: When i type a chat command followed by text (Example: /me takes a shit), it says Unknown Command.

NOTE: For those who were gonna ask if i have sscanf, i do.
Код:
#include <sscanf2>
Reply
#2

PHP код:
if (strcmp("/do"cmdtexttrue10) == 0)
    {
        new 
str[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /do [TEXT]");
        new 
name[20];
        
GetPlayerName(playerid,name,20);
        
format(str,sizeof(str),"** %s ((%s))",str,name);
        new 
Float:X,Float:Y,Float:Z;
        
GetPlayerPos(playerid,X,Y,Z);
        for(new 
0;i<MAX_PLAYERS;++i)
        {
            if(
IsPlayerInRangeOfPoint(i,5,X,Y,Z)) return SendClientMessage(i,-1,str);
        }
        return 
1;
    } 
PHP код:
if (strcmp("/me"cmdtexttrue10) == 0)
    {
        new 
str[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /me [TEXT]");
        new 
name[20];
        
GetPlayerName(playerid,name,20);
        
format(str,sizeof(str),"** %s %s **",name,str);
        new 
Float:X,Float:Y,Float:Z;
        
GetPlayerPos(playerid,X,Y,Z);
        for(new 
0;i<MAX_PLAYERS;++i)
        {
            if(
IsPlayerInRangeOfPoint(i,5,X,Y,Z)) return SendClientMessage(i,-1,str);
        }
        return 
1;
    } 
PHP код:
if (strcmp("/b"cmdtexttrue10) == 0)
    {
        new 
str[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /b [TEXT]");
        new 
name[20];
        
GetPlayerName(playerid,name,20);
        
format(str,sizeof(str),"((%s: %s))",name,str);
        new 
Float:X,Float:Y,Float:Z;
        
GetPlayerPos(playerid,X,Y,Z);
        for(new 
0;i<MAX_PLAYERS;++i)
        {
            if(
IsPlayerInRangeOfPoint(i,5,X,Y,Z)) return SendClientMessage(i,-1,str);
        }
        return 
1;
    } 
Try them, you had return 0; which you don't need.

PHP код:
if (strcmp("/o"cmdtexttrue2) == 0)
    {
        new 
str[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /o [TEXT]");
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playerid,name,sizeof(name));
        
format(str,sizeof(str),"[OOC] %s[%d]: %s",name,playerid,str);
        
SendClientMessageToAll(-1,str);
        return 
1;
    } 
Reply
#3

Tried them, but didnt work out well.

/o
How it has to be: [OOC] CrazyManiac[0]: Yo.
How it is now: [OOC] CrazyManiac[0]: /o Yo.

/b
How it has to be: ((CrazyManiac: You hired a doo lol?))
How it is now: ((CrazyManiac: /b))
When i type /b followed by text (Example: /b You hired a shit?), it says Unknown Command.

/me
How it has to be: ** CrazyManiac takes a doo. **
How it is now: ** CrazyManiac /me **
When i type /me followed by text (Example: /me takes a shit), it says Unknown Command.

/do
How it has to be: ** You see a shit ((CrazyManiac))
How it is now: ** /do ((CrazyManiac))
When i type /do followed by text (Example: /do You see a shit), it says Unknown Command.

Hope someone can fix it.
Reply
#4

Oh I see,

PHP код:
if (strcmp("/do"cmdtexttrue3) == 0)
    {
        new 
str[128],string[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /do [TEXT]");
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playerid,name,sizeof(name));
        
format(string,sizeof(string),"** %s ((%s))",str,name);
        new 
Float:X,Float:Y,Float:Z;
        
GetPlayerPos(playerid,X,Y,Z);
        for(new 
0;i<MAX_PLAYERS;++i)
        {
            if(
IsPlayerInRangeOfPoint(i,5,X,Y,Z)) return SendClientMessage(i,-1,string);
        }
        return 
1;
    } 
PHP код:
if (strcmp("/me"cmdtexttrue3) == 0)
    {
        new 
str[128],string[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /me [TEXT]");
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playerid,name,sizeof(name));
        
format(string,sizeof(string),"** %s %s **",name,string);
        new 
Float:X,Float:Y,Float:Z;
        
GetPlayerPos(playerid,X,Y,Z);
        for(new 
0;i<MAX_PLAYERS;++i)
        {
            if(
IsPlayerInRangeOfPoint(i,5,X,Y,Z)) return SendClientMessage(i,-1,string);
        }
        return 
1;
    } 
PHP код:
if (strcmp("/b"cmdtexttrue2) == 0)
    {
        new 
str[128],string[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /b [TEXT]");
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playerid,name,sizeof(name));
        
format(string,sizeof(string),"((%s: %s))",name,str);
        new 
Float:X,Float:Y,Float:Z;
        
GetPlayerPos(playerid,X,Y,Z);
        for(new 
0;i<MAX_PLAYERS;++i)
        {
            if(
IsPlayerInRangeOfPoint(i,5,X,Y,Z)) return SendClientMessage(i,-1,string);
        }
        return 
1;
    } 
PHP код:
if (strcmp("/o"cmdtexttrue2) == 0)
    {
        new 
str[128],string[128];
        if(
sscanf(cmdtext,"s[128]",str)) return SendClientMessage(playerid,-1,"USAGE: /o [TEXT]");
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playerid,name,sizeof(name));
        
format(string,sizeof(string),"[OOC] %s[%d]: %s",name,playerid,str);
        
SendClientMessageToAll(-1,string);
        return 
1;
    } 
String confliction.
Reply
#5

Firstly, yours 'b' command is not 10 characters long, only 2 (slash and name of command)

pawn Код:
if(strcmp("/b", cmdtext, true, 2) == 0)
{
    new string[128], name[MAX_PLAYER_NAME];
    if(sscanf(cmdtext,"s[128]",str))return SendClientMessage(playerid,-1,"USAGE: /b [TEXT]");
    {
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "((%s: %s))", name, string);

        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
       
        for(new i = 0; i <= MAX_PLAYERS; i++)
        {
            if(IsPlayerInRangeOfPoint(i, 5.0, X, Y, Z))
            {
                SendClientMessage(i, -1, string);
            }
        }
    }
    return true;
}
Secondly, remember about indentation. Thirdly player name can be 24 characters long, not 20 so i'd rather you to use MAX_PLAYER_NAME define or 24 than 20.
Reply
#6

@gtakillerIV: Doesn't looks good bro! Lol.


@Riddick94: Well, could you make it for me then?
Reply
#7

It has to do something with "returns" i am positive but i don't know what since i am not fully into strcmp.
Reply
#8

PHP код:
    if(!strcmp("/do"cmdtexttrue))
    {
        
// Create array...
        
static
            
str[128]
        ;
        
        
// Format Array "str"
        
if(sscanf(cmdtext,"s[128]",str))
            return 
SendClientMessage(playerid,-1,"USAGE: /do [TEXT]");
            

        
// Create Array to get name of player
        
static
            
name[24// MaxPlayer name is 24!
        
;

        
// Formating message
        
format(str,sizeof(str),"** %s ((%s))",str,(GetPlayerName(playerid,name,20), name));
        
        
        
// Create floats.
        
static
            
Float:X,
            
Float:Y,
            
Float:Z
        
;
        
        
// Store Player pos in floats createds.
        
GetPlayerPos(playerid,X,Y,Z);
        
        
        
// Making loop(otimized).
        
        // Create variables to incremment and to store sever slots.
        
static
            
Interator,
            
MaxPlayer
        
;
        
        
// Reseting variables, after don't show errors.
        
Interator 0;
        
MaxPlayers GetMaxPlayers();
        
        
// Looopiing..
        
for(;  Interator != MaxPlayers; ++Interator)
        {
            
/// if's players near player exibe message.
            
if(IsPlayerInRangeOfPoint(Interator,5,X,Y,Z))
            {
                
SendClientMessage(Interator,-1,str);
            }
        }
        return 
1;
    } 
Sorry my english, i'm Brazilian boy.
Reply
#9

Check this out.
https://sampforum.blast.hk/showthread.php?tid=336052
Reply
#10

Did you tried my code? Just replace yours old one with mine and test it. If you still have a problem then you should swap to another command processor, for example ZeeX's Command Processor or ******'s.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)