Sign in to follow this  
ZurionTV

Interaktion funktioniert nicht

Recommended Posts

Heyho zusammen,

ich habe folgendes Problem.
Ich hatte mir vor ein paar Tagen ein Starter Roleplay Script geholt und wollte das vorhandene Speedometer austauschen in dieses hier

 

Problem dabei ist das in mein Script ein Interaktion Script vorhanden ist womit ich durch eine Taste z.B. Vehicle Manager öffnen kann.
Als ich diesen Speedometer ausgetauscht habe funktionierte die Interaktion nicht mehr, ich konnte z.B. nicht mehr OnDuty gehen geschweige mein Vehicle Manager öffnen.

Das ist der Javascript von der Interaktion.

/*mp.keys.bind(0x45, true, function () { // Taste: E
    const camera = mp.cameras.new("gameplay");
    const distance = 2;

    let position = new mp.Vector3(mp.players.local.position.x, mp.players.local.position.y, mp.players.local.position.z + 0.7);
    let direction = camera.getDirection();
    let target = new mp.Vector3((direction.x * distance) + position.x, (direction.y * distance) + position.y, (direction.z * distance) + position.z);
    let raycastResult = mp.raycasting.testPointToPoint(position, target, [], -1);

    if (raycastResult != undefined) {
        let entityHandle = raycastResult.entity;
        let entityModelHash = mp.game.invoke("0x9F47B058362C84B5", entityHandle); // native GET_ENTITY_MODEL
        let entityPosition = raycastResult.position;

        if (entityModelHash != entityHandle && entityModelHash != 0) {
            mp.events.callRemote("PlayerInteract", entityModelHash, entityPosition);
            mp.gui.chat.push("DEBUG: Called PlayerInteract with entityModelHash " + entityModelHash + " and entityPosition x=" + entityPosition.x + " y=" + entityPosition.y + " z=" + entityPosition.z);
        }
    }
});*/

var isopen = 0;

mp.events.add("StartHouseMenu", (lockedhouse, c) => {
	if (mp.gui.cursor.visible)
		return;

    if (isopen == 1)
        return;
	
	isopen = 1;
    let NativeUI = require("nativeui");
    housemenu = new NativeUI.Menu("Haus", "Haussystem", new NativeUI.Point(50, 50));

    mp.gui.chat.show(false);

    housemenu.AddItem(new NativeUI.UIMenuItem("Menü schließen"));
    if (lockedhouse == 0) {       
        housemenu.AddItem(new NativeUI.UIMenuItem("Haus abschließen", "~r~Schlüssel wird benötigt!"));
        housemenu.AddItem(new NativeUI.UIMenuItem("Haus betreten"));
    } else {
        housemenu.AddItem(new NativeUI.UIMenuItem("Haus öffnen", "~r~Schlüssel wird benötigt!"));
    }

    housemenu.ItemSelect.on((item, index)  => {
        switch(index) {
            case 1:
                    mp.events.callRemote("LockThatHouse", c);
                break;
            case 2:
                    mp.events.callRemote("EnterThatHouse", c);
                break;
        };
		isopen = 0;
        housemenu.Close();
        delete housemenu;
        mp.gui.chat.show(true);
    });

});

mp.events.add("StartExitHouseMenu", (c, locked) => {
	if (mp.gui.cursor.visible)
	return;
	
    if (isopen == 1)
        return;
	
	isopen = 1
    let NativeUI = require("nativeui");
    garagemenu = new NativeUI.Menu("Haus", "Haussystem", new NativeUI.Point(50, 50));

    mp.gui.chat.show(false);
      
    garagemenu.AddItem(new NativeUI.UIMenuItem("Menü schließen"));
    garagemenu.AddItem(new NativeUI.UIMenuItem("Haus verlassen"));
    if (locked == 0) {
        garagemenu.AddItem(new NativeUI.UIMenuItem("Haus abschließen"));
    } else {
        garagemenu.AddItem(new NativeUI.UIMenuItem("Haus öffnen"));
    }

    garagemenu.ItemSelect.on((item, index)  => {
        switch(index) {
            case 1:
                mp.events.callRemote("ExitThatHouse", c);
                break;
            case 2:
                mp.events.callRemote("LockThatHouse", c);
                break;
        };
		isopen = 0;
        garagemenu.Close();
        delete garagemenu;
        mp.gui.chat.show(true);
    });
});

mp.events.add("PlayerInteraction", (duty) => {
	if (mp.gui.cursor.visible)
		return;
	
    if (isopen == 1)
        return;
	
	isopen = 1;
    let NativeUI = require("nativeui");
    imenu = new NativeUI.Menu("Interaktion`s Menü", "", new NativeUI.Point(50, 50));

    mp.gui.chat.show(false);
      
	imenu.AddItem(new NativeUI.UIMenuItem("~r~Verlassen", "~r~Menü Schließen!"));
	imenu.AddItem(new NativeUI.UIMenuItem("Ausweis Zeigen", "Zeigt einem Spieler in deiner Nähe deinen Ausweis!"));
	if (duty == 1) {
        imenu.AddItem(new NativeUI.UIMenuItem("Dienstausweis zeigen"));
    }

    imenu.ItemSelect.on((item, index)  => {
        switch(index) {
            case 1:
                mp.events.callRemote("ShowPlayerAusweis");
                break;
			case 2:
                mp.events.callRemote("ShowPlayerDienstAusweis");
                break;
        };
		isopen = 0;
        imenu.Close();
        delete imenu;
        mp.gui.chat.show(true);
    });
});

mp.events.add("VehicleInteraction", (isinvehicle, isinrepair) => {
	if (mp.gui.cursor.visible)
		return;
	
    if (isopen == 1)
        return;
	
	isopen = 1;
    let NativeUI = require("nativeui");
    imenu = new NativeUI.Menu("Interaktion`s Menü", "", new NativeUI.Point(50, 50));

    mp.gui.chat.show(false);
      
	imenu.AddItem(new NativeUI.UIMenuItem("~r~Verlassen", "~r~Menü Schließen!"));
	imenu.AddItem(new NativeUI.UIMenuItem("Fahrzeug abschließen"));
    if (isinvehicle == 1) {
	imenu.AddItem(new NativeUI.UIMenuItem("Motor An/Aus"));
	imenu.AddItem(new NativeUI.UIMenuItem("Fahrzeug parken"));
	}
	if (isinrepair == 1) {
		imenu.AddItem(new NativeUI.UIMenuItem("Fahrzeug reparieren", "Repariere dein Fahrzeug für ~g~100$"));
	}

    imenu.ItemSelect.on((item, index)  => {
        switch(index) {
            case 1:
                mp.events.callRemote("LockOrUnlockVeh");
                break;
			case 2:
				mp.events.callRemote("toggleEngine");
				break;
			case 3:
				mp.events.callRemote("ParkVehicle");
				break;
			case 4:
				mp.events.callRemote("RepairVehicle");
				break;
        };
		isopen = 0;
        imenu.Close();
        delete imenu;
        mp.gui.chat.show(true);
    });
});

mp.keys.bind(0x4D, false, function() {
	mp.events.callRemote("OpenPlayerInteraction", player);
});

mp.keys.bind(0x58, true, function() {
	mp.events.callRemote("OpenVehicleInteraction", player);
});

mp.keys.bind(0x45, false, function() {
    mp.events.callRemote("ExitHouseMenuOpen", player);
	mp.events.callRemote("HouseMenuOpen", player);
	mp.events.callRemote("OpenShopMenu", player);
	mp.events.callRemote("Fahrradverleih", player);
	mp.events.callRemote("Jobs", player);
	mp.events.callRemote("StartATM", player);
	mp.events.callRemote("StartLicenses", player);
	mp.events.callRemote("OpenShopBrowser", player);
    mp.events.callRemote("StartHanfSammeln", player);
    mp.events.callRemote("OpenKleidung", player);
	mp.events.callRemote("Egd", player);
	mp.events.callRemote("Ekey", player);
	mp.events.callRemote("OPC", player);
	mp.events.callRemote("VehicleInteraction", player);
});

 

Und das hier ist von den Speedometer was schon vorhanden war.

const updateInterval = 60;

var speedo = mp.browsers.new("package://Vehicles/speedometer.html");
var showed = false;
var player = mp.players.local;

var veh = null;
var eng = false;

var vId = -1;
var vHp = 0;
var vKm = 0;
var vMulti = 0;
var vFuel = 0;
var vFuelTank = 0;
var vFuelConsumption = 0;
var updateI = 0;
var vMode = 0;
var vCurMulti = 0;
var vCMulti = 0;

mp.events.add('render', () => {
	if(showed) {
		if (player.vehicle) {
			let vel = player.vehicle.getSpeed() * 3.6 ; 
			speedo.execute('update(' + vel.toFixed(0) + ');');
		}
	}
});

mp.events.add('epm', (multi) => {
	vMulti = multi;
	player.vehicle.setEnginePowerMultiplier(vMulti);
	mp.gui.chat.push("EPM: " + vMulti);
});

