All pastes #620291 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-07-15 11:26 UTC
rendered paste body
//Version 1.5 - Donny_K - FM-A Guild

#include <a_samp>

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

new bool:UsingFreeLookSystem[MAX_PLAYERS],
	Float:DistanceToPoint[MAX_PLAYERS],
	Float:DistanceFromPlayer[MAX_PLAYERS],
	Float:LookingAngle[MAX_PLAYERS],
	Float:HeightFromPlayerToCamera[MAX_PLAYERS] = 0.0,
	KeyTimer[MAX_PLAYERS],
	LookTimer[MAX_PLAYERS],
	Text:text;

public OnFilterScriptInit()
{
	text = TextDrawCreate(300, 200, "'");

	TextDrawSetShadow(text, 0);

	TextDrawSetOutline(text, 0);

	TextDrawBackgroundColor(text, 0xFFFFFFFF);

	TextDrawColor(text, 0x11000011);
}

forward FreeLook(playerid);

public FreeLook(playerid)
{
	if (UsingFreeLookSystem[playerid])
     {
          new Float:Pos_x,
			  Float:Pos_y,
			  Float:Pos_z,
			  Float:Point_x,
			  Float:Point_y;

          GetPlayerPos(playerid, Pos_x, Pos_y, Pos_z);

          GetPointInfrontOfPlayer(playerid, Point_x, Point_y, floatround(DistanceToPoint[playerid]));

          GetPointInfrontOfPlayer(playerid, Pos_x, Pos_y, floatround(DistanceFromPlayer[playerid]));

          SetPlayerCameraPos(playerid, Pos_x, Pos_y, Pos_z + floatround(HeightFromPlayerToCamera[playerid]));

          SetPlayerCameraLookAt(playerid, Point_x, Point_y, Pos_z);
	 }
}

stock GetPointInfrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance) //Credit to Sacky/Simon/Y_Less for this, I haven't actually found out whos the original was
{
    new Float:angle,
	    Float:z;
    
    GetPlayerPos(playerid, x, y, z);
    
    GetPlayerFacingAngle(playerid, angle);
    
    if (IsPlayerInAnyVehicle(playerid))
	 {
		 GetVehicleZAngle(GetPlayerVehicleID(playerid), angle);
	 }
    
    x += (distance * floatsin(-angle + LookingAngle[playerid], degrees));

    y += (distance * floatcos(-angle + LookingAngle[playerid], degrees));
}

forward KeyCheck(playerid);

public KeyCheck(playerid) //Sloppy code but works.
{
	if (UsingFreeLookSystem[playerid])
     {
		 new Keys[3];
		 
         GetPlayerKeys(playerid, Keys[0], Keys[1], Keys[2]);

    	 if (Keys[0] & KEY_ANALOG_LEFT)
	 	  {
 	           LookingAngle[playerid] = LookingAngle[playerid] + 1;
	 	  }
	 	  
	     if (Keys[0] & KEY_ANALOG_RIGHT)
	 	  {
         	   LookingAngle[playerid] = LookingAngle[playerid] - 1;
	 	  }
	 	  
         if (Keys[0] & KEY_ANALOG_UP)
	 	  {
   		       DistanceToPoint[playerid] = DistanceToPoint[playerid] + 1;
     	  }
     	  
         if (Keys[0] & KEY_ANALOG_DOWN)
	 	  {
         	   DistanceToPoint[playerid] = DistanceToPoint[playerid] - 1;
	 	  }
	 	  
         if (Keys[0] & KEY_LOOK_LEFT)
	 	  {
         	   HeightFromPlayerToCamera[playerid] = HeightFromPlayerToCamera[playerid] - 1;
	 	  }
	 	  
         if (Keys[0] & KEY_LOOK_RIGHT)
	 	  {
         	   HeightFromPlayerToCamera[playerid] = HeightFromPlayerToCamera[playerid] + 1;
	 	  }
	 	  
         if (Keys[0] & KEY_CROUCH)
	 	  {
         	   DistanceFromPlayer[playerid] = DistanceFromPlayer[playerid] + 1;
     	  }
     	  
         if (Keys[0] & KEY_HANDBRAKE)
	 	  {
         	   DistanceFromPlayer[playerid] = DistanceFromPlayer[playerid] - 1;
	 	  }
	 }
}


dcmd_fl(playerid, params[])
{
	#pragma unused params

	if (!UsingFreeLookSystem[playerid])
	 {
		 UsingFreeLookSystem[playerid] = true;
		 
	 	 DistanceToPoint[playerid] = 15.0;

		 DistanceFromPlayer[playerid] = 9.0;

	 	 LookingAngle[playerid] = 0.0;
	 	 
	     KeyTimer[playerid] = SetTimerEx("KeyCheck", 30, true, "i", playerid);

	     LookTimer[playerid] = SetTimerEx("FreeLook", 10, true, "i", playerid);
	 }
    else
	 {

		 UsingFreeLookSystem[playerid] = false;
		 
		 KillTimer(KeyTimer[playerid]);
		 
		 KillTimer(LookTimer[playerid]);

		 new Float:x,
			 Float:y,
			 Float:z,
			 Float:angle;

		 GetPlayerFacingAngle(playerid, angle);

		 GetPlayerPos(playerid, x, y, z);

		 SetSpawnInfo(playerid, 0, GetPlayerSkin(playerid), x, y, z, angle, 0, 0, 0, 0, 0, 0);

		 SpawnPlayer(playerid);
	 }

	return 1;
}

dcmd_flhelp(playerid, params[])
{
	#pragma unused params

	SendClientMessage(playerid, 0xffffffff, "Controls:");
	
	SendClientMessage(playerid, 0xffffffff, "=========");
	
	SendClientMessage(playerid, 0xffffffff, "You use the Numpad keys 4-5,8-2 (left,right,up,down) to changes your viewing angle or viewing distance");

	SendClientMessage(playerid, 0xffffffff, "You use the Look Left (Q) and Look Right (E) keys to change the viewing height");
	
	SendClientMessage(playerid, 0xffffffff, "Use the Crouch (C) and Handbrake (Space) keys to change the player zoom distance");
	
	SendClientMessage(playerid, 0xffffffff, "FreeLook Commands:");
	
	SendClientMessage(playerid, 0xffffffff, "==================");

	SendClientMessage(playerid, 0xffffffff, "fl - Set FreeLook mode for the player");

	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(fl, 2, cmdtext);
	
	dcmd(flhelp, 6, cmdtext);

	return 0;
}

public OnPlayerConnect(playerid)
{
	UsingFreeLookSystem[playerid] = false;
	
	DistanceToPoint[playerid] = 15.0;
	
	DistanceFromPlayer[playerid] = 9.0;
	
	LookingAngle[playerid] = 0.0;
	
    HeightFromPlayerToCamera[playerid] = 4.0;
	
	SendClientMessage(playerid, 0xffffffff, "Using FreeLook by the FM-A Guild (http://guild.wickedcode.info)");

	SendClientMessage(playerid, 0xffffffff, "Type /flhelp to get started");
	
 	TextDrawShowForPlayer(playerid, text);

	return 1;
}