27.06.2013, 03:59
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.
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;
}
Step 3.
So we're going to replace the first line.
Remove the following line:
pawn Code:
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
pawn Code:
if (strcmp("/heal", cmdtext, true, 10) == 0)
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;
}
Remove the following line:
pawn Code:
// Do something here
pawn Code:
SetPlayerHealth(playerid, 100.0);
Progress so far:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/heal", cmdtext, true, 10) == 0)
{
SetPlayerHealth(playerid, 100.0);
return 1;
}
return 0;
}
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)
pawn Code:
if (strcmp("/kill", cmdtext, true, 10) == 0)
Now where it says "Do Something", replace it with the following:
pawn Code:
SetPlayerHealth(playerid, 0);
================================================== ============================
Commands
================================================== ============================
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;
}