[Y_Hooks] Hooking custom public function -
Dayrion - 13.07.2017
Hey.
I wondering why I can't hook my own public (& forwarded) function.
PHP код:
PUBLIC:ShowFactionDialog(playerid, dialogid, bool: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(playerid, dialogid, bool:error)
{
print("ShowFactionDialog - 3.0");
switch(dialogid)
{
...
That doesn't work. Only 1.0 is called. Any suggestions or I'm doing it wrong?
Re: [Y_Hooks] Hooking custom public function -
nG Inverse - 13.07.2017
The only way I managed to make this work is by using CallRemoteFunction to call the custom function.
Re: [Y_Hooks] Hooking custom public function -
Meller - 13.07.2017
PHP код:
#include <a_samp>
main() {
CallRemoteFunction("ShowFactionDialog", "iib", 0, 0, false);
}
#include <YSI\y_hooks>
forward public ShowFactionDialog(playerid, dialogid, bool:error);
public ShowFactionDialog(playerid, dialogid, bool:error) {
print("ShowFactionDialog - 1.0");
return Y_HOOKS_CONTINUE_RETURN_1;
}
#include <YSI\y_hooks>
hook ShowFactionDialog(playerid, dialogid, bool: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.
Re: [Y_Hooks] Hooking custom public function -
Dayrion - 13.07.2017
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(playerid, dialogid, bool: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", playerid, dialogid, error);
return Y_HOOKS_CONTINUE_RETURN_1;
}
PHP код:
hook a_ShowFactionDialog(playerid, dialogid, bool:error)
{
print("a_ShowFactionDialog - 3.0");
switch(dialogid)
(Using CallLocalFunction since every other file are included in the main one)
Re: [Y_Hooks] Hooking custom public function -
Paulice - 13.07.2017
Why do you need to hook that function in particular?
Re: [Y_Hooks] Hooking custom public function -
Dayrion - 14.07.2017
Quote:
Originally Posted by Paulice
Why do you need to hook that function in particular?
|
That's not the problematic
Re: [Y_Hooks] Hooking custom public function -
nG Inverse - 14.07.2017
The speed difference is negligible. No need to worry about it.
Re: [Y_Hooks] Hooking custom public function -
Paulice - 14.07.2017
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.
Re: [Y_Hooks] Hooking custom public function -
Dayrion - 14.07.2017
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.
Re: [Y_Hooks] Hooking custom public function -
nG Inverse - 15.07.2017
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.