[Help] problem with /me and etc.
#1

Yo, i made a script for /me; /do and etc. but i got a problem.
The problem is when i type ex."/me grabs his gun from the table" it will say "Firstname_Lastname grabs" instead of "Firstname_Lastname grabs his gun from the table".
It always shows only the first word..
Код:
	if(strcmp("/me", cmd, true) == 0)
		{
		new tmp[256];
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /me [Action]");
		new name[MAX_PLAYER_NAME];
		GetPlayerName(playerid, name, sizeof name);
		format(cmdtext, 128, "* %s %s ", name, tmp );
		new Float:x, Float:y, Float:z;
		GetPlayerPos(playerid, x, y, z);
		for(new i, m = GetMaxPlayers(); i < m; i++) if (IsPlayerConnected(i))
		{
		if (IsPlayerInRangeOfPoint(i, 15.0, x, y, z)) SendClientMessage(i, COLOR_PURPLE, cmdtext);
		}
		return 1;
		}
Please tell me where is the problem and how to fix it.
Its maybe very easy but i am still new.
Reply
#2

The function "strtok" only takes one word. Not a whole sentence.
Код:
if(!strcmp(cmdtext, "/me", true, 3))
{
     if(cmdtext[3] == 0)
    {
      SendClientMessage(playerid, white, "USAGE: /me [action]");
      return 1;
    }
    new str[128];
    GetPlayerName(playerid, str, sizeof(str));
    format(str, sizeof(str), "%s %s", str, cmdtext[4]);
    SendClientMessageToAll(COLOR_WHITE, str);
    return 1;
}
Reply
#3

This script makes problems.
If i type "/mewhatsup" it will say "Firstname_Lastname hatsup" instead of "Unknown command"
It sounds like a little problem which can be ignored but it makes big problems with other commands. for example i got command
"/skin" but with this script it will mess with "/s" command and "/skin" wont work but will say "Firstname_Lastname shouts: kin"
Reply
#4

hmmm, show us your /shout command
Reply
#5

Quote:
Originally Posted by Varna
This script makes problems.
If i type "/mewhatsup" it will say "Firstname_Lastname hatsup" instead of "Unknown command"
It sounds like a little problem which can be ignored but it makes big problems with other commands. for example i got command
"/skin" but with this script it will mess with "/s" command and "/skin" wont work but will say "Firstname_Lastname shouts: kin"
You are very correct Varna, let me show you the two commands:

