SA-MP Forums Archive
how many hooks? - 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)
+--- Thread: how many hooks? (/showthread.php?tid=664019)



how many hooks? - PepsiCola23 - 17.02.2019

hey,im using y_hooks.
is there any limit of hooks?i mean can i hook onplayerspawn on 2,5,25 files?and how do i do it more than once? simply
PHP код:
hook onplayerspawn.. 
or is there another method?
also,whats the order the callback s will be called? is it the order the files are included?


Re: how many hooks? - ShadowMortar - 17.02.2019

You can
Hook:1_OnPlayerSpawn(playerid)
{
return 1;
}
//
Hook:2_OnPlayerSpawn(playerid)
{
return 1;
}
...


Re: how many hooks? - PepsiCola23 - 17.02.2019

Quote:
Originally Posted by ******
Посмотреть сообщение
1) 999 per callback. There are some lower compile-time limits, but they can be changed and will tell you how to do so.

2) All hooks are done the same. Just make sure you include y_hooks or y_unique each time.

3)

Pre hooks
Hooks in inclusion order
ALS hooks
Main callback
do i need to include y_hooks only in the main gamemode? or in every included file?


Re: how many hooks? - TheToretto - 17.02.2019

Quote:
Originally Posted by PepsiCola23
Посмотреть сообщение
do i need to include y_hooks only in the main gamemode? or in every included file?
Well if you include it in the very main file, and include your filterscripts/includes after it will be running for every script.


Re: how many hooks? - kristo - 17.02.2019

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
Well if you include it in the very main file, and include your filterscripts/includes after it will be running for every script.
That's not true. The main file rarely needs y_hooks, however each include/module that uses hooks should include either y_hooks or y_unique as the last include (preferrably y_hooks so you don't have to worry about if it has been included earlier or not). The main hooking functionality only gets included the first time, all following inclusions just increase the value of UNIQUE_SYMBOL from y_unique to avoid collisions between hook names.

Also, here's a quick example why it should be included as the last file in each include/module:

pawn Код:
// first.pwn
#include <YSI_Coding\y_hooks>

hook OnGameModeInit() { // compiles as @yH_OnGameModeInit@001
    return 1;
}


// second.pwn
#include <YSI_Coding\y_hooks>
#include "first.pwn"

hook OnGameModeInit() { // also compiles as @yH_OnGameModeInit@001
    return 1;
}
This causes a "symbol already defined" error.


pawn Код:
// first.pwn
#include <YSI_Coding\y_hooks>

hook OnGameModeInit() { // compiles as @yH_OnGameModeInit@000
    return 1;
}


// second.pwn
#include "first.pwn"
#include <YSI_Coding\y_hooks>

hook OnGameModeInit() { // compiles as @yH_OnGameModeInit@001
    return 1;
}
This, however, is fine.


Re: how many hooks? - TheToretto - 17.02.2019

Quote:
Originally Posted by kvann
Посмотреть сообщение
That's not true. The main file rarely needs y_hooks, however each include/module that uses hooks should include either y_hooks or y_unique as the last include (preferrably y_hooks so you don't have to worry about if it has been included earlier or not). The main hooking functionality only gets included the first time, all following inclusions just increase the value of UNIQUE_SYMBOL from y_unique to avoid collisions between hook names.

Also, here's a quick example why it should be included as the last file in each include/module:

pawn Код:
// first.pwn
#include <YSI_Scripting\y_hooks>

hook OnGameModeInit() { // compiles as @yH_OnGameModeInit@001
    return 1;
}


// second.pwn
#include <YSI_Scripting\y_hooks>
#include "first.pwn"

hook OnGameModeInit() { // also compiles as @yH_OnGameModeInit@001
    return 1;
}
This causes a "symbol already defined" error.


pawn Код:
// first.pwn
#include <YSI_Scripting\y_hooks>

hook OnGameModeInit() {
    return 1;
}


// second.pwn
#include "first.pwn"
#include <YSI_Scripting\y_hooks>

hook OnGameModeInit() {
    return 1;
}
This, however, is fine.
pawn Код:
// first.pwn
#include <YSI\y_hooks>

hook OnGameModeInit() {
    return 1;
}


// second.pwn
#include "first.pwn"

hook OnGameModeInit() {
    return 1;
}
OR

pawn Код:
// gamemode.pwn
#include <a_samp>
#include <YSI\y_hooks>

#include "first.pwn"

hook OnGameModeInit() {
    return 1;
}


// first.pwn
#include "first.pwn"

hook OnGameModeInit() {
    return 1;
}

Both expressions, work, no need to include it each time.


Re: how many hooks? - kristo - 17.02.2019



These two lines alone show that you didn't even bother testing your code. If you did, you would've realised that you're wrong.


Re: how many hooks? - TheToretto - 17.02.2019

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


These two lines alone show that you didn't even bother testing your code. If you did, you would've realised that you're wrong.
lol my bad. I didn't mean to include "first.pwn"

Quote:
Originally Posted by ******
Посмотреть сообщение
I understand much better, thanks @kvann too.