HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  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.  * Fordította: BBk
  32.  */
  33.  
  34. #define PLUGIN_VERSION "1.0.1"
  35.  
  36. #include <sdktools>
  37.  
  38.  
  39. public Plugin:myinfo = {
  40. name = "Double Jump",
  41. author = "Paegus",
  42. description = "Dupla ugras engedelyezese.",
  43. version = PLUGIN_VERSION,
  44. url = ""
  45. }
  46.  
  47. new
  48. Handle:g_cvJumpBoost = INVALID_HANDLE,
  49. Handle:g_cvJumpEnable = INVALID_HANDLE,
  50. Handle:g_cvJumpMax = INVALID_HANDLE,
  51. Float:g_flBoost = 250.0,
  52. bool:g_bDoubleJump = true,
  53. g_fLastButtons[MAXPLAYERS+1],
  54. g_fLastFlags[MAXPLAYERS+1],
  55. g_iJumps[MAXPLAYERS+1],
  56. g_iJumpMax
  57.  
  58. public OnPluginStart() {
  59. CreateConVar(
  60. "sm_doublejump_version", PLUGIN_VERSION,
  61. "Dupla Ugras Verzio",
  62. FCVAR_PLUGIN|FCVAR_NOTIFY
  63. )
  64.  
  65. g_cvJumpEnable = CreateConVar(
  66. "sm_doublejump_enabled", "1",
  67. "Dupla ugras engedelyezese/letiltasa.",
  68. FCVAR_PLUGIN|FCVAR_NOTIFY
  69. )
  70.  
  71. g_cvJumpBoost = CreateConVar(
  72. "sm_doublejump_boost", "250.0",
  73. "Az az ertek, ami ugrasnal felemeli a jatekost.",
  74. FCVAR_PLUGIN|FCVAR_NOTIFY
  75. )
  76.  
  77. g_cvJumpMax = CreateConVar(
  78. "sm_doublejump_max", "1",
  79. "Maximalis ugrasok szama, amig a jatekos a levegobe van.",
  80. FCVAR_PLUGIN|FCVAR_NOTIFY
  81. )
  82.  
  83. HookConVarChange(g_cvJumpBoost, convar_ChangeBoost)
  84. HookConVarChange(g_cvJumpEnable, convar_ChangeEnable)
  85. HookConVarChange(g_cvJumpMax, convar_ChangeMax)
  86.  
  87. g_bDoubleJump = GetConVarBool(g_cvJumpEnable)
  88. g_flBoost = GetConVarFloat(g_cvJumpBoost)
  89. g_iJumpMax = GetConVarInt(g_cvJumpMax)
  90. }
  91.  
  92. public convar_ChangeBoost(Handle:convar, const String:oldVal[], const String:newVal[]) {
  93. g_flBoost = StringToFloat(newVal)
  94. }
  95.  
  96. public convar_ChangeEnable(Handle:convar, const String:oldVal[], const String:newVal[]) {
  97. if (StringToInt(newVal) >= 1) {
  98. g_bDoubleJump = true
  99. } else {
  100. g_bDoubleJump = false
  101. }
  102. }
  103.  
  104. public convar_ChangeMax(Handle:convar, const String:oldVal[], const String:newVal[]) {
  105. g_iJumpMax = StringToInt(newVal)
  106. }
  107.  
  108. public OnGameFrame() {
  109. if (g_bDoubleJump) { // double jump active
  110. for (new i = 1; i <= MaxClients; i++) { // cycle through players
  111. if (
  112. IsClientInGame(i) && // is in the game
  113. IsPlayerAlive(i) // is alive
  114. ) {
  115. DoubleJump(i) // Check for double jumping
  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.