Server Problem C# Basic Setup


#1

While testing the server with C# code i ran in to this problem.
The code seem to look good, so i think it must be the set up or x64/x84 or .NET version problem.
Any info on what NET version system inviroment or pre setup settings we should use?

Console output.

“Error loading script server.lua in resource plugins: server.lua:1: attempt to call a nil value (global ‘server_script’)
stack traceback:
server.lua:1: in main chunk
Failed to load script server.lua.”

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using static CitizenFX.Core.Native.API;

namespace realisticGTA
{
public class RealisticProjectServer : BaseScript
{
public RealisticProjectServer()
{
Tick += OnTick;
}

    private async Task OnTick()
    {

        EventHandlers.Add("sendMotd", new Action<string>(ReceivedMotd));
        await Delay(100);
    }
    public bool hasReceivedMotd = false;


    private void ReceivedMotd(string motd)
    {
        if (!hasReceivedMotd)
        {
            TriggerEvent("chatMessage", "SYSTEM", new[] { 255, 0, 0 }, motd);
            hasReceivedMotd = true;
        }
    }
}

}


#2

Adding event handlers go in the constructor. You call the event in a tick.

i.e. TriggerEvent(sendMotd, "hi");

checkout [How-to] Setting up C# and creating a basic resource

You should use .NET Framework 4.5.2


#4

yea i havent come that far… a empty source code will cause the same error, i think it might be the lua scritps.
does this look correct?

__resource.lua

client_script ‘client.lua’
server_script ‘server.lua’

server.lua

server_script {
“realisticGTAserver.dll”,
“realisticGTAclient.dll”

}

client.lua

client_script {

“realisticGTAserver.dll”,
“realisticGTAclient.dll”

}


#5

You have to build your scripts with *.net so it becomes *.net.dll.

An example __resource.lua would look like this:

client_scripts {
    "realisticGTAclient.net.dll"
}
server_scripts {
    "realisticGTAserver.net.dll"
}

You cannot have multiple declarations of client_script and server_script and you cannot put *.dll’s that were compiled for server as a client script.

Again, follow that tutorial VERY CAREFULLY


#6

Also, when you use server scripts for multiple files, the name becomes server_scripts, in plural.

ex:

server_scripts {
    "SynnIAM.net.dll",
    "SynnWorld.net.dll",
    "SynnPedAI.net.dll",
}

#7

i am pretty sure this is the problem i have.
in the __resource.lua
Ive tried single quotes to…

resource_manifest_version ‘77731fab-63ca-442c-a67b-abc70f28dfa5’

client_script “client.lua”
server_script “server.lua”


#8

correction, it is this.

server_script {

“realisticGTAserver.net.dll”,
“realisticGTAclient.net.dll”

}


#9

You’re greatly confusing me. Just follow what Syntasu and I wrote and you are good.

You are now including a CLIENT SIDE script in server_script (which should be plural).

Follow Syntasu’s tutorial very carefully and consider what we have written!


#10

Yea sorry about that, i am confusing my self allot, but it is confusing, everytings changing allot, and all the files look the same.
i need to do some more testing, it might be code also. i am not sure.


#11

Looks like i was right… you have wrong documentation, it seems like they mixed up the lua script way with the .net way.
This is how you load the scripts.
__resource.lua

client_script “RealisticGTAclient.net.dll”
server_script “RealisticGTAserver.net.dll”

and put the DLL’s in the same directory… it is working now.


#12

the brackets need to be removed. in my case it seems. i read it your comment but i was so tired and frustrated it did not register in my mind that you where talking about __resource :slight_smile:


#13

i mixed up a couple documentations it seems you guys were right.
"
To make everything work we simply need to add the __resource.lua. Instead of saying the script names, we want to include the assembly name + extension. In my case it looks something like this:

client_script {
“BasicResourceShared.net.dll”,
“BasicResourceClient.net.dll”
}
server_script {
“BasicResourceShared.net.dll”,
“BasicResourceServer.net.dll”
}
And adding the start command in the server.cfg:

start basic-resource
Note: Use the name of the folder, not the name of the libraries. "


#14

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.