[Plugin] SampSharp - Write gamemodes in .NET

Quote:
Originally Posted by xyyy018
Посмотреть сообщение
Any tutorial how to compile this plugin for Linux?
You can add FCNPC to this? I can use EntityFramework? (Migrations, Codefirst etc.)
Thanks for answers!
Anything .NET library that works with mono, works in SampSharp. Just compile your plugin in visual studio and then upload it to your linux serve. One notice, I haven't compiled the plugin on mono, you'll have to do so yourself. Compile instructions are in the readme on github.

Last time I checked, EntityFramework didn't work too well, but I know they've updated it since. I myself use NHibernate. Aside from the fact that I like it better than EF, it's supposedly much faster.
Reply

Great!
How to create Player class based on GtaPlayer?
I try...
http://pastebin.com/N3kCjktM
Quote:

error CS1729: 'SampSharp.GameMode.World.GtaPlayer' does not contain a constructor that takes 0 arguments

Reply

Add a constructor:

Код:
public class Player : GtaPlayer
{
    public Player(int id) : base(id)
    {
    }
}
Don't forget to override the controller, see https://github.com/ikkentim/SampShar...rController.cs and https://github.com/ikkentim/SampShar...meMode.cs#L204
Reply

Hello again. I've created converter to convert my mapping from pawno streamer syntax (I'm using texture studio to create and export mapping) to sampsharp streamer, and got some kind of bug: colors here (at sampsharp server with converted mapping) somehow looks differently or disappear Oo. Am I doing something wrong again?
Example:
input:
Код:
tmpobjid = CreateDynamicObject(19475,1705.361,-682.467,1008.911,0.000,0.000,0.000,-1,-1,-1,300.000,300.000);
SetDynamicObjectMaterialText(tmpobjid, 0, "WC", 140, "Ariel", 200, 1, 0xFFFFFFFF, 0xFF000000, 1);
output:
Код:
tmpobjid = new DynamicObject(19475, new Vector3(1705.361f, -682.467f, 1008.911f), new Vector3(0.000f, 0.000f, 0.000f), -1, -1, null, 300.000f, 300.000f);
tmpobjid.SetMaterialText(0, "WC", ObjectMaterialSize.X512X512, "Ariel", 200, true, Color.FromString("0xFFFFFFFF", ColorFormat.ARGB), Color.FromString("0xFF000000", ColorFormat.ARGB), ObjectMaterialTextAlign.Center);
examples:
1st and 3rd screens - how it should be, 2nd and 4th - how it looks like @ sampsharp server
Reply

Okay. I try use NHibernate

GameMode.cs
Код:
using(ISession session = DbSession.OpenSession())
            {
                session.Save(new PlayerM { Nick = "Test", Password = "Test123" });
                var players = session.Query<PlayerM>();
                foreach(var player in players)
                {
                    Console.WriteLine(player.Nick);
                    Console.WriteLine(player.Password);
                }
            }
DbSession.cs
http://pastebin.com/ifVXPHjK
DbMappings.cs
http://pastebin.com/Sngj3HpR

After run server...
http://pastebin.com/EDKFeDC5

But connection string is ok. I get him from Visual Studio (I have plugin to use MySQL in Server Explorer)
Reply

Quote:
Originally Posted by xyyy018
Посмотреть сообщение
Okay. I try use NHibernate

GameMode.cs
Код:
using(ISession session = DbSession.OpenSession())
            {
                session.Save(new PlayerM { Nick = "Test", Password = "Test123" });
                var players = session.Query<PlayerM>();
                foreach(var player in players)
                {
                    Console.WriteLine(player.Nick);
                    Console.WriteLine(player.Password);
                }
            }
DbSession.cs
http://pastebin.com/ifVXPHjK
DbMappings.cs
http://pastebin.com/Sngj3HpR

After run server...
http://pastebin.com/EDKFeDC5

But connection string is ok. I get him from Visual Studio (I have plugin to use MySQL in Server Explorer)
Why won't you ****** your error before posting it here? It would take way less time than asking here. "Failed to find or load the registered .Net Framework Data Provider 'MySql.Data.MySqlClient'." says it all. Click me
Reply

