Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <smrpg>
  4. #include <sdktools>
  5.  
  6. #define PLUGIN_VERSION "1.0"
  7. #define UPGRADE_SHORTNAME "ljump"
  8.  
  9. new Handle:g_hCVIncreaseStart;
  10.  
  11. new Float:g_fLJumpPreviousVelocity[MAXPLAYERS+1][3];
  12. new Float:g_fLJumpPlayerJumped[MAXPLAYERS+1];
  13.  
  14. public Plugin:myinfo =
  15. {
  16. name = "SM:RPG Upgrade > Long Jump",
  17. author = "Jannik \"Peace-Maker\" Hartung",
  18. description = "Long Jump upgrade for SM:RPG. Boosts players jump speed.",
  19. version = PLUGIN_VERSION,
  20. url = "http://www.wcfan.de/"
  21. }
  22.  
  23. public OnPluginStart()
  24. {
  25. HookEventEx("player_footstep", Event_OnResetJump);
  26. HookEvent("player_spawn", Event_OnResetJump);
  27. HookEvent("player_death", Event_OnResetJump);
  28.  
  29. LoadTranslations("smrpg_stock_upgrades.phrases");
  30. }
  31.  
  32. public OnPluginEnd()
  33. {
  34. if(SMRPG_UpgradeExists(UPGRADE_SHORTNAME))
  35. SMRPG_UnregisterUpgradeType(UPGRADE_SHORTNAME);
  36. }
  37.  
  38. public OnAllPluginsLoaded()
  39. {
  40. OnLibraryAdded("smrpg");
  41. }
  42.  
  43. public OnLibraryAdded(const String:name[])
  44. {
  45. // Register this upgrade in SM:RPG
  46. if(StrEqual(name, "smrpg"))
  47. {
  48. SMRPG_RegisterUpgradeType("Long Jump", UPGRADE_SHORTNAME, "Boosts your jump speed.", 10, true, 5, 20, 15, _, SMRPG_BuySell, SMRPG_ActiveQuery);
  49. SMRPG_SetUpgradeTranslationCallback(UPGRADE_SHORTNAME, SMRPG_TranslateUpgrade);
  50.  
  51. g_hCVIncreaseStart = SMRPG_CreateUpgradeConVar(UPGRADE_SHORTNAME, "smrpg_ljump_incstart", "0.20", "Percent of player's initial jump distance to increase per level.", 0, true, 0.01);
  52. }
  53. }
  54.  
  55.  
  56. public SMRPG_BuySell(client, UpgradeQueryType:type)
  57. {
  58. // Nothing to apply here immediately after someone buys this upgrade.
  59. }
  60.  
  61. public bool:SMRPG_ActiveQuery(client)
  62. {
  63. new upgrade[UpgradeInfo];
  64. SMRPG_GetUpgradeInfo(UPGRADE_SHORTNAME, upgrade);
  65. return SMRPG_IsEnabled() && upgrade[UI_enabled] && SMRPG_GetClientUpgradeLevel(client, UPGRADE_SHORTNAME) > 0;
  66. }
  67.  
  68. public SMRPG_TranslateUpgrade(client, const String:shortname[], TranslationType:type, String:translation[], maxlen)
  69. {
  70. if(type == TranslationType_Name)
  71. Format(translation, maxlen, "%T", UPGRADE_SHORTNAME, client);
  72. else if(type == TranslationType_Description)
  73. {
  74. new String:sDescriptionKey[MAX_UPGRADE_SHORTNAME_LENGTH+12] = UPGRADE_SHORTNAME;
  75. StrCat(sDescriptionKey, sizeof(sDescriptionKey), " description");
  76. Format(translation, maxlen, "%T", sDescriptionKey, client);
  77. }
  78. }
  79.  
  80. public OnClientDisconnect(client)
  81. {
  82. g_fLJumpPlayerJumped[client] = -1.0;
  83. }
  84.  
  85. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seed, mouse[2])
  86. {
  87. static s_iLastButtons[MAXPLAYERS+1] = {0,...};
  88. if(!IsClientInGame(client) || !IsPlayerAlive(client))
  89. return Plugin_Continue;
  90.  
  91. // Make sure to reset the time when the player stops. Maybe he didn't took a step so player_footstep wasn't fired yet.
  92. decl Float:vVelocity[3];
  93. GetEntPropVector(client, Prop_Data, "m_vecVelocity", vVelocity);
  94. if(vVelocity[0] == 0.0 && vVelocity[1] == 0.0 && vVelocity[2] == 0.0)
  95. g_fLJumpPlayerJumped[client] = -1.0;
  96.  
  97. new bool:bFirstJump = g_fLJumpPlayerJumped[client] < 0.0;
  98.  
  99. // Player started to press space - or what ever is bound to jump..
  100. if(buttons & IN_JUMP && !(s_iLastButtons[client] & IN_JUMP))
  101. {
  102. // Make sure the player is on the ground and not on a ladder.
  103. if(GetEntityFlags(client) & FL_ONGROUND && GetEntityMoveType(client) != MOVETYPE_LADDER)
  104. {
  105. g_fLJumpPreviousVelocity[client] = vVelocity;
  106. g_fLJumpPlayerJumped[client] = GetEngineTime();
  107. }
  108. }
  109.  
  110. if(g_fLJumpPlayerJumped[client] > 0.0)
  111. {
  112. if(vVelocity[2] > g_fLJumpPreviousVelocity[client][2])
  113. {
  114. LJump_HasJumped(client, vVelocity, bFirstJump);
  115. g_fLJumpPlayerJumped[client] = -1.0;
  116. }
  117. }
  118.  
  119. s_iLastButtons[client] = buttons;
  120. return Plugin_Continue;
  121. }
  122.  
  123. public Event_OnResetJump(Handle:event, const String:error[], bool:dontBroadcast)
  124. {
  125. new client = GetClientOfUserId(GetEventInt(event, "userid"));
  126. if(!client)
  127. return;
  128.  
  129. // Don't reset the jumping right after the player jumped.
  130. // In CSGO the player_footstep event is fired right before the player takes off. Ignore that one event.
  131. if(g_fLJumpPlayerJumped[client] > 0.0 && (GetEngineTime() - g_fLJumpPlayerJumped[client]) > 0.003)
  132. g_fLJumpPlayerJumped[client] = -1.0;
  133. }
  134.  
  135. LJump_HasJumped(client, Float:vVelocity[3], bool:bFirstJump)
  136. {
  137. if(bFirstJump)
  138. {
  139. if(!SMRPG_IsEnabled())
  140. return;
  141.  
  142. new upgrade[UpgradeInfo];
  143. SMRPG_GetUpgradeInfo(UPGRADE_SHORTNAME, upgrade);
  144. if(!upgrade[UI_enabled])
  145. return;
  146.  
  147. // Are bots allowed to use this upgrade?
  148. if(IsFakeClient(client) && SMRPG_IgnoreBots())
  149. return;
  150.  
  151. // Player didn't buy this upgrade yet.
  152. new iLevel = SMRPG_GetClientUpgradeLevel(client, UPGRADE_SHORTNAME);
  153. if(iLevel <= 0)
  154. return;
  155.  
  156. if(!SMRPG_RunUpgradeEffect(client, UPGRADE_SHORTNAME))
  157. return; // Some other plugin doesn't want this effect to run
  158.  
  159. new Float:fMultiplicator;
  160. // The first jump receives a bigger boost to get away from dangerous places quickly.
  161.  
  162. fMultiplicator = GetConVarFloat(g_hCVIncreaseStart);
  163.  
  164. new Float:fIncrease = fMultiplicator * float(iLevel) + 1.0;
  165. vVelocity[0] *= fIncrease;
  166. vVelocity[1] *= fIncrease;
  167.  
  168. TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vVelocity);
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement