[FilterScript] Aero's FreeCam [Beta]
#1

Introduction
It's been too long since I've released a script, so I figure now is the time. Sorry for a short intro, but it is a simple script. I wrote it from scratch after all the other camera scripts I found felt constrictive, and any admin flight scripts were outdated -- this is not recommended as an admin flight script, however it can achieve similar goals. Anyone who used my script liked it, and I still use it often.

How It Works
An object is created, and the player's camera is attached to the object. This allows for full camera "look" using the mouse. The object is moved by using the arrow keys and shift/space, and does not change by the way you are facing. Think of it like a tank. The mouse moves the gun, while the controls move the tank. Note: the object does not turn, it swivels in place.

Meanwhile, the player is spawned at z = -30 and boxed in. It is possible to fly down to this box and see yourself. As you move with the camera, your player will follow you. When you deactivate the camera, your player is spawned at the camera's position.

Conclusion
I am definitely open to suggestions. Feel free to leave feedback. All commands and controls can be found in the script, and/or when you connect.

Known Bugs
-Only works for base player (ID 0) - most Likely fixed in next update, needs testing

Next Update - What to Expect (Updated 8/29)
-3 new special camera modes - ~80% complete
-FULL 3D movement - 100% complete
-Movement tweaks to accompany the new movement controls - Done?
-Credits CMD - 100% complete (was going to be a clickable textdraw, couldn't get it to work)

Full Changelog
-Added Textdraws for object angle and direction
-Added hud toggle command




Code
pawn Code:
//
//
//      Aero's FreeCam Filterscript
//
//
#define FILTERSCRIPT

#include <a_samp>
#include <zcmd>
#include <sscanf2>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Aero's FreeCam");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif

#define COLOR 0xDCB700FF

new CamSet[MAX_PLAYERS];
new bool:CamEnabled[MAX_PLAYERS] = false;
new CamSpeed[MAX_PLAYERS] = 3;
new PlayerCatch[MAX_PLAYERS][6];
new FlyTimer[MAX_PLAYERS];
new Float:x, Float:y, Float:z, Float:a;
new BoxCount[MAX_PLAYERS] = 0;

new PlayerText:Textdraw0[MAX_PLAYERS]; //Aero's FC
new PlayerText:Textdraw1[MAX_PLAYERS]; //Angle
new PlayerText:Textdraw2[MAX_PLAYERS]; //Direction
new bool:FCHUD[MAX_PLAYERS] = false;

CMD:freecam(playerid,params[])
{
    if(CamEnabled[playerid] == false)
    {
        GetPlayerPos(playerid, x,y,z);
        GetPlayerFacingAngle(playerid, a);
        CamSet[playerid]=CreateObject(19300,x,y,z+2,0,0,a);
        AttachCameraToObject(playerid, CamSet[playerid]);
        CamEnabled[playerid] = true;
        PlayerCatch[playerid][0] = CreateObject(3095,x,y,z-32,0,0,0);
        PlayerCatch[playerid][1] = CreateObject(3095,x,y+3,z-30,90,0,0);
        PlayerCatch[playerid][2] = CreateObject(3095,x,y-3,z-30,90,0,0);
        PlayerCatch[playerid][3] = CreateObject(3095,x+3,y,z-30,0,90,0);
        PlayerCatch[playerid][4] = CreateObject(3095,x-3,y,z-30,0,90,0);
        PlayerCatch[playerid][5] = CreateObject(3095,x,y,z-27,0,0,0);
        SetPlayerPos(playerid, x,y,z-30);
        FlyTimer[playerid] = SetTimerEx("FreeCam",10,true,"i",playerid);
        PlayerTextDrawShow(playerid, Textdraw0[playerid]);
        PlayerTextDrawShow(playerid, Textdraw1[playerid]);
        PlayerTextDrawShow(playerid, Textdraw2[playerid]);
        FCHUD[playerid] = true;
    }
    else
    {
        GetObjectPos(CamSet[playerid], x, y, z);
        GetObjectRot(CamSet[playerid], a, a, a);
        SetPlayerPos(playerid,x,y,z);
        SetPlayerFacingAngle(playerid, a);
        DestroyObject(CamSet[playerid]);
        SetCameraBehindPlayer(playerid);
        CamEnabled[playerid] = false;
        KillTimer(FlyTimer[playerid]);
        for(new i=0; i<6; i++)
        {
            if (IsValidObject(PlayerCatch[playerid][i]))
            {
                DestroyObject(PlayerCatch[playerid][i]);
            }
        }
        BoxCount[playerid] = 0;
        PlayerTextDrawHide(playerid, Textdraw0[playerid]);
        PlayerTextDrawHide(playerid, Textdraw1[playerid]);
        PlayerTextDrawHide(playerid, Textdraw2[playerid]);
        FCHUD[playerid] = false;
    }
    return 1;
}

CMD:camspeed(playerid,params[])
{
    new speed;
    if(sscanf(params,"i",speed)) return SendClientMessage(playerid,COLOR,"Usage: /camspeed [1-5] (1 = slow, 2 = half slow, 3 = medium (default), 4 = half fast, 5 = fast)");
    if(speed < 1 || speed > 5) return SendClientMessage(playerid,COLOR,"Usage: /camspeed [1-5] (1 = slow, 2 = half slow, 3 = medium (default), 4 = half fast, 5 = fast)");
    if(CamEnabled[playerid] == true)
    {
        CamSpeed[playerid] = speed;
    }
    return 1;
}

CMD:camhelp(playerid,params[])
{
    SendClientMessage(playerid,COLOR,"[FreeCam] Commands: /freecam, /camspeed, /camhelp, /fchud, /savecampos [comment (optional)]");
    SendClientMessage(playerid,COLOR,"[FreeCam] Controls: Aim with mouse, W/S is Forward/Backward, A/D is Rotation Left/Right.");
    SendClientMessage(playerid,COLOR,"[FreeCam] Controls: Press Shift for upward movement, and SpaceBar for downward monement.");
    return 1;
}

CMD:savecampos(playerid, params[])
{
    new comment[128];
    if(sscanf(params,"s",comment)){comment = "";}
    new Float:x2, Float:y2, Float:z2;
    GetPlayerCameraPos(playerid,x,y,z);
    GetPlayerCameraFrontVector(playerid,x2,y2,z2);
    new string[256];
    if(!fexist("/SavedCamPositions.txt")){format(string,sizeof(string),"FreeCam Saved Positions\r\n=============================\r\n[FreeCam] %f, %f, %f, looking at: %f, %f, %f //%s\r\n",x,y,z,x2,y2,z2,comment);}
    else format(string,sizeof(string),"[FreeCam] %f, %f, %f, looking at: %f, %f, %f //%s\r\n",x,y,z,x2,y2,z2,comment);
    new File:savepos = fopen("/SavedCamPositions.txt", io_append);
    if(savepos)
    {
        fwrite(savepos, string);
        fclose(savepos);
    }
    new string2[256];
    format(string2, sizeof(string2),"[FreeCam] %f, %f, %f, looking at: %f, %f, %f//%s",x,y,z,x2,y2,z2,comment);
    SendClientMessage(playerid,COLOR,string2);
    SendClientMessage(playerid,COLOR,"Saved to /SavedCamPositions.txt");
    return 1;
}

CMD:fchud(playerid, params[])
{
    if(CamEnabled[playerid] == false) return SendClientMessage(playerid, COLOR, "Usage: /fchud (toggles the hud while in camera mode)");
    if(FCHUD[playerid] == true)
    {
        PlayerTextDrawHide(playerid, Textdraw0[playerid]);
        PlayerTextDrawHide(playerid, Textdraw1[playerid]);
        PlayerTextDrawHide(playerid, Textdraw2[playerid]);
        FCHUD[playerid] = false;
    }
    else
    {
        PlayerTextDrawShow(playerid, Textdraw0[playerid]);
        PlayerTextDrawShow(playerid, Textdraw1[playerid]);
        PlayerTextDrawShow(playerid, Textdraw2[playerid]);
        FCHUD[playerid] = true;
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,COLOR,"FreeCam Beta: /camhelp");

    Textdraw0[playerid] = CreatePlayerTextDraw(playerid, 315.600036, 411.661895, "Aero's FreeCam");
    PlayerTextDrawLetterSize(playerid, Textdraw0[playerid], 0.230000, 1.299999);
    PlayerTextDrawTextSize(playerid, Textdraw0[playerid], 462.000000, 313.600128);
    PlayerTextDrawAlignment(playerid, Textdraw0[playerid], 2);
    PlayerTextDrawColor(playerid, Textdraw0[playerid], -5963521);
    PlayerTextDrawUseBox(playerid, Textdraw0[playerid], true);
    PlayerTextDrawBoxColor(playerid, Textdraw0[playerid], 170);
    PlayerTextDrawSetShadow(playerid, Textdraw0[playerid], 0);
    PlayerTextDrawSetOutline(playerid, Textdraw0[playerid], 1);
    PlayerTextDrawBackgroundColor(playerid, Textdraw0[playerid], 170);
    PlayerTextDrawFont(playerid, Textdraw0[playerid], 2);
    PlayerTextDrawSetProportional(playerid, Textdraw0[playerid], 1);

    Textdraw1[playerid] = CreatePlayerTextDraw(playerid, 205.999786, 412.657653, "");
    PlayerTextDrawLetterSize(playerid, Textdraw1[playerid], 0.230000, 1.299999);
    PlayerTextDrawTextSize(playerid, Textdraw1[playerid], 0.399999, 93.582229);
    PlayerTextDrawAlignment(playerid, Textdraw1[playerid], 2);
    PlayerTextDrawColor(playerid, Textdraw1[playerid], -5963521);
    PlayerTextDrawUseBox(playerid, Textdraw1[playerid], true);
    PlayerTextDrawBoxColor(playerid, Textdraw1[playerid], -1431655834);
    PlayerTextDrawSetShadow(playerid, Textdraw1[playerid], 0);
    PlayerTextDrawSetOutline(playerid, Textdraw1[playerid], 1);
    PlayerTextDrawBackgroundColor(playerid, Textdraw1[playerid], 51);
    PlayerTextDrawFont(playerid, Textdraw1[playerid], 2);
    PlayerTextDrawSetProportional(playerid, Textdraw1[playerid], 1);

    Textdraw2[playerid] = CreatePlayerTextDraw(playerid, 424.799774, 412.657531, "");
    PlayerTextDrawLetterSize(playerid, Textdraw2[playerid], 0.230000, 1.299999);
    PlayerTextDrawTextSize(playerid, Textdraw2[playerid], 46.800003, 93.582237);
    PlayerTextDrawAlignment(playerid, Textdraw2[playerid], 2);
    PlayerTextDrawColor(playerid, Textdraw2[playerid], -5963521);
    PlayerTextDrawUseBox(playerid, Textdraw2[playerid], true);
    PlayerTextDrawBoxColor(playerid, Textdraw2[playerid], -1431655834);
    PlayerTextDrawSetShadow(playerid, Textdraw2[playerid], 0);
    PlayerTextDrawSetOutline(playerid, Textdraw2[playerid], 1);
    PlayerTextDrawBackgroundColor(playerid, Textdraw2[playerid], 51);
    PlayerTextDrawFont(playerid, Textdraw2[playerid], 2);
    PlayerTextDrawSetProportional(playerid, Textdraw2[playerid], 1);

    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(CamEnabled[playerid] == true)
    {
        DestroyObject(CamSet[playerid]);
        CamSpeed[playerid] = 2;
        CamEnabled[playerid] = false;
        KillTimer(FlyTimer[playerid]);
        for(new i=0; i<6; i++)
        {
            if (IsValidObject(PlayerCatch[playerid][i]))
            {
                DestroyObject(PlayerCatch[playerid][i]);
            }
        }
        BoxCount[playerid] = 0;
    }
    return 1;
}

forward FreeCam(playerid);
public FreeCam(playerid)
{
    new Keys,ud,lr;
    GetPlayerKeys(playerid,Keys,ud,lr);
    if(CamEnabled[playerid] == true)
    {
        if(ud == KEY_UP)
        {
            GetXYInFrontOfObject(CamSet[playerid], x, y, z, 1);
            MoveObject(CamSet[playerid],x,y,z,CamSpeed[playerid]*3);
        }
        if(ud == KEY_DOWN)
        {
            GetXYInFrontOfObject(CamSet[playerid], x, y, z, -1);
            MoveObject(CamSet[playerid],x,y,z,CamSpeed[playerid]*3);
        }
        if(lr == KEY_LEFT)
        {
            GetObjectPos(CamSet[playerid], x, y, z);
            GetObjectRot(CamSet[playerid], a, a, a);
            MoveObject(CamSet[playerid],x,y,z,3,0,0,a+2);
        }
        if(lr == KEY_RIGHT)
        {
            GetObjectPos(CamSet[playerid], x, y, z);
            GetObjectRot(CamSet[playerid], a, a, a);
            MoveObject(CamSet[playerid],x,y,z,3,0,0,a-2);
        }
        if (Keys == KEY_SPRINT)
        {
            GetObjectPos(CamSet[playerid], x, y, z);
            MoveObject(CamSet[playerid],x,y,z-1,CamSpeed[playerid]*2);
        }
        if (Keys == KEY_JUMP)
        {
            GetObjectPos(CamSet[playerid], x, y, z);
            MoveObject(CamSet[playerid],x,y,z+1,CamSpeed[playerid]*2);
        }
    }
    if(BoxCount[playerid] == 100)
    {
        for(new i=0; i<6; i++)
        {
            if (IsValidObject(PlayerCatch[playerid][i]))
            {
                DestroyObject(PlayerCatch[playerid][i]);
            }
        }
        PlayerCatch[playerid][0] = CreateObject(3095,x,y,-32,0,0,0);
        PlayerCatch[playerid][1] = CreateObject(3095,x,y+3,-30,90,0,0);
        PlayerCatch[playerid][2] = CreateObject(3095,x,y-3,-30,90,0,0);
        PlayerCatch[playerid][3] = CreateObject(3095,x+3,y,-30,0,90,0);
        PlayerCatch[playerid][4] = CreateObject(3095,x-3,y,-30,0,90,0);
        PlayerCatch[playerid][5] = CreateObject(3095,x,y,-27,0,0,0);
        SetPlayerPos(playerid, x,y,-30);
        BoxCount[playerid] = 0;
    }
    BoxCount[playerid]++;
    UpdateTDs(playerid);
    return 1;
}

stock UpdateTDs(playerid)
{
    new TD1[24];
    new TD2[24];
    new Float:Rot;
    GetObjectRot(CamSet[playerid], Rot, Rot, Rot);
    new Dir = floatround(Rot,floatround_round);
    while(Dir > 360){Dir -= 360;}
    while(Dir < 0){Dir += 360;}
    format(TD1, sizeof(TD1), "Angle: %i", Dir);
    new Str[3];
    switch(Dir)
    {
        case 0..22: Str = "N";
        case 23..67: Str = "NW";
        case 68..112: Str = "W";
        case 113..157: Str = "SW";
        case 158..202: Str = "S";
        case 203..247: Str = "SE";
        case 248..292: Str = "E";
        case 293..337: Str = "NE";
        case 338..360: Str = "N";
    }
    format(TD2, sizeof(TD2), "Direction: %s", Str);
    PlayerTextDrawSetString(playerid, Textdraw1[playerid], TD1);
    PlayerTextDrawSetString(playerid, Textdraw2[playerid], TD2);
}

GetXYInFrontOfObject(objectid, &Float:x2, &Float:y2, &Float:z2, Float:distance)
{ //modified from GetXYInFrontOfPlayer
    new Float:a2;
    GetObjectPos(objectid, x2, y2, z2);
    GetObjectRot(objectid, a2, a2, a2);
    x2 += (distance * floatsin(-a2, degrees));
    y2 += (distance * floatcos(-a2, degrees));
}
Mediafire Download
Reply
#2

Good Job I really like it.
Reply
#3

awsm, THnx
Reply
#4

Tell me why I should use your free cam instead of one that is packed in default samp server?
However good job.
Reply
#5

it like camhack Ty i have search em for my videos samp
AWESOME !
Reply
#6

Nice man
Reply
#7

Thanks all. Any suggestions? Anything that can be improved?

Quote:
Originally Posted by MicroD
View Post
Tell me why I should use your free cam instead of one that is packed in default samp server?
However good job.
If you mean the fly mode, it stutters and you can see your player in that ugly falling animation. This camera moves fluidly, and that's why it's so likable.
Reply
#8

Just an question how people record tutorials and show them when player register or more...
Reply
#9

Nice camera bro.
Quote:
Originally Posted by AroseKhanNaizi
View Post
Just an question how people record tutorials and show them when player register or more...
Use a timer to change camera positions and use InterpolateCameraPos
Reply
#10

Quote:
Originally Posted by Cannary2048
View Post
Nice camera bro.

Use a timer to change camera positions and use InterpolateCameraPos
thanks +rep for both
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)