Quote:
Originally Posted by SomeDevil
Посмотреть сообщение
Hello again. I've created converter to convert my mapping from pawno streamer syntax (I'm using texture studio to create and export mapping) to sampsharp streamer, and got some kind of bug: colors here (at sampsharp server with converted mapping) somehow looks differently or disappear Oo. Am I doing something wrong again?
Example:
input:
Код:
tmpobjid = CreateDynamicObject(19475,1705.361,-682.467,1008.911,0.000,0.000,0.000,-1,-1,-1,300.000,300.000);
SetDynamicObjectMaterialText(tmpobjid, 0, "WC", 140, "Ariel", 200, 1, 0xFFFFFFFF, 0xFF000000, 1);
output:
Код:
tmpobjid = new DynamicObject(19475, new Vector3(1705.361f, -682.467f, 1008.911f), new Vector3(0.000f, 0.000f, 0.000f), -1, -1, null, 300.000f, 300.000f);
tmpobjid.SetMaterialText(0, "WC", ObjectMaterialSize.X512X512, "Ariel", 200, true, Color.FromString("0xFFFFFFFF", ColorFormat.ARGB), Color.FromString("0xFF000000", ColorFormat.ARGB), ObjectMaterialTextAlign.Center);
examples:
1st and 3rd screens - how it should be, 2nd and 4th - how it looks like @ sampsharp server
Hmm.. That's very odd...
I am simply passing the arguments straight trough to the native:
https://github.com/ikkentim/SampShar...Object.cs#L112

Could you maybe try and call StreamerNative.SetDynamicObjectMaterialText manually, to test if that does work as expected? you can get the objectid from `object.Id`
Reply

I'm not sure how to convert to int properly, since (int)0xFF000000 won't work, but this works well:
Код:
StreamerNative.SetDynamicObjectMaterialText(tmpobjid.Id, 0, "WC", ObjectMaterialSize.X512X512, "Arial", 200, true, Convert.ToInt32("0xFFFFFFFF", 16), Convert.ToInt32("0xFF000000", 16), ObjectMaterialTextAlign.Center);
but using same code here makes background color green, not black:
Код:
tmpobjid.SetMaterialText(0, "WC", ObjectMaterialSize.X512X512, "Ariel", 200, true, Color.FromInteger(Convert.ToInt32("0xFFFFFFFF", 16), ColorFormat.ARGB), Color.FromInteger(Convert.ToInt32("0xFF000000", 16), ColorFormat.ARGB), ObjectMaterialTextAlign.Center);
Reply

Quote:
Originally Posted by SomeDevil
Посмотреть сообщение
Why won't you ****** your error before posting it here? It would take way less time than asking here. "Failed to find or load the registered .Net Framework Data Provider 'MySql.Data.MySqlClient'." says it all. Click me
I try this and it no help me
Reply

Quote:
Originally Posted by SomeDevil
Посмотреть сообщение
I'm not sure how to convert to int properly, since (int)0xFF000000 won't work, but this works well:
Код:
StreamerNative.SetDynamicObjectMaterialText(tmpobjid.Id, 0, "WC", ObjectMaterialSize.X512X512, "Arial", 200, true, Convert.ToInt32("0xFFFFFFFF", 16), Convert.ToInt32("0xFF000000", 16), ObjectMaterialTextAlign.Center);
but using same code here makes background color green, not black:
Код:
tmpobjid.SetMaterialText(0, "WC", ObjectMaterialSize.X512X512, "Ariel", 200, true, Color.FromInteger(Convert.ToInt32("0xFFFFFFFF", 16), ColorFormat.ARGB), Color.FromInteger(Convert.ToInt32("0xFF000000", 16), ColorFormat.ARGB), ObjectMaterialTextAlign.Center);
Try `unchecked((int)0xYOURHEXNUMBER)`

Quote:
Originally Posted by xyyy018
Посмотреть сообщение
I try this and it no help me
Are you running linux? http://sampsharp.timpotze.nl/install...a.dll-on-linux
Reply

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
Try `unchecked((int)0xYOURHEXNUMBER)`



