sharivan

walljump.sp

Sep 24th, 2015 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.43 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5. #include <sdkhooks>
  6. #include <smlib>
  7.  
  8. #define ABS(%1)         (%1 >= 0.0 ? %1 : -%1)
  9. #define SGN(%1)         (%1 == 0.0 ? 0.0 : (%1 > 0.0 ? 1.0 : -1.0))
  10. #define MIN(%1,%2)      (%1 < %2 ? %1 : %2)
  11. #define MAX(%1,%2)      (%1 >= %2 ? %1 : %2)
  12.  
  13. #define ROTATION_ANGLE  60.0
  14.  
  15. #define VERSION         "1.0"
  16.  
  17. ConVar g_cvarEnabled = null;
  18. ConVar g_cvarMinimumIntervalBetweenJumps = null;
  19. ConVar g_cvarWallJumpVelocity = null;
  20.  
  21. float g_fRotationAngleCos;
  22. float g_fRotationAngleSin;
  23.  
  24. int g_iVelocity = -1;
  25. int g_iFlags = -1;
  26.  
  27. bool g_bEnabled[MAXPLAYERS + 1];
  28. bool g_bWasJumping[MAXPLAYERS + 1];
  29. float g_fNextThink[MAXPLAYERS + 1];
  30.  
  31. public Plugin myinfo = {
  32.     name = "Wall Jump",
  33.     author = "SHARIVAN from ΖмBя.™ Clan",
  34.     description = "Allow players to do wall jump",
  35.     version = VERSION,
  36.     url = "http://www.zmbrasil.com.br/"
  37. };
  38.  
  39. public void OnPluginStart() {
  40.     CreateConVar("wj_version", VERSION, "versão", FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  41.    
  42.     g_cvarEnabled = CreateConVar("wj_enabled", "1", "Habilita/Desabilita o funcionamento deste plugin.");
  43.     g_cvarMinimumIntervalBetweenJumps = CreateConVar("wj_minimum_interval_between_jumps", "0", "Intervalo de tempo mínimo entre cada pulo dado pelas paredes.");
  44.     g_cvarWallJumpVelocity = CreateConVar("wj_wall_jump_velocity", "300", "Velocidade aplicada no jogador após efetuadl o walljump.");
  45.    
  46.     AutoExecConfig(true, "walljump");
  47.    
  48.     float fRotationAngle = DegToRad(ROTATION_ANGLE);
  49.     g_fRotationAngleCos = Cosine(fRotationAngle);
  50.     g_fRotationAngleSin = Sine(fRotationAngle);
  51.  
  52.     g_iVelocity = FindSendPropOffs("CBasePlayer", "m_vecVelocity[0]");
  53.     g_iFlags = FindSendPropOffs("CBasePlayer", "m_fFlags");
  54.    
  55.     for (int client = 1; client <= MaxClients; client++) {
  56.         g_bEnabled[client] = true;
  57.         g_bWasJumping[client] = false;
  58.         g_fNextThink[client] = 0.0;
  59.         if (Client_IsIngame(client))
  60.             SDKHook(client, SDKHook_PostThink, OnPostThink);
  61.     }
  62. }
  63.  
  64. public void OnPluginEnd() {
  65.     for (int client = 1; client <= MaxClients; client++)
  66.         if (Client_IsIngame(client))
  67.             SDKUnhook(client, SDKHook_PostThink, OnPostThink);
  68. }
  69.  
  70. public void OnMapStart() {
  71. }
  72.  
  73. public void OnMapEnd() {
  74. }
  75.  
  76. public void OnClientPutInServer(int client) {
  77.     g_bEnabled[client] = true;
  78.     g_bWasJumping[client] = false;
  79.     g_fNextThink[client] = 0.0;
  80.     SDKHook(client, SDKHook_PostThink, OnPostThink);
  81. }
  82.  
  83. public void OnClientDisconnect(int client) {
  84.     SDKUnhook(client, SDKHook_PostThink, OnPostThink);
  85. }
  86.  
  87. stock bool PointInHull(const float vecPoint[3], const float vecHullOrigin[3], const float vecHullMins[3], const float vecHullMaxs[3], float fTolerance = 0.0) {
  88.     float vMins[3];
  89.     float vMaxs[3];
  90.    
  91.     AddVectors(vecHullOrigin, vecHullMins, vMins);
  92.     AddVectors(vecHullOrigin, vecHullMaxs, vMaxs);
  93.    
  94.     return vMins[0] - fTolerance <= vecPoint[0] &&
  95.         vMins[1] - fTolerance <= vecPoint[1] &&
  96.         vMins[2] - fTolerance <= vecPoint[2] &&
  97.         vecPoint[0] <= vMaxs[0] + fTolerance &&
  98.         vecPoint[1] <= vMaxs[1] + fTolerance &&
  99.         vecPoint[2] <= vMaxs[2] + fTolerance;
  100. }
  101.  
  102. public bool TraceHullFilter(int entity, int contentsMask) {
  103.     return entity > MaxClients;
  104. }
  105.  
  106. stock bool IsTouchingAWall(int client, const float vecDir[3], float vecNormal[3]) {
  107.     float vecPos[3];
  108.     float vecEyePos[3];
  109.     float vecMins[3];
  110.     float vecMaxs[3];
  111.    
  112.     GetClientAbsOrigin(client, vecPos);
  113.     GetClientEyePosition(client, vecEyePos);
  114.     GetClientMins(client, vecMins);
  115.     GetClientMaxs(client, vecMaxs);
  116.    
  117.     AddVectors(vecPos, vecMins, vecMins);
  118.     AddVectors(vecPos, vecMaxs, vecMaxs);
  119.    
  120.     SubtractVectors(vecMins, vecEyePos, vecMins);
  121.     SubtractVectors(vecMaxs, vecEyePos, vecMaxs);
  122.    
  123.     vecMaxs[2] = 0.0;
  124.    
  125.     float v[3];
  126.     v[0] = vecDir[0];
  127.     v[1] = vecDir[1];
  128.     v[2] = vecDir[2];
  129.     ScaleVector(v, 100.0);
  130.    
  131.     float vecEnd[3];
  132.     AddVectors(vecEyePos, v, vecEnd);
  133.    
  134.     Handle hTrace = TR_TraceHullFilterEx(vecEyePos, vecEnd, vecMins, vecMaxs, CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE|CONTENTS_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE, TraceHullFilter);
  135.     if (TR_DidHit(hTrace)) {
  136.         TR_GetEndPosition(v, hTrace);
  137.         bool bResult;
  138.         if (PointInHull(v, vecEyePos, vecMins, vecMaxs, 2.0)) {
  139.             TR_GetPlaneNormal(hTrace, vecNormal);
  140.             bResult = true;
  141.         } else
  142.             bResult = false;
  143.        
  144.         delete hTrace;
  145.        
  146.         return bResult;
  147.     }
  148.    
  149.     delete hTrace;
  150.    
  151.     return false;
  152. }
  153.  
  154. public void OnPostThink(int client) {
  155.     if (g_iVelocity == -1 || g_iFlags == -1)
  156.         return;
  157.        
  158.     if (!g_cvarEnabled.BoolValue)
  159.         return;
  160.        
  161.     if (!g_bEnabled[client])
  162.         return;
  163.        
  164.     if (GetEntityMoveType(client) != MOVETYPE_WALK)
  165.         return;
  166.    
  167.     int cflags = GetEntData(client, g_iFlags);
  168.     if ((cflags & FL_ONGROUND) != 0)
  169.         return;
  170.        
  171.     int buttons = GetClientButtons(client);
  172.     if ((buttons & IN_JUMP) == 0) {
  173.         g_bWasJumping[client] = false;
  174.         return;
  175.     }
  176.    
  177.     if (g_bWasJumping[client])
  178.         return;
  179.        
  180.     g_bWasJumping[client] = true;
  181.        
  182.     float angles[3];
  183.     GetClientEyeAngles(client, angles);
  184.    
  185.     float vecDir[3];
  186.     GetAngleVectors(angles, vecDir, NULL_VECTOR, NULL_VECTOR);
  187.    
  188.     float vecNormal[3];
  189.     if (!IsTouchingAWall(client, vecDir, vecNormal))
  190.         return;
  191.        
  192.     GetVectorAngles(vecNormal, angles);
  193.     if (angles[0] < 0 || angles[0] > 45.0)
  194.         return;
  195.        
  196.     float fTime = GetEngineTime();
  197.     float fInterval = g_cvarMinimumIntervalBetweenJumps.FloatValue;
  198.     if (g_fNextThink[client] != 0.0 && fTime + fInterval < g_fNextThink[client])
  199.         return;
  200.        
  201.     g_fNextThink[client] = fTime + fInterval;
  202.        
  203.     float u[3];
  204.     u[0] = vecNormal[0];
  205.     u[1] = vecNormal[1];
  206.     u[2] = vecNormal[2];
  207.    
  208.     float dot = GetVectorDotProduct(vecDir, vecNormal);
  209.     ScaleVector(u, 2.0 * dot);
  210.    
  211.     float fWallJumpVelocity = g_cvarWallJumpVelocity.FloatValue;
  212.     if ((buttons & IN_DUCK) != 0)
  213.         fWallJumpVelocity *= 1.5;
  214.    
  215.     SubtractVectors(vecDir, u, vecDir);
  216.     ScaleVector(vecDir, fWallJumpVelocity);
  217.    
  218.     float fWallJumpVelocityXY = SquareRoot(vecDir[0] * vecDir[0] + vecDir[1] * vecDir[1]);
  219.     vecDir[0] = (fWallJumpVelocity / fWallJumpVelocityXY) * vecDir[0];
  220.     vecDir[1] = (fWallJumpVelocity / fWallJumpVelocityXY) * vecDir[1];
  221.     vecDir[2] = 0.0;
  222.    
  223.     float fCosTeta = vecDir[0] / fWallJumpVelocity;
  224.     float fSinTeta = vecDir[1] / fWallJumpVelocity;
  225.    
  226.     vecDir[0] = fWallJumpVelocity * g_fRotationAngleCos * fCosTeta;
  227.     vecDir[1] = fWallJumpVelocity * g_fRotationAngleCos * fSinTeta;
  228.     vecDir[2] = fWallJumpVelocity * g_fRotationAngleSin;
  229.    
  230.     SetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", vecDir);
  231.     SetEntDataVector(client, g_iVelocity, vecDir);
  232. }
Advertisement
Add Comment
Please, Sign In to add comment