SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 04/09/2010, 04:39 AM   #1
Limex
Big Clucker
 
Join Date: Jun 2006
Posts: 150
Reputation: 40
Default Limex's Swimming Include (Detect swimming!)

Limex's Swimming Include


Features 1 function, and 2 callbacks!

New function: IsPlayerSwimming(playerid)

New callbacks: OnPlayerStartSwimming(playerid) and OnPlayerStopSwimming(playerid)

HOW TO USE

Make a limex-swim.inc file in your includes folder!

Put the following code in it:

pawn Code:
/*  =============================

    Limex's Swimming Include
   
    Made by Limex / A
   
    New function:
    IsPlayerSwimming(playerid)
   
    New callbacks:
    OnPlayerStartSwimming(playerid)
    OnPlayerStopSwimming(playerid)
   
    Enjoy!

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


#include <a_samp>

new bool:swimming[MAX_PLAYERS];

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

public IsPlayerSwimming(playerid)
{
    if(swimming[playerid]) return 1;
    return 0;
}

public OnPlayerUpdate(playerid)
{
    if(GetPlayerAnimationIndex(playerid))
    {
        new animlib[32];
        new animname[32];
        GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
        if(strcmp(animlib, "SWIM", true) == 0 && !swimming[playerid])
        {
            swimming[playerid] = true;
            OnPlayerStartSwimming(playerid);
        }
        else if(strcmp(animlib, "SWIM", true) != 0 && swimming[playerid] && strfind(animname, "jump", true) == -1)
        {
            swimming[playerid] = false;
            OnPlayerStopSwimming(playerid);
        }
    }
    else if(swimming[playerid])
    {
        swimming[playerid] = false;
        OnPlayerStopSwimming(playerid);
    }
    return 1;
}

Include it into your script with:

pawn Code:
#include <limex-swim>

You must add the following two callbacks into your script!

pawn Code:
public OnPlayerStartSwimming(playerid)
{
    // EXAMPLE CODE START //
    SendClientMessage(playerid, 0x33CCFFAA, "You started swimming!");
    // EXAMPLE CODE END //
    return 1;
}

public OnPlayerStopSwimming(playerid)
{
    // EXAMPLE CODE START //
    SendClientMessage(playerid, 0x33CCFFAA, "You stopped swimming!");
    // EXAMPLE CODE END //
    return 1;
}
Limex is offline   Reply With Quote
Old 04/09/2010, 05:22 AM   #2
willsuckformoney
High-roller
 
willsuckformoney's Avatar
 
Join Date: Dec 2009
Posts: 1,492
Reputation: 65
Default Re: Limex's Swimming Include (Detect swimming!)

Just wow... Never thought anyone would actually attempt to make a swimming detector... Nice job with this

EDIT: I heard something about OnPlayerUpdate causing lots of lag or something like that so I wouldn't use it.
__________________
Fuck the system.
willsuckformoney is offline   Reply With Quote
Old 04/09/2010, 11:12 AM   #3
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default Re: Limex's Swimming Include (Detect swimming!)

another cool but random release :P

This forum requires that you wait 120 seconds between posts. Please try again in 28 seconds.
GTFO.
__________________
once average now terrible
WillyP is offline   Reply With Quote
Old 04/09/2010, 11:52 AM   #4
Grim_
High-roller
 
Grim_'s Avatar
 
Join Date: Sep 2008
Location: United States
Posts: 2,896
Reputation: 118
Default Re: Limex's Swimming Include (Detect swimming!)

Quote:
Originally Posted by willsuckformoney View Post
Just wow... Never thought anyone would actually attempt to make a swimming detector... Nice job with this

EDIT: I heard something about OnPlayerUpdate causing lots of lag or something like that so I wouldn't use it.
With the code he has in it, no, it won't lag.
Grim_ is offline   Reply With Quote
Old 04/09/2010, 01:28 PM   #5
DiddyBop
Gangsta
 
DiddyBop's Avatar
 
Join Date: Aug 2009
Posts: 666
Reputation: 10
Default Re: Limex's Swimming Include (Detect swimming!)

Quote:
Originally Posted by Grim_ View Post
With the code he has in it, no, it won't lag.
pawn Code:
if(GetPlayerAnimationIndex(playerid))
    {
        new animlib[32];
        new animname[32];
        GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
        if(strcmp(animlib, "SWIM", true) == 0 && !swimming[playerid])
        {
            swimming[playerid] = true;
            OnPlayerStartSwimming(playerid);
        }
        else if(strcmp(animlib, "SWIM", true) != 0 && swimming[playerid] && strfind(animname, "jump", true) == -1)
        {
            swimming[playerid] = false;
            OnPlayerStopSwimming(playerid);
        }
    }
    else if(swimming[playerid])
    {
        swimming[playerid] = false;
        OnPlayerStopSwimming(playerid);
    }

Wont lag with 100 players on? OPD gets called like 30 times a second.. if not more.


now 100 * 30 = 3k, 3k * 60 = 180,000 Times a minute. Would be better to just put in a 1 second timer..
DiddyBop is offline   Reply With Quote
Old 04/09/2010, 02:02 PM   #6
General Abe
Big Clucker
 
General Abe's Avatar
 
Join Date: Jan 2008
Posts: 77
Reputation: 12
Default Re: Limex's Swimming Include (Detect swimming!)

Nice job. Most of the things this will be used for won't require something as frequent as OnPlayerUpdate; even a 1000ms timer will be fine for everything, I'd go for 2000.
__________________
Co-developer of Vortex Roleplay, three-time director of development & two-year assistant director of development at NGG.
General Abe is offline   Reply With Quote
Old 04/09/2010, 02:07 PM   #7
CYB3RN
Little Clucker
 
CYB3RN's Avatar
 
Join Date: Jul 2010
Location: Skopje, Macedonia.
Posts: 30
Reputation: 0
Default Re: Limex's Swimming Include (Detect swimming!)

I'm not a scripter or something,but I can say it's very useful (even tho I don't know how/does works) for RP servers,to prevent water-evaders,etc. :P
__________________
CYB3RN - SAMP player since 2008.
CYB3RN is offline   Reply With Quote
Old 04/09/2010, 02:11 PM   #8
Mauzen
High-roller
 
Mauzen's Avatar
 
Join Date: Jun 2007
Location: Western Germany
Posts: 4,877
Reputation: 1597
Default Re: Limex's Swimming Include (Detect swimming!)

Nice, another good release that makes use of 0.3b. Can be useful e.g. for RP (of course) or racing scripts.

Small tip: Use CallLocalFunction for calling your custom callbacks (OnPlayerStart/StopSwimming), instead of calling them direct. YOu do not have to have the function in your script then, but if you have it, it gets called.
Mauzen is online now   Reply With Quote
Old 05/09/2010, 09:57 PM   #9
Limex
Big Clucker
 
Join Date: Jun 2006
Posts: 150
Reputation: 40
Default Re: Limex's Swimming Include (Detect swimming!)

Thanks for all the nice comments guys!

Yes I guess it would be fine with a 1 second timer, although the timer would be required to loop through ALL players, whereas OnPlayerUpdate is only called for online players. I don't think there would be that much gain from it. Especially as I am not using any loops. However, it would be suitable to stagger the amount that the full code is executed, for example, only being called every 10 updates or so.
Limex is offline   Reply With Quote
Old 06/09/2010, 09:54 PM   #10
Hijolion
Huge Clucker
 
Hijolion's Avatar
 
Join Date: Dec 2009
Location: United States
Posts: 256
Reputation: 5
Default Re: Limex's Swimming Include (Detect swimming!)

You can also easily detect swimming

pawn Code:
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;
}

this is simply faster without lags because it simply stocks it in.
Hijolion is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FS/MAP] Swimming Pool [Ask]Terminator Filterscripts 125 23/03/2013 10:52 AM
[FilterScript] [FS] Unlimited Oxygen! Explore the Underwater world, swimming! aNdReSk Filterscripts 23 29/01/2011 06:00 PM


All times are GMT. The time now is 04:24 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.