[Tutorial] [How To] Use Common Sence Before Releasing Any Scripts
#1

Welcome to this tutorial.

I 've seen alot of peoples releasing filterscripts/gamemodes without having the required knowledge of the current most used libraries. (For example command processors, file stream systems etc.)
But first of all if you have any script ideas or want to improve your releases, so here you'll be in the right place.

Anyways now before releasing anything, ofc you have to create something. In my opinion copied scripts from well known gamemodes aren't much unique and in some cases they're also very bugged. So I prefer using own ideas and they might be often more unique and also less buggier at all.

Of course before scripting anything you have to open your PAWN script editor. :P
Good! Now you have to decide if you want to write a filterscript or a gamemode. (Or even a NPC script!)
If you decide for a filterscript and you might want to use some special includes (example ZCMD, ncbs, btxt etc.) you NEED to DEFINE

pawn Код:
#define FILTERSCRIPT
on TOP of your script, otherwise you'll have troubles later at loading/reloading and unloading the FS.

Wrong FS start example:

pawn Код:
#include <ncbs>
#include <zcmd>
//...Some code
or
pawn Код:
#include <ncbs>
#include <zcmd>
#define FILTERSCRIPT
//...Some code
Correct example:
pawn Код:
#define FILTERSCRIPT
#include <ncbs>
#include <zcmd>
//...Some code
The question is why I've done this?
First of all I define FILTERSCRIPT on top of the script because if I write a filterscript, I need the proper init callback of the includes (such as OnFilterScriptInit() or OnGameModeInit()!)

From ZCMD:

pawn Код:
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
    zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
    return CallLocalFunction("zcmd_OnFilterScriptInit", "");
}

#if defined _ALS_OnFilterScriptInit
    #undef OnFilterScriptInit
#else
    #define _ALS_OnFilterScriptInit
#endif
#define OnFilterScriptInit zcmd_OnFilterScriptInit
forward zcmd_OnFilterScriptInit();

#else /*not a filterscript*/

public OnGameModeInit()
{
    zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
    zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
    if (funcidx("zcmd_OnGameModeInit") != -1)
    {
        return CallLocalFunction("zcmd_OnGameModeInit", "");
    }  
    return 1;
}

#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit zcmd_OnGameModeInit
forward zcmd_OnGameModeInit();

#endif /*if defined FILTERSCRIPT*/
Peoples who don't know about pre compiler functions, they allow us to do text replacements while compiling.
If we define FILTERSCRIPT on top of these includes, the result would be:

pawn Код:
public OnFilterScriptInit()
{
    zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
    zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
    return CallLocalFunction("zcmd_OnFilterScriptInit", "");
}
forward zcmd_OnFilterScriptInit();
//..other lines
These lines shows above how it could compile our code for us after the text replacement. These functions above does gets called after loading your filterscript, otherwise..
pawn Код:
public OnGameModeInit()
{
    zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
    zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
    if (funcidx("zcmd_OnGameModeInit") != -1)
    {
        return CallLocalFunction("zcmd_OnGameModeInit", "");
    }  
    return 1;
}
//..other lines
these lines above does not have a valid sense and they get called after gamemode start..
So peoples without defining FILTERSCRIPT above their filterscript will just compile the wrong inits of the includes which causes to incompatibility.

For gamemode developer you don't have to use this define in your gamemode script.
I've seen bunch of gamemodes are starting like this:

pawn Код:
#if defined FILTERSCRIPT
//..Some of your codes (example hilarios defines, unused functions, includes etc.)
#else
//..Also some of your codes
#endif
The part where the compiler checks if FILTERSCRIPT is defined will be unused so you can easily delete it also.

Good after bunch time of dev you're probably done with your filterscript/gamemode and now you want to release your work here on this forum. If you want to release a filterscript, you can post your work here:
http://forum.sa-mp.com/forumdisplay.php?f=17
Otherwise if you want to release a gamemode just use this forum: http://forum.sa-mp.com/forumdisplay.php?f=71

After that you press the "New Topic" button and write stuff in your topic.
Please do your a favour and make your topic nice and readable for others to prevent any stupid comments for it.
Example how a stupid topic could be:

Quote:
HAHAHA I made cool FS :P :P :P plis download HERE!
There is nothing explained above and uses a huge font size.
Such posts deserves ofc bad comments below :P
How nicer your topic is, so much rep+ you get


Now you probably ask yourself where you can upload your stuff?
I prefer to upload small scripts in
Pastebin or any another uploader easily foundable in ******.
If you want to show scripts on topic, please use the proper higlighting.
I've seen bunch of script examples highlighted in wrong scripting language. Best way is to use
[pawn]Your code...[/pawn]
for your PAWN scripts.
Asking for reputation or sharing junked links (danger of hacker/virus attacks) will be mostly reported to the forum mods/admins.

I hope I've helped you about the common sense of releasing any scripts.
If you find any grammar mistakes, just PM me or just leave a comment below.
Of course I accept suggestions related to this topic.

Regards: BigETI
Reply
#2

[How To] Use Common Sense before writing your topic title

Hey, just kidding. But it's 'sense' and not 'sense'. But it's nice to tell people this. I don't even know myself how to create hooks.
Reply
#3

#define filterscript isnt really required if you just remove public OnGameMode InIt/Exit

But nice tut, will knock some sense into people xD
Reply
#4

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
[How To] Use Common Sense before writing your topic title

Hey, just kidding. But it's 'sense' and not 'sense'. But it's nice to tell people this. I don't even know myself how to create hooks.
Topic updated!



And thanks.
Reply
#5

Good job Eti, there's no wonder Why You made the first one
Reply
#6

Thank you
Reply
#7

IMO the '#define FILTERSCRIPT' isnt really needed, never had any problems without using that define. Aslong you dont use OnGameModeInit in a filterscript, everything is fine

Nice tutorial
Reply
#8

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
IMO the '#define FILTERSCRIPT' isnt really needed, never had any problems without using that define. Aslong you dont use OnGameModeInit in a filterscript, everything is fine

Nice tutorial
Again IF you use some includes (for example ZCMD or ncbs) for your filterscripts you have to define on top of your script
pawn Код:
#define FILTERSCRIPT
otherwise it's not necessary of course.

Well if you never used this define and just start your gamemode with the filterscripts does not occur any problem but if your FS might to crash or you just unload it and you want to reload it you'll have troubles for the initializer in the includes you use.
If you check ncbs.inc you'll see that I need this definition on top of the script to verify if it's a filterscript or not, because it has to check properly if the another used callbacks exists or not otherwise the filterscripts will run like bullshit.
Reply
#9

I quite like this tutorial, might teach people a thing or two.

One criticism though (not really a criticism, as I guess you didn't know you could do this) :
Use [noparse][/noparse] tags rather than using PHP tags to show how to use PAWN tags. Rather than:
PHP код:
[pawn][/pawn
You could (and should) have:
[pawn][/pawn]

Just replace your PHP tag bit with this:
Код:
[noparse][pawn][/pawn][/noparse]
Reply
#10

Quote:
Originally Posted by funky1234
Посмотреть сообщение
I quite like this tutorial, might teach people a thing or two.
Thanks

Quote:
Originally Posted by funky1234
Посмотреть сообщение
One criticism though (not really a criticism, as I guess you didn't know you could do this) :
Use [noparse][/noparse] tags rather than using PHP tags to show how to use PAWN tags. Rather than:
PHP код:
[pawn][/pawn
You could (and should) have:
[pawn][/pawn]

Just replace your PHP tag bit with this:
Код:
[noparse][pawn][/pawn][/noparse]
Cool I never heard of [noparse][/noparse] tags.
Thanks for it also
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)