pos saving on notepad

Started by MEGAMIND, Jun 25, 2017, 02:36 PM

Previous topic - Next topic

MEGAMIND

hi and how's everyone its a good day and hope u all are fine too Eid mubarak to all

hi i was searching for a code i founded in my old 2year book there was a code like fopen which lets you save anything on a notepad hows that possible in vcmp any ideas


i need to save player.pos on my notepad any ideas thnx for helping.........

vito1

function onPlayerCommand( player, cmd, text ){
if(cmd == "pos"){
MessagePlayer( player.Pos.x +","+ player.Pos.y +","+ player.Pos.z +","+ player.Angle, player);
}
}
log located in %AppData%\VCMP\04beta\serverlogs\<your server>


MEGAMIND

Quote from: vito1 on Jun 25, 2017, 02:43 PMfunction onPlayerCommand( player, cmd, text ){
if(cmd == "pos"){
MessagePlayer( player.Pos.x +","+ player.Pos.y +","+ player.Pos.z +","+ player.Angle, player);
}
}
log located in %AppData%\VCMP\04beta\serverlogs\<your server>
your code didnt worked its like this
 
function onPlayerCommand( player, cmd, text )
{
 if(cmd == "pos")
{
 MessagePlayer( ""+player.Pos.x +","+ player.Pos.y +","+ player.Pos.z +","+ player.Angle, player);
 }
}

btw thanks

.

Why do you retrieve a position instance every time to print each member individually? Wouldn't it just be easier to do:

print/Message/whatever(player.Pos + " " + player.Angle);
Things do know to convert themselves to strings. You don't have to do it yourself in the least efficient way.
.

vito1

Quote from: . on Jun 25, 2017, 05:08 PMWhy do you retrieve a position instance every time to print each member individually? Wouldn't it just be easier to do:
Things do know to convert themselves to strings.
1) It's important for performance, but not development commands.
2) To keep my-own format of output, without those ( ), I prefer to call instance few times in row than manually copy-pasting text. Of course it depends of one's needs.

.

#6
Quote from: vito1 on Jun 25, 2017, 05:30 PM1) It's important for performance, but not development commands.

Efficiency is not strictly limited to performance. There can also be efficiency in how clean your code looks and how fast you write it.

Quote from: vito1 on Jun 25, 2017, 05:30 PM2) To keep my-own format of output, without those ( ), ...

If anything, those () make it easier to understand what the value is/was. If you print four floats in a row you can mistake them for a quaternion. And it's not as if you're parsing things back and trying to conserve space (as if choosing a text format is an indication that you need to conserve space).

Quote from: vito1 on Jun 25, 2017, 05:30 PM... I prefer to call instance few times in row than manually copy-pasting text. ...

I'm sorry, what?



Please put a little more effort in finding a better argument. Not that there needs to be one.
.

vito1

#7
Quote from: . on Jun 25, 2017, 05:37 PMIf you print four floats in a row you can mistake them for a quaternion
Nope, since I know what I expect in output.
I prefer to use position-angle format as one array [x,y,z,angle] to manage player's position. So it's easy to copy-paste this format (for me). And faster to code ;)

Mötley

You posted a bad post in LU about saving positions, So I created a fast snippet to clear the future confusion.

All you had was

else if( szCommand == "s" )
{
 print( pPlayer.Pos );
 }



You deleted the post and took ownership of my fastly thrown together crappy code. I know how you like to lock topics so I had to code that in literally one minute :/

http://forum.liberty-unleashed.co.uk/index.php?topic=2925.msg15121;topicseen#new

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;
}

You obviously haven't learned anything.... ;D ;D ;D ;D

MEGAMIND

Quote from: TurboGrafx on Jun 27, 2017, 12:35 AMYou posted a bad post in LU about saving positions, So I created a fast snippet to clear the future confusion.

All you had was

else if( szCommand == "s" )
{
 print( pPlayer.Pos );
 }



You deleted the post and took ownership of my fastly thrown together crappy code. I know how you like to lock topics so I had to code that in literally one minute :/

http://forum.liberty-unleashed.co.uk/index.php?topic=2925.msg15121;topicseen#new

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;
}

You obviously haven't learned anything.... ;D ;D ;D ;D


I think u still didnt got my question do u well the problem was solved my self in Lu and vcmp both the code u replied to my question is irrelevant thnx for being over efficient problem solved locking topic