[Tutorial] How to hook Functions and Callbacks.
#7

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
For hooking functions, you can just do:

pawn Код:
#define <native> <hooked function>
In this case:

pawn Код:
#define SetPlayerScore SetPlayerScoreEx
Funny, I can't find that to be working, though, I haven't tried it out. The pre-processor also agrees with me on this one. Here is a little test I did:

Original code:
pawn Код:
#include <a_samp>

#define SetPlayerScore SetPlayerScoreEx

new playerScore[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    SetPlayerScore(playerid, 1);
    return 1;
}

SetPlayerScoreEx(playerid, value)
{
    playerScore[playerid] = value;
    SetPlayerScore(playerid, value);
    return 1;
}
Pre-processed code:
pawn Код:
#include <a_samp>

#define SetPlayerScore SetPlayerScoreEx

new playerScore[(500)];

public OnPlayerConnect(playerid)
{
    SetPlayerScoreEx(playerid, 1);
    return 1;
}

SetPlayerScoreEx(playerid, value)
{
    playerScore[playerid] = value;
    SetPlayerScoreEx(playerid, value);
    return 1;
}
I mean SetPlayerScore under the SetPlayerScoreEx function was also defined to SetPlayerScoreEx, won't that create a loop without a loop?

Source: http://slice-vps.nl/ppg/

Quote:
Originally Posted by Lordz™
Посмотреть сообщение
pawn Код:
stock SetPlayerScoreEx(playerid, amount) //Two parameters: playerid, for the player and amount, the amount to set.
{ //Opening brackets to execute the functions below.
//We'll choose our made enum above and set it.
   L_PLAYER_INFO[playerid][L_SCORE] = amount; //It sets the server sided score to amount. Amount will be specified on the function by user itself.
   SetPlayerPos(playerid, amount); //We'll later undefine 'SetPlayerPos' function and hook it with our current stock. So it's necessary to use this function too or it doesn't make any sense it saying 'hooking SetPlayerPos.'
   return 1; //Returning the function.
} //Closing brackets.
Mistakes happen, now fix them.
Reply


Messages In This Thread
How to hook Functions and Callbacks. - by Lordzy - 12.11.2012, 17:44
Re: How to hook Functions and Callbacks. - by Emmet_ - 12.11.2012, 17:58
Re: How to hook Functions and Callbacks. - by Lordzy - 12.11.2012, 18:01
Re: How to hook Functions and Callbacks. - by Stylock - 12.11.2012, 19:33
Re: How to hook Functions and Callbacks. - by Lordzy - 13.11.2012, 04:25
Re: How to hook Functions and Callbacks. - by XtremeR - 13.11.2012, 04:57
Re: How to hook Functions and Callbacks. - by Cell_ - 13.11.2012, 11:41
Re: How to hook Functions and Callbacks. - by Y_Less - 13.11.2012, 11:56
Re: How to hook Functions and Callbacks. - by Lordzy - 13.11.2012, 11:56
Re: How to hook Functions and Callbacks. - by Cell_ - 13.11.2012, 12:00
Re: How to hook Functions and Callbacks. - by Lordzy - 13.11.2012, 12:07
Re: How to hook Functions and Callbacks. - by Y_Less - 13.11.2012, 12:54
Re: How to hook Functions and Callbacks. - by dr.lozer - 26.12.2012, 17:10
Re: How to hook Functions and Callbacks. - by Lordzy - 27.12.2012, 03:14
Re: How to hook Functions and Callbacks. - by Windrush - 27.12.2012, 10:03
Re: How to hook Functions and Callbacks. - by Eoussama - 11.11.2017, 19:26

Forum Jump:


Users browsing this thread: 2 Guest(s)