Advertisement
De4dpOol

De4dpOol's Rappelling System (Fully Automatic)

Mar 23rd, 2015
1,528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. /*==============================================================================
  2. ----------------------------De4dpOol's rappelling System------------------------
  3. ==============================================================================*/
  4.  
  5. //Include(s)
  6. #include <a_samp>
  7. #include <zcmd>
  8. #include <line>
  9.  
  10. //Forward(s)//
  11. forward FallingChecker(playerid);
  12. forward DeActivateRappel(playerid);
  13.  
  14. //New(s)//
  15. new Float:LastZ[MAX_PLAYERS];
  16. new Rope[MAX_PLAYERS];
  17. new IsRappelling[MAX_PLAYERS];
  18. new LandingChecker[MAX_PLAYERS];
  19. new Rappel[MAX_PLAYERS];
  20. new Float:PlayerHealth[MAX_PLAYERS];
  21.  
  22. //Function(s)//
  23. GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  24. {
  25. new Float:a;
  26. GetPlayerPos(playerid, x, y, a);
  27. GetPlayerFacingAngle(playerid, a);
  28. if (GetPlayerVehicleID(playerid))
  29. {
  30. GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  31. }
  32. x += (distance * floatsin(-a, degrees));
  33. y += (distance * floatcos(-a, degrees));
  34. }
  35.  
  36. RappelPlayer(playerid)
  37. {
  38. new Float: Px, Float: Py, Float: Pz;
  39. GetPlayerPos(playerid, Px, Py, Pz);
  40. GetXYInFrontOfPlayer(playerid, Px, Py, 0.2);
  41. SetPlayerVelocity(playerid, 0.0, 0.0, -0.2);
  42. Rope[playerid] = CreateLineSegment(19087, 2.46, Px, Py, Pz, Px, Py, Pz - 1000.0, .RotX = 90.0, .objlengthoffset = -(2.46/2), .worldid = -1, .interiorid = -1, .playerid = -1, .maxlength = 1000.0);
  43. ApplyAnimation(playerid,"ped","abseil",4.0,0,0,0,1,0);
  44. return 1;
  45. }
  46.  
  47. NotFalling(playerid)
  48. {
  49. DestroyLineSegment(Rope[playerid]);
  50. ClearAnimations(playerid);
  51. IsRappelling[playerid] = 0;
  52. KillTimer(LandingChecker[playerid]);
  53. SetPlayerHealth(playerid, PlayerHealth[playerid]);
  54. return 1;
  55. }
  56.  
  57. //Public(s)
  58. public OnPlayerUpdate(playerid)
  59. {
  60. if(Rappel[playerid] == 0) return 1;
  61. if(GetPlayerAnimationIndex(playerid) && (IsRappelling[playerid] == 0))
  62. {
  63. new animlib[32];
  64. new animname[32];
  65. GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
  66. if((!strcmp(animlib, "PED", true, 3)) && (!strcmp(animname, "FALL_fall", true, 9)))
  67. {
  68. RappelPlayer(playerid);
  69. IsRappelling[playerid] = 1;
  70. GetPlayerHealth(playerid, PlayerHealth[playerid]);
  71. SetPlayerHealth(playerid, 999999.0);
  72. LandingChecker[playerid] = SetTimerEx("FallingChecker",500,1,"i",playerid);
  73. }
  74. }
  75. return 1;
  76. }
  77.  
  78. public FallingChecker(playerid)
  79. {
  80. new Float:z;
  81. GetPlayerPos(playerid,z,z,z);
  82. if(LastZ[playerid] == z)
  83. {
  84. NotFalling(playerid);
  85. }
  86. LastZ[playerid] = z;
  87. return 1;
  88. }
  89.  
  90. public OnPlayerDisconnect(playerid, reason)
  91. {
  92. if(IsValidLineSegment(Rope[playerid])) DestroyLineSegment(Rope[playerid]);
  93. Rappel[playerid] = 0;
  94. IsRappelling[playerid] = 0;
  95. KillTimer(LandingChecker[playerid]);
  96. return 1;
  97. }
  98.  
  99. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  100. {
  101. if((newkeys & KEY_JUMP) && (Rappel[playerid] == 0))
  102. {
  103. if(IsPlayerInAnyVehicle(playerid))
  104. {
  105. if((GetVehicleModel(GetPlayerVehicleID(playerid)) == 487) && (GetPlayerVehicleSeat(playerid) != 0))//If its a Marverick and player is a passenger.
  106. {
  107. RemovePlayerFromVehicle(playerid);
  108. }
  109. }
  110. Rappel[playerid] = 1;
  111. SetTimerEx("DeActivateRappel", 5000, 0, "i", playerid);
  112. }
  113. return 1;
  114. }
  115.  
  116. public DeActivateRappel(playerid)
  117. {
  118. Rappel[playerid] = 0;
  119. return 1;
  120. }
  121.  
  122. //Cmd(s)//
  123. CMD:test2(playerid, params[])//To activate Rappelling, press jump to start rappelling.
  124. {
  125. SetPlayerPos(playerid, 0.0, 0.0, 200.0);
  126. return 1;
  127. }
  128. /*==============================================================================
  129. ---------------------------------End of Script----------------------------------
  130. ==============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement