Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Releases Plugins [Plugin] SampSharp - Write game modes in .NET Core

 
  • 1 Vote(s) - 5 Average
Plugin SampSharp - Write game modes in .NET Core
tim
Offline

Burgershot Member
Posts: 2
Threads: 1
Joined: Apr 2019
Reputation: 0
Location: The Netherlands
#1
2020-09-28, 09:06 PM (This post was last modified: 2020-09-28, 09:11 PM by tim.)
[Image: sampsharp.png]

SampSharp

[Image: SampSharp.svg] [Image: SampSharp.svg] [Image: SampSharp.svg] [Image: total.svg]
Join us on Discord

SampSharp is a plugin and library which allows you to write SA-MP game modes in C#. The plugin works both on Linux and Windows. The library contains various classes for every type of resource available in SA-MP (players, vehicles, textdraws, etc). Aside from this wrapper around native functions, the library also contains a good structure to build your gamemode on. This plugin was initially released in 2014, and has received a good ever since and I'm still available for any questions related to this plugin.

SampSharp provides two structures for developing game modes. SampSharp.GameMode and SampSharp.Entities.

SampSharp.GameMode provides a simple object-oriented structure for developing your game mode. All callbacks are forwarded to the implementation of BaseMode and vanilla callbacks are forwarded as events to the related instances (eg. OnPlayerText fires the PlayerText event on the related Player instance). A simple code sample can be found below.


PHP Code:
public class GameMode : BaseMode
{
    protected override void OnPlayerConnected(BasePlayer player, EventArgs e)
    {
        base.OnPlayerConnected(player, e);

        player.SendClientMessage($"Welcome {player.Name}, to a whole new world!");
    }

    [Command("spawn")]
    public static void VehicleCommand(BasePlayer player, VehicleModelType model)
    {
        Console.WriteLine($"Spawning a {model} for {player.Name}");
        var vehicle = GtaVehicle.Create(model, player.Position + new Vector3(0, 0, 0.5f), player.Rotation.Z);
        player.PutInVehicle(vehicle);
        player.SendClientMessage(Color.GreenYellow, $"You have spawned a {model}!");
    }
} 

SampSharp.Entities (only available since early 2020) provides an Entity-Component-System structure with full dependency injection support for developing your game mode. SampSharp.Entities is still in active development but is already stable and usable. Below, a similar code sample can be found:

PHP Code:
    public class SampleSystem : ISystem
    
{
        [Event]
        public void OnPlayerConnected(Player player)
        {
            player.SendClientMessage($"Welcome {player.Name}, to a whole new world!");
        }

        [PlayerCommand("spawn")]
        public static void VehicleCommand(Player player, VehicleModelType model, IWorldService worldService)
        {
            Console.WriteLine($"Spawning a {model} for {player.Name}");
            var vehicle = worldService.CreateVehicle(model, player.Position + new Vector3(0, 0, 0.5f), player.Rotation.Z, -1, -1);
            player.PutInVehicle(vehicle);
            player.SendClientMessage(Color.GreenYellow, $"You have spawned a {model}!");
        }
    } 

Download

Stable version: [Image: SampSharp.svg] [Image: total.svg]
Unstable version: [Image: SampSharp.svg]

https://github.com/ikkentim/SampSharp/releases


Documentation

Our documentation website is still in development and some vital documentation is still lacking. If you need any assistance, feel free to join our Discord server!

https://sampsharp.net
Author of SampSharp and SanMap
tim
Offline

Burgershot Member
Posts: 2
Threads: 1
Joined: Apr 2019
Reputation: 0
Location: The Netherlands
#2
2020-09-28, 09:09 PM (This post was last modified: 2020-09-28, 09:13 PM by tim.)
Ugh the formatting is totally ruined, every time I edit the posts it adds more line breaks after every line :cry:

edit: manged to fix it
Rique_FTW
Offline

Burgershot Member
Posts: 4
Threads: 1
Joined: Jan 2021
Reputation: 0
Location: Brasil, São Paulo - SP
#3
2021-01-28, 02:39 PM
Tim, is there any way to do a “hook”?
Sasino97
Offline

Software Developer
Posts: 108
Threads: 16
Joined: Apr 2019
Reputation: 7
Location: Tampa, FL
#4
2021-01-29, 04:05 AM
⭐⭐⭐⭐⭐

This is by far the best SA-MP plugin after Incognito's Streamer.
It's incredible how well made the C# API is, and how familiar it feels if you're already a C# programmer.

(2021-01-28, 02:39 PM)Rique_FTW Wrote: Tim, is there any way to do a “hook”?

If by hooking you mean handling multiple time the same event in different parts of your code, e.g. OnPlayerConnect, you can do so by attaching multiple handlers to the `Connected` event of your `BasePlayer` class, or the `PlayerConnected` event of your `BaseMode` class.
[Image: Sasinosoft.png]
Rique_FTW
Offline

Burgershot Member
Posts: 4
Threads: 1
Joined: Jan 2021
Reputation: 0
Location: Brasil, São Paulo - SP
#5
2021-02-10, 12:42 AM (This post was last modified: 2021-02-10, 01:33 AM by Rique_FTW.)
Code:
[Event]
public void OnPlayerConnect(Player player) {
    player.SendClientMessage($"» {player.Name} (ID: {player.Id}) connected.");
}
player.Id not found.

One more doubt. I can't use accentuation (I'm Brazilian).
Example:
Code:
Input code: Queda de conexão
Output server: Queda de conex?o
Banditul Away

Burgershot Member
Posts: 38
Threads: 0
Joined: Apr 2019
Reputation: 2
#6
2021-02-14, 11:26 AM (This post was last modified: 2021-02-14, 11:41 AM by Banditul.)
(2021-02-10, 12:42 AM)Rique_FTW Wrote:
Code:
[Event]
public void OnPlayerConnect(Player player) {
    player.SendClientMessage($"» {player.Name} (ID: {player.Id}) connected.");
}
player.Id not found.

One more doubt. I can't use accentuation (I'm Brazilian).
Example:
Code:
Input code: Queda de conexão
Output server: Queda de conex?o

@Rique_FTW
I see you are using the ECS (.Entity) and to get player id you need to use
PHP Code:
player.Entity.Handle 

As for accents and that sort of things add
PHP Code:
.UseEncodingCodePage("cp860") 
to your gamemode builder (Program.cs) and specify the code page for portuguese language uses. I assume that is the cp860 but not sure

I recommend you to join discord server for faster help regarding S#
Rique_FTW
Offline

Burgershot Member
Posts: 4
Threads: 1
Joined: Jan 2021
Reputation: 0
Location: Brasil, São Paulo - SP
#7
2021-02-16, 01:23 AM
Thank you very much. It worked perfectly <3
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode