Skip to content

Commit

Permalink
feat: added some player camera function
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Sep 8, 2022
1 parent 1068486 commit d7befab
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/controllers/gamemode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
GetGravity,
LimitGlobalChatRadius,
LimitPlayerMarkerRadius,
SendRconCommand,
SetGameModeText,
SetGravity,
SetNameTagDrawDistance,
Expand Down Expand Up @@ -117,4 +118,5 @@ export abstract class BaseGameMode extends AbstractGM {
return SetWorldTime(hour);
}
public static setTeamCount = SetTeamCount;
public static sendRconCommand = SendRconCommand;
}
60 changes: 58 additions & 2 deletions src/controllers/player/basePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,32 @@ import {
SetPlayerFightingStyle,
SetPlayerArmour,
GetPlayerArmour,
SetCameraBehindPlayer,
SetPlayerCameraPos,
SetPlayerCameraLookAt,
GetPlayerCameraAspectRatio,
GetPlayerCameraFrontVector,
GetPlayerCameraPos,
GetPlayerCameraMode,
GetPlayerCameraTargetPlayer,
GetPlayerCameraTargetVehicle,
GetPlayerCameraZoom,
} from "@/wrapper/functions";
import logger from "@/logger";
import { BaseGameMode } from "../gamemode";
import {
CameraCutStylesEnum,
CameraModesEnum,
FightingStylesEnum,
PlayerStateEnum,
SpecialActionsEnum,
SpectateModesEnum,
WeaponSkillsEnum,
} from "@/enums";
import { BaseVehicle } from "../vehicle";
import { BaseVehicle, BaseVehicleEvent } from "../vehicle";
import { basePos } from "@/types";
import { GetPlayerWeather } from "omp-wrapper";
import { GetPlayerCameraTargetPlayerObj, GetPlayerWeather } from "omp-wrapper";
import { BasePlayerEvent } from "./playerEvent";

export abstract class BasePlayer {
private _id: number;
Expand Down Expand Up @@ -408,4 +421,47 @@ export abstract class BasePlayer {
public getArmour(): number {
return GetPlayerArmour(this.id);
}
public setCameraBehind(): number {
return SetCameraBehindPlayer(this.id);
}
public setCameraPos(x: number, y: number, z: number): number {
return SetPlayerCameraPos(this.id, x, y, z);
}
public setCameraLookAt(
x: number,
y: number,
z: number,
cut: CameraCutStylesEnum
): number {
return SetPlayerCameraLookAt(this.id, x, y, z, cut);
}
public getCameraAspectRatio(): number {
return GetPlayerCameraAspectRatio(this.id);
}
public getCameraFrontVector(): basePos {
const [x, y, z] = GetPlayerCameraFrontVector(this.id);
return { x, y, z };
}
public getCameraMode(): CameraModesEnum {
return GetPlayerCameraMode(this.id);
}
public getCameraPos(): basePos {
const [x, y, z] = GetPlayerCameraPos(this.id);
return { x, y, z };
}
public getCameraTargetPlayer<P extends BasePlayer>(
players: Array<P>
): P | undefined {
const target = GetPlayerCameraTargetPlayer(this.id);
return players.find((p) => p.id === target);
}
public getCameraTargetVehicle<V extends BaseVehicle>(
vehicles: Array<V>
): V | undefined {
const target = GetPlayerCameraTargetVehicle(this.id);
return vehicles.find((v) => v.id === target);
}
public getCameraZoom(): number {
return GetPlayerCameraZoom(this.id);
}
}
22 changes: 22 additions & 0 deletions src/enums/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ export enum CameraCutStylesEnum {
CUT,
}

export enum CameraModesEnum {
BEHINDCAR = 3,
FOLLOWPED = 4,
SNIPER = 7,
ROCKETLAUNCHER = 8,
FIXED = 15,
_1STPERSON = 16,
CAM_ON_A_STRING = 18,
BEHINDBOAT = 22,
CAMERA = 46,
ROCKETLAUNCHER_HS = 51,
AIMWEAPON = 53,
AIMWEAPON_FROMCAR = 55,
DW_HELI_CHASE = 56,
DW_CAM_MAN = 57,
DW_BIRDY = 58,
DW_PLANE_SPOTTER = 59,
DW_PLANECAM1 = 62,
DW_PLANECAM2 = 63,
DW_PLANECAM3 = 64,
}

export enum SpectateModesEnum {
NORMAL = 1,
FIXED,
Expand Down
10 changes: 6 additions & 4 deletions src/wrapper/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import { rgba } from "@/utils/colorUtils";
import {
CameraCutStylesEnum,
CameraModesEnum,
CarModTypeEnum,
ConnectionStatusEnum,
FightingStylesEnum,
Expand Down Expand Up @@ -2491,7 +2493,7 @@ export const SetPlayerCameraLookAt = (
x: number,
y: number,
z: number,
cut: number
cut: CameraCutStylesEnum
): number => {
return samp.callNative(
"SetPlayerCameraLookAt",
Expand All @@ -2508,15 +2510,15 @@ export const SetCameraBehindPlayer = (playerid: number): number => {
return samp.callNative("SetCameraBehindPlayer", "i", playerid);
};

export const GetPlayerCameraPos = (playerid: number): Array<any> => {
export const GetPlayerCameraPos = (playerid: number): Array<number> => {
return samp.callNative("GetPlayerCameraPos", "iFFF", playerid);
};

export const GetPlayerCameraFrontVector = (playerid: number): Array<any> => {
export const GetPlayerCameraFrontVector = (playerid: number): Array<number> => {
return samp.callNative("GetPlayerCameraFrontVector", "iFFF", playerid);
};

export const GetPlayerCameraMode = (playerid: number): number => {
export const GetPlayerCameraMode = (playerid: number): CameraModesEnum => {
return samp.callNative("GetPlayerCameraMode", "i", playerid);
};

Expand Down

0 comments on commit d7befab

Please sign in to comment.