SA-MP Forums Archive
Using Includes more as Frameworks - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: Using Includes more as Frameworks (/showthread.php?tid=355242)



Using Includes more as Frameworks - Calgon - 29.06.2012

Using Includes (and plugin(s)) more as Frameworks
As primarily a PHP coder, I started off using includes just to include my other work, and splitting the work in to separate files. There are advantages to doing this in Pawn, but personally I prefer just to put everything significant inside my gamemode and use includes for including the SA-MP natives in to my script. I never thought includes were very useful until last year, I thought just the SA-MP natives and a few zcmd includes would be useful and would save me some time.

But recently, it has become clear to me that people really don't use includes as they should be used - many includes have been written by people such as ******, RyDeR`, MP2, Joe Staff and loads of other people - but do you just ignore them because of the compatibility issues with your scripts or just ignore them because you think you can write the code again in a few minutes?

This is a serious problem with scripters in SA-MP, many of us just duck out and become lazy, because we can't be bothered to write our own code anymore. We should be using the resources as they are freely available to us, whether it's a basic command system or a group system.

We should be using includes as frameworks.

The list below is a list of things you should consider using based on what else you're using to create your gamemode - for example, you shouldn't use the SQLite Improved include if you have no intentions of using SQLite.

Here's a short list of includes that are useful and will heavily increase the workload on your script if you use them:
Utilities
Here's a short list of the includes you should use for writing code more efficiently:
fixes.inc
Patching SA-MP bugs you find is not an easy task particularly - you can use this include to patch various SA-MP bugs that have yet to be fixed.

» Read more

Cuff Offsets
MP2 spent a while to get the offsets of the cuff objects for every skin. This is a must-use if you want to use the cuff objects - just for it all to look neat and in place when you apply the object.

» Read more

foreach
foreach replaces some* loops (normally the main player loop) with a faster, more efficient loop.

This is a much neater way to deal with groups of data you need to loop. Not just for player loops, but also for custom arrays using the iterator functions.

» Read more

SQLite Improved
The built-in SQLite is more powerful than most people realize. One issue, however, is that the native functions given are very few and low-level. This library is doing something about that!

While this library mainly has functions that facilitate development, it also brings new functionality and solves crucial bugs.

» Read more

y_ini
In short, y_ini is an include which uses the native SA-MP file functions to provide an easy-to-use set of scripting functions to process INI files. There are plenty of advantages to using this over other released includes, which are outlined in the release thread.

» Read more

y_commands
Personally, I've always preferred using zcmd over y_commands, however y_commands has an advantage - it has support for the other YSI libraries, and more functions available to save you time coding.

This library allows you to create commands efficiently and with ease - you don't have to spend ages using strtok, you can use this in combination with sscanf and save yourself plenty of time.

» Read more

sscanf
There are two (major) versions of sscanf; a version in an include and a version in a plugin. The plugin version has much greater functionality and is a lot more stable - so I'll forward you to that instead of the include.

sscanf allows you to split data from strings in to different variables by a delimiter (it can be anything, as long as it's one character).

The correct pronunciation is apparently es-scan-eff.

» Read more

svAddons
This script adds some useful functions that the SA:MP team decided to not include in the default server package. This include requires your server to be running on 0.3e.

» Read more

svCheats
This script allows you to select all of the cheats you want protection against, change the settings for the cheats, and give certain people a certain security level to bypass anticheat checks.

» Read more

y_timers
This include allows you to quickly and easily define timer functions, that is functions which are to be called after a given time. The library provides two systems: tasks, which are functions that run all the time in the background (for example streamers); and timers, which are functions you can start, stop, and call on a delay at will.

» Read more
Systems
Mainly to annoy the OP, but also a set of libraries to save you from writing a load of code for something you have already in a matter of seconds set out for you. Here's the list:
y_languages and y_text
y_text is the single most complex library in YSI 3.0, but using it is (hopefully) very simple. The library works on the idea from HTML/CSS/JavaScript of separation of content, style and logic.

Whereas, y_languages is intended for scripters to be able to write multilingual modes with the aid of the include.

» Read more

y_groups
What are groups? An admin level is a group of players, a gang is a group of players, a team is a group of players, a faction is group of players - why have different code for each of these things? y_groups is an abstraction of all of these things now supported by most of the YSI libraries to allow you to define exactly who can do what.

» Read more

jBan
jBan is a simple include that will allow server owners to easily have a player banning system using a MySQL database as the storage center for the ban information. It should be compatible with just about every script out there.

» Read more

gCamera
gCamera is an include which allows you to add VERY EASILY speed cameras near highways, it will detect when a player passes it at high speed.

You can set the speed limit in kmh AND mph, and also the limit & fine PER CAMERA! It also includes an pretty awesome flash effect made with textdraws!
» Read more

Player Inventory
It's an easy to use function-adding include to implement inventory for players. It even saves and loads items.

» Read more
Notes:

This is more of a tutorial and a discussion, there are other threads in here too that could just be conceived as tutorials, so here's probably the most relevant place for this type of thread. Also, this.

If you have any suggestions of includes to add, please reply and I'll consider updating this post.


Re: Using Includes more as Frameworks - SuperViper - 29.06.2012

svCheats (Anticheat): https://sampforum.blast.hk/showthread.php?tid=338516

svAddons (Scripting Functions): https://sampforum.blast.hk/showthread.php?tid=348044


Re: Using Includes more as Frameworks - MP2 - 29.06.2012

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Cuff Offsets
MP2 spent a few hours (or days maybe?) nolifing to get the offsets of the cuff objects for every skin. This is a must-use if you want to use the cuff objects - just for it all to look neat and in place.

» Read more
*cough*

It took about half an hour to an hour using a small script to make it fast. Thanks for including it though


Re: Using Includes more as Frameworks - MP2 - 30.06.2012

I think his point is instead of scripting everything from scratch, use libraries as a 'base'.


Re: Using Includes more as Frameworks - Steven82 - 30.06.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
I think his point is instead of scripting everything from scratch, use libraries as a 'base'.
Which then a lot of people think well then their script isn't from scratch and they get all obsessed with everything from scratch. The point of the topic is, libraries are epic and save a SHITLOAD of scripting time.

For example, for my /cuff command I am using your include. Why? Because it's awesome how you got all the correct offsets and it's so much easier for me to use. I don't even have to deal with attaching player objects.

Overall, great topic!


Re: Using Includes more as Frameworks - Calgon - 30.06.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
*cough*

It took about half an hour to an hour using a small script to make it fast. Thanks for including it though
Haha, just kidding. Nice work anyway.

Quote:
Originally Posted by ******
Посмотреть сообщение
I'm a bit confused as to what this topic is trying to be. Is it a tutorial on using includes? Is it an includes directory (of which there already is one in another forum), or what?
More of a tutorial, but I wanted to have more of a discussion side to it so people could discuss ways they could work on new gamemodes using libraries (whether they're mentioned here or not) - so it's probably a bit of both.


Re: Using Includes more as Frameworks - cessil - 01.07.2012

If I were to create a roleplay script I would split a lot of it into sections, my first would be an AC include to hook the default functions like GivePlayerMoney ect.
Then I'd also use includes for features such as Bank, fishing, ect. although I haven't thought it through on what would go into which include.

Here's a rough idea
#include <anticheat>
#include <z_cmd>
#include <colours>
#include <gen_commands>
#include <fishing>
#include <bank>
#include <police>

Or I'd use includes within includes like
#include <commands>
and then inside commands.inc it'd be split up with <police_commands> ect.

I've been using other languages and I really like having several files ~1000 lines over one big file with ~100,000 lines


Re: Using Includes more as Frameworks - Calgon - 01.07.2012

Quote:
Originally Posted by cessil
Посмотреть сообщение
If I were to create a roleplay script I would split a lot of it into sections, my first would be an AC include to hook the default functions like GivePlayerMoney ect.
Then I'd also use includes for features such as Bank, fishing, ect. although I haven't thought it through on what would go into which include.

Here's a rough idea
#include <anticheat>
#include <z_cmd>
#include <colours>
#include <gen_commands>
#include <fishing>
#include <bank>
#include <police>

Or I'd use includes within includes like
#include <commands>
and then inside commands.inc it'd be split up with <police_commands> ect.

I've been using other languages and I really like having several files ~1000 lines over one big file with ~100,000 lines
I know what you mean, but I'm trying to suggest that people use released plugins and includes as libraries to save them time, so they don't have to write as much code.


Re: Using Includes more as Frameworks - ReneG - 01.07.2012

Quote:
Originally Posted by cessil
Посмотреть сообщение
If I were to create a roleplay script I would split a lot of it into sections, my first would be an AC include to hook the default functions like GivePlayerMoney ect.
Then I'd also use includes for features such as Bank, fishing, ect. although I haven't thought it through on what would go into which include.

Here's a rough idea
#include <anticheat>
#include <z_cmd>
#include <colours>
#include <gen_commands>
#include <fishing>
#include <bank>
#include <police>

Or I'd use includes within includes like
#include <commands>
and then inside commands.inc it'd be split up with <police_commands> ect.

I've been using other languages and I really like having several files ~1000 lines over one big file with ~100,000 lines
How long does that take to compile on your system?


Re: Using Includes more as Frameworks - TheChaoz - 01.07.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
How long does that take to compile on your system?
I'm using this method on my SV, and I can ensure you that the difference between this method and "normal" script (all inside the same file) isn't noticeable. Plus it give you many adventages when it's applied on big GM/SV.
For example you have all systems in a very organized way, due this you can find bugs much faster, and you can enable/disable them by removing the include line.
Problems: when you have many systems and they are related each other and the order of the actions of each system affects the other, it's quite annoying, as you can't hook callbacks in a simple way, so you may end calling them in the main script (one after the other), clearly ain't the best way.