Sign in to follow this  
Asznee

Problems with a MOTD function

Recommended Posts

Hey, so currently I'm about to do my first gamemode, I coded several years in PAWN (for SA:MP) so a bit knowledge is there when it comes to coding.

I'm currently figuring out, how I make a MOTD function which gets shown when you connect.

So, I'm currently "learning by reading", that means, I downloaded the WiredPlayers Gamemode (maybe a bad decision, just like Godfather on SA:MP, but it helps me getting a bit of experience)

and watch some parts of the script and how it does work.

 

So, I created my database things where MySQL is going to connect ect. and now I wanted to add a MOTD function, to do basic things like "Save & Show messages from my Database".

That's what is in my Database.cs:

 

        public static List<MOTDModel> LoadMOTD()
        {
            List<MOTDModel> motdList = new List<MOTDModel>();

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                MySqlCommand command = connection.CreateCommand();
                command.CommandText = "SELECT * FROM motd";

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while(reader.Read())
                    {
                        MOTDModel motdModel = new MOTDModel();
                        motdModel.message = reader.GetString("message");
                    }
                }
            }
            return motdList;
        }

 

That's what the MOTDModel.cs looks like:

using System;

namespace firstresource.model
{
    public class MOTDModel
    {
        public string message { get; set; }
    }
}

 

So, now I have the Login.cs and I just want to show it there at "OnPlayerConnect", but how do I do that actually?

I tried something like "player.SendChatMessage(MOTDModel.message);" but that doesn't seem to work.

Can anybody help me with this little thing?

Would be really nice. Thanks!

Share this post


Link to post
Share on other sites
Posted (edited)

@Asznee You need something to handle your MOTD list, if you already have that please send that too so people can help you easier...

Otherwise it can be from your OnPlayerConnected, maybe you're not using the hook correctly.

 

[ServerEvent(Event.PlayerConnected)]
public void OnPlayerConnected(Client player)
{
    foreach(MOTDModel motto in MOTDHandler.MOTD_LIST)
    {
       player.SendChatMessage(motto.message); 
    }
}

This code above sends every motto in the list to the player as soon as he connects to the server and by the way using WiredRP as a resource is not a bad idea...

Edited by Original

Share this post


Link to post
Share on other sites
vor 4 Stunden schrieb Original:

@Asznee You need something to handle your MOTD list, if you already have that please send that too so people can help you easier...

Otherwise it can be from your OnPlayerConnected, maybe you're not using the hook correctly.

 

[ServerEvent(Event.PlayerConnected)]
public void OnPlayerConnected(Client player)
{
    foreach(MOTDModel motto in MOTDHandler.MOTD_LIST)
    {
       player.SendChatMessage(motto.message); 
    }
}

This code above sends every motto in the list to the player as soon as he connects to the server and by the way using WiredRP as a resource is not a bad idea...

Oh, its not? I thought so, because the Godfather was a mess back in the days. There were several people editing the Godfather and it was just shit, they used file-based systems to read and save player data and everything else and the servers were lagging like hell actually.

 

I already did the OnPlayerConnected part, it looks like this right now:

 [ServerEvent(Event.PlayerConnected)]
        public void OnPlayerConnected(Client player)
        {
            //player.SendChatMessage(motdmessage.message);
            NAPI.Player.SetPlayerSkin(player, PedHash.Strperf01SMM);
            player.Transparency = 255;

            InitializePlayerData(player);


            Task.Factory.StartNew(() =>
            {
                AccountModel account = Database.GetAccount(player.SocialClubName);

                switch (account.status)
                {
                    case -1:
                        // account banned
                        break;
                    case 0:
                        //register
                        break;
                    default:
                        // Welcome / login
                        break;
                }
            });
        }

 

I'm now trying to figure out some MySQL Problems, my server says 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=8.0.15.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.

 

And there is also that function called 

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

 

Do I need that actually? Because it gets me in some trouble tbh and I don't see the point where I need to have that.

Share this post


Link to post
Share on other sites
Posted (edited)
Spoiler

 

1 hour ago, Asznee said:

Oh, its not? I thought so, because the Godfather was a mess back in the days. There were several people editing the Godfather and it was just shit, they used file-based systems to read and save player data and everything else and the servers were lagging like hell actually.

 

I already did the OnPlayerConnected part, it looks like this right now:


 [ServerEvent(Event.PlayerConnected)]
        public void OnPlayerConnected(Client player)
        {
            //player.SendChatMessage(motdmessage.message);
            NAPI.Player.SetPlayerSkin(player, PedHash.Strperf01SMM);
            player.Transparency = 255;

            InitializePlayerData(player);


            Task.Factory.StartNew(() =>
            {
                AccountModel account = Database.GetAccount(player.SocialClubName);

                switch (account.status)
                {
                    case -1:
                        // account banned
                        break;
                    case 0:
                        //register
                        break;
                    default:
                        // Welcome / login
                        break;
                }
            });
        }

 

I'm now trying to figure out some MySQL Problems, my server says 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=8.0.15.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.

 

And there is also that function called 

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

 

Do I need that actually? Because it gets me in some trouble tbh and I don't see the point where I need to have that.

 

 

If you're using Visual Studio to debug, compile and run your program, for example if you followed this tutorial on this site for setting up C#, this one to be exact link then you need to manually copy System.Data.Common.dll, System.Data.dll, System.Text.Encoding.CodePages.dll, System.Text.Encoding.dll from the runtime folder to your resource folder each time after you compile it. Or you can just setup a build event in VS to do it for you.

 

Edited by MiMIMi

Share this post


Link to post
Share on other sites

Ye thank you, I now finally can start my Server, but I still have some problems with my MOTD function.

Is there any tutorial I could follow or something similar?

 

I'm actually giving up on that function and deleted all content which contained something about MOTD.

 

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.