SHOW:
|
|
- or go back to the newest paste.
| 1 | /* | |
| 2 | - | SetPlayerCamera function by MP2 |
| 2 | + | HUD-less Camera System |
| 3 | by MP2 | |
| 4 | ||
| 5 | - | Works by putting players in to spectate mode then setting the camera on the |
| 5 | + | |
| 6 | - | next OnPlayerUpdate call. |
| 6 | + | |
| 7 | Version: 3.0 (3th of April 2013) | |
| 8 | ||
| 9 | ||
| 10 | HOW IT WORKS | |
| 11 | - | #define CAMUPDATE_SET 1 // Just set the camera |
| 11 | + | |
| 12 | - | #define CAMUPDATE_MOVE 2 // 'CAMERA_MOVE' in SetPlayerCameraLookAt (reset) |
| 12 | + | There are 3 ways to set a camera: |
| 13 | - | #define CAMUPDATE_MOVE2 3 // 'CAMERA_MOVE' in SetPlayerCameraLookAt (move) |
| 13 | + | |
| 14 | - | #define CAMUPDATE_INTERPOLATE 4 // Interpolation |
| 14 | + | - Set (SetPlayerCamera) |
| 15 | • Set a player's camera instantly to a static location | |
| 16 | ||
| 17 | - Move (SetPlayerCamera: ) | |
| 18 | • Move (interpolate) a player's camera from it's current position to a new one | |
| 19 | ||
| 20 | - Interpolate (InterpolatePlayerCamera) | |
| 21 | • Like Move but with a specified delay. Doesn't interpolate from current pos, | |
| 22 | can interpolate from anywhere, TO anywhere. | |
| 23 | ||
| 24 | To remove the HUD, the player is placed in to 'spectator mode'. | |
| 25 | When in spectator mode and not spectating a player/vehicle, the player will see | |
| 26 | a bridge, which I refer to as 'Spectator's Bridge'. If you set the player's camera | |
| 27 | straight away, it will not work; they will be staring at that brige. | |
| 28 | To get around this, you have to have a small delay. A timer would be your first thought | |
| 29 | (as it was mine) but I use OnPlayerUpdate (hooked) as if a player was paused when | |
| 30 | their camera was set, when they resume the game they will be still staring at | |
| 31 | Spectator's Bridge. This fixes that. | |
| 32 | ||
| 33 | This include can be used for many things: | |
| 34 | - Login screens | |
| 35 | - Ban screens | |
| 36 | - Tutorials | |
| 37 | - 'CCTV' cameras | |
| 38 | - Menus | |
| 39 | - Cutscenes | |
| 40 | - and whatever else your imagination can think of! | |
| 41 | ||
| 42 | If you have any suggestions, have found a bug (problem/issue) or just want to give some feedback | |
| 43 | (negative or positive, I'm always open to advice!) | |
| 44 | feel free to do so here: http://forum.sa-mp.com/showthread.php?p=2362690 | |
| 45 | ||
| 46 | Enjoy! | |
| 47 | ||
| 48 | */ | |
| 49 | ||
| 50 | // This include uses y_hooks by Y_Less (part of the 'YSI' library) | |
| 51 | // You will need it. Google it. | |
| 52 | #include <YSI\y_hooks> | |
| 53 | ||
| 54 | new pUpdateCam[MAX_PLAYERS]; // Cam needs setting? See defines below | |
| 55 | #define CAMUPDATE_NONE 0 | |
| 56 | #define CAMUPDATE_SET 1 // Just set the camera (static) | |
| 57 | #define CAMUPDATE_MOVE 2 // 'CAMERA_MOVE' in SetPlayerCameraLookAt (reset to old pos) | |
| 58 | #define CAMUPDATE_MOVE2 3 // 'CAMERA_MOVE' in SetPlayerCameraLookAt (move to new pos) | |
| 59 | #define CAMUPDATE_INTERPOLATE 4 // Interpolation starts | |
| 60 | ||
| 61 | enum E_CAMUPDATE_COORDS | |
| 62 | {
| |
| 63 | Float:CAMUPDATE_camPos[3], | |
| 64 | Float:CAMUPDATE_camLook[3], | |
| 65 | Float:CAMUPDATE_camPosNEW[3], // For interpolation (AFTER POS) | |
| 66 | Float:CAMUPDATE_camLookNEW[3] // For interpolation (AFTER LOOK) | |
| 67 | } | |
| 68 | new Float:pUpdateCamCoords[MAX_PLAYERS][E_CAMUPDATE_COORDS]; // Camera coords (pos+lookat) | |
| 69 | ||
| 70 | new CAM_OnPlayerUpdate_Calls[MAX_PLAYERS]; // Times needed to be called (set to 2 on set) | |
| 71 | ||
| 72 | /* FUNCTIONS | |
| 73 | native SetPlayerCamera(playerid, Float:x, Float:y, Float:z, Float:lookx, Float:looky, Float:lookz, bool:camera_interpolate=false); | |
| 74 | ||
| 75 | native InterpolatePlayerCamera(playerid, Float:startposx, Float:startposy, Float:startposz, Float:startlookx, Float:startlooky, Float:startlookz, Float:toposx, Float:toposy, Float:toposz, Float:tolookx, Float:tolooky, Float:tolookz, interpolation_time=3000); | |
| 76 | */ | |
| 77 | ||
| 78 | // Set a player's camera. If camera_interpolate is true the camera will interpolate (NO TIME CONTROL - see InterpolatePlayerCamera) | |
| 79 | stock SetPlayerCamera(playerid, Float:x, Float:y, Float:z, Float:lookx, Float:looky, Float:lookz, bool:camera_interpolate=false) | |
| 80 | {
| |
| 81 | TogglePlayerSpectating(playerid, true); | |
| 82 | ||
| 83 | if(camera_interpolate == false) // Just set | |
| 84 | {
| |
| 85 | pUpdateCam[playerid] = CAMUPDATE_SET; | |
| 86 | ||
| 87 | // Store the new coordinates | |
| 88 | pUpdateCamCoords[playerid][CAMUPDATE_camPos][0] = x; | |
| 89 | pUpdateCamCoords[playerid][CAMUPDATE_camPos][1] = y; | |
| 90 | pUpdateCamCoords[playerid][CAMUPDATE_camPos][2] = z; | |
| 91 | ||
| 92 | pUpdateCamCoords[playerid][CAMUPDATE_camLook][0] = lookx; | |
| 93 | pUpdateCamCoords[playerid][CAMUPDATE_camLook][1] = looky; | |
| 94 | pUpdateCamCoords[playerid][CAMUPDATE_camLook][2] = lookz; | |
| 95 | } | |
| 96 | else // We will need to re-set the camera to where it currently is | |
| 97 | {
| |
| 98 | pUpdateCam[playerid] = CAMUPDATE_MOVE; | |
| 99 | new Float:curx, Float:cury, Float:curz; // Cam pos | |
| 100 | new Float:curvx, Float:curvy, Float:curvz; // Front vector | |
| 101 | GetPlayerCameraPos(playerid, curx, cury, curz); | |
| 102 | GetPlayerCameraFrontVector(playerid, curvx, curvy, curvz); | |
| 103 | ||
| 104 | // NEW coordinates (after setting) | |
| 105 | pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][0] = x; | |
| 106 | pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][1] = y; | |
| 107 | pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][2] = z; | |
| 108 | - | public OnPlayerUpdate(playerid) |
| 108 | + | |
| 109 | pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][0] = lookx; | |
| 110 | - | if(pUpdateCam[playerid] != 0) // If camera needs setting, let's do it |
| 110 | + | |
| 111 | pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][2] = lookz; | |
| 112 | - | switch(pUpdateCam[playerid]) |
| 112 | + | |
| 113 | // CURRENT coordinates | |
| 114 | - | case CAMUPDATE_SET: |
| 114 | + | |
| 115 | pUpdateCamCoords[playerid][CAMUPDATE_camPos][1] = cury; | |
| 116 | - | SetPlayerCameraPos(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camPos][0], pUpdateCamCoords[playerid][CAMUPDATE_camPos][1], pUpdateCamCoords[playerid][CAMUPDATE_camPos][2]); |
| 116 | + | |
| 117 | - | SetPlayerCameraLookAt(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camLook][0], pUpdateCamCoords[playerid][CAMUPDATE_camLook][1], pUpdateCamCoords[playerid][CAMUPDATE_camLook][2]); |
| 117 | + | |
| 118 | - | |
| 118 | + | |
| 119 | - | pUpdateCam[playerid] = 0; // Doesn't need updating anymore |
| 119 | + | |
| 120 | curz += curvz; | |
| 121 | - | case CAMUPDATE_MOVE: |
| 121 | + | |
| 122 | pUpdateCamCoords[playerid][CAMUPDATE_camLook][0] = curx; | |
| 123 | - | // Set it back to the old one first |
| 123 | + | |
| 124 | - | SetPlayerCameraPos(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camPos][0], pUpdateCamCoords[playerid][CAMUPDATE_camPos][1], pUpdateCamCoords[playerid][CAMUPDATE_camPos][2]); |
| 124 | + | |
| 125 | - | SetPlayerCameraLookAt(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camLook][0], pUpdateCamCoords[playerid][CAMUPDATE_camLook][1], pUpdateCamCoords[playerid][CAMUPDATE_camLook][2]); |
| 125 | + | |
| 126 | - | |
| 126 | + | CAM_OnPlayerUpdate_Calls[playerid] = 3; |
| 127 | return 1; | |
| 128 | } | |
| 129 | - | case CAMUPDATE_MOVE2: |
| 129 | + | |
| 130 | // Interpolate a player's camera. | |
| 131 | - | // Now move it |
| 131 | + | |
| 132 | - | SetPlayerCameraPos(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][2]); |
| 132 | + | |
| 133 | - | SetPlayerCameraLookAt(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][2], CAMERA_MOVE); |
| 133 | + | |
| 134 | - | |
| 134 | + | |
| 135 | - | pUpdateCam[playerid] = 0; // Doesn't need updating anymore |
| 135 | + | |
| 136 | ||
| 137 | - | case CAMUPDATE_INTERPOLATE: |
| 137 | + | |
| 138 | pUpdateCamCoords[playerid][CAMUPDATE_camPos][1] = startposy; | |
| 139 | - | InterpolateCameraPos(playerid, |
| 139 | + | |
| 140 | - | pUpdateCamCoords[playerid][CAMUPDATE_camPos][0], pUpdateCamCoords[playerid][CAMUPDATE_camPos][1], pUpdateCamCoords[playerid][CAMUPDATE_camPos][2], |
| 140 | + | |
| 141 | - | pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][2], |
| 141 | + | |
| 142 | - | GetPVarInt(playerid, "CAM_IP_TIME"), CAMERA_MOVE); |
| 142 | + | |
| 143 | pUpdateCamCoords[playerid][CAMUPDATE_camLook][2] = startlookz; | |
| 144 | - | InterpolateCameraLookAt(playerid, |
| 144 | + | |
| 145 | - | pUpdateCamCoords[playerid][CAMUPDATE_camLook][0], pUpdateCamCoords[playerid][CAMUPDATE_camLook][1], pUpdateCamCoords[playerid][CAMUPDATE_camLook][2], |
| 145 | + | |
| 146 | - | pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][2], |
| 146 | + | |
| 147 | - | GetPVarInt(playerid, "CAM_IP_TIME"), CAMERA_MOVE); |
| 147 | + | |
| 148 | - | |
| 148 | + | |
| 149 | - | DeletePVar(playerid, "CAM_IP_TIME"); // Delete it; no longer needed. |
| 149 | + | |
| 150 | - | |
| 150 | + | |
| 151 | - | pUpdateCam[playerid] = 0; // Doesn't need updating anymore |
| 151 | + | |
| 152 | ||
| 153 | SetPVarInt(playerid, "CAM_IP_TIME", interpolation_time); | |
| 154 | ||
| 155 | CAM_OnPlayerUpdate_Calls[playerid] = 3; | |
| 156 | - | // Hooking |
| 156 | + | |
| 157 | - | #if defined NOHUDCAM_OnPlayerUpdate |
| 157 | + | |
| 158 | - | return NOHUDCAM_OnPlayerUpdate(playerid); |
| 158 | + | |
| 159 | - | #else |
| 159 | + | hook OnPlayerUpdate(playerid) |
| 160 | - | return 1; |
| 160 | + | {
|
| 161 | - | #endif |
| 161 | + | if(CAM_OnPlayerUpdate_Calls[playerid] > 1) // We need to do stuff |
| 162 | {
| |
| 163 | - | #if defined NOHUDCAM_OnPlayerUpdate |
| 163 | + | CAM_OnPlayerUpdate_Calls[playerid]--; |
| 164 | - | forward NOHUDCAM_OnPlayerUpdate(playerid); |
| 164 | + | DoPlayerCameraSet(playerid); |
| 165 | - | #endif |
| 165 | + | |
| 166 | - | #if defined _ALS_OnPlayerUpdate |
| 166 | + | |
| 167 | - | #undef OnPlayerUpdate |
| 167 | + | |
| 168 | - | #else |
| 168 | + | |
| 169 | - | #define _ALS_OnPlayerUpdate |
| 169 | + | forward CAM_DoPlayerCameraSet(playerid); |
| 170 | - | #endif |
| 170 | + | public CAM_DoPlayerCameraSet(playerid) |
| 171 | - | #define OnPlayerUpdate NOHUDCAM_OnPlayerUpdate |
| 171 | + | |
| 172 | DoPlayerCameraSet(playerid); | |
| 173 | return 1; | |
| 174 | } | |
| 175 | ||
| 176 | stock DoPlayerCameraSet(playerid) | |
| 177 | {
| |
| 178 | switch(pUpdateCam[playerid]) | |
| 179 | {
| |
| 180 | case CAMUPDATE_SET: | |
| 181 | {
| |
| 182 | SetPlayerCameraPos(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camPos][0], pUpdateCamCoords[playerid][CAMUPDATE_camPos][1], pUpdateCamCoords[playerid][CAMUPDATE_camPos][2]); | |
| 183 | SetPlayerCameraLookAt(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camLook][0], pUpdateCamCoords[playerid][CAMUPDATE_camLook][1], pUpdateCamCoords[playerid][CAMUPDATE_camLook][2]); | |
| 184 | } | |
| 185 | case CAMUPDATE_MOVE: | |
| 186 | {
| |
| 187 | // Set it back to the old one first | |
| 188 | SetPlayerCameraPos(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camPos][0], pUpdateCamCoords[playerid][CAMUPDATE_camPos][1], pUpdateCamCoords[playerid][CAMUPDATE_camPos][2]); | |
| 189 | SetPlayerCameraLookAt(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camLook][0], pUpdateCamCoords[playerid][CAMUPDATE_camLook][1], pUpdateCamCoords[playerid][CAMUPDATE_camLook][2]); | |
| 190 | ||
| 191 | if(CAM_OnPlayerUpdate_Calls[playerid] == 1) | |
| 192 | {
| |
| 193 | pUpdateCam[playerid] = CAMUPDATE_MOVE2; | |
| 194 | CAM_OnPlayerUpdate_Calls[playerid] = 3; | |
| 195 | } | |
| 196 | } | |
| 197 | case CAMUPDATE_MOVE2: | |
| 198 | {
| |
| 199 | // Now move it | |
| 200 | SetPlayerCameraPos(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][2]); | |
| 201 | SetPlayerCameraLookAt(playerid, pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][2], CAMERA_MOVE); | |
| 202 | } | |
| 203 | case CAMUPDATE_INTERPOLATE: | |
| 204 | {
| |
| 205 | InterpolateCameraPos(playerid, | |
| 206 | pUpdateCamCoords[playerid][CAMUPDATE_camPos][0], pUpdateCamCoords[playerid][CAMUPDATE_camPos][1], pUpdateCamCoords[playerid][CAMUPDATE_camPos][2], | |
| 207 | pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camPosNEW][2], | |
| 208 | GetPVarInt(playerid, "CAM_IP_TIME"), CAMERA_MOVE); | |
| 209 | ||
| 210 | InterpolateCameraLookAt(playerid, | |
| 211 | pUpdateCamCoords[playerid][CAMUPDATE_camLook][0], pUpdateCamCoords[playerid][CAMUPDATE_camLook][1], pUpdateCamCoords[playerid][CAMUPDATE_camLook][2], | |
| 212 | pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][0], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][1], pUpdateCamCoords[playerid][CAMUPDATE_camLookNEW][2], | |
| 213 | GetPVarInt(playerid, "CAM_IP_TIME"), CAMERA_MOVE); | |
| 214 | ||
| 215 | DeletePVar(playerid, "CAM_IP_TIME"); // No longer needed. | |
| 216 | } | |
| 217 | } | |
| 218 | } |