Hooking callbacks
#7

Hi,

I shall explain what I have so far, and maybe someone can help me with my error now.

I have an include file called OnPlayerConnect.pwn:
Код:
public OnPlayerConnect(playerid){
	//To create a callback, we use CallLocalFunction. For more explanation about CallLocalFunction, go to wiki.sa-mp.com/wiki/CallLocalFunction
	CallLocalFunction("L_OnPlayerConnect", "i", playerid);
	return 1;
}

#if defined _ALS_OnPlayerConnect //If _ALS_OnPlayerConnect is defined:
  #undef OnPlayerConnect //If defined, it will undefine OnPlayerConnect.
#else //Else if not:
#define _ALS_OnPlayerConnect //If not, we'll define _ALS_OnPlayerConnect.
#endif //As we started a PAWN function '#if', it's necessary to use #endif or you'll get troubled.

//As the callback 'OnPlayerConnect' is undefined now, we can define it to whatever but here we are hooking it. So define it to our callback created, 'L_OnPlayerSConnect'.
#define OnPlayerConnect L_OnPlayerConnect

//Even though we hooked it, we must forward the callback too inorder to get it used.

forward L_OnPlayerSpawn(playerid, weaponid); //We must forward the callback which created itself.
And I also have a user.pwn, which is an include for stuff related to a user. In here I call OnPlayerConnect:
Код:
forward OnPlayerConnect(playerid);
public OnPlayerConnect(playerid){
	//On connect, check if username exists in database
    TogglePlayerSpectating(playerid, true);
    new query[128], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername, sizeof(playername));
    mysql_format(mysql, query, sizeof(query), "SELECT `id`, `username`, `password` FROM `user` WHERE `username` = '%e' LIMIT 1;", playername);
    mysql_tquery(mysql, query, "OnUserCheck", "i", playerid);
	return 1;
}
I have then included both of these files into my main gamemode. If however, I try to use OnPlayerConnect callback in a different include or in my main gamemode, I get the following error:
Код:
error 021: symbol already defined: "L_OnPlayerConnect"
So yeah, clearly Im doing something wrong. Any ideas? DOnt know if any of what I said makes sense to anyone. I wont lie, I'm brand new to hooking
Reply


Messages In This Thread
Hooking callbacks - by Jonesy96 - 01.06.2016, 23:34
Re: Hooking callbacks - by OmegaKiller72 - 01.06.2016, 23:53
Re: Hooking callbacks - by OmegaKiller72 - 01.06.2016, 23:56
Re: Hooking callbacks - by Jonesy96 - 02.06.2016, 00:00
Re: Hooking callbacks - by OmegaKiller72 - 02.06.2016, 00:15
Re: Hooking callbacks - by Abagail - 02.06.2016, 00:16
Re: Hooking callbacks - by Jonesy96 - 02.06.2016, 00:35
Re: Hooking callbacks - by Sew_Sumi - 02.06.2016, 01:59
Re: Hooking callbacks - by iggy1 - 02.06.2016, 02:14
Re: Hooking callbacks - by Jonesy96 - 02.06.2016, 13:35

Forum Jump:


Users browsing this thread: 1 Guest(s)