Advertisement
Southclaw

Southclaw's Underwater Swimming Fix

Oct 23rd, 2012
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.60 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <YSI\y_timers>
  5.  
  6.  
  7. /*
  8.  *  SwimFix by Southclaw (2012)
  9.  *
  10.  *      While underwater, a player has an idle Z velocity of 0.01715
  11.  *      I found this gets annoying when trying to swim through underwater
  12.  *      passages as the player gets stuck on the ceiling a lot.
  13.  *
  14.  *      This short FS just simply keeps the player at a Z velocity of 0
  15.  *      while idle or swimming forward, this is detected using camera
  16.  *      vectors and the checks are done on a 1 second timer instead of
  17.  *      OnPlayerUpdate.
  18.  *
  19.  *
  20.  *  Do what you want with it, but keep my name on it :)
  21.  *
  22.  */
  23.  
  24. new
  25.     bool:gSwimmingDown[MAX_PLAYERS];
  26.  
  27.  
  28. ptask SwimCameraCheck[1000](playerid)
  29. {
  30.     new
  31.         Float:vx,
  32.         Float:vy,
  33.         Float:vz,
  34.         Float:vecz;
  35.  
  36.     GetPlayerVelocity(playerid, vx, vy, vz);
  37.     GetPlayerCameraFrontVector(playerid, vecz, vecz, vecz);
  38.  
  39. /*
  40.  *  Here, the camera vector is checked, if it's below 0.1
  41.  *  the player is looking downwards. I chose 0.1 because it
  42.  *  it gives a bit of looking space for swimming forwards.
  43.  */
  44.  
  45.     if(vecz < 0.1)
  46.         gSwimmingDown[playerid] = true;
  47.  
  48.     else
  49.         gSwimmingDown[playerid] = false;
  50. }
  51.  
  52. public OnPlayerUpdate(playerid)
  53. {
  54.     if(gSwimmingDown[playerid])
  55.     {
  56.         new animidx = GetPlayerAnimationIndex(playerid);
  57.         switch(animidx)
  58.         {
  59. /*
  60.  *  If the player is using animations for swimming down,
  61.  *  forward or just idle, they will get pushed down a bit.
  62.  */
  63.             case 1541, 1544:
  64.             {
  65.                 new
  66.                     Float:vx,
  67.                     Float:vy,
  68.                     Float:vz;
  69.  
  70.                 GetPlayerVelocity(playerid, vx, vy, vz);
  71.                 SetPlayerVelocity(playerid, vx, vy, -0.0026);
  72.             }
  73.         }
  74.     }
  75.     return 1;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement