//======================================================================================
//
// Project: 		CIVIL's MW2 Movie Mod						
//											
// Author:		Civil, CoDTVMM Team			
//											
// Purpose: 		VER#14 - IW4 Movie mod w/ dvars integration			
//											
// Last Update: 	07/23/2015 11:17				
//											
// Desc + ToDo: 	CAMERA SCRIPTS						
//	
//======================================================================================
//											
//   Feel free to use the code, just give CREDIT where CREDIT is due !!!
//   If you had problems, just contact me on skype (about.txt)	
//   Don't try to change smth by yourself if you have problems	
//											
//======================================================================================
// I know that's not the easiest and cleanest way to do a camera script
// But it works really well so for me it doesn't matter, you're not 
// supposed to read this tho 
//
// The bezier script was ripped from the CoDTVMM for Call of Duty 4: Modern Warfare
// I just made it working on WarfareČ. All credits goes to the CoDTVMM team
//======================================================================================


#include maps\mp\gametypes\_hud_util;
#include maps\mp\_utility;
#include common_scripts\utility;
#using_animtree( "destructibles" );

init()
{
	level thread LetsStart();
}

LetsStart()
{

    for(;;)
    {
        level waittill( "connected", player );
        player thread PlayerSpawn();
    }
}

PlayerSpawn()
{
    self endon( "disconnect" );
    for(;;)
    {
        self waittill("spawned_player");

	setDvar("camera_thirdperson", "0");
	self show();

	setDvarIfUninitialized( "sv_fps", "20" ); // Was not in the MW2 engine, must init it

	thread ResetCamPos();
        thread SaveCamPos();
	thread SaveAngles();
	self.cameratime = 5;
	thread CameraStart();
	thread BezierStart();
	thread InitGrenadeCam();
	thread CamDebug();	
    }
}

//=============================== MUM, GET THE CAM'RA!===================================
// Ikr arrays are existing lol
// But I didn't put it in to prevent bugs
//========================================================================================


HideCamNode()
{
	self.posi1 hide();
	self.posi2 hide();
	self.posi3 hide();
	self.posi4 hide();
	self.posi5 hide();
	self.posi6 hide();
	self.posi7 hide();
	self.posi8 hide();
	self.posi9 hide();
	self.posi10 hide();
}

ShowCamNode()
{
	self.posi1 show();
	self.posi2 show();
	self.posi3 show();
	self.posi4 show();
	self.posi5 show();
	self.posi6 show();
	self.posi7 show();
	self.posi8 show();
	self.posi9 show();
	self.posi10 show();
}


SaveCamPos() // Cluster killer lmao, but it allows to edit each node so ye
{
self endon("disconnect");
self endon("death");
self notifyOnPlayerCommand("mvm_cam_save", "mvm_cam_save");

for ( ;; )
	{

	self waittill("mvm_cam_save");

	posnum = getDvar("mvm_cam_save", "");
	
		
		if( posnum == "1" )
        	{
            	self.spos[1]["origin"] = self GetOrigin();
            	self.spos[1]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi1))
		{
			self.posi1 delete();
		}
		self.posi1 = spawn("script_model", self.origin);
  		self.posi1 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 1 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
		if(self.poscount <= 1)
			{
            		self.poscount = 1;
			}
        	}        	
		
		else if( posnum == "2" )
        	{
            	self.spos[2]["origin"] = self GetOrigin();
            	self.spos[2]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi2))
		{
			self.posi2 delete();
		}
		self.posi2 = spawn("script_model", self.origin);
  		self.posi2 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 2 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 2)
			{
            		self.poscount = 2;
			}
        	}
		
		else if( posnum == "3" )
        	{
            	self.spos[3]["origin"] = self GetOrigin();
            	self.spos[3]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi3))
		{
			self.posi3 delete();
		}
		self.posi3 = spawn("script_model", self.origin);
  		self.posi3 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 3 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 3)
			{
            		self.poscount = 3;
			}
        	}

        	else if( posnum == "4" )
        	{
            	self.spos[4]["origin"] = self GetOrigin();
            	self.spos[4]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi4))
		{
			self.posi4 delete();
		}
		self.posi4 = spawn("script_model", self.origin);
  		self.posi4 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 4 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 4)
			{
            		self.poscount = 4;
			}
        	}
		
		else if( posnum == "5" )
        	{
            	self.spos[5]["origin"] = self GetOrigin();
            	self.spos[5]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi5))
		{
			self.posi5 delete();
		}
		self.posi5 = spawn("script_model", self.origin);
  		self.posi5 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 5 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 5)
			{
            		self.poscount = 5;
			}
        	}

		else if( posnum == "6" )
        	{
            	self.spos[6]["origin"] = self GetOrigin();
            	self.spos[6]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi6))
		{
			self.posi6 delete();
		}
		self.posi6 = spawn("script_model", self.origin);
  		self.posi6 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 6 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 6)
			{
            		self.poscount = 6;
			}
        	}

		else if( posnum == "7" )
        	{
            	self.spos[7]["origin"] = self GetOrigin();
            	self.spos[7]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi7))
		{
			self.posi7 delete();
		}
		self.posi7 = spawn("script_model", self.origin);
  		self.posi7 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 7 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 7)
			{
            		self.poscount = 7;
			}
        	}

		else if( posnum == "8" )
        	{
            	self.spos[8]["origin"] = self GetOrigin();
            	self.spos[8]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi8))
		{
			self.posi8 delete();
		}
		self.posi8 = spawn("script_model", self.origin);
  		self.posi8 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 8 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 8)
			{
            		self.poscount = 8;
			}
        	}

		else if( posnum == "9" )
        	{
            	self.spos[9]["origin"] = self GetOrigin();
            	self.spos[9]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi9))
		{
			self.posi9 delete();
		}
		self.posi9 = spawn("script_model", self.origin);
  		self.posi9 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 9 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 9)
			{
            		self.poscount = 9;
			}
        	}

		else if( posnum == "10" )
        	{
            	self.spos[10]["origin"] = self GetOrigin();
            	self.spos[10]["angles"] = self GetPlayerAngles();
		if(isDefined(self.posi10))
		{
			self.posi10 delete();
		}
		self.posi10 = spawn("script_model", self.origin);
  		self.posi10 setModel("test_sphere_silver");
            	self IPrintLn("Pos^2 10 ^7Saved");
		self IPrintLn(self.origin);
		self IPrintLn(self.anlges);
            	if(self.poscount <= 10)
			{
            		self.poscount = 10;
			}
        	}
        	
		else
        	{
	    	self IPrintLn("^1WHAT THE F#CK YOU JUST TYPED M8 ??");
		self IPrintLnBold("^1POSITION NUMBER NOT ALLOWED");
        	}
   	}
}

ResetCamPos()
{
    self endon( "disconnect" );
    self endon("death");
    self notifyOnPlayerCommand( "mvm_cam_reset", "mvm_cam_reset" );
    for(;;)
    {
        self waittill( "mvm_cam_reset" );
        
	// LOOKS RETARDED IKR, WAS TO LAZY TO i++


        self.spos[1]["origin"] = undefined;
        self.spos[1]["angles"] = undefined;
        self.spos[2]["origin"] = undefined;
        self.spos[2]["angles"] = undefined;
        self.spos[3]["origin"] = undefined;
        self.spos[3]["angles"] = undefined;
        self.spos[4]["origin"] = undefined;
        self.spos[4]["angles"] = undefined;
        self.spos[5]["origin"] = undefined;
        self.spos[5]["angles"] = undefined;
        self.spos[6]["origin"] = undefined;
        self.spos[6]["angles"] = undefined;
        self.spos[7]["origin"] = undefined;
        self.spos[7]["angles"] = undefined;
        self.spos[8]["origin"] = undefined;
        self.spos[8]["angles"] = undefined;
        self.spos[9]["origin"] = undefined;
        self.spos[9]["angles"] = undefined;
        self.spos[10]["origin"] = undefined;
        self.spos[10]["angles"] = undefined;

	self.posi1 delete();
	self.posi2 delete();
	self.posi3 delete();
	self.posi4 delete();
	self.posi5 delete();
	self.posi6 delete();
	self.posi7 delete();
	self.posi8 delete();
	self.posi9 delete();
	self.posi10 delete();

	self IPrintLn("^1All points deleted");
        self IPrintLnBold("^1All points deleted");
        self.poscount = 1;
    }
}


