blumi

solved [Server Side c#] attributes don't work

Recommended Posts

Hello to all,

I started learning API on the c # serve side. I tried to write a spawn system player. I checked the documentation and found the code:

[DisableDefaultOnConnectSpawn]
[ServerEvent(Event.PlayerConnected)]
public void OnPlayerConnected(Client player)
{
    NAPI.Player.SpawnPlayer(player, new Vector3(2, 5, 8)); // Will spawn the player at the given position
}

My compiler is showing me an error: the type or namespace “DisableDefaultOnConnectSpawnAttribute” could not be found. Can anybody help me?

Thank you in advance

Share this post


Link to post
Share on other sites

Use this:

NAPI.Server.SetAutoSpawnOnConnect(false);
NAPI.Server.SetAutoRespawnAfterDeath(false);

 

Edited by Flashrex

Share this post


Link to post
Share on other sites
12 минуты назад, Flashrex сказал:

Use this:

NAPI.Server.SetAutoSpawnOnConnect(false);
NAPI.Server.SetAutoRespawnAfterDeath(false);

 

I tried to do that) But my "OnPlayerConnected" method doesn't work)
 

 [ServerEvent(Event.PlayerConnected)]
public void OnPlayerConnected(Client player)
{
     Spawn(player);
     NAPI.Chat.SendChatMessageToAll("~b~ Connected!");
}

 

Share this post


Link to post
Share on other sites

Show me your console.

Did you add :Script after your class name?

For example:

class Main : Script {
	//Code
}

 

Did you include your resource in your settings.xml?

<resource src="myGamemode" />

 

Edited by Flashrex

Share this post


Link to post
Share on other sites
31 минуту назад, Flashrex сказал:

Show me your console.

Did you add :Script after your class name?

For example:

class Main : Script {
	//Code
}

 

Did you include your resource in your settings.xml?

<resource src="myGamemode" />

 

Yes, I did. 
I can show you my code: 

using System.Collections.Generic;
using GTANetworkAPI;

namespace CriminalBelarus
{
    public class Main : Script
    {
        private List<Vehicle> _vehicles = new List<Vehicle>();


        [ServerEvent(Event.ResourceStart)]
        public void OnResourceStart()
        {
            NAPI.Server.SetAutoSpawnOnConnect(false);
            NAPI.Server.SetAutoRespawnAfterDeath(false);
            NAPI.Server.SetDefaultSpawnLocation(new Vector3(-1036.182, -2729.434, 13.75665));

            SpawnCars();

            NAPI.Util.ConsoleOutput("Criminal Belarus has been loaded!");

        }

        [ServerEvent(Event.PlayerConnected)]
        public void OnPlayerConnected(Client player)
        {
            SpawnPlayer(player);
            NAPI.Chat.SendChatMessageToAll($"~b~ Hello!");
        }


        private void SpawnPlayer(Client player)
        {
            Vector3 spawnPos = new Vector3(-1036.182, -2729.434, 13.75665);

            NAPI.Player.SpawnPlayer(player, spawnPos);
            player.Position = spawnPos;
            player.Health = 100;
        }

        private void SpawnCars()
        {
            VehicleHash vehcleHash = NAPI.Util.VehicleNameToModel("tribike2");

            Vehicle vehicle = NAPI.Vehicle.CreateVehicle(vehcleHash, new Vector3(-1019, -2692.058, 13.99043), 59, 27, 27);
            Vehicle vehicle2 = NAPI.Vehicle.CreateVehicle(vehcleHash, new Vector3(-1017, -2688.171, 13.99043), 59, 27, 27);
            _vehicles.Add(vehicle);
            _vehicles.Add(vehicle2);

        }
    }
}

Yes, I included resuorces in settings.xml OnResourceLoaded-Event was executed, but OnPlayerConnected-Event was not executed. In another script, "welcomemessages" is the default script that the OnPlayerConnected-Event was executed. This is so strange)

Edited by blumi

Share this post


Link to post
Share on other sites

Are you compiling your resource on .Net Core 2.2?

Did you reference the bootstrapper.dll directly or are you using the nuget? (Nuget is outdated)

Is the bootstrapper and the bridge both on 0.3.7.0 (look in server-console)?

Edited by Flashrex

Share this post


Link to post
Share on other sites
2 минуты назад, Flashrex сказал:

Are you compiling your resource on .Net Core 2.2?

Did you reference the bootstrapper.dll directly or are you using the nuget? (Nuget is outdated)

Is the bootstrapper and the bridge both on 0.3.7.0 (look in server-console)?

I'm compiling resource on .Net Core 2.0. Maybe this is the reason)
Here is Console output Image

Share this post


Link to post
Share on other sites

I found that on Discord:

Zitat

you need to replace the bootstrapper.dll in
RAGEMP\server-files\bridge\runtime
with the one from your gtanetwork.api nuget package

 

 

Edited by Flashrex

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.