SA-MP Forums Archive
[Help] COmmand - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Help] COmmand (/showthread.php?tid=81586)



[Help] COmmand - borisblat - 12.06.2009

Код:
Quote:
if(strcmp(cmdtext, "/InviteDrift", true) == 0) { tmp = strtok(cmdtext, idx); new string[256], string2[256]; new otherplayer = strval(tmp); new name[MAX_PLAYER_NAME]; new opname[MAX_PLAYER_NAME]; GetPlayerName(playerid,name,sizeof(name)); GetPlayerName(otherplayer,opname,sizeof(opname)); if(!strlen(tmp)) return SendClientMessage(playerid, WHITE, "Use: /InviteDrift [playerid]"); format(string,sizeof(string), ".Drift - [ID:%d | %s] הוזמנת לקרב על ידי השחקן", playerid, name); format(string2,sizeof(string2), ".Drift - לדריפט [ID:%d | %s] הזמנת בהצלחה את השחקן", otherplayer, opname); SendClientMessage(otherplayer, LIGHTBLUE, string); SendClientMessage(playerid, LIGHTBLUE, string2); return 1; }
it's says me unknown command
why? :S




Re: [Help] COmmand - Luca Dimonte - 12.06.2009

Here

if(strcmp(cmdtext, "/InviteDrift", true) == 0)
{

tmp = strtok(cmdtext, idx);

you are comparing the whole thing typed by the player (maybe "/invitedrift 5"?), so that's different from "/Invitedrift", and will never find the command.

Later you store in tmp the playerid.

tmp = strtok(cmdtext, idx);

If you see that, you forgot to do the same in the if statement. It would be

tmp = strtok (cmdtext, idx); // added
if(strcmp(tmp, "/InviteDrift", true) == 0)
{
tmp = strtok(cmdtext, idx);



Re: [Help] COmmand - borisblat - 12.06.2009

so i put "tmp" instead "cmdtext"?

modify: don't work XD, and i didn't really understood, you said too much times "tmp = strtok "


Re: [Help] COmmand - Luca Dimonte - 12.06.2009

You use strtok to split a player command, and analize separately each word in the command

"/Invitedrift 5"

are two words: "/invitedrift" and "5", both on cmdtext. You can't analize cmdtext within an 'if (strcmp(blabla) == 0)' because you get all the words and it fails on what you want, so your first need is to get the command word. That's why you use strtok for first time

tmp = strtok (cmdtext, idx) // first use of strtok -> you get "/invitedrift"

now you can compare in the if statement.

if (strcmp (tmp, "/Invitedirft", true) == 0)

If the result of the comparison is true, you need to get the playerid to be invited, so again you use strtok

tmp = strtok (cmdtext, idx) // second use of strtok -> you get "5" (or whatever playerid might be)

If it doesn't work, did you set idx = 0?


Re: [Help] COmmand - borisblat - 12.06.2009

well, i will try it, if i understood it right, but can't you just type the command?


this is how i understood from you:
Код:
   if(strcmp(cmdtext, "/InviteDrift", true) == 0)
   {
    tmp = strtok(cmdtext, idx);
    if (strcmp (tmp, "/Invitedirft", true) == 0)
		{
		  new string[256], string2[256];
		  new otherplayer = strval(tmp);
		  new name[MAX_PLAYER_NAME];
		  new opname[MAX_PLAYER_NAME];

		  GetPlayerName(playerid,name,sizeof(name));
	  	GetPlayerName(otherplayer,opname,sizeof(opname));


      if(!strlen(tmp)) return SendClientMessage(playerid, WHITE, "USE: /InviteDrift [playerid]");
      if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid, WHITE, "Invalid playerID.");
    	  format(string,sizeof(string), ".Drift - [ID:%d | %s] дежоръ мгшйфи тм йгй дщзчп", playerid, name);
      	format(string2,sizeof(string2), ".Drift - мгшйфи [ID:%d | %s] джоръ бдцмзд аъ дщзчп", otherplayer, opname);
     	SendClientMessage(otherplayer, LIGHTBLUE, string);
    	SendClientMessage(playerid, LIGHTBLUE, string2);
    }


	  return 1;
}



Re: [Help] COmmand - Luca Dimonte - 12.06.2009

If you think you understand what I say, you'll learn better if you try it by yourself instead of me doing the command


Re: [Help] COmmand - borisblat - 12.06.2009

here is what i understood

Код:
   if(strcmp(cmdtext, "/InviteDrift", true) == 0)
   {
    tmp = strtok(cmdtext, idx);
    if (strcmp (tmp, "/Invitedirft", true) == 0)
		{
		  new string[256], string2[256];
		  new otherplayer = strval(tmp);
		  new name[MAX_PLAYER_NAME];
		  new opname[MAX_PLAYER_NAME];

		  GetPlayerName(playerid,name,sizeof(name));
	  	GetPlayerName(otherplayer,opname,sizeof(opname));


      if(!strlen(tmp)) return SendClientMessage(playerid, WHITE, "USE: /InviteDrift [playerid]");
      if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid, WHITE, "Invalid playerID.");
    	  format(string,sizeof(string), ".Drift - [ID:%d | %s] дежоръ мгшйфи тм йгй дщзчп", playerid, name);
      	format(string2,sizeof(string2), ".Drift - мгшйфи [ID:%d | %s] джоръ бдцмзд аъ дщзчп", otherplayer, opname);
     	SendClientMessage(otherplayer, LIGHTBLUE, string);
    	SendClientMessage(playerid, LIGHTBLUE, string2);
    }


	  return 1;
}
and it is not working XD



