[Include] Limex's Swimming Include (Detect swimming!)
#32

Hey Limex,
I have optimized the code a bit for you.

Here is the code:
pawn Код:
/* =============================

Limex's Swimming Include

Made by Limex / A

New function:
IsPlayerSwimming(playerid)

New callbacks:
OnPlayerStartSwimming(playerid)
OnPlayerStopSwimming(playerid)

Enjoy!

edit By Gamer_Z | ****** did mention code optimizing tips too and I used them here.
note:
OnPlayerUpdate Code should be as fast and efficient as possible!

============================= */


#include <a_samp>

#define ANIM_SWIM1 1544 //wasn't so hard to get! , just debug
#define ANIM_SWIM2 1540
#define ANIM_SWIM3 1541
#define ANIM_SWIM4 1538
#define ANIM_SWIM5 1539
#define ANIM_JUMP1 1197//this too!
#define ANIM_JUMP2 1195
#define ANIM_JUMP3 1198
#define ANIM_JUMP4 1064
#define ANIM_JUMP5 1062
#define ANIM_JUMP6 1542

#if !defined SWIM_NO_CALLBACKS
    #define SWIM_USE_CALLBACKS
#endif

#if defined SWIM_USE_CALLBACKS

new swimming[MAX_PLAYERS] = {0,...};//sorry I don't know if bool or normal variables are faster so I used them to enchance the performance of IsPlayerSwiming
stock IsPlayerSwimming(playerid)
{
    return swimming[playerid];
}

forward OnPlayerStartSwimming(playerid);
forward OnPlayerStopSwimming(playerid);

public OnPlayerUpdate(playerid)
{
    if(swimming[playerid] == 0)
    {
        switch(GetPlayerAnimationIndex(playerid))
        {
            case ANIM_SWIM1,ANIM_SWIM2,ANIM_SWIM3,ANIM_SWIM4,ANIM_SWIM5:
            {
                swimming[playerid] = 1;
                OnPlayerStartSwimming(playerid);
            }
        }
    }
    else
    {
        switch(GetPlayerAnimationIndex(playerid))
        {
            case ANIM_JUMP1,ANIM_JUMP2,ANIM_JUMP3,ANIM_JUMP4,ANIM_JUMP5,ANIM_JUMP6,ANIM_SWIM1,ANIM_SWIM2,ANIM_SWIM3,ANIM_SWIM4,ANIM_SWIM5:
            {
           
            }
            default:
            {
                swimming[playerid] = 0;
                OnPlayerStopSwimming(playerid);
            }
        }
    }
    return 1;
}

//OnPlayerStartSwimming(playerid)SendClientMessage(playerid,0xFFFFFFFF,"You Started swimming");
//OnPlayerStopSwimming(playerid)SendClientMessage(playerid,0xFFFFFFFF,"You Stoped swimming");

#else
stock IsPlayerSwimming(playerid)
{
    switch(GetPlayerAnimationIndex(playerid))
    {
        case ANIM_SWIM1,ANIM_SWIM2,ANIM_SWIM3,ANIM_SWIM4,ANIM_SWIM5:
        {
            return 1;
        }
        case ANIM_JUMP1,ANIM_JUMP2,ANIM_JUMP3,ANIM_JUMP4,ANIM_JUMP5,ANIM_JUMP6:
        {
            return -1;//or 2?
        }
        default:
            return 0;
    }
}
#endif
Have fun
Reply


Messages In This Thread
Limex's Swimming Include (Detect swimming!) - by Limex - 04.09.2010, 04:39
Re: Limex's Swimming Include (Detect swimming!) - by willsuckformoney - 04.09.2010, 05:22
Re: Limex's Swimming Include (Detect swimming!) - by WillyP - 04.09.2010, 11:12
Re: Limex's Swimming Include (Detect swimming!) - by Grim_ - 04.09.2010, 11:52
Re: Limex's Swimming Include (Detect swimming!) - by DiddyBop - 04.09.2010, 13:28
Re: Limex's Swimming Include (Detect swimming!) - by General Abe - 04.09.2010, 14:02
Re: Limex's Swimming Include (Detect swimming!) - by CYB3RN - 04.09.2010, 14:07
Re: Limex's Swimming Include (Detect swimming!) - by Mauzen - 04.09.2010, 14:11
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 05.09.2010, 21:57
Re: Limex's Swimming Include (Detect swimming!) - by Hijolion - 06.09.2010, 21:54
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 06.09.2010, 23:36
Re: Limex's Swimming Include (Detect swimming!) - by MrDeath537 - 07.09.2010, 01:03
Re: Limex's Swimming Include (Detect swimming!) - by willsuckformoney - 07.09.2010, 01:15
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 12.09.2010, 02:37
Re: Limex's Swimming Include (Detect swimming!) - by willsuckformoney - 12.09.2010, 02:56
Re: Limex's Swimming Include (Detect swimming!) - by wups - 12.09.2010, 07:56
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 12.11.2010, 21:26
Re: Limex's Swimming Include (Detect swimming!) - by Grim_ - 12.11.2010, 21:29
Re: Limex's Swimming Include (Detect swimming!) - by Hiddos - 12.11.2010, 21:30
Re: Limex's Swimming Include (Detect swimming!) - by dark_clown - 12.11.2010, 21:38
Re: Limex's Swimming Include (Detect swimming!) - by Gigi-The-Beast - 13.11.2010, 11:11
Re: Limex's Swimming Include (Detect swimming!) - by Grim_ - 13.11.2010, 17:48
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 12.12.2010, 22:00
Re: Limex's Swimming Include (Detect swimming!) - by Mean - 24.12.2010, 14:37
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 27.12.2010, 00:24
Re: Limex's Swimming Include (Detect swimming!) - by Bodo4you - 27.12.2010, 08:16
Re: Limex's Swimming Include (Detect swimming!) - by Lorenc_ - 27.12.2010, 08:38
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 28.12.2010, 07:03
Re: Limex's Swimming Include (Detect swimming!) - by TheKingWillem - 28.12.2010, 14:09
Re: Limex's Swimming Include (Detect swimming!) - by wups - 28.12.2010, 14:38
Re: Limex's Swimming Include (Detect swimming!) - by Limex - 13.01.2011, 20:36
Re: Limex's Swimming Include (Detect swimming!) - by Gamer_Z - 07.06.2011, 01:21
Re: Limex's Swimming Include (Detect swimming!) - by Deskoft - 07.06.2011, 01:32
Re: Limex's Swimming Include (Detect swimming!) - by Gamer_Z - 07.06.2011, 01:40
Re: Limex's Swimming Include (Detect swimming!) - by Denisucoz - 27.05.2014, 16:02

Forum Jump:


Users browsing this thread: 3 Guest(s)