Sign in to follow this  
Maxx Meyer

Javascript Interval Buggy

Recommended Posts

Error: async hook stack has become corrupted (actual: 10, expected: 11)

setInterval(function() {
    mp.players.forEach(function(player){
        mp.trigger('playerAutoSave', player);
    });
}, 8000);

mp.events.add("playerAutoSave", (player) => {
    player.loggedInAs = "";
    gm.mysql.handle.query("UPDATE `account` SET money = ?, posX = ?, posY = ?, posZ = ? WHERE `username` = ?", [player.money, player.position.x, player.position.y, player.position.z, player.name], function(err,res){
        if(!err){
            console.log(`[Auto Save] Es wurden alle Accounts gespeichert.`)
        } else (
            console.log("ERROR: " + err)
        )
    });
});

 

Some fixxes avaible?

 

Share this post


Link to post
Share on other sites

you have error with async function , test add await before ou request if you mysql is in async 

im use this and im not have a problème 

async function saveWorld(){
	const start = new Date().getTime();
	var vehicles = {};

    mp.vehicles.forEachInDimension(0, (vehicle) => {
    	if(vehicle.getVariable('entreprise') === null){
	    	var info = vehicle.position;
	    	info.h = vehicle.heading;
	    	info.model = vehicle.model;
	    	info.colorP = vehicle.getColorRGB(0);
	    	info.colorS = vehicle.getColorRGB(1);
	    	info.owner = vehicle.getVariable('owner');
	    	info.locked = vehicle.locked;
	    	vehicles[vehicle.numberPlate] = info;
	    }
    });


	await mp.function.writeFile("save/vehicle.json",JSON.stringify(vehicles));
	const time = new Date().getTime() - start;

	if (time >= 500) {
		console.log(`monde save: ${time / 1000}s`);
	}
	else {
		console.log(`monde save: ${time / 1000}s`);
	}
}

setInterval(saveWorld, 15000);

 

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.