Advertisement
Julian90

OnPlayerJump - v0.0.1

Sep 16th, 2014
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.04 KB | None | 0 0
  1. /*
  2.         OnPlayerJump - By: [J]ulian.
  3.     v0.0.1 - 17/09/2014
  4.                - Lanzamiento inicial.
  5.  
  6.     Requerido:
  7.       - y_hooks: http://forum.sa-mp.com/showthread.php?t=166016
  8. */
  9.  
  10. #include <YSI\y_hooks>
  11.  
  12. forward OnPlayerJump(playerid, bool:start, Float:z, Float:dist, time);
  13. /*
  14.     native IsPlayerJumping(playerid);
  15.     native GetPlayerJumpStartTime(playerid);
  16. */
  17.  
  18. //#define JUMP_HEALTH_RESTORE
  19.  
  20. #define INVALID_JUMP    -1
  21.  
  22. enum JUMP_INFO {
  23.     Float:JUMP_POS[2],
  24.     JUMP_STATE,
  25.     JUMP_TIME,
  26. }
  27. new JumpInfo[MAX_PLAYERS][JUMP_INFO];
  28.  
  29. stock IsPlayerJumping(playerid)
  30. {
  31.     if(!IsPlayerConnected(playerid)) return 0;
  32.     return JumpInfo[playerid][JUMP_STATE];
  33. }
  34.  
  35. stock GetPlayerJumpStartTime(playerid)
  36. {
  37.     if(IsPlayerJumping(playerid))
  38.     {
  39.         return JumpInfo[playerid][JUMP_TIME];
  40.     }
  41.     return INVALID_JUMP;
  42. }
  43.  
  44. hook OnPlayerConnect(playerid)
  45. {
  46.     JumpInfo[playerid][JUMP_STATE] = 0;
  47.     JumpInfo[playerid][JUMP_TIME] = 0;
  48.     return 1;
  49. }
  50.  
  51. hook OnPlayerUpdate(playerid)
  52. {
  53.     if(GetPlayerAnimationIndex(playerid))
  54.     {
  55.         static anim[2][32];
  56.         if(GetAnimationName(GetPlayerAnimationIndex(playerid), anim[0], 32, anim[1], 32))
  57.         {
  58.             if(!JumpInfo[playerid][JUMP_STATE])
  59.             {
  60.                 if(!strcmp(anim[0], "PED", true) && !strcmp(anim[1], "JUMP_LAUNCH")
  61.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "JUMP_LAUNCH_R")
  62.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "JUMP_GLIDE")
  63.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "FALL_GLIDE")
  64.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "CLIMB_JUMP_B"))
  65.                 {
  66.                     JumpInfo[playerid][JUMP_STATE] = 1;
  67.                     JumpInfo[playerid][JUMP_TIME] = gettime();
  68.                     GetPlayerPos(playerid, JumpInfo[playerid][JUMP_POS][0], JumpInfo[playerid][JUMP_POS][0], JumpInfo[playerid][JUMP_POS][0]);
  69.                     CallLocalFunction("OnPlayerJump", "iiffi", playerid, true, JumpInfo[playerid][JUMP_POS][0], INVALID_JUMP, JumpInfo[playerid][JUMP_TIME]);
  70.                 }
  71.             }
  72.             else
  73.             {
  74.                 if(!strcmp(anim[0], "PED", true) && !strcmp(anim[1], "FALL_COLLAPSE")
  75.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "FALL_LAND")
  76.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "JUMP_LAND")
  77.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "KO_SKID_BACK")
  78.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "CLIMB_STAND")
  79.                 || !strcmp(anim[0], "PED", true) && !strcmp(anim[1], "CLIMB_JUMP2FALL"))
  80.                 {
  81.                     JumpInfo[playerid][JUMP_STATE] = 0;
  82.                     GetPlayerPos(playerid, JumpInfo[playerid][JUMP_POS][1], JumpInfo[playerid][JUMP_POS][1], JumpInfo[playerid][JUMP_POS][1]);
  83.                     CallLocalFunction("OnPlayerJump", "iiffi", playerid, false, JumpInfo[playerid][JUMP_POS][0], JumpInfo[playerid][JUMP_POS][1]-JumpInfo[playerid][JUMP_POS][0], JumpInfo[playerid][JUMP_TIME]);
  84.                 }
  85.             }
  86.         }
  87.     }
  88.     return 1;
  89. }
  90.  
  91. #if defined JUMP_HEALTH_RESTORE
  92. hook OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
  93. {
  94.     if(issuerid == INVALID_PLAYER_ID && weaponid == WEAPON_COLLISION)
  95.     {
  96.         new Float:vida;
  97.         GetPlayerHealth(playerid, vida);
  98.         SetPlayerHealth(playerid, vida+amount);
  99.     }
  100.     return 1;
  101. }
  102. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement