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

Ive done what it says but in the console it says Resource loading for basic-resource failed: and the server doesnt work

There should be an error associated, could you please share that?

Leading on from what @MrArca9 said about the OnPlayerSpawned function, using the variable player

isn’t going to work because we removed the player variable from the constructor

I have experienced this issue in that Visual Studio refuses to build anything. What would be the best-practice method of obtaining this variable? Would it be a case of creating a property within the class and assigning it from a constructor parameter, or something else?

You can get the Player object server side by defining a Player object when adding the Eventhandler and then using the FromSource.

EventHandlers.Add("onPlayerSpawned", new Action<Player>(OnPlayerSpawned));

private void OnPlayerSpawned([FromSource]Player player){
    // Do your thing with player
    player.TriggerEvent("myEvent");
}
1 Like