Re: [Help] COmmand - Luca Dimonte - 12.06.2009

Quote:
Originally Posted by borisblat
here is what i understood

Код:
  if(strcmp(cmdtext, "/InviteDrift", true) == 0)
  {
    tmp = strtok(cmdtext, idx);
    if (strcmp (tmp, "/Invitedirft", true) == 0)
		{
		  new string[256], string2[256];
		  new otherplayer = strval(tmp);
		  new name[MAX_PLAYER_NAME];
		  new opname[MAX_PLAYER_NAME];

		  GetPlayerName(playerid,name,sizeof(name));
	  	GetPlayerName(otherplayer,opname,sizeof(opname));


      if(!strlen(tmp)) return SendClientMessage(playerid, WHITE, "USE: /InviteDrift [playerid]");
      if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid, WHITE, "Invalid playerID.");
   	  format(string,sizeof(string), ".Drift - [ID:%d | %s] дежоръ мгшйфи тм йгй дщзчп", playerid, name);
     	format(string2,sizeof(string2), ".Drift - мгшйфи [ID:%d | %s] джоръ бдцмзд аъ дщзчп", otherplayer, opname);
    	SendClientMessage(otherplayer, LIGHTBLUE, string);
    	SendClientMessage(playerid, LIGHTBLUE, string2);
   }


	  return 1;
}
and it is not working XD
Why two times "if (strcmp (tmp, "/Invitedirft", true) == 0)"? Are you new to function strtok? Delete the second one. I must go, can't help anymore by now. Hope you get it.


Re: [Help] COmmand - MenaceX^ - 12.06.2009

Quote:
Originally Posted by Luca Dimonte
Here

if(strcmp(cmdtext, "/InviteDrift", true) == 0)
{

tmp = strtok(cmdtext, idx);

you are comparing the whole thing typed by the player (maybe "/invitedrift 5"?), so that's different from "/Invitedrift", and will never find the command.

Later you store in tmp the playerid.

tmp = strtok(cmdtext, idx);

If you see that, you forgot to do the same in the if statement. It would be

tmp = strtok (cmdtext, idx); // added
if(strcmp(tmp, "/InviteDrift", true) == 0)
{
tmp = strtok(cmdtext, idx);
Why are you saying so?


Re: [Help] COmmand - borisblat - 12.06.2009

Quote:
Originally Posted by Luca Dimonte
Quote:
Originally Posted by borisblat
here is what i understood

Код:
  if(strcmp(cmdtext, "/InviteDrift", true) == 0)
  {
    tmp = strtok(cmdtext, idx);
    if (strcmp (tmp, "/Invitedirft", true) == 0)
		{
		  new string[256], string2[256];
		  new otherplayer = strval(tmp);
		  new name[MAX_PLAYER_NAME];
		  new opname[MAX_PLAYER_NAME];

		  GetPlayerName(playerid,name,sizeof(name));
	  	GetPlayerName(otherplayer,opname,sizeof(opname));


      if(!strlen(tmp)) return SendClientMessage(playerid, WHITE, "USE: /InviteDrift [playerid]");
      if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid, WHITE, "Invalid playerID.");
   	  format(string,sizeof(string), ".Drift - [ID:%d | %s] дежоръ мгшйфи тм йгй дщзчп", playerid, name);
     	format(string2,sizeof(string2), ".Drift - мгшйфи [ID:%d | %s] джоръ бдцмзд аъ дщзчп", otherplayer, opname);
    	SendClientMessage(otherplayer, LIGHTBLUE, string);
    	SendClientMessage(playerid, LIGHTBLUE, string2);
   }


	  return 1;
}
and it is not working XD
emm yeah i'm new, if i do only one time and i'm doing "cmdtext" it don't work when i put the id
if i do "tmp" it works but it do this thing on every command that i type even if i type "/ssafasf"
it will do it..

Why two times "if (strcmp (tmp, "/Invitedirft", true) == 0)"? Are you new to function strtok? Delete the second one. I must go, can't help anymore by now. Hope you get it.