SA-MP Forums Archive
[Tutorial] How to make commands with strcmp - 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: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make commands with strcmp (/showthread.php?tid=446744)



How to make commands with strcmp - DJTunes - 27.06.2013

Tutorial:
How to make commands with strcmp!


What is strcmp?: Strcmp is the default command processor for PAWNO.
How can I know this?: When you load a new script, search "strcmp", and a search will come up positive, bringing you to the place where you can make new commands.

Requirements: Warning: You must have all of the needed requirements before taking a step further into this tutorial.

Requirement Downloads
PAWN Download (Windows) = http://files.sa-mp.com/samp03x_svr_R1-2_win32.zip
PAWN Download (Linux) = http://files.sa-mp.com/samp03xsvr_R1-2.tar.gz

Tutorial Start!
Step 1.
You must open a new fresh script with PAWNO. To start a new script, go to "File", and then click "New".
In this tutorial, you will be creating a heal command, and a kill command. In later tutorials may we create advanced commands.

Step 2.
Press Ctrl + F at the same time until a box pops up; type "strcmp". It should bring you to an area in the script which displays this:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}
Let's explain! So first of all, where it says "/mycommand" is the text that one must enter to execute the command. "true" means that the command is wanting to be executed as a player enters the command. Where it says "// Do something here" is where we add all of the features we may want this command to do. Let's go ahead to step 3.

Step 3.
So we're going to replace the first line.
Remove the following line:
pawn Code:
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
Now, where you removed that line, paste this where it was before it was removed:
pawn Code:
if (strcmp("/heal", cmdtext, true, 10) == 0)
As explained previously, "/Heal" will be the command that you must type to execute the command. But, if you were to load the script with just THIS command, nothing would happen as we've not added anything! Let's do that now.

This is what we have done so far:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/heal", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}
Step 4.
Remove the following line:
pawn Code:
// Do something here
Add this line to where the old line was:
pawn Code:
SetPlayerHealth(playerid, 100.0);
"SetPlayerHealth" makes their health 100. 100.0 signals once the command is executed to give the player who did it (signaled with playerid) 100 health. You can increase/decrease the health - It's your future!

Progress so far:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/heal", cmdtext, true, 10) == 0)
    {
        SetPlayerHealth(playerid, 100.0);
        return 1;
    }
    return 0;
}
Step 5.
Now, we're going to make a kill command.
The kill command will kill the player who executed the command by setting his/her health to 0.00.

Change the following command to bellow:
pawn Code:
if (strcmp("/command", cmdtext, true, 10) == 0)
to:
pawn Code:
if (strcmp("/kill", cmdtext, true, 10) == 0)
"/kill" signals the word you must type to execute the command.

Now where it says "Do Something", replace it with the following:
pawn Code:
SetPlayerHealth(playerid, 0);
This will set the player's health to 0, which kills them.
================================================== ============================
Commands
================================================== ============================
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/heal", cmdtext, true, 10) == 0)
    {
        SetPlayerHealth(playerid, 100.0);
        return 1;
    }
    return 0;
}
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/kill", cmdtext, true, 10) == 0)
    {
        SetPlayerHealth(playerid, 0);
        return 1;
    }
    return 0;
}



AW: How to make commands with strcmp - BigETI - 27.06.2013

"strcmp" is still not a command processor. It only allows you to compare 2 strings, period.


Re: AW: How to make commands with strcmp - DJTunes - 27.06.2013

Quote:
Originally Posted by BigETI
View Post
"strcmp" is still not a command processor. It only allows you to compare 2 strings, period.
I didn't know how to define it as...


Re: How to make commands with strcmp - cessil - 27.06.2013

before making a tutorial you should understand what you're doing yourself
https://sampwiki.blast.hk/wiki/Strcmp