[Plugin] SampSharp - Write gamemodes in .NET

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
I wasn't successful either. NHibernate is supposedly much faster so I've been using that. I'll look in the near future into why EF doesn't seem to be compatible. It's most likely related to the mono version used.
Thanks for the quick response! I'll look into NHiberate, thank you!! Also, can you explain to me when I should be creating custom controllers? I've been putting all my functions/commands in classes, but should I be using controllers for this instead? I'm just a bit confused, thanks for your help!
Reply

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
It's not a very interesting class... But here it is.
https://gist.github.com/ikkentim/438...0cf34c2e2805a1
Hm okay, so then how do you access the PlayerInfo variables in your class that extends from GTAPlayer? Do you just have a PlayerInfo class in it or inherit from it? Sorry I'm a bit confused, I've only used Entity Framework before and I'd love to have the "proper etiquette" while coding my gamemode. Thanks for your help, I really appreciate it.
Reply

Quote:
Originally Posted by unSatisfied
Посмотреть сообщение
Hm okay, so then how do you access the PlayerInfo variables in your class that extends from GTAPlayer? Do you just have a PlayerInfo class in it or inherit from it? Sorry I'm a bit confused, I've only used Entity Framework before and I'd love to have the "proper etiquette" while coding my gamemode. Thanks for your help, I really appreciate it.
You simply store it as a property in the player class. You can set this value when the player logs in or out.

You wouldn't have been able to do this with entity framework either, because the instance (GtaPlayer) is already created when you connect, so you'd have to populate this instance with data loaded from the database, which isn't possible in entity framework.
Reply

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
You simply store it as a property in the player class. You can set this value when the player logs in or out.

You wouldn't have been able to do this with entity framework either, because the instance (GtaPlayer) is already created when you connect, so you'd have to populate this instance with data loaded from the database, which isn't possible in entity framework.
Thanks! Sorry for so many questions, but is there also anyway to set a ListDialog's Id? In the OnResponse event, there's an Id property but there isn't in the ListDialog class.
Reply

Quote:
Originally Posted by unSatisfied
Посмотреть сообщение
Thanks! Sorry for so many questions, but is there also anyway to set a ListDialog's Id? In the OnResponse event, there's an Id property but there isn't in the ListDialog class.
It always uses the same id. You should listen to the dialog.Response event: http://api.sampsharp.timpotze.nl/htm...84a214d9b6.htm

notice: the api.sampsharp.timpotze.nl documentation may be a bit out of date... Will be updated with v0.7

notice2: the dialog class will slightly change in v0.7. But it should be fine for now

notice3: If you have a github account, check out the gitter chat group at http://gitter.im/ikkentim/sampsharp
Reply

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
It always uses the same id. You should listen to the dialog.Response event: http://api.sampsharp.timpotze.nl/htm...84a214d9b6.htm

notice: the api.sampsharp.timpotze.nl documentation may be a bit out of date... Will be updated with v0.7

notice2: the dialog class will slightly change in v0.7. But it should be fine for now

notice3: If you have a github account, check out the gitter chat group at http://gitter.im/ikkentim/sampsharp
I will definitely check out the github chat, thanks
Reply

Is there way to make parametr name? I want change info if is not valid param form Usage /command [variable_name] to Usage /command [parametr_name].
Reply

Quote:
Originally Posted by Reek
Посмотреть сообщение
Is there way to make parametr name? I want change info if is not valid param form Usage /command [variable_name] to Usage /command [parametr_name].
For v0.6 (currently on NuGet): http://sampsharp.timpotze.nl/command...#usage-message
For v0.7 (currently on master branch): http://sampsharp.timpotze.nl/player-...#usage-message
Reply

Okay, thanks. Now I have another question. Can you explain me how controllers works? Or give me link to reading.
Reply

http://sampsharp.timpotze.nl/controllers note that this is for v0.7 (I don't know which version you are using)

So controllers are mainly for listening to events so you can distribute them over a set of objects interested in these events. You can also register pooled types in the controllers (pooled types are types which have IDs such as players and vehicles).

A v0.6 example of registering overridden pooled types: https://github.com/ikkentim/SampShar...t.cs#L154-L187

