Jump to content

OnPlayerConnect() isn't getting called if script is running on .dll but it is running if it is in .cs


$kylar

Recommended Posts

I've made a very simple script.

 

using System;
using GTANetworkAPI;

namespace GTA_V_RP
{

    public class Main : Script
    {
        [ServerEvent(Event.ResourceStart)]
        public void OnResourceStart()
        {
            NAPI.Util.ConsoleOutput($"{NAPI.Server.GetServerName()} has loaded.");
            NAPI.Server.SetGlobalServerChat(false);
        }

        [ServerEvent(Event.ChatMessage)]
        public void OnChatMessage(Client player, string message)
        {
            foreach(Client players in NAPI.Player.GetPlayersInRadiusOfPlayer(5.0, player))
            {
                if (players.Equals(player))
                    player.SendChatMessage($"I say: {message}");
                else
                    players.SendChatMessage($"{NAPI.Player.GetPlayerName(player)} says: {message}");
            }
        }

        [ServerEvent(Event.PlayerConnected)]
        public void OnPlayerConnected(Client client)
        {
            NAPI.Util.ConsoleOutput("Test");
            client.SendNotification("Hi", false);
        }

        [ServerEvent(Event.PlayerSpawn)]
        public void OnPlayerRespawn(Client player)
        {
            NAPI.Util.ConsoleOutput("Test");
            player.SendChatMessage("spawned");
        }

        [Command("kill")]
        public void CMD_Kill(Client sender)
        {
            NAPI.Player.SetPlayerHealth(sender, 0);
        }
    }
}

 

Now the problem arises is that if I build it into a .dll file and run it. The script runs. OnResourceStart() even gets called. However OnPlayerConnected(), OnPlayerSpawned() never gets called unless I explicitly call them.

 

However if I make it into a .cs file and the script compiles itself when the server is initiated then everything works fine.

 

And yes, I've set the meta.xml perfectly fine. It is correct, if it weren't then OnResourceStart() wouldn't have called in the first place.

Link to comment
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.
×
×
  • Create New...