Jump to content

[Server Side c#] attributes don't work


blumi

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

Link to comment
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!");
}

 

Link to comment
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
Link to comment
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
Link to comment
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

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...