A v0.7 example of registering overridden pooled types:

PHP код:
[PooledType]
public class 
Player BasePlayer
{
// .....

If you don't need to do one of these things you don't *need* to use controllers, but you can use them for other purposes you like.
Reply

Followed this guide exactly:
http://sampsharp.timpotze.nl/starting-development

Still getting this:
Quote:

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[12:22:13]
[12:22:13] Server Plugins
[12:22:13] --------------
[12:22:13] Loading plugin: SampSharp.dll
[12:22:13]
[12:22:13] SampSharp Plugin
[12:22:13] ----------------
[12:22:13] v0.7.0, ©2014-2016 Tim Potze
[12:22:13]
[12:22:13] Loaded.
[12:22:13] Loaded 1 plugins.

[12:22:13]
[12:22:13] Filterscripts
[12:22:13] ---------------
[12:22:13] Loading filterscript 'empty.amx'...
[12:22:13] Loaded 1 filterscripts.

[12:22:13] Filterscript 'empty.amx' load failed.
[12:22:13] Gamemode
[12:22:13] ---------------
[12:22:13] Loading gamemode: YourGamemode:GameMode
[12:22:13] Loading image...
[12:22:13] Creating gamemode instance...
[12:22:13] Loaded.
[12:22:13]
[12:22:13] Number of vehicle models: 0
Quote:

[01/10/2016 12:22:13] Exception thrownOnGameModeInit:
System.MissingMethodException: Attempted to access a missing method.
at (wrapper managed-to-native) SampSharp.GameMode.Natives.Native:Print (string)
at SampSharp.GameMode.LogWriter.Write (System.String value) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.LogWriter.WriteLine (System.String value) [0x00000] in <filename unknown>:0
at System.Console.WriteLine (System.String value) [0x00000] in C:\buildroot\release\repos\mono\mcs\class\corlib\S ystem\Console.cs:452
at YourGamemode.GameMode.OnInitialized (System.EventArgs e) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.BaseMode.OnGameModeInit () [0x00000] in <filename unknown>:0
[01/10/2016 12:22:13] Exception thrownOnTick:
System.MissingMethodException: Attempted to access a missing method.
at (wrapper managed-to-native) SampSharp.GameMode.Natives.Native:Print (string)
at SampSharp.GameMode.LogWriter.Write (System.String value) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.LogWriter+<>c__DisplayClass2.<W rite>b__0 () [0x00000] in <filename unknown>:0
at SampSharp.GameMode.Tools.Sync+SyncTask.Run () [0x00000] in <filename unknown>:0
at SampSharp.GameMode.Controllers.SyncController._gam eMode_Tick (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.BaseMode.OnTick (System.EventArgs e) [0x00000] in <filename unknown>:0
at SampSharp.GameMode.BaseMode.OnTick () [0x00000] in <filename unknown>:0

http://prntscr.com/conc7h
http://prntscr.com/condvp
http://prntscr.com/condnv
Reply

If you use the 0.7.0 version of the plugin (which you are) you must make sure you use the latest _prerelease_ version of the framework. When you add the NuGet package to your project, make sure the "include prereleases" checkbox is checked.

Edit: yea, I need to update the documentation (:
Reply

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
If you use the 0.7.0 version of the plugin (which you are) you must make sure you use the latest _prerelease_ version of the framework. When you add the NuGet package to your project, make sure the "include prereleases" checkbox is checked.

Edit: yea, I need to update the documentation (:
Works now thank you.

Edit:
This doesn't bug me because I can just Alt-F4 but it freezes here: (crashes when you ctrl-c the server)
http://prntscr.com/coo3my
Reply

Glad to hear it's working. I've had a few reports about the crash when shutting the server down and I'll be looking into it
Reply

#C script would benefit from this pretty well. Dunno why this is still a valid plugin, 2014 it first came out hahahha!
Reply

This plugin is still being maintained, improved and used, so it has at least outlived the other .net and php plugins.
Reply

It's scaleable/asynchronous: assuming you write your code right (ie. with good use of tasks), your server can be as feature rich at 1000 players as it could be at 1.

This is a huge, huge, huge, huge, HUGE improvement over Pawn. Because of this lack of scaleability there are whole schools of thought around optimization lead by some of the most recognizable developers on these forums. Also - proper containers (lists, dictionaries, sets, etc) with dynamic memory allocation/management.

I'd be interested to hear how it performs directly against Pawn too - given the way that Tim has implemented it I have a sneaking suspicion that it'd perform better than Pawn even without threading. Though this is pure speculation on my part.



It's .NET: there are at least tens of thousands of methods/functions - and that's a conservative estimate on my part. The only stat I could find is for types (most of which will be classes) - 40,000. Alongside Java it has to be one of the most popular languages in the world, which means it's very robust, and it has a very active, contributing community.

One of the many cool things I have done in SAMP# is to host my web UCP directly from the gamemode where all calls are made directly to the game with no sort of messaging interface - if I wanted to have a button on the UCP that sets someone's health to 100, all I had to do was player.Health = 100 and it would reflect immediately ingame.

Entity Framework (which Tim fixed last night) has the capacity to analyse an entire database and develop a OOP implementation of that object model, meaning no direct database code. It's what all ORMs (including the ones written for SA-MP) want to be when they grow up.



It's easy to work with: Development lifecycle is a fraction of what it was using Pawn - simply being about to to list.Add(bla) rather than fucking about with arrays saves a ton of time. It's modular + OOP - meaning your code can be split into individual 100 line files that implement a specific feature, rather than having a 150,000 line behemoth. Visual Studio (the IDE that people most commonly write C# in) is personally my favourite IDE on the planet and I think most other IDEs are pale imitations of what VS has achieved.


Pawn is a dinosaur: like let's look at the crux of this; for what it was designed to do, Pawn is a fantastic.

But it was written in the 00's to control MP3 players and things that are alike. That's why it doesn't have things like asynchronicity or dynamic memory management: it had a set of simple tasks to achieve.

The only other thing that I can think of that uses Pawn is AMXX on GoldSource (Half Life 1/CS 1.6) and I strongly suspect AMXX's implementation was what influenced the SA-MP development team to implement it here. But even AMXX/AlliedModders have acknowledged that Pawn struggles to rise to the challenge - now demonstrated by the fact that they basically overhauled it for SourceMod.




Now I owe an awful lot to Pawn: it is the first language I learnt (for AMXX on The Specialists) when I was 11, and therefore I owe my entire career to that small but versatile little programming language. But try as I might (like many others) to improve Pawn to implement things like OOP, it was not built for it and all you do is introduce instability in return for a nearly-but-not-quite-there syntactical sugar. I ask you all this: can you think of any other modern multiplayer project that uses Pawn?

I only have one concern around this - and that would be is if Tim were to fall off the radar and the plugin fell into disrepair - but a) that hasn't happened and b) the project is open-source and if it came to it I would maintain it.
Reply

Quote:
Originally Posted by Alcatrik
Посмотреть сообщение
...

I only have one concern around this - and that would be is if Tim were to fall off the radar and the plugin fell into disrepair - but a) that hasn't happened and b) the project is open-source and if it came to it I would maintain it.
Well said.

The last part:
I forked the source and I have extensive knowledge around C and C++, so if he falls off the radar, I will try to continue it, but that's the thing, you can save your own copy of the source and continue it. You can also just customize it to your liking and release it as your own.

I'm also using Lua (NuGet package: NLua).
Reply

I'm likely not to fall off the radar within the foreseeable future I've spend loads of time on the library and it would be such a waste to let it decay. I'm having a lot of fun maintaining it and the thought people (love to) use it only makes it more enjoyable. The only thing I see happening is that I tune down the amount of time I work on it every now and then if something else requires more attention. I've done this in the recent past during the final phase of my BSc in software engineering.

Reply

Hello, is it possible to export a SampSharp project as a filterscript/plugin?

EDIT:

Also, why can't it find the GtaPlayer class?
This code won't compile:
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SampSharp.GameMode.World;

namespace Sasinosoft.Roleplay
{
    class Player : GtaPlayer
    {
        
    }
}
EDIT 2:
Solved
The class was "BasePlayer" not "GtaPlayer"...
Please can you update the API documentation and the tutorials, because some other newbies like me could get the same problems...
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)