[Y_Hooks] Hooking custom public function
#1

Hey.
I wondering why I can't hook my own public (& forwarded) function.
PHP код:
PUBLIC:ShowFactionDialog(playeriddialogidbool:error)
{
    if(!
IsPlayerConnected(playerid))
        return 
f_c_LOG(LOG_ERROR"Error in the script. %i is trying to access at \"ShowFactionDialog\" but it's an invalid ID."playerid);
    print(
"ShowFactionDialog - 1.0");
    return 
Y_HOOKS_CONTINUE_RETURN_1;

later in another file (where y_hooks is included)..
PHP код:
hook ShowFactionDialog(playeriddialogidbool:error)
{
    print(
"ShowFactionDialog - 3.0");
    switch(
dialogid)
    {
... 
That doesn't work. Only 1.0 is called. Any suggestions or I'm doing it wrong?
Reply
#2

The only way I managed to make this work is by using CallRemoteFunction to call the custom function.
Reply
#3

PHP код:
#include <a_samp>
main() {
    
CallRemoteFunction("ShowFactionDialog""iib"00false);
}
#include <YSI\y_hooks>
forward public ShowFactionDialog(playeriddialogidbool:error);
public 
ShowFactionDialog(playeriddialogidbool:error) {
    print(
"ShowFactionDialog - 1.0");
    return 
Y_HOOKS_CONTINUE_RETURN_1;
}
#include <YSI\y_hooks>
hook ShowFactionDialog(playeriddialogidbool:error) {
    print(
"ShowFactionDialog - 3.0");

Код:
 =======================================
 |                                     |
 |        YSI version 4.00.0001        |
 |        By Alex "******" Cole        |
 |                                     |
 =======================================

ShowFactionDialog - 3.0
ShowFactionDialog - 1.0
Number of vehicle models: 0
Seems like you were trying to call ShowFactionDialog as a normal function? I haven't got too much knowledge of y_hooks, but it seems like it wont be hooking up if the callback you're hooking isn't called as a callback, but instead called as a function.


I tried at first using ShowFactionDialog as a function, didn't give anything except 1.0, like yours.
Reply
#4

Quote:
Originally Posted by nG Inverse
Посмотреть сообщение
The only way I managed to make this work is by using CallRemoteFunction to call the custom function.
Ye'p, I thought the same thing and it works. The problem is : "It will be slower than a normal big function ?"
Meller: The function cannot be hooked since nothing call it. So yeah, it won't work with the first (mine) way.
You need to call it by yourself with a custom function:
PHP код:
PUBLIC:ShowFactionDialog(playeriddialogidbool:error)
{
    if(!
IsPlayerConnected(playerid))
        return 
f_c_LOG(LOG_ERROR"Error in the script. %i is trying to access at \"ShowFactionDialog\" but it's an invalid ID."playerid);
    print(
"ShowFactionDialog - 1.0");
    
CallLocalFunction("a_ShowFactionDialog""iii"playeriddialogiderror);
    return 
Y_HOOKS_CONTINUE_RETURN_1;

PHP код:
hook a_ShowFactionDialog(playeriddialogidbool:error)
{
    print(
"a_ShowFactionDialog - 3.0");
    switch(
dialogid
(Using CallLocalFunction since every other file are included in the main one)
Reply
#5

Why do you need to hook that function in particular?
Reply
#6

Quote:
Originally Posted by Paulice
Посмотреть сообщение
Why do you need to hook that function in particular?
That's not the problematic
Reply
#7

The speed difference is negligible. No need to worry about it.
Reply
#8

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
That's not the problematic
It is related, I don't see why ShowFactionDialog should be hooked more than once. Unless you're implementing modular programming in a way you shouldn't.
Reply
#9

Quote:
Originally Posted by Paulice
Посмотреть сообщение
It is related, I don't see why ShowFactionDialog should be hooked more than once. Unless you're implementing modular programming in a way you shouldn't.
I do modular programming.
Quote:
Originally Posted by nG Inverse
Посмотреть сообщение
The speed difference is negligible. No need to worry about it.
Are you sure? If yes, alright thanks for your response.
Reply
#10

Quote:
Originally Posted by Paulice
Посмотреть сообщение
It is related, I don't see why ShowFactionDialog should be hooked more than once. Unless you're implementing modular programming in a way you shouldn't.
I would love to hear how you "properely" utilize modules for your mode.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)