[Plugin] SampSharp - Write gamemodes in .NET

When does SampSharp support Chinese?
Reply

Quote:
Originally Posted by Gigi-The-Beast
Посмотреть сообщение
@ikkentim would it be difficult to make a wrapper for FCNPC ?
And how it is going for 0.8, are you making some progress?
Will you implement the "gamemode reload without server restart" option?
Had a vacation recently and have been very busy with work, should be resuming with sampsharp in 2 weeks or so I think... I've already implemented restarted w/o gamemode reloading

It's very easy to write wrappers. One example would be the streamer wrapper: https://github.com/ikkentim/SampSharp-streamer

These basic wrappers have been written by newbprogramming(iirc )
RNPC: https://pastebin.com/KxeiAdaR
ColAndreas: https://pastebin.com/rMgFa8sp

Quote:
Originally Posted by daemondas
Посмотреть сообщение
Use GlobalObject not DynamicObject.
example:
Код:
new GlobalObject(353, new Vector3(player.Position.X, player.Position.Y, player.Position.Z-1), new Vector3(90, 90, 90));
You can use DynamicObject, simply load the streamer extension and streamer plugin (version 2.8.2 is currently the latest supported plugin version!)

Quote:
Originally Posted by wsll789
Посмотреть сообщение
When does SampSharp support Chinese?
It's a bit broken atm... With version 0.8 it should be properly supported again!
Reply

Quote:
Originally Posted by Nominal
Посмотреть сообщение
How to use other plugins if I fully write my gamemode in C#? How can I include colandreas, routeconnector, etc?
You can do it this way:
http://sampsharp.timpotze.nl/natives

Or these ways (RNPC): (I made these, you can take them and improve them, all good)
https://pastebin.com/KxeiAdaR
(ColAndreas):
https://pastebin.com/rMgFa8sp
(Look at the RNPCInternal and ColAndreasInternal classes)

Make sure the plugin.dll is in the plugins folder and loaded before SampSharp.dll
Код:
#server.cfg
plugins crashdetect.dll ColAndreas.dll RNPC.dll SampSharp.dll
Reply

Hello again, is it possible to remove removebuildingforplayer limit with this plugin ?

Also I want to make command when I am getting error in the command section. How do I resolve this problem ?
Reply

Quote:
Originally Posted by sampkinq
Посмотреть сообщение
Hello again, is it possible to remove removebuildingforplayer limit with this plugin ?
No you cannot remove any internal samp limits, only find work around solutions (like streamers and whatnot).

Quote:
Originally Posted by sampkinq
Посмотреть сообщение
Also I want to make command when I am getting error in the command section. How do I resolve this problem ?
What kind of command are you trying to make? Can you provide code / logs of the error?
Reply

This encoding also I'm a little clumsy. If you have training videos more quickly I can learn.

I'm waiting for your help @AwareWolf

Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

using SampSharp.GameMode; // Contains BaseMode class
using SampSharp.GameMode.Controllers; // Contains ControllerCollection class
using SampSharp.GameMode.API.NativeObjects;
using SampSharp.GameMode.World;
using SampSharp.GameMode.SAMP;
using SampSharp.GameMode.Definitions;


namespace MyGamemode
{
    public class GameMode : BaseMode
    {
        #region Overrides of BaseMode

        protected override void OnInitialized(EventArgs e)
        {
            Console.WriteLine("\n----------------------------------");
            Console.WriteLine(" C# Mode");
            Console.WriteLine("----------------------------------\n");
            SetGameModeText("C Test Mode");

            base.OnInitialized(e);
        }

        protected override void LoadControllers(ControllerCollection controllers)
        {
            base.LoadControllers(controllers);
        }

        public override void SetGameModeText(string text)
        {
            base.SetGameModeText(text);
        }

        protected override void OnPlayerConnected(SampSharp.GameMode.World.BasePlayer player, EventArgs e)
        {
            player.SendClientMessage(0xD33257FF, "[{0}] Welcome {1}({2})", DateTime.Now, player.Name, player.Id);
            player.GiveMoney(500);
            base.OnPlayerConnected(player, e);
        }

        protected override void OnPlayerDisconnected(SampSharp.GameMode.World.BasePlayer player, SampSharp.GameMode.Events.DisconnectEventArgs e)
        {
            base.OnPlayerDisconnected(player, e);
        }

        protected override void OnPlayerCommandText(SampSharp.GameMode.World.BasePlayer player, SampSharp.GameMode.Events.CommandTextEventArgs e)
        {
            base.OnPlayerCommandText(player, e);
        }
        #endregion
    }
}

class AnyClass
{
    [Command("helloworld")]
    private static void HelloWorldCommand(BasePlayer sender, int times)
    {
        for (var i = 0; i < times; i++)
            sender.SendClientMessage("Hello, world!");
    }
}
Код:
[Command("helloworld")]  <--- Error
Reply

Quote:
Originally Posted by sampkinq
Посмотреть сообщение
This encoding also I'm a little clumsy. If you have training videos more quickly I can learn.

I'm waiting for your help @AwareWolf
Needs to be at the top of the script.
Код:
using SampSharp.GameMode.SAMP.Commands;
If you are using Visual Studio or MonoDevelop, you can usually hover your mouse over the error (Command), IntelliSense will tell you why it's giving the error and usually suggest fixes and with your permission edit the script for you and add that line for you.

