Author Topic: saving a player position  (Read 63 times)

mega mind

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-5
    • View Profile
saving a player position
« on: June 11, 2017, 11:03:32 pm »
Quote
function onPlayerCommand(player, cmd, text)
{
  if ( cmd == "print")
  {
    if (player.Spawned)
    {
     
      local pos = player.Pos, x = pos.x, y = pos.y, z = pos.z;

      print("Vector( " + x + ", " + y + ", " + z +");" );

      return true
    }
    else MessagePlayer("You never spawned", player, 255, 0, 0);
  }
}

or
save it to ur commands onplayercommands and when in game do /s the positons or values will be displayed on the console..
Quote
else if( szCommand == "s" )
{
 print( pPlayer.Pos );
 }


in game printing pos

Quote
Player_Pos <- array(GetMaxPlayers());

class Player_Stores_Pos
{
  /* No true reason to set these as floats */
 
  X = 0;
  Y = 0;
  Z = 0;

  Position_Exist = false;
 
}

function onPlayerCommand(player, cmd, text)
{
  if ( cmd == "print")
  {
    if (player.Spawned)
    {
     
      local pos = player.Pos, x = pos.x, y = pos.y, z = pos.z;

      /* This print will return a vector that can be copied and pasted via in scripting */
      print("Vector( " + x + ", " + y + ", " + z +");" );

      return true
    }
    else MessagePlayer("You never spawned", player, 255, 0, 0);
  }

  //--------------------------------------------------------------------------

  if ( cmd == "setclass")
  {
     /* You should add this on player join instead */
     Player_Pos[player.ID] = Player_Stores_Pos();

     MessagePlayer("You have set the position class", player, 100, 0, 115);

     return true;
  }

  if ( cmd == "endclass")
  {
     /* You should add this on player part instead */
     Player_Pos[player.ID] = null;

     MessagePlayer("You have cleared the position array", player, 100, 0, 115);

     return true;
  }

  //--------------------------------------------------------------------------

  if ( cmd == "save")
  {
    if (player.Spawned)
    {
     
      local pos = player.Pos, x = pos.x, y = pos.y, z = pos.z;
     
      /* Now store the positions */
      Player_Pos[player.ID].X = x;
      Player_Pos[player.ID].Y = y;
      Player_Pos[player.ID].Z = z;

      Player_Pos[player.ID].Position_Exist = true;

      local District = GetDistrictName(Player_Pos[player.ID].X, Player_Pos[player.ID].Y);
      MessagePlayer("Position Saved in: " + District, player, 100, 0, 115);

      return true
    }
    else MessagePlayer("You never spawned", player, 255, 0, 0);
  }

  if ( cmd == "load")
  {
    if (player.Spawned)
    {
      if (Position_Exist == true)
      {
        player.Pos = Vector(Player_Pos[player.ID].X, Player_Pos[player.ID].Y, Player_Pos[player.ID].Z);
      }
      else MessagePlayer("I think you forgot to save a position ? :P xD", player, 255, 255, 33);

      return true
    }
    else MessagePlayer("You never spawned", player, 255, 0, 0);
  }

  //--------------------------------------------------------------------------
 
  return 1;
}

 

© Liberty Unleashed Team.