CONTENTS OF THREAD:
- [Only registered and activated users can see links. Click Here To Register...]
saving/loading/updating databases using SQL
- [Only registered and activated users can see links. Click Here To Register...]
- [Only registered and activated users can see links. Click Here To Register...]
(By Yashi)
- [Only registered and activated users can see links. Click Here To Register...]
(By Grasshoppa)
- [Only registered and activated users can see links. Click Here To Register...]
- [Only registered and activated users can see links. Click Here To Register...]
- [Only registered and activated users can see links. Click Here To Register...]
So I figured I'd post some basic guides and tutorials for coding. These are NOT source dependent. You will simply need to understand how to modify the codes.
Nothing in here is a working feature, when I use things like Pk events as an example I have NOT posted full working codes to add a pk event to your server. I'm giving you examples of how to program parts of these events yourself.
These are all intended as basic conceptual help for coding. If I made a mistake in my explanations, please let me know (flame if you want, I'm far from sensitive lol). I am by no means an expert coder and especially not so at C#. I am working with the 1.0 source simply because it's what has been interesting me lately, feel free to apply these theories to sources you use though.
That being said, enjoy.
If you have any requests for advice (again, NOT FULL CODES) let me know
If I got something wrong, please let me know and I'll fix it (and give credit obviously)
Note: this thread will be updated in time. These are just some basic things I had time to write up right now.
--------------------------------------------------
How to do something to/retrieve all online players [CoFuture: 4267 source]
Finding online players can be useful for all sorts of things, random events, pk wars, finding number of players online and countless other things. Here is a brief explanation of how to go about it.
*Note* These structures will work for all sorts of sources, you just need to know how to modify it.
Start.Clients can be used in a number of ways such as to find out how many players are online (Start.Clients.Count). Perhaps the most useful way to apply this though is to use of "foreach".
foreach means exactly what it says. The loop occurs once for each item in the structure (in this case a Dictionary named Clients)
The way to use this to execute code once for each player connected to the server is as follows
In this example if you want the code inside the loop to effect only the character, you are going to want to do Player.Value.Char.*Extension*
The possible extensions are ANYTHING under Character.cs (Name, Level, Reborn, GuildID etcetcetc)
here is an example of how the foreach loop can be used
Hopefully that will help you understand how to do that a little bit better. To do it in other sources should function exactly the same! You will just need to modify the variable names.
--------------------------------------------------
Intro to hashtables:
(Just starting to learn these myself so bear with me)
Hashtables can be thought of a bit like an in-source database. They are data structures that are intended to map keys (player name for example) to certain values (player score in an event)
To make a new hashtable all you have to do [CoFuture: 4267 source, should be identical in others though] is place something like this in the Start.cs file (will differ with other sources)
This creates the initial Hashtable known as PkWarScore.
To enter an initial value for a character into this hashtable, you simply need to use something like this:
Start.PkWarScore.Add(Client.Char.Name, #); (where # is the score to set that char name to)
If you are updating a value for a character in a hashtable (already exists in the structure) you want to use something like this:
Start.PkWarScore[Client.Char.Name] = (int)Start.PkWarScore[Client.Char.Name] + 1;
This is saying that Where Char.Name exists in PkWarScore, add 1 to their score (number modifiable obviously)
To find out if the player is already in the hashtable or not you simply want to use some if statements to control logic flow.
To reiterate: When using hashtables you have multiple ways to modify things.
Add (adds a new item to a hashtable)
Clear (clears/wipes entire hashtable)
Contains (checks if hashtable contains something)
Remove (Removes/clears a specific entry to a hashtable)
PkWarScore[Client.Char.Name] (updates an existing entry for lack of a better explanation. Just look at the code. It will help you more.)
So for example to clear an entire hashtable (event is over for example) just do
Start.PkWarScore.Clear
If there are any further questions on the basics behind hashtables please let me know, bearing in mind that I am just picking up some of this stuff myself still.
--------------------------------------------------
Credits:
Pro4Never (me)
Will add names as people help correct shit.
Again: hope this helps some people, if you have requests or questions just lemme know. I plan to add more stuff in time.
- [Only registered and activated users can see links. Click Here To Register...]
saving/loading/updating databases using SQL
- [Only registered and activated users can see links. Click Here To Register...]
- [Only registered and activated users can see links. Click Here To Register...]
(By Yashi)
- [Only registered and activated users can see links. Click Here To Register...]
(By Grasshoppa)
- [Only registered and activated users can see links. Click Here To Register...]
- [Only registered and activated users can see links. Click Here To Register...]
- [Only registered and activated users can see links. Click Here To Register...]
So I figured I'd post some basic guides and tutorials for coding. These are NOT source dependent. You will simply need to understand how to modify the codes.
Nothing in here is a working feature, when I use things like Pk events as an example I have NOT posted full working codes to add a pk event to your server. I'm giving you examples of how to program parts of these events yourself.
These are all intended as basic conceptual help for coding. If I made a mistake in my explanations, please let me know (flame if you want, I'm far from sensitive lol). I am by no means an expert coder and especially not so at C#. I am working with the 1.0 source simply because it's what has been interesting me lately, feel free to apply these theories to sources you use though.
That being said, enjoy.
If you have any requests for advice (again, NOT FULL CODES) let me know
If I got something wrong, please let me know and I'll fix it (and give credit obviously)
Note: this thread will be updated in time. These are just some basic things I had time to write up right now.
--------------------------------------------------
How to do something to/retrieve all online players [CoFuture: 4267 source]
Finding online players can be useful for all sorts of things, random events, pk wars, finding number of players online and countless other things. Here is a brief explanation of how to go about it.
*Note* These structures will work for all sorts of sources, you just need to know how to modify it.
Code:
Start.Clients
foreach means exactly what it says. The loop occurs once for each item in the structure (in this case a Dictionary named Clients)
The way to use this to execute code once for each player connected to the server is as follows
In this example if you want the code inside the loop to effect only the character, you are going to want to do Player.Value.Char.*Extension*
The possible extensions are ANYTHING under Character.cs (Name, Level, Reborn, GuildID etcetcetc)
here is an example of how the foreach loop can be used
Hopefully that will help you understand how to do that a little bit better. To do it in other sources should function exactly the same! You will just need to modify the variable names.
--------------------------------------------------
Intro to hashtables:
(Just starting to learn these myself so bear with me)
Hashtables can be thought of a bit like an in-source database. They are data structures that are intended to map keys (player name for example) to certain values (player score in an event)
To make a new hashtable all you have to do [CoFuture: 4267 source, should be identical in others though] is place something like this in the Start.cs file (will differ with other sources)
This creates the initial Hashtable known as PkWarScore.
To enter an initial value for a character into this hashtable, you simply need to use something like this:
Start.PkWarScore.Add(Client.Char.Name, #); (where # is the score to set that char name to)
If you are updating a value for a character in a hashtable (already exists in the structure) you want to use something like this:
Start.PkWarScore[Client.Char.Name] = (int)Start.PkWarScore[Client.Char.Name] + 1;
This is saying that Where Char.Name exists in PkWarScore, add 1 to their score (number modifiable obviously)
To find out if the player is already in the hashtable or not you simply want to use some if statements to control logic flow.
To reiterate: When using hashtables you have multiple ways to modify things.
Add (adds a new item to a hashtable)
Clear (clears/wipes entire hashtable)
Contains (checks if hashtable contains something)
Remove (Removes/clears a specific entry to a hashtable)
PkWarScore[Client.Char.Name] (updates an existing entry for lack of a better explanation. Just look at the code. It will help you more.)
So for example to clear an entire hashtable (event is over for example) just do
Start.PkWarScore.Clear
If there are any further questions on the basics behind hashtables please let me know, bearing in mind that I am just picking up some of this stuff myself still.
--------------------------------------------------
Credits:
Pro4Never (me)
Will add names as people help correct shit.
Again: hope this helps some people, if you have requests or questions just lemme know. I plan to add more stuff in time.