SA-MP Forums Archive
[Tutorial] How to add Cameras to your Script. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to add Cameras to your Script. (/showthread.php?tid=384100)



How to add Cameras to your Script. - Norhy - 10.10.2012

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



Re: How to add Cameras to your Script. - XtremeR - 10.10.2012

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


Re: How to add Cameras to your Script. - Norhy - 10.10.2012

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.


Re: How to add Cameras to your Script. - Glint - 10.10.2012

Nice for a first tutorial!


Re: How to add Cameras to your Script. - NewerthRoleplay - 10.10.2012

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


Re: How to add Cameras to your Script. - Norhy - 10.10.2012

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

@ NewerethRoleplay: Thanks for noticing Fixed.


Re: How to add Cameras to your Script. - Ghost_Boii - 10.10.2012

Nice Tutorial +Rep


Re: How to add Cameras to your Script. - Norhy - 10.10.2012

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


Re: How to add Cameras to your Script. - Coder_ - 14.10.2012

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


Re: How to add Cameras to your Script. - Coder_ - 16.10.2012

Anyone can help?


Re: How to add Cameras to your Script. - skullmuncher1337 - 16.10.2012

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


Re: How to add Cameras to your Script. - Omirrow - 02.07.2013

Simple and nice.