interface GuardData {
position: Vector3;
heading: number;
weapon: number;
hash: number;
range: number;
}
class SecurityGuard {
private static readonly GUARD_CONFIG: GuardData[] = [
{
position: new mp.Vector3(123.45, -567.89, 25.0), // Измените координаты под вашу территорию
heading: 180.0,
weapon: 0x1B06D571, // WEAPON_PISTOL
hash: mp.game.joaat('s_m_m_security_01'), // Скин охранника
range: 30.0 // Радиус патрулирования
}
];
private guards: Map<number, PlayerMp> = new Map();
private paths: Map<number, Vector3[]> = new Map();
constructor() {
this.initialize();
this.setupEvents();
}
private initialize(): void {
SecurityGuard.GUARD_CONFIG.forEach((config, index) => {
const ped = mp.peds.new(
config.hash,
config.position,
config.heading,
mp.players.local.dimension
);
// Создаем маршрут патрулирования
const patrolPoints = this.generatePatrolPath(
config.position,
config.range
);
this.paths.set(ped.id, patrolPoints);
// Выдаем оружие
ped.setCanBeDamaged(true);
ped.setArmour(100);
ped.giveWeapon(config.weapon, 999, true);
this.startPatrol(ped, patrolPoints);
});
}
private setupEvents(): void {
mp.events.add('entityStreamIn', (entity: EntityMp) => {
if (entity.type === 'ped' && this.guards.has(entity.id)) {
this.onGuardStreamIn(entity);
}
});
}
private generatePatrolPath(center: Vector3, range: number): Vector3[] {
const points: Vector3[] = [];
const segments = 4; // Количество точек патрулирования
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const x = center.x + Math.cos(angle) * range;
const y = center.y + Math.sin(angle) * range;
points.push(new mp.Vector3(x, y, center.z));
}
return points;
}
private startPatrol(ped: PedMp, points: Vector3[]): void {
let currentPoint = 0;
setInterval(() => {
if (!ped || !ped.handle) return;
const nextPoint = points[currentPoint];
mp.game.ai.taskGoToCoordAnyMeans(
ped.handle,
nextPoint.x,
nextPoint.y,
nextPoint.z,
1.0, // Скорость ходьбы
0,
false,
786603, // Обычная ходьба
0
);
// Переход к следующей точке
currentPoint = (currentPoint + 1) % points.length;
}, 10000); // Каждые 10 секунд меняем точку назначения
}
private onGuardStreamIn(guard: EntityMp): void {
// Дополнительная логика при появлении охранника в зоне стрима
const ped = guard as PedMp;
// Устанавливаем боевой режим
mp.game.ai.taskCombatPed(
ped.handle,
mp.players.local.handle,
0,
16
);
// Проверяем наличие угроз
this.checkForThreats(ped);
}
private checkForThreats(guard: PedMp): void {
const interval = setInterval(() => {
if (!guard || !guard.handle) {
clearInterval(interval);
return;
}
// Проверяем близлежащих игроков
mp.players.forEachInRange(guard.position, 20, (player: PlayerMp) => {
if (player.handle !== mp.players.local.handle) return;
// Если игрок держит оружие, охранник атакует
if (player.weapon !== 0) {
mp.game.ai.taskCombatPed(
guard.handle,
player.handle,
0,
16
);
}
});
}, 1000);
}
}
// Создаем экземпляр класса при запуске скрипта
const securitySystem = new SecurityGuard();