Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- //------------------------------------------------------------------------------
- #define MOVE_SPEED 100.0
- #define ACCEL_RATE 0.03
- #define CAMERA_MODE_NONE 0
- #define CAMERA_MODE_FLY 1
- #define MOVE_FORWARD 1
- #define MOVE_BACK 2
- #define MOVE_LEFT 3
- #define MOVE_RIGHT 4
- #define MOVE_FORWARD_LEFT 5
- #define MOVE_FORWARD_RIGHT 6
- #define MOVE_BACK_LEFT 7
- #define MOVE_BACK_RIGHT 8
- //------------------------------------------------------------------------------
- #define DIALOG_FILENAME 2000
- #define DIALOG_LIST 2001
- #define DIALOG_ROT 2002
- #define DIALOG_MOVE 2003
- #define DIALOG_SALVARE 2004
- //------------------------------------------------------------------------------
- enum noclipenum
- {
- cameramode,
- flyobject,
- mode,
- lrold,
- udold,
- lastmove,
- Float:accelmul
- }
- //------------------------------------------------------------------------------
- enum cInfo
- {
- Float:cStartX,
- Float:cStartY,
- Float:cStartZ,
- Float:cEndX,
- Float:cEndY,
- Float:cEndZ,
- Float:cStartLookX,
- Float:cStartLookY,
- Float:cStartLookZ,
- Float:cEndLookX,
- Float:cEndLookY,
- Float:cEndLookZ,
- MoveSpeed,
- RotSpeed,
- cName[32]
- }
- //------------------------------------------------------------------------------
- new noclipdata[MAX_PLAYERS][noclipenum];
- new Position[MAX_PLAYERS][cInfo];
- new Start[MAX_PLAYERS];
- //------------------------------------------------------------------------------
- CMD:cam(playerid, params[])
- {
- if(GetPVarType(playerid, "FlyMode")) CancelFlyMode(playerid);
- else FlyMode(playerid);
- return 1;
- }
- //------------------------------------------------------------------------------
- CMD:camera(playerid, params[])
- {
- ShowPlayerDialog(playerid, DIALOG_LIST, DIALOG_STYLE_LIST, "Options", "{FFFFFF}Start Position\nEnd Position\nRotation Speed\nMove Speed\nPreview\nSave", "Continue", "Exit");
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new string[200];
- if(dialogid == DIALOG_LIST)
- {
- if(response)
- {
- if(listitem == 0)
- {
- SendClientMessage(playerid, -1, "{FF0000}[CAMERA]: {FFFFFF}Press {FF0000}'LMB' {FFFFFF}and select your start position.");
- Start[playerid] = 1;
- }
- if(listitem == 1)
- {
- SendClientMessage(playerid, -1, "{FF0000}[CAMERA]: {FFFFFF}Press {FF0000}'LMB' {FFFFFF}and select your finish position.");
- Start[playerid] = 2;
- }
- if(listitem == 2)
- {
- format(string, sizeof(string), "{FFFFFF}Select your speed rotation.\n\nCurrent Speed: {FF0000}%d\n\n{FF0000}* NOTE: {FFFFFF}1000 miliseconds = 1 seconds.", Position[playerid][RotSpeed]);
- ShowPlayerDialog(playerid, DIALOG_ROT, DIALOG_STYLE_INPUT, "Rotation speed", string, "Continue", "Exit");
- }
- if(listitem == 3)
- {
- format(string, sizeof(string), "{FFFFFF}Select your moving speed.\n\nCurrent Speed: {FF0000}%d\n\n{FF0000}* NOTE: {FFFFFF}1000 miliseconds = 1 seconds.", Position[playerid][MoveSpeed]);
- ShowPlayerDialog(playerid, DIALOG_MOVE, DIALOG_STYLE_INPUT, "Moving Speed", string, "Continue", "Exit");
- }
- if(listitem == 4)
- {
- SendClientMessage(playerid, -1, "{FF0000}[CAMERA]: {FFFFFF}You started preview.");
- SetTimerEx("Menu", Position[playerid][MoveSpeed], false, "i", playerid);
- DestroyObject(noclipdata[playerid][flyobject]);
- SetCameraBehindPlayer(playerid);
- InterpolateCameraPos(playerid, Position[playerid][cStartX], Position[playerid][cStartY], Position[playerid][cStartZ], Position[playerid][cEndX], Position[playerid][cEndY], Position[playerid][cEndZ], Position[playerid][MoveSpeed]);
- InterpolateCameraLookAt(playerid, Position[playerid][cStartLookX], Position[playerid][cStartLookY], Position[playerid][cStartLookZ], Position[playerid][cEndLookX], Position[playerid][cEndLookY], Position[playerid][cEndLookZ], Position[playerid][RotSpeed]);
- }
- if(listitem == 5)
- {
- SendClientMessage(playerid, -1, "{FF0000}[SAVE]: {FFFFFF}Do you want to save this project?");
- ShowPlayerDialog(playerid, DIALOG_SALVARE, DIALOG_STYLE_MSGBOX, "Save", "Do you want to save this project?", "Yes", "No");
- }
- }
- }
- if(dialogid == DIALOG_ROT)
- {
- if(response)
- {
- SendClientMessage(playerid, -1, "{FF0000}[CAMERA]: {FFFFFF}You've selected your Rotation Speed.");
- Position[playerid][RotSpeed] = strval(inputtext);
- ShowPlayerDialog(playerid, DIALOG_LIST, DIALOG_STYLE_LIST, "Options", "{FFFFFF}Start Position\nEnd Position\nRotation Speed\nMove Speed\nPreview\nSave", "Continue", "Exit");
- }
- }
- if(dialogid == DIALOG_MOVE)
- {
- if(response)
- {
- SendClientMessage(playerid, -1, "{FF0000}[CAMERA]: {FFFFFF}You've selected your Moving Speed..");
- Position[playerid][MoveSpeed] = strval(inputtext);
- ShowPlayerDialog(playerid, DIALOG_LIST, DIALOG_STYLE_LIST, "Options", "{FFFFFF}Start Position\nEnd Position\nRotation Speed\nMove Speed\nPreview\nSave", "Continue", "Exit");
- }
- }
- if(dialogid == DIALOG_SALVARE)
- {
- if(response)
- {
- new movestring[1000], rotstring[1000];
- format(movestring, sizeof(movestring), "InterpolateCameraPos(playerid, %f, %f, %f, %f, %f, %f, %d);\r\n", Position[playerid][cStartX], Position[playerid][cStartY], Position[playerid][cStartZ], Position[playerid][cEndX], Position[playerid][cEndY], Position[playerid][cEndZ], Position[playerid][MoveSpeed]);
- format(rotstring, sizeof(rotstring), "InterpolateCameraLookAt(playerid, %f, %f, %f, %f, %f, %f, %d);", Position[playerid][cStartLookX], Position[playerid][cStartLookY], Position[playerid][cStartLookZ], Position[playerid][cEndLookX], Position[playerid][cEndLookY], Position[playerid][cEndLookZ], Position[playerid][RotSpeed]);
- new File:file = fopen("camera.txt");
- fwrite(file, movestring);
- fwrite(file, rotstring);
- fclose(file);
- }
- else
- {
- SendClientMessage(playerid, -1, "{FF0000}[PROJECT]: {FFFFFF}You've exited your project, and it didn't been saved.");
- Start[playerid] = 0;
- Position[playerid][cStartX] = 0;
- Position[playerid][cStartY] = 0;
- Position[playerid][cStartZ] = 0;
- Position[playerid][cEndX] = 0;
- Position[playerid][cEndY] = 0;
- Position[playerid][cEndZ] = 0;
- Position[playerid][cStartLookX] = 0;
- Position[playerid][cStartLookY] = 0;
- Position[playerid][cStartLookZ] = 0;
- Position[playerid][cEndLookX] = 0;
- Position[playerid][cEndLookY] = 0;
- Position[playerid][cEndLookZ] = 0;
- Position[playerid][MoveSpeed] = 0;
- Position[playerid][RotSpeed] = 0;
- Position[playerid][cName] = 0;
- }
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- forward Menu(playerid);
- public Menu(playerid)
- {
- ShowPlayerDialog(playerid, DIALOG_LIST, DIALOG_STYLE_LIST, "Options", "{FFFFFF}Start Position\nEnd Position\nRotation Speed\nMove Speed\nPreview\nSave", "Continue", "Exit");
- FlyMode(playerid);
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- new Float:X, Float:Y, Float:Z;
- GetPlayerPos(playerid, X, Y, Z);
- if(newkeys && KEY_FIRE)
- {
- if(Start[playerid] == 1)
- {
- SendClientMessage(playerid, -1, "{FF0000}[CAMERA]: {FFFFFF}This it's your Start's position.");
- ShowPlayerDialog(playerid, DIALOG_LIST, DIALOG_STYLE_LIST, "Options", "{FFFFFF}Start Position\nEnd Position\nRotation Speed\nMove Speed\nPreview\nSave", "Continue", "Exit");
- Position[playerid][cStartX] = X;
- Position[playerid][cStartY] = Y;
- Position[playerid][cStartZ] = Z;
- Position[playerid][cStartLookX] = X;
- Position[playerid][cStartLookY] = Y;
- Position[playerid][cStartLookZ] = Z;
- }
- if(Start[playerid] == 2)
- {
- SendClientMessage(playerid, -1, "{FF0000}[CAMERA]: {FFFFFF}This it's your End's position.");
- ShowPlayerDialog(playerid, DIALOG_LIST, DIALOG_STYLE_LIST, "Options", "{FFFFFF}Start Position\nEnd Position\nRotation Speed\nMove Speed\nPreview\nSave", "Continue", "Exit");
- Position[playerid][cEndX] = X;
- Position[playerid][cEndY] = Y;
- Position[playerid][cEndZ] = Z;
- Position[playerid][cEndLookX] = X;
- Position[playerid][cEndLookY] = Y;
- Position[playerid][cEndLookZ] = Z;
- Start[playerid] = 0;
- }
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnFilterScriptExit()
- {
- for(new x; x < MAX_PLAYERS; x++)
- {
- if(noclipdata[x][cameramode] == CAMERA_MODE_FLY) CancelFlyMode(x);
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerConnect(playerid)
- {
- noclipdata[playerid][cameramode] = CAMERA_MODE_NONE;
- noclipdata[playerid][lrold] = 0;
- noclipdata[playerid][udold] = 0;
- noclipdata[playerid][mode] = 0;
- noclipdata[playerid][lastmove] = 0;
- noclipdata[playerid][accelmul] = 0.0;
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerUpdate(playerid)
- {
- if(noclipdata[playerid][cameramode] == CAMERA_MODE_FLY)
- {
- new keys,ud,lr;
- GetPlayerKeys(playerid,keys,ud,lr);
- if(noclipdata[playerid][mode] && (GetTickCount() - noclipdata[playerid][lastmove] > 100))
- {
- MoveCamera(playerid);
- }
- if(noclipdata[playerid][udold] != ud || noclipdata[playerid][lrold] != lr)
- {
- if((noclipdata[playerid][udold] != 0 || noclipdata[playerid][lrold] != 0) && ud == 0 && lr == 0)
- {
- StopPlayerObject(playerid, noclipdata[playerid][flyobject]);
- noclipdata[playerid][mode] = 0;
- noclipdata[playerid][accelmul] = 0.0;
- }
- else
- {
- noclipdata[playerid][mode] = GetMoveDirectionFromKeys(ud, lr);
- MoveCamera(playerid);
- }
- }
- noclipdata[playerid][udold] = ud; noclipdata[playerid][lrold] = lr;
- return 0;
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnFilterScriptInit()
- {
- print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
- print("* * * * * * * * * * * * H-CAMERA EDITOR * * * * * * * * * * * * * * *");
- print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
- return 1;
- }
- //------------------------------------------------------------------------------
- stock GetMoveDirectionFromKeys(ud, lr)
- {
- new direction = 0;
- if(lr < 0)
- {
- if(ud < 0) direction = MOVE_FORWARD_LEFT;
- else if(ud > 0) direction = MOVE_BACK_LEFT;
- else direction = MOVE_LEFT;
- }
- else if(lr > 0)
- {
- if(ud < 0) direction = MOVE_FORWARD_RIGHT;
- else if(ud > 0) direction = MOVE_BACK_RIGHT;
- else direction = MOVE_RIGHT;
- }
- else if(ud < 0) direction = MOVE_FORWARD;
- else if(ud > 0) direction = MOVE_BACK;
- return direction;
- }
- //------------------------------------------------------------------------------
- stock MoveCamera(playerid)
- {
- new Float:FV[3], Float:CP[3];
- GetPlayerCameraPos(playerid, CP[0], CP[1], CP[2]);
- GetPlayerCameraFrontVector(playerid, FV[0], FV[1], FV[2]);
- if(noclipdata[playerid][accelmul] <= 1) noclipdata[playerid][accelmul] += ACCEL_RATE;
- new Float:speed = MOVE_SPEED * noclipdata[playerid][accelmul];
- new Float:X, Float:Y, Float:Z;
- GetNextCameraPosition(noclipdata[playerid][mode], CP, FV, X, Y, Z);
- MovePlayerObject(playerid, noclipdata[playerid][flyobject], X, Y, Z, speed);
- noclipdata[playerid][lastmove] = GetTickCount();
- return 1;
- }
- //------------------------------------------------------------------------------
- stock GetNextCameraPosition(move_mode, Float:CP[3], Float:FV[3], &Float:X, &Float:Y, &Float:Z)
- {
- #define OFFSET_X (FV[0]*6000.0)
- #define OFFSET_Y (FV[1]*6000.0)
- #define OFFSET_Z (FV[2]*6000.0)
- switch(move_mode)
- {
- case MOVE_FORWARD:
- {
- X = CP[0]+OFFSET_X;
- Y = CP[1]+OFFSET_Y;
- Z = CP[2]+OFFSET_Z;
- }
- case MOVE_BACK:
- {
- X = CP[0]-OFFSET_X;
- Y = CP[1]-OFFSET_Y;
- Z = CP[2]-OFFSET_Z;
- }
- case MOVE_LEFT:
- {
- X = CP[0]-OFFSET_Y;
- Y = CP[1]+OFFSET_X;
- Z = CP[2];
- }
- case MOVE_RIGHT:
- {
- X = CP[0]+OFFSET_Y;
- Y = CP[1]-OFFSET_X;
- Z = CP[2];
- }
- case MOVE_BACK_LEFT:
- {
- X = CP[0]+(-OFFSET_X - OFFSET_Y);
- Y = CP[1]+(-OFFSET_Y + OFFSET_X);
- Z = CP[2]-OFFSET_Z;
- }
- case MOVE_BACK_RIGHT:
- {
- X = CP[0]+(-OFFSET_X + OFFSET_Y);
- Y = CP[1]+(-OFFSET_Y - OFFSET_X);
- Z = CP[2]-OFFSET_Z;
- }
- case MOVE_FORWARD_LEFT:
- {
- X = CP[0]+(OFFSET_X - OFFSET_Y);
- Y = CP[1]+(OFFSET_Y + OFFSET_X);
- Z = CP[2]+OFFSET_Z;
- }
- case MOVE_FORWARD_RIGHT:
- {
- X = CP[0]+(OFFSET_X + OFFSET_Y);
- Y = CP[1]+(OFFSET_Y - OFFSET_X);
- Z = CP[2]+OFFSET_Z;
- }
- }
- }
- //------------------------------------------------------------------------------
- stock CancelFlyMode(playerid)
- {
- DeletePVar(playerid, "FlyMode");
- CancelEdit(playerid);
- TogglePlayerSpectating(playerid, false);
- DestroyPlayerObject(playerid, noclipdata[playerid][flyobject]);
- noclipdata[playerid][cameramode] = CAMERA_MODE_NONE;
- return 1;
- }
- //------------------------------------------------------------------------------
- stock FlyMode(playerid)
- {
- new Float:X, Float:Y, Float:Z;
- GetPlayerPos(playerid, X, Y, Z);
- noclipdata[playerid][flyobject] = CreatePlayerObject(playerid, 19300, X, Y, Z, 0.0, 0.0, 0.0);
- TogglePlayerSpectating(playerid, true);
- AttachCameraToPlayerObject(playerid, noclipdata[playerid][flyobject]);
- SetPVarInt(playerid, "FlyMode", 1);
- noclipdata[playerid][cameramode] = CAMERA_MODE_FLY;
- return 1;
- }
- //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement