Olá! hoje venho trazer um código novo que lhe permite movimentar câmera por todo mapa sem a necessidade do personagem
Comando: /camon para estar ativado o modo de câmera e /camoff desativar o modo de camera
Código desenvolvido por: ApelaMGA
Comando: /camon para estar ativado o modo de câmera e /camoff desativar o modo de camera
- Código:
#include <a_samp>
#include <zcmd>
new
bool: IsPlayerInCameraAtivada [MAX_PLAYERS char],
ObjectCam [MAX_PLAYERS],
Float: PlayerCameraAcelerar [MAX_PLAYERS]
;
enum
{
CAM_MODE_STOP,
CAM_MODE_FORWARD,
CAM_MODE_BACKWARD,
CAM_MODE_LEFT,
CAM_MODE_RIGHT,
CAM_MODE_FORWARD_LEFT,
CAM_MODE_FORWARD_RIGHT,
CAM_MODE_BACKWARD_LEFT,
CAM_MODE_BACKWARD_RIGHT
}
public OnPlayerUpdate(playerid)
{
new keys,ud,lr,direction;
GetPlayerKeys(playerid, keys, ud, lr);
direction = GetPlayerNextCamDirection(ud, lr);
if(direction)
{
new Float:pos[3], Float:vector[3], Float:x, Float:y, Float:z, Float:speed;
GetPlayerCameraPos(playerid, pos[0], pos[1], pos[2]);
GetPlayerCameraFrontVector(playerid, vector[0], vector[1], vector[2]);
GetPlayerNextCamPos(direction, pos, vector, x, y, z);
PlayerCameraAcelerar[playerid] += 0.05;
if(PlayerCameraAcelerar[playerid] > 1.0)
PlayerCameraAcelerar[playerid] = 1.0;
if( (keys & KEY_JUMP) == KEY_JUMP )
speed = 200.0 * PlayerCameraAcelerar[playerid];
else if( (keys & KEY_WALK) == KEY_WALK )
speed = 10.0 * PlayerCameraAcelerar[playerid];
else
speed = 50.0 * PlayerCameraAcelerar[playerid];
MovePlayerObject(playerid, ObjectCam[playerid], x, y, z, speed, 0.0, 0.0, 0.0);
}
else
{
StopPlayerObject(playerid, ObjectCam[playerid]);
PlayerCameraAcelerar[playerid] = 0.0;
}
return 1;
}
CMD:camon(playerid)
{
TogglePlayerFreeCam(playerid, true);
return true;
}
CMD:camoff(playerid)
{
TogglePlayerFreeCam(playerid, false);
return true;
}
TogglePlayerFreeCam(playerid, bool:toggle)
{
if(toggle == IsPlayerInCameraAtivada{playerid})
return 0;
if(toggle)
{
switch(GetPlayerState(playerid))
{
case PLAYER_STATE_NONE, PLAYER_STATE_WASTED, PLAYER_STATE_SPECTATING:
return 0;
case PLAYER_STATE_DRIVER, PLAYER_STATE_PASSENGER:
{
new
Float: x,
Float: y,
Float: z
;
GetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
SetPlayerPos(playerid, x, y, z);
}
}
new
Float: x,
Float: y,
Float: z
;
GetPlayerPos(playerid, x, y, z);
IsPlayerInCameraAtivada{playerid} = true;
TogglePlayerSpectating(playerid, true);
ObjectCam[playerid] = CreatePlayerObject(playerid, 19300, x, y, z, 0.0, 0.0, 0.0);
AttachCameraToPlayerObject(playerid, ObjectCam[playerid]);
GameTextForPlayer(playerid, "~w~Camera ~g~ativa", 2000, 4);
}
else
{
new
Float: x,
Float: y,
Float: z
;
GetPlayerObjectPos(playerid, ObjectCam[playerid], x, y, z);
DestroyPlayerObject(playerid, ObjectCam[playerid]);
ObjectCam[playerid] = INVALID_OBJECT_ID;
IsPlayerInCameraAtivada{playerid} = false;
TogglePlayerSpectating(playerid, false);
SetPlayerPos(playerid, x, y, z);
GameTextForPlayer(playerid, "~w~Camera ~r~desativda", 2000, 4);
}
return 1;
}
GetPlayerNextCamDirection(ud, lr)
{
new direction;
if(ud < 0)
{
if(lr > 0)
direction = CAM_MODE_FORWARD_RIGHT;
else if(lr < 0)
direction = CAM_MODE_FORWARD_LEFT;
else
direction = CAM_MODE_FORWARD;
}
else if(ud > 0)
{
if(lr > 0)
direction = CAM_MODE_BACKWARD_RIGHT;
else if(lr < 0)
direction = CAM_MODE_BACKWARD_LEFT;
else
direction = CAM_MODE_BACKWARD;
}
else if(lr > 0)
direction = CAM_MODE_RIGHT;
else if(lr < 0)
direction = CAM_MODE_LEFT;
else
direction = CAM_MODE_STOP;
return direction;
}
GetPlayerNextCamPos(direction, Float:pos[3], Float:vector[3], &Float:x, &Float:y, &Float:z)
{
#define OFFSET_X (vector[0] * 6000.0)
#define OFFSET_Y (vector[1] * 6000.0)
#define OFFSET_Z (vector[2] * 6000.0)
switch(direction)
{
case CAM_MODE_FORWARD:
{
x = pos[0] + OFFSET_X;
y = pos[1] + OFFSET_Y;
z = pos[2] + OFFSET_Z;
}
case CAM_MODE_BACKWARD:
{
x = pos[0] - OFFSET_X;
y = pos[1] - OFFSET_Y;
z = pos[2] - OFFSET_Z;
}
case CAM_MODE_LEFT:
{
x = pos[0] - OFFSET_Y;
y = pos[1] + OFFSET_X;
z = pos[2];
}
case CAM_MODE_RIGHT:
{
x = pos[0] + OFFSET_Y;
y = pos[1] - OFFSET_X;
z = pos[2];
}
case CAM_MODE_FORWARD_LEFT:
{
x = pos[0] + (OFFSET_X - OFFSET_Y);
y = pos[1] + (OFFSET_Y + OFFSET_X);
z = pos[2] + OFFSET_Z;
}
case CAM_MODE_FORWARD_RIGHT:
{
x = pos[0] + (OFFSET_X + OFFSET_Y);
y = pos[1] + (OFFSET_Y - OFFSET_X);
z = pos[2] + OFFSET_Z;
}
case CAM_MODE_BACKWARD_LEFT:
{
x = pos[0] + (-OFFSET_X - OFFSET_Y);
y = pos[1] + (-OFFSET_Y + OFFSET_X);
z = pos[2] - OFFSET_Z;
}
case CAM_MODE_BACKWARD_RIGHT:
{
x = pos[0] + (-OFFSET_X + OFFSET_Y);
y = pos[1] + (-OFFSET_Y - OFFSET_X);
z = pos[2] - OFFSET_Z;
}
}
}
Código desenvolvido por: ApelaMGA
Última edição por Apelaum em Sex 15 Abr 2022 - 11:08, editado 3 vez(es)