Scripting command(s)
#1

Hello, everyone! I want to make a command. /onduty and /offduty for cops. I want like:
I did /offduty
I got the message: You're now an off-duty cop.
Everyone got: Wrench(ID.) is now an off-duty cop.
etc.
I did this:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/offduty", cmdtext, true, 5) == 0)
	{
SendClientMessage(playerid,0xFFFFFF,"You're now an off-duty cop.");
        format(fstr, sizeof(fstr), "%s [%d] is now an off-duty cop.", GetName(playerid), playerid, GetName(targetid), targetid, reason);
        }
 	return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/onduty", cmdtext, true, 5) == 0)
	{
SendClientMessage(playerid,0xFFFFFF,"You're now an on-duty cop.");
        format(fstr, sizeof(fstr), "%s [%d] is now an on-duty cop.", GetName(playerid), playerid, GetName(targetid), targetid, reason);
        }
 	return 0;
}
I am sure that it is wrong. How can I do this? Please help me guys.
Reply
#2

You only need to add SendClientMessageToAll under the both formats! And you don't need both callbacks (OnPlayerCommandText), only one.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/offduty", cmdtext, true, 5) == 0)
    {
            new string[128];
        SendClientMessage(playerid,0xFFFFFF,"You're now an off-duty cop.");
        format(string, sizeof(string), "%s [%d] is now an off-duty cop.", GetName(playerid), playerid, GetName(targetid), targetid, reason);
        SendClientMessageToAll(-1, string);
    }

    if (strcmp("/onduty", cmdtext, true, 5) == 0)
    {
            new string[128];
        SendClientMessage(playerid,0xFFFFFF,"You're now an on-duty cop.");
        format(string, sizeof(string), "%s [%d] is now an on-duty cop.", GetName(playerid), playerid, GetName(targetid), targetid, reason);
        SendClientMessageToAll(-1, string);
    }
    return 0;
}
You must not define a global string, you must make one for each format, regards!
Reply
#3

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/offduty"cmdtexttrue5) == 0)
    {
SendClientMessage(playerid,0xFFFFFF,"You're now an off-duty cop.");
        
format(fstrsizeof(fstr), "%s [%d] is now an off-duty cop."GetName(playerid), playeridGetName(targetid), targetidreason);
        
SendClientMessageToAll(0xFF0000FF,fstr);
        }
     return 
0;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/onduty"cmdtexttrue5) == 0)
    {
SendClientMessage(playerid,0xFFFFFF,"You're now an on-duty cop.");
        
format(fstrsizeof(fstr), "%s [%d] is now an on-duty cop."GetName(playerid), playeridGetName(targetid), targetidreason);
        
SendClientMessageToAll(0xFF0000FF,fstr);
        }
     return 
0;

Reply
#4

Thank ya very much, guys!
Reply
#5

Why aren't you using ZCMD ? And for the cmd you could use a boolean.
Reply
#6

I recommend you to use PawnCMD. It uses memory hacking to increase speed and is way easier to write down every single time.

https://sampforum.blast.hk/showthread.php?tid=608474
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)