Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- *
- *
- *
- *
- *
- */
- #include <a_samp>
- /* ** Server Data ** */
- const
- Float: spawnX = 0.0, // The SPAWN X you're willing to work from
- Float: spawnY = 0.0, // The SPAWN Y you're willing to work from
- Float: spawnZ = 5.0, // The SPAWN Y you're willing to work from
- Float: camRadius = 20.0, // The radius of the camera rotating
- Float: camSpeed = 1.25, // The speed of the camera moving around. MUST NOT BE NULL; IT WONT MOVE IF SO!
- Float: camHeight = 6.0 // The height of the camera once moving!
- ;
- /* ** Player Data ** */
- new
- prc_Timer [MAX_PLAYERS], // The timer for the movement.
- bool: prc_Moving [MAX_PLAYERS], // Check if the player is moving his camera
- Float: prc_Degree [MAX_PLAYERS] // The degree counter to show which the player is on.
- ;
- forward MoveCamera(playerid);
- main() { }
- public OnGameModeInit()
- {
- SetGameModeText("RotationCamera test");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- return 1;
- }
- public OnGameModeExit()
- return 1;
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, spawnX, spawnY, spawnZ);
- if(prc_Moving[playerid] == false) // Check whether the camera is already set.
- {
- prc_Degree[playerid] = 0; // Reseting the variable
- prc_Timer[playerid] = SetTimerEx("MoveCamera", 75, true, "d", playerid); // Setting the timer
- prc_Moving[playerid] = true; // okay, now we're going to activate the moving variable
- }
- return 1;
- }
- public MoveCamera(playerid) // The core of the movement
- {
- static // Static for the repeation :O
- Float: nX, // The newX
- Float: nY // the newY
- ;
- if(prc_Moving[playerid] == false) // check whether the timer is activated and the variable isn't.
- {
- KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running.
- prc_Degree[playerid] = 0; // Reseting the variable
- }
- if(prc_Degree[playerid] >= 360) prc_Degree[playerid] = 0; // If the rotation is past 360, reset to 0 (looks more neater)
- prc_Degree[playerid] += camSpeed; // For some smooth rotation, I'm using 1.25
- nX = spawnX + camRadius * floatcos(prc_Degree[playerid], degrees);
- nY = spawnY + camRadius * floatsin(prc_Degree[playerid], degrees);
- // So, we're going to get the spawn axis and add the radius in to them.
- // Then we use the trignometric functions to apply such angles to the movement
- // making it look nice.
- SetPlayerCameraPos(playerid, nX, nY, spawnZ + camHeight); // Setting the Camera position around the player
- SetPlayerCameraLookAt(playerid, spawnX, spawnY, spawnZ); // Looking at the player position from there :)
- SetPlayerFacingAngle(playerid, prc_Degree[playerid] - 90.0); // to make it face the camera :)
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(prc_Moving[playerid] == true)
- {
- KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running.
- prc_Degree[playerid] = 0; // Reseting the variable
- prc_Moving[playerid] = false; // Reseting the variable
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(prc_Moving[playerid] == true)
- {
- KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running.
- prc_Degree[playerid] = 0; // Reseting the variable
- prc_Moving[playerid] = false; // Reseting the variable
- SetCameraBehindPlayer(playerid); // Preventing bugs from appearing.
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement