Skip to content

Commit

Permalink
feat: added some player functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Sep 11, 2022
1 parent 5835467 commit 1520270
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/controllers/player/basePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ import {
ClearAnimations,
GetPlayerAnimationIndex,
GetAnimationName,
SetPlayerShopName,
SetPlayerPosFindZ,
SetPlayerWorldBounds,
SetPlayerChatBubble,
GetPlayerDistanceFromPoint,
GetPlayerCustomSkin,
GetPlayerTargetPlayer,
GetPlayerLastShotVectors,
} from "@/wrapper/functions";
import logger from "@/logger";
import { BaseGameMode } from "../gamemode";
Expand Down Expand Up @@ -638,4 +646,47 @@ export abstract class BasePlayer {
const [animLib, animName] = GetAnimationName(this.getAnimationIndex());
return { animLib, animName };
}
public setShopName(shopName: string): void {
SetPlayerShopName(this.id, shopName);
}
public setPosFindZ(x: number, y: number, z = 150): Promise<number> {
return new Promise<number>((resolve) => {
SetPlayerPos(this.id, x, y, z);
setTimeout(() => resolve(SetPlayerPosFindZ(this.id, x, y, z)));
});
}
public setWorldBounds(
x_max: number,
x_min: number,
y_max: number,
y_min: number
): void {
SetPlayerWorldBounds(this.id, x_max, x_min, y_max, y_min);
}
public setChatBubble(
text: string,
color: string,
drawDistance: number,
expireTime: number
): void {
SetPlayerChatBubble(this.id, text, color, drawDistance, expireTime);
}
public getDistanceFromPoint(X: number, Y: number, Z: number): number {
return GetPlayerDistanceFromPoint(this.id, X, Y, Z);
}
public getCustomSkin(): number {
return GetPlayerCustomSkin(this.id);
}
public getTargetPlayer<P extends BasePlayer>(
players: Array<P>
): undefined | P {
const pid = GetPlayerTargetPlayer(this.id);
if (pid === InvalidEnum.PLAYER_ID) return undefined;
return players.find((p) => p.id === pid);
}
public getLastShotVectors() {
const [fOriginX, fOriginY, fOriginZ, fHitPosX, fHitPosY, fHitPosZ] =
GetPlayerLastShotVectors(this.id);
return { fOriginX, fOriginY, fOriginZ, fHitPosX, fHitPosY, fHitPosZ };
}
}
2 changes: 1 addition & 1 deletion src/wrapper/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ export const RemoveBuildingForPlayer = (
);
};

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

Expand Down

0 comments on commit 1520270

Please sign in to comment.