Re: Limex's Swimming Include (Detect swimming!) -
Gigi-The-Beast - 13.11.2010
Quote:
Originally Posted by Limex
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.
|
then use foreach with it, so it will loop only through online players
anyway, good release
Re: Limex's Swimming Include (Detect swimming!) -
Grim_ - 13.11.2010
OnPlayerUpdate is only called for connected players anyway, and again, the current code will not make the server lag.
Re: Limex's Swimming Include (Detect swimming!) -
Limex - 12.12.2010
Thanks for the nice comments
Re: Limex's Swimming Include (Detect swimming!) -
Mean - 24.12.2010
n1c3...
Re: Limex's Swimming Include (Detect swimming!) -
Limex - 27.12.2010
th4nk5
Re: Limex's Swimming Include (Detect swimming!) -
Bodo4you - 27.12.2010
Very usefull for RP servers and not only.
Re: Limex's Swimming Include (Detect swimming!) -
Lorenc_ - 27.12.2010
Quote:
Originally Posted by Hijolion
You can also easily detect swimming
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; }
this is simply faster without lags because it simply stocks it in.
|
^ basicly what he said was wat i was going to say..
Re: Limex's Swimming Include (Detect swimming!) -
Limex - 28.12.2010
Okay then Lorenc_, explain to my how you will make it do something AS SOON as the person gets into the water with that function? You'd have to add a timer or use OnPlayerUpdate and then add callbacks, just as I did with this script.
This is why I made this script, because it has callbacks, and not just a function.
If you already have the callbacks in your script, then the function is more efficient because it just reads a static variable instead of checking the whole animations again.
Re: Limex's Swimming Include (Detect swimming!) -
TheKingWillem - 28.12.2010
You could make something like when u enter the water u get a swimming suit and a swimming helmet? Just an idea
Re: Limex's Swimming Include (Detect swimming!) -
wups - 28.12.2010
Quote:
Originally Posted by TheKingWillem
You could make something like when u enter the water u get a swimming suit and a swimming helmet? Just an idea
|
are there such objects?
Re: Limex's Swimming Include (Detect swimming!) -
Limex - 13.01.2011
Well this is just providing the framework, not any flashy features.
Re: Limex's Swimming Include (Detect swimming!) -
Gamer_Z - 07.06.2011
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
Re: Limex's Swimming Include (Detect swimming!) - Deskoft - 07.06.2011
Quote:
Originally Posted by Hijolion
You can also easily detect swimming
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; }
this is simply faster without lags because it simply stocks it in.
|
Thanks.
Re: Limex's Swimming Include (Detect swimming!) -
Gamer_Z - 07.06.2011
Quote:
Originally Posted by Deskoft
Thanks.
|
yes yes that is faster but the one I 'made faster' is more precise.
Re: Limex's Swimming Include (Detect swimming!) -
Denisucoz - 27.05.2014
Thank you!