Simple command

Simple command

A command is something you can type into the chatbox using a / infront of the word, if the command exists then it will do what id does if not you will most likely get a "Server: Unkown command" message.

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;
}

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;
}

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;
}

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!


Back | Home