- Joined
- Dec 31, 2012
- Messages
- 6
- Reaction score
- 0
How to script a /kill command
--------------------------------------------------------------------------
INTRODUCTION
In this tutorial I will be teaching you how to script a /kill command in your script.
Requirements
*Pawno
*Basic Knowledge
What will /kill do?
Code:
Once you enter this command, it will kill you, and you will re-spawn.
Why is this command needed?
Code:
An example of why this is needed is because sometimes you'll want to switch teams without having to do suicide, so you'll easily press F4, and then type /kill. Or you could just want to re-spawn back to your spawn.
STEPS
STEP 1
First open Pawno, or whatever you use to script.
STEP 2
Find "public OnPlayerCommandText(playerid, cmdtext[])".
OnPlayerCommandText is called whenever someone types a command on the server. For instance we're doing /kill so if we'd typed "/kill", and then hit "Enter" we would send a command which is why this goes in OnPlayerCommandText. Playerid is there so it can tell what ID, and cmdtext is there because it can tell what command you're entering.
STEP 3
Do you see the following?
Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
Code:
if (strcmp("/kill", cmdtext, true, 5) == 0)
{
SetPlayerHealth(playerid, 0.0);
In the code above /kill is added into this so we can know what to type to kill ourselves. We also see cmdtext once again saying to us that /kill is the command to enter to use this command. At the start of the code you see "if", well "if" tells us that if /kill is entered then the command will process. SetPlayerHealth indicates that we're wanting to do something with our health. You can also see playerid again. 0.0 means that we're wanting to set our player's health to 0.
Now you should see:
Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/kill", cmdtext, true, 5) == 0)
{
SetPlayerHealth(playerid, 0.0);
return 1;
}
This is what it looks like:
To view the content, you need to sign in or register
This is what the command looks like when it's all done. As you can see you must be sure "return 1;" is there, and bellow that line that "return 1;" is on, there should be "}".
STEP 4
Compile your Game-Mode/Script/Whatever you've added this to
-------------------------------------------------------------------------------------
Now you can type "/kill" on your server!
This is a basic command.