SA-MP Forums Archive
Scripting command(s) - 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)
+--- Thread: Scripting command(s) (/showthread.php?tid=625413)



Scripting command(s) - Wrench - 01.01.2017

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.


Respuesta: Scripting command(s) - Goncho28 - 01.01.2017

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!


Re: Scripting command(s) - Loinal - 01.01.2017

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;




Re: Scripting command(s) - Wrench - 01.01.2017

Thank ya very much, guys!


Re: Scripting command(s) - saffierr - 01.01.2017

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


Re: Scripting command(s) - Codeah - 01.01.2017

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