Advertisement
IllidanS4

SetGravity

Jun 29th, 2013
1,527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.56 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #if defined _setgravity_included
  4.   #endinput
  5. #endif
  6. #define _setgravity_included
  7.  
  8. static bool:moving[MAX_PLAYERS char];
  9. static falltime[MAX_PLAYERS];
  10. static Float:velZ[MAX_PLAYERS];
  11. static Float:gravity[MAX_PLAYERS];
  12. static bool:setgravity[MAX_PLAYERS char];
  13.  
  14. SetGravity_OnPlayerConnect(playerid)
  15. {
  16.     moving{playerid} = false;
  17.     velZ{playerid} = 0.0;
  18.     gravity[playerid] = 0.0;
  19.     setgravity{playerid} = false;
  20. }
  21.  
  22. SetGravity_OnPlayerUpdate(playerid)
  23. {
  24.     if(setgravity{playerid} && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  25.     {
  26.         new Float:x, Float:y, Float:z;
  27.         GetPlayerVelocity(playerid, x, y, z);
  28.         new anim = GetPlayerAnimationIndex(playerid);
  29.         if(anim == 1130 || anim == 1132 || anim == 1195)
  30.         {
  31.             if(!moving{playerid} || z == 0.0)
  32.             {
  33.                 velZ[playerid] = z;
  34.                 moving{playerid} = true;
  35.                 falltime[playerid] = GetTickCount();
  36.             }
  37.             new time = GetTickCount()-falltime[playerid];
  38.             z = (gravity[playerid]*time)/1000.0;
  39.             if(z > 1.17) z = 1.17;
  40.             SetPlayerVelocity(playerid, x, y, velZ[playerid]-z);
  41.         }else{
  42.             moving{playerid} = false;
  43.         }
  44.     }
  45. }
  46.  
  47. stock SetPlayerGravity(playerid, Float:newgravity)
  48. {
  49.     setgravity{playerid} = true;
  50.     gravity[playerid] = newgravity*50.0;
  51.     moving{playerid} = false;
  52. }
  53.  
  54. stock ResetPlayerGravity(playerid)
  55. {
  56.     setgravity{playerid} = false;
  57.     gravity[playerid] = 0.0;
  58.     moving{playerid} = false;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement