[Tutorial] How to make commands with strcmp
#1

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:
  • PAWN compiler.
  • Basic PAWN knowledge.
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;
}
Reply
#2

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

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...
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)