SA-MP Forums Archive
How to? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to? (/showthread.php?tid=314586)



How to? - [BFK]MetalHead - 30.01.2012

Hey guys,
I wanna create a custom callback.Can anyone tell me how can i do it ?
The callback would be IsPlayerSwimming(playerid)
I have the stock for it
pawn Код:
stock IsPlayerInWater(playerid)
{
    new animlib[32],tmp[32];
    GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,tmp,32);
    if(!strcmp(animlib, "SWIM") && !IsPlayerInAnyVehicle(playerid)) return true;
    return false;
}
Thanks.


Re: How to? - CyNiC - 30.01.2012

Put in any place out of brackets:

pawn Код:
forward IsPlayerInWater(playerid);
public IsPlayerInWater(playerid)
{
    new animlib[32],tmp[32];
    GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,tmp,32);
    if(!strcmp(animlib, "SWIM") && !IsPlayerInAnyVehicle(playerid)) return true;
    return false;
}



Re: How to? - [BFK]MetalHead - 30.01.2012

Would this work through an include?I am creating include and i wanna do if a player includes it in his scrip the would be able to use it as a callback like in his GM
pawn Код:
#include <include>
public IsPlayerInWater(playerid)
{
         //code here
         return 1;
}



Re: How to? - CyNiC - 30.01.2012

I understand now, you need to use a timer to check if the players are on water, then, call the function.

Your include should be like this:
pawn Код:
#include <a_samp>

forward WaterChecking();

static max_players;

new bool:AlreadyInWater[MAX_PLAYERS];

public OnGameModeInit()
{  
    max_players = GetMaxPlayers();
    SetTimer("WaterChecking", 1000, true);
    return CallLocalFunction("H_OnGameModeInit","");
}


public WaterChecking()
{
    for(new i = 0; i < max_players; i++)
    {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
             if(PlayerInWater(i))
             {
                 if(!AlreadyInWater[i])
                 {
                     CallLocalFunction("IsPlayerInWater", "d", playerid);
                     AlreadyInWater[i] = true;
                 }                
             }
             else
             {
                 AlreadyInWater[i] = false;                
             }    
        }
    }
    return 1;
}

PlayerInWater(playerid)
{
    new animlib[32],tmp[32];
    GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,tmp,32);
    if(!strcmp(animlib, "SWIM") && !IsPlayerInAnyVehicle(playerid)) return true;
    return false;
}

#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit H_OnGameModeInit
forward H_OnGameModeInit();



Re: How to? - [BFK]MetalHead - 30.01.2012

Thanks.But can you also explain me how this works?I am new to custom callbacks.
Also you are calling the local function IsPlayerInWater while the ummm. whatever is PlayerInWater should i change it?