[Tutorial] First Person View scripting.
#1

First of all, Let me tell what First Person View.
: First person view is one type of view which will show you that view from like real life you see. It will work also in vehicle too.

Screen Shot :
Click on the screenshot to see more.
Okey, Let's make the script.

First of all,

You have to put some " new " variables.
PHP код:
new FirstPerson[MAX_PLAYERS];
new 
FirstPersonObject[MAX_PLAYERS];
new 
bool:FPS[MAX_PLAYERS]; 
After those variables put some stocks in that scirpt.
You can use farward and public functions but, I am using stock. Because i think stock is good for little scripting functions.
PHP код:
stock StartFPS(playerid//To start the FPS mod.
{
    
FirstPersonObject[playerid] = CreateObject(193000.00.00.00.00.00.0);//You must need this, if you don't the camera will glitch.
    
AttachObjectToPlayer(FirstPersonObject[playerid],playerid0.00.120.70.00.00.0);//Just Attached the object.
    
AttachCameraToObject(playeridFirstPersonObject[playerid]);//Now, I have sttach my camera to that object that i have created.
    
FirstPerson[playerid] = 1;//New variable is now TRUE ( 1= True)
    
CallLocalFunction("OnPlayerHaveFirstPerson""i"playerid);//I have called the Local Function of OnPlayerHaveFirstPerson .
    
return 1;
}
stock StopFPS(playerid//As you have start the FPS, That must need deactive function too .
{
    
SetCameraBehindPlayer(playerid);// Just moved his camera behind the player.
    
DestroyObject(FirstPersonObject[playerid]);//Destroyed that Object that i have created on first.
    
FirstPerson[playerid] = 0;// 0= False . 
    
CallLocalFunction("OnPlayerDoNotHaveFirstPerson""i"playerid);//Same as before, I have just deactive that callback ( called OnPlayerDoNotHaveFirstPerson .
    
return 1;
}
stock Reset(playerid)
{
    
FirstPerson[playerid] = 0;//Just if you are bugged . Reset.

You can use Below script in public OnPlayerDeath(playerid, killerid, reason)
PHP код:
if(FirstPerson[playerid] == 1
{
    
StopFPS[playerid];

All things are now done.

All you need Commands now.
PHP код:
CMD:fps(playeridparams[])
{
    
//SendClientMessageEx(playerid, COLOR_LIME, "If you think you cannot use /fps , Please /resetfps to fix it up. Then use /fps again."); //Depend on you that you will use it or not.
    
if(FPS[playerid] == false// You can use FPS[playerid] == 0) 0=False.
    
{
        
FPS[playerid] = true;//Same as before, You can use 1 tho.
        
StartFPS(playerid);//Called that StartFPS stock to use FPS.
    
}
    else if(
FPS[playerid] == true)// Same as before, you can use 1 here.
    
{
        
FPS[playerid] = false;// You can use 0 if you don't want to false.
        
StopFPS(playerid);//Called Stock StopFPS
    
}
    return 
1;
}
CMD:resetfps(playeridparams[])
{
    
Reset(playerid);
    return 
1;

If you think CallLocalFunction have no use, you can delete that line, there no rule that you will use CallLocalFunction. It fully depend on you, There many pro scripter, hope they will understand my point of view. Thanks.
Found problem? reply or PM me .
Reply
#2

Simple, but nicely explained.

P.S: You should re-start the FPS mode when the player dies. Example is below.

PHP код:
//OnPlayerDeath
if(FirstPerson[playerid] == 1
{
    
StartFPS[playerid];

Reply
#3

Quote:
Originally Posted by Karan007
Посмотреть сообщение
Simple, but nicely explained.

P.S: You should re-start the FPS mode when the player dies. Example is below.

PHP код:
//OnPlayerDeath
if(FirstPerson[playerid] == 1
{
    
StartFPS[playerid];

Okey, Added.
That will be StopFPS[playerid]; not StartFPS.
Reply
#4

What is the use of OnPlayerHaveFirstPerson and OnPlayerDoNotHaveFirstPerson for?
You have explained that part but you haven't mentioned the use of these callbacks.
Reply
#5

Quote:
Originally Posted by SoFahim
Посмотреть сообщение
Okey, Added.
That will be StopFPS[playerid]; not StartFPS.
Should be StartFPS to start it back again if the player had FPS on. It's kind of annoying to put back /fps when a player died to get the FPS view again.
Reply
#6

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
What is the use of OnPlayerHaveFirstPerson and OnPlayerDoNotHaveFirstPerson for?
You have explained that part but you haven't mentioned the use of these callbacks.
OnPlayerHaveFirstPerson and OnPlayerDoNotHaveFirstPerson is used because of no crash when we use fps.

There no main point of use it. Just to avoid glitch and crash, I am using it.

Quote:
Originally Posted by Karan007
Посмотреть сообщение
Should be StartFPS to start it back again if the player had FPS on. It's kind of annoying to put back /fps when a player died to get the FPS view again.
No , sorry to say, you are wrong about it. If a player Death, his FPS should be reset. So his death would not bugged. You can use it by your own risk.
Reply
#7

Oh yeah, sorry! I got mistaken, you should add the code i've posted OnPlayerSpawn
Reply
#8

Quote:
Originally Posted by Karan007
Посмотреть сообщение
Oh yeah, sorry! I got mistaken, you should add the code i've posted OnPlayerSpawn
Nope. Everyone don't like this, That's why command system. He can use it who like FPS mod. Simple.

Quote:
Originally Posted by Humza
Посмотреть сообщение
Nice SoFahim +REP
Thanks.
Reply
#9

Quote:
Originally Posted by SoFahim
Посмотреть сообщение
OnPlayerHaveFirstPerson and OnPlayerDoNotHaveFirstPerson is used because of no crash when we use fps.

There no main point of use it. Just to avoid glitch and crash, I am using it.
You do realize that the code calls the callback and you told me that it is only placed there to prevent a crash but it has no further use? You should remove that CallLocalFunction otherwise if it has no use at all because removing it won't cause any crashes on my point of view.
Reply
#10

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
You do realize that the code calls the callback and you told me that it is only placed there to prevent a crash but it has no further use? You shouldv remoe that CallLocalFunction othwisere if it has no use at all because removing it won't cause any crashes on my point of view.
Yes. You are right tho. It useless in one side. I just though about that, And also it crashed many time without that CAllLocalFunction ( IDK why ) and that's why i use it, after that it never crash. In your point of view, it's useless, Okey. I will reedit the thread and add something. If anyone want to use okey if he don't he can delete the line tho. There no problem at all.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)