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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.