SA-MP Forums Archive
Two commands doing the same thing - 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: Two commands doing the same thing (/showthread.php?tid=92982)



Two commands doing the same thing - ilikepie2221 - 22.08.2009

Is there a way for like two commands to do the same thing without having to copy and paste the whole code twice?

For example, I want /a and /b to do the samething, but not have to do

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  if(strcmp(cmdtext, "/a", true) == 0)
  {
   // CODE
   return 1;
  }
  if(strcmp(cmdtext, "/b", true) == 0)
  {
   // SAME CODE
   return 1;
  }
  return 0;
}



Re: Two commands doing the same thing - ronyx69 - 22.08.2009

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  if(strcmp(cmdtext, "/a", true) == 0||strcmp(cmdtext, "/b", true) == 0)
  {
   // TEH CODEZ FOR U XD
   return 1;
  }
  return 0;
}



Re: Two commands doing the same thing - ilikepie2221 - 22.08.2009

Thank you, . But is there a way to implement dmcd in this manner?


Re: Two commands doing the same thing - snoob - 22.08.2009

hi
pawn Код:
if(strcmp(cmdtext, "/a", true) == 0)

// /a is 2 character so it should be
                       
if(strcmp(cmdtext, "/a", true) == 2)



Re: Two commands doing the same thing - Memoryz - 22.08.2009

Why would you need to implement dcmd on a /b function..?


Re: Two commands doing the same thing - ronyx69 - 22.08.2009

Код:
dcmd_some-kind-of-command(playerid,params[])
{
	//code here
}
dcmd_other-command-with-other-name-but-the-same-result(playerid,params[])
{
	return dcmd_some-kind-of-command(playerid, params);
}



Quote:
Originally Posted by snoob
hi
pawn Код:
if(strcmp(cmdtext, "/a", true) == 0)

// /a is 2 character so it should be
                       
if(strcmp(cmdtext, "/a", true) == 2)
wut d fook? It should be 0 not 2 because i don't know what what .. what!? It definately needs to be 0...


Re: Two commands doing the same thing - ilikepie2221 - 22.08.2009

Quote:
Originally Posted by Memoryz
Why would you need to implement dcmd on a /b function..?
Eh, I was just using it as an example, I'm trying to develop a /su(spect) command for Cops, so that's why. And thanks Ronyx, I'll try it out.