CameraStart()
{
self endon("disconnect");
self endon("death");
self notifyOnplayerCommand( "mvm_cam_start", "mvm_cam_start" );
for(;;)
    {
        self waittill("mvm_cam_start");

	if(self.poscount == 1)
        {
	self IPrintLn("^1Need atleast 2 points to start");
        self IPrintLnBold("^1Need atleast 2 points to start"); 
	return;
        }
	
	self setClientDvar("cg_drawgun", 0);
	self setClientDvar("cg_draw2d", 0);
	self thread HideCamNode();	

	self SetOrigin(self.saved_originstart);
	self SetPlayerAngles(self.saved_anglesstart);
	wait ( 0.01 );
	camera = spawn( "script_model", self.origin );
	camera setModel( "tag_origin" );
	camera EnableLinkTo();
	camera RotateTo( self.angles );
	wait ( 0.01 );
        
        self PlayerLinkToDelta( camera, "tag_origin", 1, 360, 360, 360, 360, false );
        self freezecontrols(false);

	if(self.poscount == 2)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo( self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );

	    wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 2, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 2, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 3)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo(self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 3, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 3, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 3, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 3, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 4)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo(self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 4, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 4, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 4, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 4, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[4]["angles"], self.cameratime / 4, 0, 0 );
            camera MoveTo( self.spos[4]["origin"]+(0,0,-50), self.cameratime / 4, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 5)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo( self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 5, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 5, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 5, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 5, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[4]["angles"], self.cameratime / 5, 0, 0 );
            camera MoveTo( self.spos[4]["origin"]+(0,0,-50), self.cameratime / 5, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[5]["angles"], self.cameratime / 5, 0, 0 );
            camera MoveTo( self.spos[5]["origin"]+(0,0,-50), self.cameratime / 5, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 6)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo( self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 6, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 6, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 6, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 6, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[4]["angles"], self.cameratime / 6, 0, 0 );
            camera MoveTo( self.spos[4]["origin"]+(0,0,-50), self.cameratime / 6, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[5]["angles"], self.cameratime / 6, 0, 0 );
            camera MoveTo( self.spos[5]["origin"]+(0,0,-50), self.cameratime / 6, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[6]["angles"], self.cameratime / 6, 0, 0 );
            camera MoveTo( self.spos[6]["origin"]+(0,0,-50), self.cameratime / 6, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 7)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo( self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 7, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 7, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 7, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 7, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[4]["angles"], self.cameratime / 7, 0, 0 );
            camera MoveTo( self.spos[4]["origin"]+(0,0,-50), self.cameratime / 7, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[5]["angles"], self.cameratime / 7, 0, 0 );
            camera MoveTo( self.spos[5]["origin"]+(0,0,-50), self.cameratime / 7, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[6]["angles"], self.cameratime / 7, 0, 0 );
            camera MoveTo( self.spos[6]["origin"]+(0,0,-50), self.cameratime / 7, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[7]["angles"], self.cameratime / 7, 0, 0 );
            camera MoveTo( self.spos[7]["origin"]+(0,0,-50), self.cameratime / 7, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 8)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo( self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 8, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 8, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 8, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 8, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[4]["angles"], self.cameratime / 8, 0, 0 );
            camera MoveTo( self.spos[4]["origin"]+(0,0,-50), self.cameratime / 8, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[5]["angles"], self.cameratime / 8, 0, 0 );
            camera MoveTo( self.spos[5]["origin"]+(0,0,-50), self.cameratime / 8, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[6]["angles"], self.cameratime / 8, 0, 0 );
            camera MoveTo( self.spos[6]["origin"]+(0,0,-50), self.cameratime / 8, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[7]["angles"], self.cameratime / 8, 0, 0 );
            camera MoveTo( self.spos[7]["origin"]+(0,0,-50), self.cameratime / 8, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[8]["angles"], self.cameratime / 8, 0, 0 );
            camera MoveTo( self.spos[8]["origin"]+(0,0,-50), self.cameratime / 8, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 9)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo( self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[4]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[4]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[5]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[5]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[6]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[6]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[7]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[7]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[8]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[8]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[9]["angles"], self.cameratime / 9, 0, 0 );
            camera MoveTo( self.spos[9]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }
        else if(self.poscount == 10)
        {
            camera RotateTo( self.spos[1]["angles"], 0.1, 0, 0 );
            camera MoveTo( self.spos[1]["origin"]+(0,0,-50), 0.1, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[2]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[2]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[3]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[3]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[4]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[4]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[5]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[5]["origin"]+(0,0,-50), self.cameratime / 9, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[6]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[6]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[7]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[7]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[8]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[8]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[9]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[9]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);

            camera RotateTo( self.spos[10]["angles"], self.cameratime / 10, 0, 0 );
            camera MoveTo( self.spos[10]["origin"]+(0,0,-50), self.cameratime / 10, 0, 0 );
        
            wait ( self.cameratime / self.poscount);
        }

        self Unlink();
	wait 0.05;
        setDvar("cg_draw2D", "1");
        setDvar("cg_drawGun", "1");
	self thread ShowCamNode();
    }
}

SaveAngles()
{
    self endon( "death" ); 
    self endon( "disconnect" );
    self notifyOnPlayerCommand( "mvm_cam_rot", "mvm_cam_rot" );
    for(;;)
    {
        self waittill( "mvm_cam_rot" );
	argumentstring = getDvar("mvm_cam_rot", "");
        arguments = StrTok(argumentstring, " ,");

        setDvar("arg_angleZ", arguments[0]);
        
        level.player SetPlayerAngles(self.angles + (0, 0, getDvarFloat("arg_angleZ", "")));
        self IPrintLn("^3Angle ^1changed to : ^7" + getDvarFloat("arg_angleZ", "") + " ");
	wait(0.2);
    }
}

InitGrenadeCam()
{
    self endon("death");
    self endon("disconnect");
    self notifyOnPlayerCommand( "mvm_cam_nade", "mvm_cam_nade" );
    for(;;)
    {
	self waittill("mvm_cam_nade");

	if( !isDefined(self.nademode))
	{
	self thread GrenadeCam();
	self iPrintLn( "^5GRENADE CAM ^2ON" );
	self.nademode = 1;
	}
	else if(self.nademode == 1)
	{
        self notify("endnade");
	self iPrintLn( "^5GRENADE CAM ^1OFF" );
	self.nademode = undefined;
	}
     }
}

GrenadeCam()      // Thanks Luster for the base script
{
	self endon("endnade");
	self endon("disconnect");
	
	for(;;)
            {
           	self waittill ( "grenade_fire", grenade, weaponName );
                self playerlinktoDelta( grenade, undefined, 50);
		setDvar("camera_thirdperson", "1");
		setDvar("camera_thirdpersonoffset", "0 0 45");
                self setorigin(grenade.origin + ( 0, 0, 180 )  );
  		while(isdefined(grenade))
                wait 0.05;
            }
     
}

CamDebug()
{
		if( !isDefined(self.saved_originstart) )
        	{
            	self.saved_originstart = self GetOrigin();
            	self.saved_anglesstart = (0,360,0);
            	self.poscount = 0;
		}
}



//========================================== BEZIER SCRIPT ===============================
//========================================================================================

