how many hooks?
#1

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?
Reply
#2

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

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?
Reply
#4

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.
Reply
#5

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.
Reply
#6

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.
Reply
#7



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.
Reply
#8

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"

I understand much better, thanks @kvann too.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)