(please note my GameMode is called SampServer and yours is called MyGamemode, do not be confused with the namespace naming :P)
Reply

I understand, thank you for your help.
Reply

Quote:
Originally Posted by AwareWolf
Посмотреть сообщение
You can do it this way:
http://sampsharp.timpotze.nl/natives

Or these ways (RNPC): (I made these, you can take them and improve them, all good)
https://pastebin.com/KxeiAdaR
(ColAndreas):
https://pastebin.com/rMgFa8sp
(Look at the RNPCInternal and ColAndreasInternal classes)

Make sure the plugin.dll is in the plugins folder and loaded before SampSharp.dll
Код:
#server.cfg
plugins crashdetect.dll ColAndreas.dll RNPC.dll SampSharp.dll
Thank you sir, for example, if a native returns me something, I can use it with the invoke?

For example: native FCNPC_GetPosition
Reply

Quote:
Originally Posted by Nominal
Посмотреть сообщение
Thank you sir, for example, if a native returns me something, I can use it with the invoke?

For example: native FCNPC_GetPosition
Yes, simply mark them as out parameters:

Код:
 [NativeMethod(Function = "FCNPC_GetPosition")]
        public virtual int GetPosition(int id, out float x, out float y, out float z)
        {
            throw new NativeNotImplementedException();
        }
Reply

Quote:
Originally Posted by Nominal
Посмотреть сообщение
Thank you sir, for example, if a native returns me something, I can use it with the invoke?

For example: native FCNPC_GetPosition
Ikkentim provided the answer to your question, but I'd like to explain how to retrieve Array reference types.

The most extreme example of getting back an Array reference type is found in the ColAndreas include (CA_RayCastMultiLine).
Код:
        [NativeMethod(11, 11, 11, 11, 11, Function = "CA_RayCastMultiLine")]
        public virtual int RayCastMultiLine(float startX, float startY, float startZ, float endX, float endY, float endZ, out float[] x, out float[] y, out float[] z, out float[] distance, out int[] modelId, int size)
        {
            throw new NativeNotImplementedException();
        }
Ikkentim told me before, those 11s you see tell SampSharp you are expecting back around 10 results in the array (1-based, not 0-based), though it does not appear that it matters to use that (because the array returns in any size) even though it's required to supply that number otherwise you won't get back any result.
(He actually said 12s but providing 12s wasn't working for me.)
Reply

Thank you for the explanation, you guys are amazing!
Reply

Think I'm going to give this a shot. Seems like it could really cut development time a whole bunch with command groups and creating group permissions and such. Very rich, nice.
Reply

Every time I attempt to launch, the console returns me with a message saying "Gamemode RP : GameMode , library not found!", I have no idea how to fix this. Help


MY BAD LOL I DIDN't BUILD THE SOLUTION
Reply

Quote:
Originally Posted by sammp
Посмотреть сообщение
Every time I attempt to launch, the console returns me with a message saying "Gamemode RP : GameMode , library not found!", I have no idea how to fix this. Help


MY BAD LOL I DIDN't BUILD THE SOLUTION
Good luck man
Reply

Well, I'm stuck again. This time with commands.

How do I make a command that doesn't need a sender?

i.e if i wanted to make a /help command, I get "unknown command" unless i unclude BasePlayer, but that makes it "/help [player]"
Reply

Quote:
Originally Posted by sammp
Посмотреть сообщение
Well, I'm stuck again. This time with commands.

How do I make a command that doesn't need a sender?

i.e if i wanted to make a /help command, I get "unknown command" unless i unclude BasePlayer, but that makes it "/help [player]"
Never used C#, not to mention these plugin. But as far as programming logic goes, you need to return true in your command callback...
Reply

Quote:
Originally Posted by sammp
Посмотреть сообщение
Well, I'm stuck again. This time with commands.

How do I make a command that doesn't need a sender?

i.e if i wanted to make a /help command, I get "unknown command" unless i unclude BasePlayer, but that makes it "/help [player]"
Either:

Код:
[Command("help")]
public static void HelpCommand(BasePlayer sender) {
sender.SendClientMessage("help here");
}
or put

Код:
[Command("help")]
public void HelpCommand() {
SendClientMessage("help here");
}
inside of your custom player class
Reply

Okay, next problem. I have my player class (player.cs), and when I attempt to execute this command, it returns with "unknown command".

Edit: the command works when I put it in Gamemode.cs, but not in Player.cs

player.cs:
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SampSharp.GameMode;
using SampSharp.GameMode.World;
using SampSharp.GameMode.SAMP;
using SampSharp.GameMode.SAMP.Commands;

namespace RoleplayGM
{
    class Player : BasePlayer
    {
        #region Player Commands
        [Command("help")]
        public void HelpCommand()
        {
            SendClientMessage("This is a command called help");
        }

        #endregion
    }
}
Reply

Quote:
Originally Posted by sammp
Посмотреть сообщение
Okay, next problem. I have my player class (player.cs), and when I attempt to execute this command, it returns with "unknown command".

Edit: the command works when I put it in Gamemode.cs, but not in Player.cs
Don't forget to register the Player class to the PlayerController class and the PlayerController class to the BaseMode class, like so:


(I forgot to as well haha)
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)