How To Create A Command [ For Begginers ]
#1

Simple Command

Introduction
A Command is Something You can Type Into Chat Box using a / In Front of the word.

Step 1:
In pawno open up a new file and scroll down until you see this.

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  {
    // Do something here
    return 1;
  }
  return 0;
}

Step 2:


This is the basis of your command, first off i'll teach you how to make a simple /kill command, for commiting suicide.

Ok, so first of all you need to change the "mycommand" part, change it to /kill. Then where you see the "10" change that to 5 because there is 4 letters in kill and 1 /. It should not look like this…

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  if (strcmp("/kill", cmdtext, true, 5) == 0)
  {
    // Do something here
    return 1;
  }
  return 0;
}
Step 3:
Once you have done that correctly you can now move on to the next part, in this command we want to set the players health to "0" so we mush use the function called SetPlayerHealth(…), take a look at the command now

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  if (strcmp("/kill", cmdtext, true, 5) == 0)
  {
    SetPlayerHealth(playerid, 0.0);
    return 1;
  }
  return 0;
}
Last Step:

Notice how i set the second part of the function to "0.0" the .0 shows that the number is a float, you dont need to worry too much about that at this stage.

Save your script, compile and test it, did it work? If yes then try setting it too 100.0 and changing /kill to /heal! and if you look through the includes list on the right hand side of pawno, you could even set their armour!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 4 Guest(s)