BezierStart()
{
self endon("disconnect");
self endon("death");


self notifyOnplayerCommand( "mvm_cam_bezier", "mvm_cam_bezier" );
for(;;)
    {
    self waittill("mvm_cam_bezier");


	if(self.poscount == 1)
        {
	self IPrintLn("^1Need atleast 2 points to start");
        self IPrintLnBold("^1Need atleast 2 points to start"); 
	return;
        }

	self freezecontrols(true);
	self thread Prepare();	
	self setOrigin(self.spos[1]["origin"]);
	self setPlayerAngles(self.spos[1]["angles"]);
	wait ( 0.1 );
	self thread BezierFlight();

	self waittill("fin");
	self freezecontrols(false);
        setDvar("cg_draw2D", 1);
        setDvar("cg_drawGun", 1);
	self setClientDvar("timescale", "1");
	self thread ShowCamNode();
       }
}


BezierFlight()
{
self endon("fin");

self setClientDvar("cg_drawgun", 0);
self setClientDvar("cg_draw2d", 0);

dist=level.alldist;
mul = 3; // seems that's the best
level.multiplier = getDvarint("sv_fps") / 100; // sv_fps = 20 afaik
for (i = 0; i <= dist*10*level.multiplier/mul; i++) 
		{		
		t=(i*mul/(dist*10*level.multiplier));
		self.x=0;
		self.y=0;
		self.z=0;
		self.a=0;
		self.b=0;
		self.c=0;
		for(z=1;z<=self.poscount;z++)		
        		{
				self.x+=float(koeff(z-1, self.poscount-1)*pow((1-t),self.poscount-z)*pow(t,z-1)*self.spos[z]["origin"][0]);
				self.y+=float(koeff(z-1, self.poscount-1)*pow((1-t),self.poscount-z)*pow(t,z-1)*self.spos[z]["origin"][1]);
				self.z+=float(koeff(z-1, self.poscount-1)*pow((1-t),self.poscount-z)*pow(t,z-1)*self.spos[z]["origin"][2]);
				self.a+=float(koeff(z-1, self.poscount-1)*pow((1-t),self.poscount-z)*pow(t,z-1)*self.spos[z]["angles"][0]);
				self.b+=float(koeff(z-1, self.poscount-1)*pow((1-t),self.poscount-z)*pow(t,z-1)*self.spos[z]["angles"][1]);
				self.c+=float(koeff(z-1, self.poscount-1)*pow((1-t),self.poscount-z)*pow(t,z-1)*self.spos[z]["angles"][2]);
			}		
		vect = (self.x, self.y, self.z);
		vectA= (self.a, self.b, self.c);

		self setOrigin(vect);
		self setPlayerAngles(vectA);
		wait .05;
 		}
 	level.flight = 0;
	self.canUse = true;
	wait 5;
	self notify("fin");
}

Prepare() 
{
	level.alldist = 0;

	for(k=1; k<self.poscount; k++)
	{
		x=self.spos[k]["angles"][1];
		y=self.spos[k+1]["angles"][1];
		
		if(y - x >= 180)
		{
		 self.spos[k]["angles"]+=(0,360,0);
		}

		else if(y - x <= -180)
		{
		 self.spos[k+1]["angles"]+=(0,360,0);
		}

		level.partdist[k] = distance(self.spos[k]["origin"], self.spos[k+1]["origin"] );
		level.angledist[k] = distance(self.spos[k]["angles"], self.spos[k+1]["angles"]);
		level.alldist+=level.partdist[k];
		level.alldist+=level.angledist[k];
		self thread HideCamNode();
	}

}

// Some math shit that I don't understand lol

float(var) 
{
 setDvar("temp", var);
 return getDvarfloat("temp");
}


koeff(x,y)
{
	return (fact(y)/(fact(x)*fact(y-x)));
}

fact(x)
{
	c=1;
	if(x==0) return 1;
	for(i=1;i<=x;i++)
	c=c*i;
	return c;
}

pow(a,b)
{
	x=1;
	if(b!=0)
	{
		for(i=1;i<=b;i++)
		x=x*a;
	}
	return x;
}

mod(a) 
{
 	if (a >= 0) return a;
 	else return a * (-1);
}


//================================= END OF FILE ===================================
