hanf vielleicht fertig
This commit is contained in:
@@ -5,7 +5,7 @@ import { getAnimFromId } from "../util/animationSync";
|
||||
import { getCreatedPedByName } from "../Ped/PedCreator";
|
||||
import KeyBinder from 'ragemp-better-bindings';
|
||||
|
||||
const hanfPlantObjects = {
|
||||
export const hanfPlantObjects = {
|
||||
stage1: mp.game.joaat('bkr_prop_weed_bud_pruned_01a'),
|
||||
stage2: mp.game.joaat('bkr_prop_weed_bud_01b'),
|
||||
stage3: mp.game.joaat('prop_weed_02'),
|
||||
@@ -43,7 +43,7 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
let currentlyPlanting: boolean = false;
|
||||
let lastPlantingState = true;
|
||||
|
||||
mp.events.add("SERVER:Hanf_BuySeed", price => {
|
||||
mp.events.add("SERVER:Hanf_BuySeed", (maxSeedsToBuy, price) => {
|
||||
if (globalData.InMenu || globalData.InChat) {
|
||||
return;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
|
||||
var seedsToBuy = 0;
|
||||
|
||||
var countItems = [...Array(50).keys()].map(x => x + 1);
|
||||
var countItems = [...Array(maxSeedsToBuy).keys()].map(x => x + 1);
|
||||
|
||||
var soloPriceItem = createMenuItem("Einzelpreis", "Preis pro Samen", item => {
|
||||
item.SetRightLabel("$" + moneyformat(price));
|
||||
@@ -93,6 +93,56 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
menu.Open();
|
||||
});
|
||||
|
||||
mp.events.add("SERVER:Hanf_SellCannabisMenu", (maxCannabisToSell, price) => {
|
||||
if (globalData.InMenu || globalData.InChat) {
|
||||
return;
|
||||
}
|
||||
|
||||
globalData.InMenu = true;
|
||||
|
||||
var menu = new Menu("Cannabis verkaufen", "Verkaufe dein Cannabis", new Point(50, 50));
|
||||
|
||||
var cannabisToSell = 0;
|
||||
|
||||
var countItems = [...Array(maxCannabisToSell).keys()].map(x => x + 1);
|
||||
|
||||
var soloPriceItem = createMenuItem("Einzelpreis", "Preis pro Hanfblüte", item => {
|
||||
item.SetRightLabel("$" + moneyformat(price));
|
||||
});
|
||||
menu.AddItem(soloPriceItem);
|
||||
|
||||
var countItem = new UIMenuListItem("Anzahl", "Wähle die Anzahl der Blüten aus", new ItemsCollection(countItems), 0);
|
||||
menu.AddItem(countItem);
|
||||
|
||||
var buyItem = new UIMenuItem("Verkaufen", "Verkaufe dein Cannabis");
|
||||
buyItem.BackColor = new Color(0, 100, 0);
|
||||
buyItem.HighlightedBackColor = new Color(0, 150, 0);
|
||||
menu.AddItem(buyItem);
|
||||
|
||||
var completePriceItem = new UIMenuItem("Gesamtpreis", "Preis für alle Blüten");
|
||||
menu.AddItem(completePriceItem);
|
||||
|
||||
menu.ListChange.on((item, index) => {
|
||||
if (item === countItem) {
|
||||
cannabisToSell = Number(countItem.SelectedValue);
|
||||
completePriceItem.SetRightLabel("$" + moneyformat(cannabisToSell * price));
|
||||
}
|
||||
});
|
||||
|
||||
menu.ItemSelect.on((item, index) => {
|
||||
if (item === buyItem) {
|
||||
mp.events.callRemote("CLIENT:Hanf_SellCannabis", cannabisToSell);
|
||||
menu.Close();
|
||||
}
|
||||
});
|
||||
|
||||
menu.MenuClose.on(() => {
|
||||
globalData.InMenu = false;
|
||||
});
|
||||
|
||||
menu.Open();
|
||||
});
|
||||
|
||||
mp.events.add("SERVER:Hanf_PlayManufacturerAnim", animId => {
|
||||
var anim = getAnimFromId(animId);
|
||||
var npc = getCreatedPedByName("hanf_verarbeiter_typ");
|
||||
@@ -154,9 +204,9 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//if (!isSurfaceAllowed()) {
|
||||
// return false;
|
||||
//}
|
||||
if (!isSurfaceAllowed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentPlantingPreviewObject) {
|
||||
var objectPos = getPlantPreviewPosition();
|
||||
@@ -177,14 +227,29 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
const GET_RAYCAST_RESULT_NATIVE = "0x65287525D951F6BE";
|
||||
|
||||
function isSurfaceAllowed() {
|
||||
return true;
|
||||
const player = mp.players.local;
|
||||
var position = player.position;
|
||||
var raycast = mp.game.invoke(RAYCAST_POINT_TO_POINT_NATIVE, position.x, position.y, position.z + 5, position.x, position.y, position.z - 5, -1, undefined, 0);
|
||||
var position = getPlantPreviewPosition();
|
||||
var raycast = mp.game.invoke(RAYCAST_POINT_TO_POINT_NATIVE, position.x, position.y, position.z + 5, position.x, position.y, position.z - 5, 1, 0, 7);
|
||||
mp.gui.chat.push("raycast = " + raycast);
|
||||
var hit: boolean, coord: Vector3Mp, surfaceNormal: Vector3Mp, materialHash: number, entityHit: EntityMp;
|
||||
var raycastResult = mp.game.invoke(GET_RAYCAST_RESULT_NATIVE, raycast, hit, coord, surfaceNormal, materialHash, entityHit);
|
||||
var resultObj = {
|
||||
hit: [false],
|
||||
coord: [new mp.Vector3()],
|
||||
surface: [new mp.Vector3()],
|
||||
material: [0],
|
||||
entityHit: [null]
|
||||
};
|
||||
|
||||
mp.gui.chat.push("result: " + raycastResult + ", hit = " + hit + ", test = " + materialHash);
|
||||
var raycastResult = -1;
|
||||
var retries = 10;
|
||||
|
||||
do {
|
||||
raycastResult = mp.game.invoke(GET_RAYCAST_RESULT_NATIVE, raycast, resultObj.hit, resultObj.coord, resultObj.surface, resultObj.material, resultObj.entityHit);
|
||||
retries--;
|
||||
} while (raycastResult != 0 && raycastResult != 2 && retries > 0);
|
||||
|
||||
|
||||
mp.gui.chat.push("result: " + raycastResult + ", result = " + JSON.stringify(resultObj));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -270,17 +335,15 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
|
||||
mp.events.add("SERVER:Hanf_UpdateHanfData", dataJson => {
|
||||
mp.console.logInfo(dataJson);
|
||||
|
||||
var data: Array<CannabisData> = <Array<CannabisData>>JSON.parse(dataJson)
|
||||
|
||||
var newPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 0);
|
||||
var removedPlants = currentHanfData.filter(d => data.filter(x => x.Id === d.Id).length == 0);
|
||||
var existingPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 1);
|
||||
|
||||
mp.gui.chat.push(`new: ${newPlants.length}, removed: ${removedPlants.length}, existing: ${existingPlants.length}`);
|
||||
|
||||
newPlants.forEach(plant => {
|
||||
var model = getPlantModel(plant);
|
||||
mp.gui.chat.push("new id: " + plant.Id + ", model = " + model);
|
||||
var object = mp.objects.new(getPlantModel(plant), new mp.Vector3(plant.X, plant.Y, plant.Z));
|
||||
hanfDataIdToObjectMap.set(plant.Id, object);
|
||||
|
||||
@@ -292,7 +355,6 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
});
|
||||
|
||||
removedPlants.forEach(plant => {
|
||||
//mp.gui.chat.push("removed id: " + plant.Id);
|
||||
var object = hanfDataIdToObjectMap.get(plant.Id);
|
||||
hanfDataIdToObjectMap.delete(plant.Id);
|
||||
object.destroy();
|
||||
@@ -302,11 +364,9 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
});
|
||||
|
||||
existingPlants.forEach(plant => {
|
||||
//mp.gui.chat.push("existing plant: " + plant.Id + ", plant time = " + new Date(plant.Time).toLocaleTimeString() + ", current time = " + new Date().toLocaleTimeString());
|
||||
var object = hanfDataIdToObjectMap.get(plant.Id);
|
||||
var model = getPlantModel(plant);
|
||||
if (model != object.model) {
|
||||
//mp.gui.chat.push("existing plant: " + plant.Id + ", changing model to = " + model);
|
||||
object.destroy();
|
||||
var object = mp.objects.new(model, new mp.Vector3(plant.X, plant.Y, plant.Z));
|
||||
hanfDataIdToObjectMap.delete(plant.Id);
|
||||
@@ -341,4 +401,43 @@ export default function hanfSystem(globalData: IGlobalData) {
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
mp.events.addProc("SERVER:Hanf_GetModelToGivePlayer", id => {
|
||||
var plant = currentHanfData.filter(x => x.Id == id)[0];
|
||||
var model = getPlantModel(plant);
|
||||
if (model == hanfPlantObjects.stage1) {
|
||||
return 1;
|
||||
} else if (model == hanfPlantObjects.stage3) {
|
||||
return 2;
|
||||
} else if (model == hanfPlantObjects.stage4) {
|
||||
return 3;
|
||||
}
|
||||
});
|
||||
|
||||
//var rotationTestObject: ObjectMp = null;
|
||||
//var a1: number, a2: number, a3: number, a4: number, a5: number, a6: number;
|
||||
//mp.events.add(RageEnums.EventKey.PLAYER_COMMAND, (f) => {
|
||||
// var args = f.split(' ');
|
||||
// if (args[0] != "a") {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// a1 = parseFloat(args[1] || "0");
|
||||
// a2 = parseFloat(args[2] || "0");
|
||||
// a3 = parseFloat(args[3] || "0");
|
||||
// a4 = parseFloat(args[4] || "0");
|
||||
// a5 = parseFloat(args[5] || "0");
|
||||
// a6 = parseFloat(args[6] || "0");
|
||||
|
||||
// mp.gui.chat.push(`a1: ${a1.toFixed(2)}, a2: ${a2.toFixed(2)}, a3: ${a3.toFixed(2)}, a4: ${a4.toFixed(2)}, a5: ${a5.toFixed(2)}, a6: ${a6.toFixed(2)},`)
|
||||
|
||||
// if (rotationTestObject != null) {
|
||||
// rotationTestObject.attachTo(Number(mp.players.local.handle), mp.players.local.getBoneIndex(57005), a1, a2, a3, a4, a5, a6, true, false, false, false, 0, true);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// rotationTestObject = mp.objects.new(mp.game.joaat("prop_cs_trowel"), mp.players.local.position, {
|
||||
// alpha: 255
|
||||
// });
|
||||
//});
|
||||
}
|
||||
Reference in New Issue
Block a user