1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

Save Coords to txt File

Discussion in 'Scripts' started by Firesky, Apr 4, 2017.

  1. Firesky

    Firesky Member

    Messages:
    13
    Likes Received:
    4
    Joined:
    Apr 4, 2017
    I'm pretty newbie at programming, just a simple script to save current coordenates in-game to a txt file.
    Hopefully someone may find it usefull.

    Download: https://www.mediafire.com/?pzxddq4qoanpvyx

    [​IMG]
    Syntax: /coords coordname (Save to .txt file)
    Code:
    [Command("coords")]
            public void coords(Client player, string coordName)
            {
                Vector3 playerPosGet = API.getEntityPosition(player);
                var pPosX = (playerPosGet.X.ToString().Replace(',', '.') + ", ");
                var pPosY = (playerPosGet.Y.ToString().Replace(',', '.') + ", ");
                var pPosZ = (playerPosGet.Z.ToString().Replace(',', '.'));
                Vector3 playerRotGet = API.getEntityRotation(player);
                var pRotX = (playerRotGet.X.ToString().Replace(',', '.') + ", ");
                var pRotY = (playerRotGet.Y.ToString().Replace(',', '.') + ", ");
                var pRotZ = (playerRotGet.Z.ToString().Replace(',', '.'));
    
                API.sendChatMessageToPlayer(player, "Your position is: ~y~" + playerPosGet, "~w~Your rotation is: ~y~" + playerRotGet);
                StreamWriter coordsFile;
                if (!File.Exists("SavedCoords.txt"))
                {
                    coordsFile = new StreamWriter("SavedCoords.txt");
                }
                else
                {
                    coordsFile = File.AppendText("SavedCoords.txt");
                }
                API.sendChatMessageToPlayer(player, "~r~Coordinates have been saved!");
                coordsFile.WriteLine("| " + coordName + " | " + "Saved Coordenates: " + pPosX + pPosY + pPosZ + " Saved Rotation: " + pRotX + pRotY + pRotZ);
                coordsFile.Close();
            }
    
    Syntax: /savedcoords (Display saved coords in-game)
    Code:
    [Command("savedcoords")]
            public void savedCoords(Client player)
            {
                API.sendChatMessageToPlayer(player, "~r~Current Saved Coordenates:");
                int counter = 0;
                string coordsLine;
                System.IO.StreamReader file = new System.IO.StreamReader("SavedCoords.txt");
                while ((coordsLine = file.ReadLine()) != null)
                {
                    API.sendChatMessageToPlayer(player, coordsLine);
                    counter++;
                }
                file.Close();
            }
    Changelog:
    Code:
    12/04 - Changed the way coordenates were saved, now there is no need to format the coordenate in order to add to the project. 
    [​IMG]
     
    Last edited: Apr 12, 2017
    NCUNHA, kushovu and Kiase like this.
  2. « Joseph »

    « Joseph » Member

    Messages:
    18
    Likes Received:
    1
    Joined:
    Feb 10, 2017
    Good job. I respect people who are just beginning in programming, but don't be afraid to put their work on the show. I'm too self-critical for this)
     
    Firesky likes this.
  3. Firesky

    Firesky Member

    Messages:
    13
    Likes Received:
    4
    Joined:
    Apr 4, 2017
  4. DurtyFree

    DurtyFree New Member

    Messages:
    0
    Likes Received:
    0
    Joined:
    Oct 30, 2016
    Really good point.
    And good work @Firesky, keep up
     
    Firesky likes this.
  5. Firesky

    Firesky Member

    Messages:
    13
    Likes Received:
    4
    Joined:
    Apr 4, 2017
    Thanks Durty.
    Released a small update, now there is no need to format the coordenates to add to the project.
    [​IMG]
     
    kushovu likes this.
  6. 8o8inSquares

    8o8inSquares New Member

    Messages:
    4
    Likes Received:
    0
    Joined:
    May 24, 2017
  7. NCUNHA

    NCUNHA New Member

    Messages:
    1
    Likes Received:
    0
    Joined:
    May 26, 2017
    Quite useful. I'm also a bit eager to post myself since I'm still learning but by reading your code I just learned how to handle coords.
    Thank you!
    Also leaving a reply here so I can return back to it later.
     
  8. enviel

    enviel Member

    Messages:
    23
    Likes Received:
    5
    Joined:
    Jan 26, 2017
    you could just do this for saving to file, less code
    don't need to check if the file exist, one will created if doesn't
    Code:
    File.AppendAllText("filename.txt", "the text here\n");
    actually i used this too for saving coord

    and use this for read from file
    Code:
    foreach (string line in File.ReadLines("filename.txt"))
    {
        API.sendChatMessageToPlayer(player, line);
    }
    
     

Share This Page