Writing a gamemode from scratch can be a long and tedious process (I should know, as I've started writing one in 2008, and lost all my progress because of a hd format... VCS is really important!). That's why you should rely on proven solutions. Welcome to the world of YSI.
What is YSI?
It's a collection of open source libraries written by Y_Less. You don't have to know anything about how they work internally, they Just Work ™. Most popular library is y_iterate, formerly known as foreach. YSI alone contains 44 libraries, ranging from colour definition helpers, to complete player account system. You don't have to use all libraries, however whole YSI package is required as some of them are interdependent.
Motivation
Y_Less usually releases a topic describing what the specific library does with simple example and is eager to help in sa-mp scripting help subforum (I spend a lot of time there too). However the knowledge is scrambled, questions are repeated over and over again, people request real-life examples, and the wiki is not yet complete. If you know your way around YSI, feel free to contribute there, there's even a bug bounty for your input! I don't like contributing to wikis, as the tone and guidelines are too strict (also that my english is quite below the required level for editorial writing), so that's why I'll just use my blog. We're going to use YSI 4, not the YSI 3.1 - that's very important distinction as a lot of thing changed, including file structure.
Installation
I'm going to assume your setup is similar to mine from previous pawn post. That's the current project layout
You might see that my sublime doesn't display binary files, and that's ok. Anyhow, time to fetch the YSI. There is one issue though
See this folder with @ and revision hash next to it? This is a submodule. If you wanted to download the repository the standard way, the contents of that thingy won't be downloaded. So: fire up your git bash, and navigate to our Resources
folder. Now run
git clone -b YSI.tl --single-branch --depth=1 --recursive https://github.com/Y-Less/YSI-Includes.git
(you can paste into git bash using insert
button). Wait a while for files to download, and voila, latest YSI with its dependencies has been downloaded. Long story short: this command clones YSI-Includes repository, specifically a single branch - YSI.tl, and recurses through all dependencies downloading them. In the future to update to latest YSI just write git pull
and it should work. Copy everything except files and folders starting with .git to your Platform
and your new project. In your project folder type git status
- if under untracked files you see pawno folder, double check that you've removed all .git* files from copied YSI.
All done!
Let's just test everything is hooked up properly and we can move on. Open up your main gamemode file, and write
#include <a_samp>
#include <YSI\y_va>
main() {
va_print("Hello world! %d %d %d", 1, 2, 3);
}
Then compile (Tools -> Build
, f5
, or ctrl+shift+p
and search build
). The result should look like this
If for some reason the compilation doesn't seem to run at all, remove hard links of pawn compiler and replace them with standard copied files. No idea why this happens.
In next post I'll recommend some standard plugins, and we'll dig in into first YSI library, y_iterate.