Код:
if(!strcmp(cmdtext,"/s",true,2)) 
{
	if(cmdtext[4] == " ") return SendClientMessage(playerid,"0x0000ff,"USAGE: /s text");
	
	new str[128],name[MAX_PLAYERNAME];
	GetPlayerName(playerid,name,sizeof(name));
	format(str,sizeof(str),"%s [ID: %d] shouts: %s,name,playerid,cmdtext[3])
	SendClientMessageToAll(0xffffffaa,str);
	
	return 1;
}
Код:
if(!strcmp(cmdtext,"/skin",true,5))
{
	new tmp[56], skin, Index;
	
	tmp=strtok(cmdtext,Index);
	if(!strlen(tmp)) return SendClientMessage(playerid,0xff0000aa,"USAGE: /skin skinid");
	
	skin=strval(tmp);
	if(skin<0 || skin>299) return SendClientMessage(playerid,0xffffffaa,"Invalid Skin Id);

	SetPlayerSkin(playerid,skin);
	SendClientMessage(playerid,0x00ffffaa,"You have changed your skin successfully");

	return 1;
}
Now if you type in /s and you don't have anything in front, it will say USAGE : /s text. If you type /skin and nothing after it, then it will say USAGE: /skin skinid.
Reply
#6

Quote:
Originally Posted by DJDhan
Quote:
Originally Posted by Varna
This script makes problems.
If i type "/mewhatsup" it will say "Firstname_Lastname hatsup" instead of "Unknown command"
It sounds like a little problem which can be ignored but it makes big problems with other commands. for example i got command
"/skin" but with this script it will mess with "/s" command and "/skin" wont work but will say "Firstname_Lastname shouts: kin"
You are very correct Varna, let me show you the two commands:

Код:
if(!strcmp(cmdtext,"/s",true,2)) 
{
	if(cmdtext[4] == " ") return SendClientMessage(playerid,"0x0000ff,"USAGE: /s text");
	
	new str[128],name[MAX_PLAYERNAME];
	GetPlayerName(playerid,name,sizeof(name));
	format(str,sizeof(str),"%s [ID: %d] shouts: %s,name,playerid,cmdtext[3])
	SendClientMessageToAll(0xffffffaa,str);
	
	return 1;
}
Код:
if(!strcmp(cmdtext,"/skin",true,5))
{
	new tmp[56], skin, Index;
	
	tmp=strtok(cmdtext,Index);
	if(!strlen(tmp)) return SendClientMessage(playerid,0xff0000aa,"USAGE: /skin skinid");
	
	skin=strval(tmp);
	if(skin<0 || skin>299) return SendClientMessage(playerid,0xffffffaa,"Invalid Skin Id);

	SetPlayerSkin(playerid,skin);
	SendClientMessage(playerid,0x00ffffaa,"You have changed your skin successfully");

	return 1;
}
Now if you type in /s and you don't have anything in front, it will say USAGE : /s text. If you type /skin and nothing after it, then it will say USAGE: /skin skinid.
Your /s command script gives me these errors:

E:\Bayside - Roleplay\gamemodes\Bayside-RPG.pwn(391) : error 033: array must be indexed (variable "-unknown-")
E:\Bayside - Roleplay\gamemodes\Bayside-RPG.pwn(391) : error 001: expected token: "-string end-", but found "-identifier-"
E:\Bayside - Roleplay\gamemodes\Bayside-RPG.pwn(391) : error 029: invalid expression, assumed zero
E:\Bayside - Roleplay\gamemodes\Bayside-RPG.pwn(391) : fatal error 107: too many error messages on one line

PS - I just showed random example (with /s and /skin) how commands can mess up if i use this script.
Reply
#7

Sorry about that:

Код:
if(!strcmp(cmdtext,"/s",true,2)) 
{
	if(cmdtext[4] == " ") return SendClientMessage(playerid,"0x0000ff,"USAGE: /s text");
	
	new str[128],name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
	format(str,sizeof(str),"%s [ID: %d] shouts: %s",name,playerid,cmdtext[3])
	SendClientMessageToAll(0xffffffaa,str);
	
	return 1;
}
And yes, I am giving these examples to let you know that my examples don't mix and mess up. Try to get the difference between your command and my examples.
Reply
#8

I get same errors again ..
All the errors are on this line
Код:
	if(cmdtext[4] == " ") return SendClientMessage(playerid,"0x0000ff,"USAGE: /s text");
Reply
#9

Pff ok
Код:
if(!strcmp(cmdtext,"/s",true,2)) 
{
	if(cmdtext[3] == " ")
       { 
       SendClientMessage(playerid,"0x0000ff,"USAGE: /s text");
       return 1;
       }
	
	new str[128],name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
	format(str,sizeof(str),"%s [ID: %d] shouts: %s",name,playerid,cmdtext[3])
	SendClientMessageToAll(0xffffffaa,str);
	
	return 1;
}
Reply
#10

Dude, don't post untested scripts. I still get same errors on this line:
Код:
SendClientMessage(playerid,"0x0000ff,"USAGE: /s text");


EDIT: I fixed the errors in your script but it still makes the problems that i mentioned before.
I will try to explain it again:

*I type "/s Hey" in the game console*
Steven_Anderson shouts: Hey
*I type "/sHey" in the game console*
Steven_Anderson shouts: ey
*I type "/skin 120" in the game console*
Steven_Anderson shouts: in 120

PS - I do not have command "/skin". I just give example how the commands can mess up with this script!

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)