Are you running linux? http://sampsharp.timpotze.nl/install...a.dll-on-linux
Yet again working fine with native, but not with sampsharp one
Reply

Quote:
Originally Posted by SomeDevil
Посмотреть сообщение
Yet again working fine with native, but not with sampsharp one
Not with the StreamerNative.x function? hmm then there must be something wrong with the signature of the native i guess. I'll look into it.
Reply

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
Not with the StreamerNative.x function? hmm then there must be something wrong with the signature of the native i guess. I'll look into it.
Oh, I meant it works fine with StreamerNative.x, but not with tmpobj.SetMaterialText
Reply

Quote:
Originally Posted by SomeDevil
Посмотреть сообщение
Oh, I meant it works fine with StreamerNative.x, but not with tmpobj.SetMaterialText
Ah okay! That makes things a little better. I think Color.FromString may not work properly. Could you try Color.FromInteger(0xffffffff) ?
Reply

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
Ah okay! That makes things a little better. I think Color.FromString may not work properly. Could you try Color.FromInteger(0xffffffff) ?
Код:
tmpobjid = new DynamicObject(19475, new Vector3(1705.361f, -682.467f, 1008.911f), new Vector3(0.000f, 0.000f, 0.000f), -1, -1, null, 300.000f, 300.000f);
tmpobjid.SetMaterialText(0, "WC", ObjectMaterialSize.X512X512, "Ariel", 200, true, Color.FromInteger(0xFFFFFFFF, ColorFormat.ARGB), Color.FromInteger(0xFF000000, ColorFormat.ARGB), ObjectMaterialTextAlign.Center);
Creates green background, but should be black Also tried ColorFormat.RGBA - creates blue background and ColorFormat.RGB - transparent background

P.S. text "WC" appears normally (white)
Reply

How create timer for player?
Reply

Quote:
Originally Posted by xyyy018
Посмотреть сообщение
How create timer for player?
Just store a Timer as a field in the player class.
Reply

Okay, you can tell me, why when I get damage my script crash?
Stack
Quote:

25/02/2016 10:47:02] Exception thrownOnPlayerTakeDamage:
System.NullReferenceException: Object reference not set to an instance of an object
at SSS.Player.OnTakeDamage (SampSharp.GameMode.Events.DamageEventArgs e) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.Controllers.GtaPlayerController .<RegisterEvents>b__19 (System.Object sender, SampSharp.GameMode.Events.DamageEventArgs args) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.BaseMode.OnPlayerTakeDamage (SampSharp.GameMode.World.GtaPlayer player, SampSharp.GameMode.Events.DamageEventArgs e) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.BaseMode.OnPlayerTakeDamage (Int32 playerid, Int32 issuerid, Single amount, Int32 weaponid, Int32 bodypart) [0x00000] in <filename unknown>:0

But I check in OnTakeDamage
Код:
 base.OnTakeDamage(e); //here
            if (e.OtherPlayer.Id != InvalidId)
            {
                    
                    Player TakeBy = (Player)e.OtherPlayer;
                    if (TakeBy.Attraction == AttractionTypes.Attraction_WG)
                        TakeBy.wgDamages += e.Amount;
            }
:S
Reply

Quote:
Originally Posted by xyyy018
Посмотреть сообщение
Okay, you can tell me, why when I get damage my script crash?
Stack

But I check in OnTakeDamage
Код:
 base.OnTakeDamage(e); //here
            if (e.OtherPlayer.Id != InvalidId)
            {
                    
                    Player TakeBy = (Player)e.OtherPlayer;
                    if (TakeBy.Attraction == AttractionTypes.Attraction_WG)
                        TakeBy.wgDamages += e.Amount;
            }
:S
If you're running on windows, you can build a symbols file for your game mode in order to get more useful stack traces. http://sampsharp.timpotze.nl/configu...#debug-symbols

Did you Register your player class in your own PlayerController, which you replaced the GtaPlayerController with? See my previous post: http://forum.sa-mp.com/showpost.php?...&postcount=172
Reply

I can compile this plugin for Linux using Cygwin?
Reply


Forum Jump:


Users browsing this thread: 10 Guest(s)