Sign in to follow this  
0xNull

function working only for one player

Recommended Posts

Hello, i have such code:

 

mp.events.add('playerJoin', (player) =>{
  player.outputChatBox('!{red}►!{white}[!{#17d666}SERVER!{white}]: Hello. First you need auth. Use /login for this.');
  player.cop = 0;
  player.exit = 0;
  player.robb = 0;
  player.ingame = 0;
  player.au = 0;
});

mp.events.addCommand('mp', (player)=>{

if (player.au == 0){

player.outputChatBox('!{red}►!{white}[!{#17d666}SERVER!{white}]: Need to auth. Use /login.');

}

if (player.au == 1){

startMP();

}


function startMP() {


  if (startmp == 0){

    player.ingame = 1;
    player.cop = 1;

    countplayers +=1;

    var timertostart = setTimeout(teleporttomp, 5000);

    startmp = 1;

    player.outputChatBox('!{red}►!{white}[!{#17d666}SERVER!{white}]: Your role is cop');

    mysqlc.query("SELECT null FROM game WHERE name = ?", player.name, function(e, result) {
        if (!e) {
            if ( !result.length ) {

              mysqlc.query("INSERT INTO game (name, sost) VALUES (?,?)", [player.name, 1], function(e) {
                  if ( e ) console.log ( e );
              });

            } else {
              mysqlc.query("UPDATE game SET sost=? WHERE name=?", [1, player.name], function(e) {
                  if ( e ) console.log ( e );
              });
            }
        } else console.log (e);
    });

  }


  if (startmp == 1 && countplayers == 1 && player.ingame == 0){

    player.ingame = 1;
    player.robber = 1;

    player.outputChatBox('!{red}►!{white}[!{#17d666}SERVER!{white}]: Your role is robber');

    countplayers +=1;

    mysqlc.query("SELECT null FROM game WHERE name = ?", player.name, function(e, result) {
        if (!e) {
            if ( !result.length ) {

              mysqlc.query("INSERT INTO game (name, sost) VALUES (?,?)", [player.name, 2], function(e) {
                  if ( e ) console.log ( e );
              });

            } else {
              mysqlc.query("UPDATE game SET sost=? WHERE name=?", [2, player.name], function(e) {
                  if ( e ) console.log ( e );
              });
            }
        } else console.log (e);
    });

  }
  if (startmp == 1 && countplayers != 1 && player.ingame == 0){

    countplayers +=1;

    player.ingame = 1;
    player.cop = 1;

    player.outputChatBox('!{red}►!{white}[!{#17d666}SERVER!{white}]: Твоя роль: Коп.');

    mysqlc.query("SELECT null FROM game WHERE name = ?", player.name, function(e, result) {
        if (!e) {
            if ( !result.length ) {

              mysqlc.query("INSERT INTO game (name, sost) VALUES (?,?)", [player.name, 1], function(e) {
                  if ( e ) console.log ( e );
              });

            } else {
              mysqlc.query("UPDATE game SET sost=? WHERE name=?", [1, player.name], function(e) {
                  if ( e ) console.log ( e );
              });
            }
        } else console.log (e);
    });

  }

  if (nachalo == 1 && player.ingame == 0 && startmp == 1){

    player.outputChatBox('!{red}►!{white}[!{#17d666}SERVER!{white}]: Game already begin.');

  }


  function teleporttomp() {

if (countplayers >=2){

    setTimeout(endmp, 10000);

    reason = 1;
    nachalo = 1;

    if (spawncar == 0){
    copcar2 = mp.vehicles.new(-1627000575, new mp.Vector3(408.7535400390625, -985.9756469726562, 28.87946128845215));
    copcar3 = mp.vehicles.new(-1627000575, new mp.Vector3(408.854248046875, -991.5232543945312, 28.880756378173828));
    copcar4 = mp.vehicles.new(-1627000575, new mp.Vector3(408.9591979980469, -997.333251953125, 28.88153648376465));
    copcar5 = mp.vehicles.new(-1627000575, new mp.Vector3(409.0743103027344, -1003.7307739257812, 28.881433486938477));
    copcar6 = mp.vehicles.new(-1627000575, new mp.Vector3(404.4643249511719, -1016.8744506835938, 28.93781852722168));
    copcar7 = mp.vehicles.new(-1627000575, new mp.Vector3(405.6515808105469, -971.7103271484375, 28.973918914794922));
    robcar = mp.vehicles.new(1878062887, new mp.Vector3(148.70083618164062, -1028.100341796875, 28.839427947998047));
    robcar.dimension = 2;
    copcar2.dimension = 2;
    copcar3.dimension = 2;
    copcar4.dimension = 2;
    copcar5.dimension = 2;
    copcar6.dimension = 2;
    copcar7.dimension = 2;
    spawncar = 1;
  }

    mysqlc.query("SELECT sost FROM game WHERE name = ?", [player.name], function(e, result) {
        if ( result.length ) {

            player.role= result[0]["sost"];
			console.log(player.role);
            if (player.role == 1) // cop
            {
              player.spawn(new mp.Vector3(457.8045959472656, -990.8690795898438, 30.689599990844727));
              player.model = -1699520669;
              player.dimension = 2;
              player.giveWeapon(453432689, 1000);
            }
            if (player.role == 2) // robber
            {
              player.spawn(new mp.Vector3(150.1586151123047, -1040.0599365234375, 29.37407684326172));
              player.dimension = 2;
              player.model = -1067576423;

            }

        } else console.log('request failure');

  });

For some reason, if some player started this event,  him gived role of Robber. If some try to join in this event, him gives role cops, but when called function "teleporttomp" - player, that was "Robber" (who started event) got his role, but all, who was "Cop" - not considered. This happenes because it working only for one player and after just ceases to work. Why so happenes? How to fix this? I need teleport whole players, which now is in this event, on their position with their roles. 

 

Please, help me :o

 

P.S Sorry for my english :D

Edited by 0xNull

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.