This site has been archived and made available for preservation purposes. No edits can be made.

Results 1 to 3 of 3

Thread: [Tutorial] How to hook callbacks

  1. #1

    [Tutorial] How to hook callbacks

    [size=18pt]How to hook callbacks[/size]
    Using the ALS method into hooking callbacks if you're making a include with a callback.

    • [li][size=14pt]What is this?[/size][/li]

    Well, making a include may seem simple though having callbacks in the include to actually be compiled within the gamemode you're creating may seem frustrating. You'd get errors like, 'Symbol is already define, 'Callback(params)'. This tutorial will help you prevent this cause.

    • [li][size=14pt]The ALS hooking method[/size][/li]

    Code :
    /* codename: myinclude.inc */
    #include <vaultmp> 
     
    public OnPlayerDeath(clientID)
    {
    	timestamp();
    	new name[32]; new str[64];
    	GetPlayerName(clientID, name);
    	strformat(str, sizeof(str), false, "OnPlayerDeath: %s died\n", name);
    	print(str, 1, -1, 1);
    	return 1;
    }

    gamemode:
    Code :
    #include <vaultmp>
    #include <myinclude>
     
    public OnPlayerDeath(clientID)
    {
      return 1;
    }

    Now compiling for this would return a error:
    Code :
    error 021: symbol already defined: "OnPlayerJoin"

    Preventing this all we do is:

    Code :
    /* codename: myinclude.inc */
    #include <vaultmp> 
     
    //Calling the callback again.
    public OnPlayerJoin(clientID)
    {
    	timestamp();
    	new name[32]; new str[64];
    	GetPlayerName(clientID, name);
    	strformat(str, sizeof(str), false, "OnPlayerDeath: %s died\n", name);
    	print(str, 1, -1, 1);
        //Return your callback
    	return myhook_OnPlayerJoin(clientID);
    }
     
    //if the ALS hook method is already defined:
    #if defined _ALS_OnPlayerJoin
        // Undefine the callback
    	#undef OnPlayerJoin
    #else
        //redefine the callback.
    	#define _ALS_OnPlayerJoin
    #endif
     
    //defining OnPlayerJoin with your 'onplayerjoin' that was returned.
    #define OnPlayerJoin myhook_OnPlayerJoin
    //forwarding it so we don't get any warnings referring to the code.
    forward myhook_OnPlayerJoin(playerid);

    Yeah, that's how its done. Compile and there should be no problem. Most things shall work correctly.

    Tutorials still in development. Sorry for mistakes.
    A gaming community ran by one person, with servers made by individuals (in this case, me, myself)
    I plan to look for a trusted person who will help me create a decent roleplay/deathmatch server on Vault-TEC,
    PM me if you're interested

  2. #2
    Nice one Lorenc! Time to bring all the Pawn knowledge from SA:MP and put it to use here

  3. #3
    First tutorial I've read on this forum, it's pretty good man. First time I've seen scripting in Vault MP and as I can see it is in pawn and everything just seems so similar to SA-MP which is really good as I have experience in scripting with SA-MP so hopefully I'll be able to make a few decent scripts for VMP

Similar Threads

  1. Tutorial
    By Flyingcoyote in forum Discussion
    Replies: 1
    Last Post: 08-14-2011, 03:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •