How to?
#1

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.
Reply
#2

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;
}
Reply
#3

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;
}
Reply
#4

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();
Reply
#5

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)