UNPKG

samp-node-lib

Version:

NodeJS library for Scripting San Andreas Multiplayer:SAMP depends on samp-node plugin

71 lines 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SampPlayer = void 0; const SampPlayerNativeFunctions_1 = require("./SampPlayerNativeFunctions"); const SampFunctions_1 = require("./SampFunctions"); const TextDraw_1 = require("./TextDraw"); const TextDraws_1 = require("./TextDraws"); const createPromise_1 = require("./createPromise"); class SampPlayer extends SampPlayerNativeFunctions_1.SampPlayerNativeFunctions { constructor(playerid) { super(playerid); this.state = {}; this.dialog = {}; } get vehicleId() { return this.GetPlayerVehicleID(); } get position() { const p = this.GetPlayerPos(); const { vehicleId } = this; const angle = vehicleId !== 0 ? (0, SampFunctions_1.GetVehicleZAngle)(vehicleId) : this.GetPlayerFacingAngle(); return { x: p[0], y: p[1], z: p[2], angle, vehicleId }; } get trailerId() { const { vehicleId } = this; return vehicleId !== 0 ? (0, SampFunctions_1.GetVehicleTrailer)(vehicleId) : 0; } get speed() { const { vehicleId } = this; const speed = vehicleId !== 0 ? (0, SampFunctions_1.GetVehicleVelocity)(vehicleId) : this.GetPlayerVelocity(); return { x: speed[0], y: speed[1], z: speed[2] }; } setState(newState) { this.state = Object.assign(Object.assign({}, this.state), newState); } TextDraw(config, name) { return new TextDraw_1.TextDraw(this.playerid, config, name); } TextDrawShow(name) { TextDraws_1.TextDraws.getAll(this.playerid).filter(td => td.name === name).forEach(td => td.show()); } TextDrawHide(name) { TextDraws_1.TextDraws.getAll(this.playerid).filter(td => td.name === name).forEach(td => td.hide()); } TextDrawDestory(name) { TextDraws_1.TextDraws.destroy(this.playerid, name); } ShowDialog(dialogid, style, caption, info, button1, button2) { const { resolve, promise } = (0, createPromise_1.createPromise)(); this.dialog[`id${dialogid}`] = resolve; const result = (0, SampFunctions_1.ShowPlayerDialog)(this.playerid, dialogid, style, caption, info, button1, button2); if (result === 0) { delete this.dialog[`id${dialogid}`]; throw new Error('player is not connected'); } promise.then(() => delete this.dialog[`id${dialogid}`]); return promise; } } exports.SampPlayer = SampPlayer; //# sourceMappingURL=SampPlayer.js.map