/*mp.keys.bind(0x47, true, function() {
	if(!player.vehicle)
		return;
	
	if(mp.gui.cursor.visible)
		return;
	
	vMode = vMode + 1;
	if (vMode > 2) {
		vMode = 0;
	}
	setMulti()
});*/


mp.events.add('vehicleEnter', (id, hp, km, multi, fuel, fuelTank, fuelConsumption) => {
	vId = id;
	vHp = hp;
	vKm = km;
	vMulti = multi;
	vFuel = fuel;
	vFuelTank = fuelTank;
	vFuelConsumption = fuelConsumption;
	vMode = 0;
	veh = player.vehicle;
	
	if(!showed) {
		showed = true;
		speedo.execute("show();");
	} /*else {
		mp.gui.chat.push("NOT Showing Speedo");
	}*/

	if (vFuel == 0) {
		mp.game.graphics.notify("~r~ Achtung Tank ist leer!");
	} 

	speedo.execute('updateG(' + (vFuel / vFuelTank * 100 ) + ',' + vKm.toFixed(2) + ');');

	//setMulti()
	//mp.gui.chat.push("EPM: " + vMulti + "Reduced: " + vCurMulti);

});


mp.events.add("playerEnterVehicle", (vehicle, seat) => {
	if (seat == 0) {
		if (!vehicle.getIsEngineRunning()) {
			vehicle.setEngineOn(false, true, true);
		}
	}
	veh = vehicle;
});

mp.events.add("StopJobVehSpeedo", () => {
	speedo.execute("hide();");
	showed = false;
});

mp.events.add("playerLeaveVehicle", () => {
	speedo.execute("hide();");
	showed = false;

	updateVeh();

	/*if (eng) {
		veh.setEngineOn(true, true, true);
	}*/

	vId = -1;
	vHp = 0;
	vKm = 0;
	vMulti = 0;
	vCurMulti = 0;
	vFuel = 0;
	vFuelTank = 0;
	vFuelConsumption = 0;
	vMode = 0;

	updateI = 0;
	eng = false;
});

/*function setMulti() {
	switch(vMode) {
		case 1:
			vCurMulti = 1 / 2;
			vCMulti = 12.5;
			mp.gui.chat.push("Cruise Modus");
		  break;
		case 2:
			vCurMulti = 1 / 10;
			vCMulti = 10;
			mp.gui.chat.push("Eco Modus");
		  break;
		default:
			vCurMulti = vMulti;
			vCMulti = 7.5;
			mp.gui.chat.push("Sport Modus");	
	  }
	mp.gui.chat.push("EPM: " + vCurMulti);
	
	//etm
	player.vehicle.setEnginePowerMultiplier(vCurMulti);
}*/

function updateVeh() {
	if (vId != -1) {
		mp.events.callRemote("updateVehicle", vId, vKm, vFuel);
	}
}

function setEng(v, s) {
	if (v.getIsEngineRunning() != s) {
		v.setEngineOn(s, true, true);
	}	
}

setInterval(function(){_intervalFunction();},1000);

function _intervalFunction() {
	let vehicle = player.vehicle;
	if (vehicle) {
		let speed =  vehicle.getSpeed(); 
		let trip = speed / 1000;
		if (vFuel > 0) {
			vFuel = vFuel - (vFuelConsumption * trip);
			if (vFuel < 0) {
				vFuel = 0;
			}
			if (vFuel == 0) {
				updateVeh();
			} 
		}

		vKm = vKm + trip;
		speedo.execute('updateG(' + (vFuel / vFuelTank * 100 ) + ',' + vKm.toFixed(2) + ');');
		updateI++;
		if (updateI == updateInterval) {
			updateI = 0;
			updateVeh();
		}
		eng = vehicle.getIsEngineRunning();
	}
};

mp.keys.bind(0x57, true, function() {
	if (state == 1 && localPlayer.vehicle) {
		wDown = true;
		localPlayer.vehicle.setMaxSpeed(9999);
	}
});

mp.keys.bind(0x57, false, function() {
	if (state == 1 && localPlayer.vehicle) {
		let speed = localPlayer.vehicle.getSpeed();
		localPlayer.vehicle.setMaxSpeed(speed);
		cSpeed = speed;
		wDown = false;
		speedo.execute('updateC(' + (speed * 3.6).toFixed(0) + ');');		
	}   
});

 

Ich hoffe ihr könnt mir helfen dieses Problem aus der Welt zu schaffen.
Mfg
ZurionTV

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.