CMHDev

[C#] /Save command

Recommended Posts

I have seen the example posted by rootcause with a rescue command as it is on
samp for java script and i said to do one for C #.

U2xm7OR.png

 

You must use the System.IO library

using System.IO;

And this is the proper command..

        [Command("save","Use /save [Position Name]", GreedyArg = true)]
        public void CMD_SavePosition(Client player, string PosName = "No Set")
        {
            var pos = (player.IsInVehicle) ? player.Vehicle.Position : player.Position;
            var rot = (player.IsInVehicle) ? player.Vehicle.Rotation : player.Rotation;
        
            using (var stream = File.AppendText("SavePos.txt"))
            {
                if (player.IsInVehicle)
                {
                    NAPI.Notification.SendNotificationToPlayer(player, "~g~In car ~w~postion saved with name ~r~" + PosName, true);
                    stream.WriteLine("IN VEH || " + PosName + ":" + pos.X + ", " + pos.Y + ", " + pos.Z + "    Rot:    " + rot.Z);
                    stream.Close();
                }
                else
                {
                    NAPI.Notification.SendNotificationToPlayer(player, "~g~On foot ~w~position saved with name ~r~" + PosName, true);
                    stream.WriteLine("ON FOOT|| " + PosName + ":" + pos.X + ", " + pos.Y + ", " + pos.Z + "    Rot:    " + rot.Z);
                    stream.Close();
                }
            }
        }

The positions you find saved in the SavePos.txt file in the server folder

GGP5qD1.png

That's how they look

ON FOOT|| No Set: -439.8961, 6023.063, 31.49012    Rot:    2.175138
ON FOOT|| Police: -440.5302, 6034.081, 31.34053    Rot:    2.944162
IN VEH || Spawn Adder: -440.6177, 6035.974, 30.93323    Rot:    2.784058

 

Edited by CMHDev
add images
  • Like 1

Share this post


Link to post
Share on other sites

Good job for helping the community, but I don't understand why people abuse 'var' on C# when you know the type of the variable you're dealing with

  • Like 1

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

  • Recently Browsing   0 members

    No registered users viewing this page.