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 12, 2022
1 parent 28e59e5 commit bbf89f2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
46 changes: 45 additions & 1 deletion src/controllers/player/basePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BanEx,
GetPlayerName,
SendClientMessage,
SendClientMessageToAll,
SetPlayerName,
} from "@/utils/helperUtils";
import {
Expand Down Expand Up @@ -113,12 +114,15 @@ import {
SetPlayerAmmo,
GetPlayerAmmo,
SetPlayerArmedWeapon,
SendDeathMessageToPlayer,
SendDeathMessage,
} from "@/wrapper/functions";
import { logger } from "@/logger";
import { BaseGameMode } from "../gamemode";
import {
CameraCutStylesEnum,
CameraModesEnum,
DamageDeathReasonEnum,
FightingStylesEnum,
InvalidEnum,
PlayerStateEnum,
Expand Down Expand Up @@ -175,6 +179,14 @@ export abstract class BasePlayer {
return SendClientMessage(this, color, msg);
}

public static sendClientMessageToAll<P extends BasePlayer>(
players: Array<P>,
color: string,
msg: string
) {
SendClientMessageToAll(players, color, msg);
}

public isNpc(): boolean {
return this._isNpc;
}
Expand Down Expand Up @@ -714,7 +726,7 @@ export abstract class BasePlayer {
public getWeaponState(): WeaponStatesEnum {
return GetPlayerWeaponState(this.id);
}
public giveWeapon(weaponid: number, ammo: number): number {
public giveWeapon(weaponid: WeaponEnum, ammo: number): number {
return GivePlayerWeapon(this.id, weaponid, ammo);
}
public setAmmo(weaponid: number, ammo: number) {
Expand All @@ -726,4 +738,36 @@ export abstract class BasePlayer {
public setArmedWeapon(weaponid: number): number {
return SetPlayerArmedWeapon(this.id, weaponid);
}
// not test
public clearDeathMessage() {
for (let i = 0; i < 5; i++) {
this.sendDeathMessageToPlayer(
InvalidEnum.PLAYER_ID,
InvalidEnum.PLAYER_ID,
DamageDeathReasonEnum.CONNECT
);
}
}
public sendDeathMessage<P extends BasePlayer>(
killer: P | InvalidEnum.PLAYER_ID,
weapon: WeaponEnum | DamageDeathReasonEnum
): void {
SendDeathMessage(
killer === InvalidEnum.PLAYER_ID ? killer : killer.id,
this.id,
weapon
);
}
public sendDeathMessageToPlayer<P extends BasePlayer>(
killer: P | InvalidEnum.PLAYER_ID,
killee: P | InvalidEnum.PLAYER_ID,
weapon: WeaponEnum | DamageDeathReasonEnum
): void {
SendDeathMessageToPlayer(
this.id,
killer === InvalidEnum.PLAYER_ID ? killer : killer.id,
killee === InvalidEnum.PLAYER_ID ? killee : killee.id,
weapon
);
}
}
12 changes: 0 additions & 12 deletions src/controllers/player/playersFunc.ts

This file was deleted.

15 changes: 12 additions & 3 deletions src/enums/weapon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export enum WeaponEnum {
FIREEXTINGUISHER = 42,
CAMERA = 43,
PARACHUTE = 46,
VEHICLE = 49,
DROWN = 53,
COLLISION = 54,
}
export enum WeaponSkillsEnum {
PISTOL,
Expand All @@ -64,10 +61,22 @@ export enum BulletHitTypesEnum {
OBJECT,
PLAYER_OBJECT,
}

export enum WeaponStatesEnum {
UNKNOWN = -1,
NO_BULLETS,
LAST_BULLET,
MORE_BULLETS,
RELOADING,
}

export enum DamageDeathReasonEnum {
VEHICLE = 49,
HELICOPTERBLADES = 50,
EXPLOSION = 51,
DROWN = 53,
COLLISION = 54,
CONNECT = 200,
DISCONNECT = 201,
SUICIDE = 255,
}
6 changes: 4 additions & 2 deletions src/wrapper/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CameraModesEnum,
CarModTypeEnum,
ConnectionStatusEnum,
DamageDeathReasonEnum,
FightingStylesEnum,
KeysEnum,
MarkerModesEnum,
Expand All @@ -17,6 +18,7 @@ import {
SpectateModesEnum,
TextDrawAlignEnum,
VehicleModelInfoEnum,
WeaponEnum,
WeaponSkillsEnum,
WeaponStatesEnum,
} from "@/enums";
Expand Down Expand Up @@ -46,7 +48,7 @@ export const SendPlayerMessageToAll = (
export const SendDeathMessage = (
killer: number,
killee: number,
weapon: number
weapon: WeaponEnum | DamageDeathReasonEnum
): number => {
return samp.callNative("SendDeathMessage", "iii", killer, killee, weapon);
};
Expand All @@ -55,7 +57,7 @@ export const SendDeathMessageToPlayer = (
playerid: number,
killer: number,
killee: number,
weapon: number
weapon: WeaponEnum | DamageDeathReasonEnum
): number => {
return samp.callNative(
"SendDeathMessageToPlayer",
Expand Down

0 comments on commit bbf89f2

Please sign in to comment.