15.05.2012, 00:40
Hello and welcome to my tutorial.
I am here to explain and give a tutorial about "Death Camera's".
What I will be showing you today:
I will be making clear comments about what I am doing, so if you struggle you should be able to read them and then you should be good to continue. Although, if you have any problems, please don't hesitate to post on here!
Let's get started!
At the top of the script, make sure that you have got this included:
This here, will allow you the usage of the "Pawn" scripting for SA-MP. Without this, you will struggle to script anything.
Now that we have got that part done, we need to define some colours into the script!
We are going to be defining a colour, "White".
To do this, underneath where you have done the "#include" section, add the following piece of script:
This is defining the colour, so that when we use it in a SendClientMessage; it will work.
Example:
Second section:
(Player variables and forwards)
Let's start by explaining to you the function that involves "forward".
To create a timer, for example. What we are doing is when a player dies, the deathcam will spectate the killer, so the timer will start and 10 seconds later; we will respawn.
A forward, will define a "public" function.
So, to define our public function, we are going to need to add something along the lines of this:
The function is now called: EndDeathCam. The "(playerid)" section of this forward means that it will be used for a player who set the timer off.
Next, we need to add our player variables!
To do this, all we need to do is add "new WhatOurVariableIs[MAX_PLAYERS];", that would define it for the player's that are in the game.
So, to add ours we will need to add this to the top of the script:
If you try to compile when you have just added these; you are going to get 2 warnings. Not errors, but warnings because none of the "new's" have been used as of yet. Here is what the warning will look like:
Don't worry about these warnings though, because they will all be removed by you in time, along more of the script.
Under "OnPlayerConnect(playerid)", you will want to notify the script to clear all player variables, so then the player doesn't have any items such as a fishing rod or bait. More is explained below.
The reason for this is, to reset all player variables that we have just added.
Having: "Died[playerid] = 0;" will make it so the script can see that the player hasn't died
Having: "KilledBy[playerid] = 0;" will make it so the script can see that the player hasn't been killed yet.
Also, now if you tried to compile. You should have noticed that the warning codes have gone. This is because you have now used the variables in the script, so they aren't "Not being used".
The thing that I have show you above with OnPlayerConnect(playerid), you need to do the same for OnPlayerDisconnect(playerid, reason).
That will ensure the script that when a player disconnects, it will remove all of the variables that have been stored in the script, whilst the player has been connected.
Now that we have the defines, includes and player variables out of the way, we can crack on with the rest of the script!
Third section:
(Script functions and timers(with public function))
This section of the tutorial, will show you the basics of OnPlayerDeat, also how to create timers with a public function to display the outcome, also how to create the actual Death Cam.
Now to explain:
if(Died[playerid] == 1) - If the player who has died's variable = 1, then the script will continue.
Died[playerid] = 0; - This sets the script's variable to "0", telling the script that he has already died and no need to call this function again.
if(KilledBy[playerid] != INVALID_PLAYER_ID) - This is checking that the player who killed him isn't an invalid player.
TogglePlayerSpectating(playerid, 1); - This sets the player to spectating.
PlayerSpectatePlayer(playerid, killerid); - This sets the player who got killed, to spectate the player who killed him/her.
SetTimerEx("EndDeathCam", 10000, 1, "i", playerid); - This sets the timer as to when the player should stop watching the camera and re-spawn.
Now, onto the public funtion.
This is called when the 10 seconds are up with the camera timer.
This is what it would look like:
Time to explain:
TogglePlyerSpectating(playerid, 0); - This sets the player who was spectating the killer, to stop spectating anyone and to spawn.
Died[playerid] = 0; - This is re-assuring the script that the playerid has not died again.
That comes to an end of my tutorial, thank you for reading and if you have got any questions, please post them here!
I know that there is a lot of writing, but it all will help newbie's in scripting. I hope that people will learn something from this because it will make me feel better :3.
Otherwise, good luck with your scripting!
- iGetty out.
I am here to explain and give a tutorial about "Death Camera's".
What I will be showing you today:
- How to add a death camera to a player when they kill somebody.
- How to set a timer for the death camera to set the player to spawn
I will be making clear comments about what I am doing, so if you struggle you should be able to read them and then you should be good to continue. Although, if you have any problems, please don't hesitate to post on here!
Let's get started!
At the top of the script, make sure that you have got this included:
pawn Code:
#include <a_samp>
Now that we have got that part done, we need to define some colours into the script!
We are going to be defining a colour, "White".
To do this, underneath where you have done the "#include" section, add the following piece of script:
pawn Code:
#define WHITE 0xFFFFFFAA
Example:
pawn Code:
SendClientMessage(playerid, WHITE, "This will show the colour in WHITE.");
(Player variables and forwards)
Let's start by explaining to you the function that involves "forward".
To create a timer, for example. What we are doing is when a player dies, the deathcam will spectate the killer, so the timer will start and 10 seconds later; we will respawn.
A forward, will define a "public" function.
So, to define our public function, we are going to need to add something along the lines of this:
pawn Code:
forward EndDeathCam(playerid);
Next, we need to add our player variables!
To do this, all we need to do is add "new WhatOurVariableIs[MAX_PLAYERS];", that would define it for the player's that are in the game.
So, to add ours we will need to add this to the top of the script:
pawn Code:
new Died[MAX_PLAYERS], KilledBy[MAX_PLAYERS];
Code:
warning 203: symbol is never used: "Died" warning 203: symbol is never used: "KilledBy"
Under "OnPlayerConnect(playerid)", you will want to notify the script to clear all player variables, so then the player doesn't have any items such as a fishing rod or bait. More is explained below.
pawn Code:
public OnPlayerConnect(playerid)
{
//You will want to add the following:
Died[playerid] = -1;
KilledBy[playerid] = -1;
return 1;
}
Having: "Died[playerid] = 0;" will make it so the script can see that the player hasn't died
Having: "KilledBy[playerid] = 0;" will make it so the script can see that the player hasn't been killed yet.
Also, now if you tried to compile. You should have noticed that the warning codes have gone. This is because you have now used the variables in the script, so they aren't "Not being used".
The thing that I have show you above with OnPlayerConnect(playerid), you need to do the same for OnPlayerDisconnect(playerid, reason).
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
//You will want to add the following:
Died[playerid] = 0;
KilledBy[playerid] = 0;
return 1;
}
Now that we have the defines, includes and player variables out of the way, we can crack on with the rest of the script!
Third section:
(Script functions and timers(with public function))
This section of the tutorial, will show you the basics of OnPlayerDeat, also how to create timers with a public function to display the outcome, also how to create the actual Death Cam.
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
Died[playerid] = 1;
if(Died[playerid] == 1)
{
Died[playerid] = 0;
if(KilledBy[playerid] != INVALID_PLAYER_ID)
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, killerid);
SendClientMessage(playerid, WHITE, "You have been killed, you are now spectating your killer.");
SetTimerEx("EndDeathCam", 10000, 1, "i", playerid);
}
else
{
TogglePlayerSpectating(playerid, 0);
}
return 1;
}
if(Died[playerid] == 1) - If the player who has died's variable = 1, then the script will continue.
Died[playerid] = 0; - This sets the script's variable to "0", telling the script that he has already died and no need to call this function again.
if(KilledBy[playerid] != INVALID_PLAYER_ID) - This is checking that the player who killed him isn't an invalid player.
TogglePlayerSpectating(playerid, 1); - This sets the player to spectating.
PlayerSpectatePlayer(playerid, killerid); - This sets the player who got killed, to spectate the player who killed him/her.
SetTimerEx("EndDeathCam", 10000, 1, "i", playerid); - This sets the timer as to when the player should stop watching the camera and re-spawn.
Now, onto the public funtion.
This is called when the 10 seconds are up with the camera timer.
This is what it would look like:
pawn Code:
public EndDeathCam(playerid)
{
TogglePlayerSpectating(playerid, 0);
Died[playerid] = 0;
}
TogglePlyerSpectating(playerid, 0); - This sets the player who was spectating the killer, to stop spectating anyone and to spawn.
Died[playerid] = 0; - This is re-assuring the script that the playerid has not died again.
That comes to an end of my tutorial, thank you for reading and if you have got any questions, please post them here!
I know that there is a lot of writing, but it all will help newbie's in scripting. I hope that people will learn something from this because it will make me feel better :3.
Otherwise, good luck with your scripting!
- iGetty out.