[Tutorial] How to add Cameras to your Script.
#1

Introduction

Hello. You may ask yourself, what does he mean by 'Cameras'. Well, i'm new to this Community so i decided to make a Tutorial. This tutorial is about adding Camera views to your Script. What do i mean? Well, lets say you're at a Airport, somewhere in a Tower, you type /camera in the Tower and you'll see your Camera will be at the Airport's Entrance. Lets go.

Step 1

Alright, first we'll need to chceck if the player's already in the 'Camera view'. We'll do it like this:
Code:
new IsPlayerChecking[MAX_PLAYERS];
Put this in the Top of the Script.

Step 2: The Command

Good. Now we need to make a command, we'll do this at the public OnPlayerCommandText. I use the classic strcmp but you can use DCMD or ZCMD, your choice.
Code:
if (strcmp("/camera", cmdtext, true, 6) == 0)
Alright, what's this? This is the line where we create our Command, the "/camera" is the Command's name. You need to put it in Brackets. cmdtext defines that the text is a commands. '6' is the lenght of the command.

Now we'll check if the player is in the Spectating state.
Code:
if(IsPlayerChecking[playerid] == 0)
{

}
Now this will check if the player is in Spec. state. 0 means false what means he's not. 1 is for true what means he's.

Now we should make the player non-controllable. Why? Because when he'll be in the Spec. state he'll be still able to move, but he wouldn't see where he moves.
Code:
if(IsPlayerChecking[playerid] == 0)
{
    ToggePlayerControllable(playerid, false);
}
So this function will make the player lose the control over his character. I think i don't need to explain this.

So, we've got a command that checks if the player's spectating or not. Now we'll add the Camera coordinates. We need the position of the Camera Postiton, and the coodrs of the point where the Camera will look at. In my case it'll be from one of the A69 tower's and it'll be looking at the Gate.
Code:
if(IsPlayerChecking[playerid] == 0)
{
    ToggePlayerControllable(playerid, false);
    SetPlayerCameraPos(playerid, 102.09620, 1903.80322, 34.71486); // Set the Camera's position.
    SetPlayerCameraLookAt(playerid, 97.01453, 1920.62439, 18.15041); // Where should it look at.
    IsPlayerChecking[playerid] = 1; // Checks if the player's is in Spec. state. 1 - True, 0 - False.
}
These functions will make our Camera look at a specific location. The first function will set the Camera's position and the second one will set the view of the Camera, so where it should look at.

Alright. Now we have everything we need. One last thing is missing. After some time the player's bored of the spectating and want to play again, so we need to switch him back to Character and make him Controllable.
Code:
else
{
    SetCameraBehindPlayer(playerid);
    TogglePlayerControllable(playerid, true);
    IsPlayerChecking[playerid] = 0;
}
the 'else' means the player's in the Spectating state, and that he needs to be switched back. SetCameraBehindPlayer will set the player's camera back to it's old position. The last function will define that the Player's not spectating anymore.

Here's the Full Command:
Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/camera", cmdtext, true, 6) == 0)
   {
       if(IsPlayerChecking[playerid] == 0)
       {
           TogglePlayerControllable(playerid, false);
	   SetPlayerCameraPos(playerid, 102.09620, 1903.80322, 34.71486); // You can change to your own coords.
	   SetPlayerCameraLookAt(playerid, 97.01453, 1920.62439, 18.15041); // Same as above.
	   IsPlayerChecking[playerid] = 1;
       }
       else
       {
           SetCameraBehindPlayer(playerid);
	   TogglePlayerControllable(playerid, true);
           IsPlayerChecking[playerid] = 0;
       }
       return 1;
}
return 0;
}
The End
I hope i teached someone how to make Camera views, you must not use a Command to trigger it, you can also use OnPlayerKeyStateChange, be crative. I recommend this mainly for RP server for RPing and so on.

I'm new to this Forum, Community and i'll try to make my best here. If something's wrong, reply to this Topic and i'll try to help you
Reply
#2

well,
+ 2 reps for u coz its ur first tut, and a very nice start!
keep it up!
Reply
#3

Quote:
Originally Posted by XtremeR
View Post
well,
+ 2 reps for u coz its ur first tut, and a very nice start!
keep it up!
Thank you for you rating, i'm very happy that you liked my tutorial.
Reply
#4

Nice for a first tutorial!
Reply
#5

Your variable is defined wrong, the first is IsPlayerSpectating you then checked / set the variable IsPlayerChecking
Reply
#6

Quote:
Originally Posted by Glint
View Post
Nice for a first tutorial!
Thank you for your rating.

@ NewerethRoleplay: Thanks for noticing Fixed.
Reply
#7

Nice Tutorial +Rep
Reply
#8

Quote:
Originally Posted by Ghost_Boii
View Post
Nice Tutorial +Rep
Thank you very much.
Reply
#9

Why i got "Server unknow command" ? :FFF
Without errors:S
Reply
#10

Anyone can help?
Reply
#11

nice work on the tut

Quote:
Originally Posted by XtremeR
View Post
well,
+ 2 reps for u coz its ur first tut, and a very nice start!
keep it up!
how do you give 2 reps lol
Reply
#12

Simple and nice.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)