Advertisement
Guest User

doublejump

a guest
Dec 11th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. /*
  2. * Double Jump
  3. *
  4. * Description:
  5. * Allows players to double-jump
  6. * Original idea: NcB_Sav
  7. *
  8. * Convars:
  9. * sm_doublejump_enabled [bool] : Enables or disable double-jumping. Default: 1
  10. * sm_doublejump_boost [amount] : Amount to boost the player. Default: 250
  11. * sm_doublejump_max [jumps] : Maximum number of re-jumps while airborne. Default: 1
  12. *
  13. * Changelog:
  14. * v1.0.1
  15. * Minor code optimization.
  16. * v1.0.0
  17. * Initial release.
  18. *
  19. * Known issues:
  20. * Doesn't register all mouse-wheel triggered +jumps
  21. *
  22. * Todo:
  23. * Employ upcoming OnClientCommand function to remove excess OnGameFrame-age.
  24. *
  25. * Contact:
  26. * Paegus: paegus@gmail.com
  27. * SourceMod: http://www.sourcemod.net
  28. * Hidden:Source: http://www.hidden-source.com
  29. * NcB_Sav: http://forums.alliedmods.net/showthread.php?t=99228
  30. */
  31. #define PLUGIN_VERSION "1.0.1"
  32.  
  33. #include <sdktools>
  34.  
  35.  
  36. public Plugin:myinfo = {
  37. name = "Double Jump",
  38. author = "Paegus",
  39. description = "Allows double-jumping.",
  40. version = PLUGIN_VERSION,
  41. url = ""
  42. }
  43.  
  44. new
  45. Handle:g_cvJumpBoost = INVALID_HANDLE,
  46. Handle:g_cvJumpEnable = INVALID_HANDLE,
  47. Handle:g_cvJumpMax = INVALID_HANDLE,
  48. Float:g_flBoost = 250.0,
  49. bool:g_bDoubleJump = true,
  50. g_fLastButtons[MAXPLAYERS+1],
  51. g_fLastFlags[MAXPLAYERS+1],
  52. g_iJumps[MAXPLAYERS+1],
  53. g_iJumpMax
  54.  
  55. public OnPluginStart() {
  56. CreateConVar(
  57. "sm_doublejump_version", PLUGIN_VERSION,
  58. "Double Jump Version",
  59. FCVAR_PLUGIN|FCVAR_NOTIFY
  60. )
  61.  
  62. g_cvJumpEnable = CreateConVar(
  63. "sm_doublejump_enabled", "1",
  64. "Enables double-jumping.",
  65. FCVAR_PLUGIN|FCVAR_NOTIFY
  66. )
  67.  
  68. g_cvJumpBoost = CreateConVar(
  69. "sm_doublejump_boost", "250.0",
  70. "The amount of vertical boost to apply to double jumps.",
  71. FCVAR_PLUGIN|FCVAR_NOTIFY
  72. )
  73.  
  74. g_cvJumpMax = CreateConVar(
  75. "sm_doublejump_max", "1",
  76. "The maximum number of re-jumps allowed while already jumping.",
  77. FCVAR_PLUGIN|FCVAR_NOTIFY
  78. )
  79.  
  80. HookConVarChange(g_cvJumpBoost, convar_ChangeBoost)
  81. HookConVarChange(g_cvJumpEnable, convar_ChangeEnable)
  82. HookConVarChange(g_cvJumpMax, convar_ChangeMax)
  83.  
  84. g_bDoubleJump = GetConVarBool(g_cvJumpEnable)
  85. g_flBoost = GetConVarFloat(g_cvJumpBoost)
  86. g_iJumpMax = GetConVarInt(g_cvJumpMax)
  87. }
  88.  
  89. public convar_ChangeBoost(Handle:convar, const String:oldVal[], const String:newVal[]) {
  90. g_flBoost = StringToFloat(newVal)
  91. }
  92.  
  93. public convar_ChangeEnable(Handle:convar, const String:oldVal[], const String:newVal[]) {
  94. if (StringToInt(newVal) >= 1) {
  95. g_bDoubleJump = true
  96. } else {
  97. g_bDoubleJump = false
  98. }
  99. }
  100.  
  101. public convar_ChangeMax(Handle:convar, const String:oldVal[], const String:newVal[]) {
  102. g_iJumpMax = StringToInt(newVal)
  103. }
  104.  
  105. public OnGameFrame() {
  106. if(IsClientVIP(client))
  107. {
  108. if (g_bDoubleJump) { // double jump active
  109. for (new i = 1; i <= MaxClients; i++) { // cycle through players
  110. if (
  111. IsClientInGame(i) && // is in the game
  112. IsPlayerAlive(i) // is alive
  113. ) {
  114. DoubleJump(i) // Check for double jumping
  115. }
  116. }
  117. }
  118. }
  119. }
  120.  
  121. stock DoubleJump(const any:client) {
  122. new
  123. fCurFlags = GetEntityFlags(client), // current flags
  124. fCurButtons = GetClientButtons(client) // current buttons
  125.  
  126. if (g_fLastFlags[client] & FL_ONGROUND) { // was grounded last frame
  127. if (
  128. !(fCurFlags & FL_ONGROUND) && // becomes airbirne this frame
  129. !(g_fLastButtons[client] & IN_JUMP) && // was not jumping last frame
  130. fCurButtons & IN_JUMP // started jumping this frame
  131. ) {
  132. OriginalJump(client) // process jump from the ground
  133. }
  134. } else if ( // was airborne last frame
  135. fCurFlags & FL_ONGROUND // becomes grounded this frame
  136. ) {
  137. Landed(client) // process landing on the ground
  138. } else if ( // remains airborne this frame
  139. !(g_fLastButtons[client] & IN_JUMP) && // was not jumping last frame
  140. fCurButtons & IN_JUMP // started jumping this frame
  141. ) {
  142. ReJump(client) // process attempt to double-jump
  143. }
  144.  
  145. g_fLastFlags[client] = fCurFlags // update flag state for next frame
  146. g_fLastButtons[client] = fCurButtons // update button state for next frame
  147. }
  148.  
  149. stock OriginalJump(const any:client) {
  150. g_iJumps[client]++ // increment jump count
  151. }
  152.  
  153. stock Landed(const any:client) {
  154. g_iJumps[client] = 0 // reset jumps count
  155. }
  156.  
  157. stock ReJump(const any:client) {
  158. if ( 1 <= g_iJumps[client] <= g_iJumpMax) { // has jumped at least once but hasn't exceeded max re-jumps
  159. g_iJumps[client]++ // increment jump count
  160. decl Float:vVel[3]
  161. GetEntPropVector(client, Prop_Data, "m_vecVelocity", vVel) // get current speeds
  162.  
  163. vVel[2] = g_flBoost
  164. TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vVel) // boost player
  165. }
  166. }
  167.  
  168. stock bool IsClientVIP(int client)
  169. {
  170. return CheckCommandAccess(client, "", ADMFLAG_RESERVATION);
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement