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

@CMHDev

Thanks for your Presentation buddy,

I have a question, is there any way to save client data automatically without any /save or some like that with manually event?

I mean i want to write a script that save client Data when Disconnected from the server, is there any way? How? can you post any script?

Share this post


Link to post
Share on other sites
On 4/2/2019 at 6:33 AM, robearded said:

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

Totally agree with this. "'var' on C# when you know the type of the variable"

Share this post


Link to post
Share on other sites
On 3/8/2020 at 1:13 PM, LT.Steiner said:

@CMHDev

Thanks for your Presentation buddy,

I have a question, is there any way to save client data automatically without any /save or some like that with manually event?

I mean i want to write a script that save client Data when Disconnected from the server, is there any way? How? can you post any script?

I didn't quite understand what you wanted to do? I think you want to save the players' data. Practically you need help with the client logout event with mySQL

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/8/2020 at 3:13 PM, LT.Steiner said:

@CMHDev

Thanks for your Presentation buddy,

I have a question, is there any way to save client data automatically without any /save or some like that with manually event?

I mean i want to write a script that save client Data when Disconnected from the server, is there any way? How? can you post any script?

Process the saving on the event when the player disconnects, think simple.

Edited by Heathen

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.