Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #include <smlib>
- #define ABS(%1) (%1 >= 0.0 ? %1 : -%1)
- #define SGN(%1) (%1 == 0.0 ? 0.0 : (%1 > 0.0 ? 1.0 : -1.0))
- #define MIN(%1,%2) (%1 < %2 ? %1 : %2)
- #define MAX(%1,%2) (%1 >= %2 ? %1 : %2)
- #define ROTATION_ANGLE 60.0
- #define VERSION "1.0"
- ConVar g_cvarEnabled = null;
- ConVar g_cvarMinimumIntervalBetweenJumps = null;
- ConVar g_cvarWallJumpVelocity = null;
- float g_fRotationAngleCos;
- float g_fRotationAngleSin;
- int g_iVelocity = -1;
- int g_iFlags = -1;
- bool g_bEnabled[MAXPLAYERS + 1];
- bool g_bWasJumping[MAXPLAYERS + 1];
- float g_fNextThink[MAXPLAYERS + 1];
- public Plugin myinfo = {
- name = "Wall Jump",
- author = "SHARIVAN from ΖмBя.™ Clan",
- description = "Allow players to do wall jump",
- version = VERSION,
- url = "http://www.zmbrasil.com.br/"
- };
- public void OnPluginStart() {
- CreateConVar("wj_version", VERSION, "versão", FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
- g_cvarEnabled = CreateConVar("wj_enabled", "1", "Habilita/Desabilita o funcionamento deste plugin.");
- g_cvarMinimumIntervalBetweenJumps = CreateConVar("wj_minimum_interval_between_jumps", "0", "Intervalo de tempo mínimo entre cada pulo dado pelas paredes.");
- g_cvarWallJumpVelocity = CreateConVar("wj_wall_jump_velocity", "300", "Velocidade aplicada no jogador após efetuadl o walljump.");
- AutoExecConfig(true, "walljump");
- float fRotationAngle = DegToRad(ROTATION_ANGLE);
- g_fRotationAngleCos = Cosine(fRotationAngle);
- g_fRotationAngleSin = Sine(fRotationAngle);
- g_iVelocity = FindSendPropOffs("CBasePlayer", "m_vecVelocity[0]");
- g_iFlags = FindSendPropOffs("CBasePlayer", "m_fFlags");
- for (int client = 1; client <= MaxClients; client++) {
- g_bEnabled[client] = true;
- g_bWasJumping[client] = false;
- g_fNextThink[client] = 0.0;
- if (Client_IsIngame(client))
- SDKHook(client, SDKHook_PostThink, OnPostThink);
- }
- }
- public void OnPluginEnd() {
- for (int client = 1; client <= MaxClients; client++)
- if (Client_IsIngame(client))
- SDKUnhook(client, SDKHook_PostThink, OnPostThink);
- }
- public void OnMapStart() {
- }
- public void OnMapEnd() {
- }
- public void OnClientPutInServer(int client) {
- g_bEnabled[client] = true;
- g_bWasJumping[client] = false;
- g_fNextThink[client] = 0.0;
- SDKHook(client, SDKHook_PostThink, OnPostThink);
- }
- public void OnClientDisconnect(int client) {
- SDKUnhook(client, SDKHook_PostThink, OnPostThink);
- }
- stock bool PointInHull(const float vecPoint[3], const float vecHullOrigin[3], const float vecHullMins[3], const float vecHullMaxs[3], float fTolerance = 0.0) {
- float vMins[3];
- float vMaxs[3];
- AddVectors(vecHullOrigin, vecHullMins, vMins);
- AddVectors(vecHullOrigin, vecHullMaxs, vMaxs);
- return vMins[0] - fTolerance <= vecPoint[0] &&
- vMins[1] - fTolerance <= vecPoint[1] &&
- vMins[2] - fTolerance <= vecPoint[2] &&
- vecPoint[0] <= vMaxs[0] + fTolerance &&
- vecPoint[1] <= vMaxs[1] + fTolerance &&
- vecPoint[2] <= vMaxs[2] + fTolerance;
- }
- public bool TraceHullFilter(int entity, int contentsMask) {
- return entity > MaxClients;
- }
- stock bool IsTouchingAWall(int client, const float vecDir[3], float vecNormal[3]) {
- float vecPos[3];
- float vecEyePos[3];
- float vecMins[3];
- float vecMaxs[3];
- GetClientAbsOrigin(client, vecPos);
- GetClientEyePosition(client, vecEyePos);
- GetClientMins(client, vecMins);
- GetClientMaxs(client, vecMaxs);
- AddVectors(vecPos, vecMins, vecMins);
- AddVectors(vecPos, vecMaxs, vecMaxs);
- SubtractVectors(vecMins, vecEyePos, vecMins);
- SubtractVectors(vecMaxs, vecEyePos, vecMaxs);
- vecMaxs[2] = 0.0;
- float v[3];
- v[0] = vecDir[0];
- v[1] = vecDir[1];
- v[2] = vecDir[2];
- ScaleVector(v, 100.0);
- float vecEnd[3];
- AddVectors(vecEyePos, v, vecEnd);
- Handle hTrace = TR_TraceHullFilterEx(vecEyePos, vecEnd, vecMins, vecMaxs, CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE|CONTENTS_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE, TraceHullFilter);
- if (TR_DidHit(hTrace)) {
- TR_GetEndPosition(v, hTrace);
- bool bResult;
- if (PointInHull(v, vecEyePos, vecMins, vecMaxs, 2.0)) {
- TR_GetPlaneNormal(hTrace, vecNormal);
- bResult = true;
- } else
- bResult = false;
- delete hTrace;
- return bResult;
- }
- delete hTrace;
- return false;
- }
- public void OnPostThink(int client) {
- if (g_iVelocity == -1 || g_iFlags == -1)
- return;
- if (!g_cvarEnabled.BoolValue)
- return;
- if (!g_bEnabled[client])
- return;
- if (GetEntityMoveType(client) != MOVETYPE_WALK)
- return;
- int cflags = GetEntData(client, g_iFlags);
- if ((cflags & FL_ONGROUND) != 0)
- return;
- int buttons = GetClientButtons(client);
- if ((buttons & IN_JUMP) == 0) {
- g_bWasJumping[client] = false;
- return;
- }
- if (g_bWasJumping[client])
- return;
- g_bWasJumping[client] = true;
- float angles[3];
- GetClientEyeAngles(client, angles);
- float vecDir[3];
- GetAngleVectors(angles, vecDir, NULL_VECTOR, NULL_VECTOR);
- float vecNormal[3];
- if (!IsTouchingAWall(client, vecDir, vecNormal))
- return;
- GetVectorAngles(vecNormal, angles);
- if (angles[0] < 0 || angles[0] > 45.0)
- return;
- float fTime = GetEngineTime();
- float fInterval = g_cvarMinimumIntervalBetweenJumps.FloatValue;
- if (g_fNextThink[client] != 0.0 && fTime + fInterval < g_fNextThink[client])
- return;
- g_fNextThink[client] = fTime + fInterval;
- float u[3];
- u[0] = vecNormal[0];
- u[1] = vecNormal[1];
- u[2] = vecNormal[2];
- float dot = GetVectorDotProduct(vecDir, vecNormal);
- ScaleVector(u, 2.0 * dot);
- float fWallJumpVelocity = g_cvarWallJumpVelocity.FloatValue;
- if ((buttons & IN_DUCK) != 0)
- fWallJumpVelocity *= 1.5;
- SubtractVectors(vecDir, u, vecDir);
- ScaleVector(vecDir, fWallJumpVelocity);
- float fWallJumpVelocityXY = SquareRoot(vecDir[0] * vecDir[0] + vecDir[1] * vecDir[1]);
- vecDir[0] = (fWallJumpVelocity / fWallJumpVelocityXY) * vecDir[0];
- vecDir[1] = (fWallJumpVelocity / fWallJumpVelocityXY) * vecDir[1];
- vecDir[2] = 0.0;
- float fCosTeta = vecDir[0] / fWallJumpVelocity;
- float fSinTeta = vecDir[1] / fWallJumpVelocity;
- vecDir[0] = fWallJumpVelocity * g_fRotationAngleCos * fCosTeta;
- vecDir[1] = fWallJumpVelocity * g_fRotationAngleCos * fSinTeta;
- vecDir[2] = fWallJumpVelocity * g_fRotationAngleSin;
- SetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", vecDir);
- SetEntDataVector(client, g_iVelocity, vecDir);
- }
Advertisement
Add Comment
Please, Sign In to add comment