Initial commit — Southwest Roleplay FiveM
This commit is contained in:
36
src/server/core/commands/guards/phone.command.guard.ts
Normal file
36
src/server/core/commands/guards/phone.command.guard.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { phoneSystem } from '../../../features/phone';
|
||||
|
||||
type PhoneCommandGuardOptions = {
|
||||
on?: boolean;
|
||||
unlocked?: boolean;
|
||||
};
|
||||
|
||||
export const PhoneCommandGuard = (options?: PhoneCommandGuardOptions): CommandGuard => {
|
||||
return (player: PlayerMp) => {
|
||||
if (!options) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!player.character?.phone || !player.character.phone.item) {
|
||||
return `You must have a phone.`;
|
||||
}
|
||||
|
||||
if (options.on !== undefined) {
|
||||
if (options.on === true && !phoneSystem.isPhoneOn(player.character.phone.item)) {
|
||||
return `Your phone must be turned on.`;
|
||||
} else if (options.on === false && phoneSystem.isPhoneOn(player.character.phone.item)) {
|
||||
return `Your phone must be turned off.`;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.unlocked !== undefined) {
|
||||
if (options.unlocked === true && !phoneSystem.isPlayerPhoneLocked(player as PlayerMpLoggedIn)) {
|
||||
return `Your phone must be locked.`;
|
||||
} else if (options.unlocked === false && phoneSystem.isPlayerPhoneLocked(player as PlayerMpLoggedIn)) {
|
||||
return `Your phone must be unlocked.`;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user