const business = require('./sBusiness');
const misc = require('../sMisc');
const i18n = require('../sI18n');
let weaponShops = {};
function createWeaponShopEntities(id, position) {
let colShape = mp.colshapes.newSphere(position.x, position.y, position.z, 1.0);
colShape.weaponShopID = id;
weaponShops[id] = {
colShape: colShape,
marker: mp.markers.new(1, new mp.Vector3(position.x, position.y, position.z - 2.25), 2.0, {
color: [224, 50, 50, 200]
}),
label: mp.labels.new(`Waffen Shop (${id})`, position,
{
los: true,
font: 4,
drawDistance: 20.0,
color: [255, 255, 255, 255]
}),
blip: mp.blips.new(110, position, {
name: "Waffen Shop",
scale: 1.0,
color: 0,
shortRange: true
})
};
}
function deleteWeaponShopEntities(id) {
if (weaponShops[id]) {
if (weaponShops[id].colShape) weaponShops[id].colShape.destroy();
if (weaponShops[id].marker) weaponShops[id].marker.destroy();
if (weaponShops[id].label) weaponShops[id].label.destroy();
if (weaponShops[id].blip) weaponShops[id].blip.destroy();
}
}
async function loadWeaponShops() {
const d = await misc.query("SELECT * FROM weapon_shops", (e, rows) => {
if (e) {
console.log(`Weapon shop loading failed: ${e.message}`);
} else {
rows.forEach((row) => createWeaponShopEntities(row.ID, new mp.Vector3(row.ShopX, row.ShopY, row.ShopZ)));
console.log(`Loaded ${rows.length} weapon shop(s).`);
}
});
};
loadWeaponShops();
async function createWeaponShop(position) {
return new Promise((resolve, reject) => {
const d = misc.query("INSERT INTO weapon_shops SET ShopX=?, ShopY=?, ShopZ=?", [position.x, position.y, position.z], (e, result) => {
if(e) {
console.log(`Weapon Shop adding failed: ${e.message}`);
reject(e);
} else {
createWeaponShopEntities(result.insertId, position);
resolve(result.insertId);
}
});
});
};
createWeaponShop();
async function deleteWeaponShop(id) {
return new Promise((resolve, reject) => {
const d = misc.query("DELETE FROM weapon_shops WHERE ID=?", [id], (error, result) => {
if(e) {
console.log(`Weapon Shop removing failed: ${e.message}`);
reject(error);
} else {
if(result.affectedRows > 0) {
deleteWeaponShopEntities(id);
delete weaponShops[id];
}
resolve(result.affectedRows);
}
});
});
};
deleteWeaponShop();
Alles anzeigen