Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////
- //
- // Physics Control
- // (for TF2)
- // by thaCURSEDpie
- //
- // 2012-07-04
- //
- // pre-alpha
- //
- //
- // This plugin aims to give server-admins
- // greater control over the game's physics.
- //
- ////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////
- //
- // Includes et cetera
- //
- ////////////////////////////////////////////////////////////
- #pragma semicolon 1
- #define PLUGIN_VERSION "0.0.0"
- #define SHORT_DESCRIPTION "Physics Control by thaCURSEDpie"
- #define MAX_PLAYERS 33
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #include <tf2>
- ////////////////////////////////////////////////////////////
- //
- // Global vars
- //
- ////////////////////////////////////////////////////////////
- //-- Handles
- new Handle:hEnabled = INVALID_HANDLE;
- new Handle:hAirstrafeMult = INVALID_HANDLE;
- new Handle:hBhopMult = INVALID_HANDLE;
- new Handle:hBhopMaxDelay = INVALID_HANDLE;
- new Handle:hBhopZMult = INVALID_HANDLE;
- //-- Values
- new Float:fAirstrafeMult = 1.0;
- new Float:fBhopMult = 1.0;
- new Float:fBhopMaxDelay = 1.0;
- new Float:fBhopZMult = 1.0;
- new bool:bModEnabled = true;
- //-- Player properties
- new Float:fAirstrafeMults[MAX_PLAYERS];
- new Float:fBhopMults[MAX_PLAYERS];
- new Float:fBhopZMults[MAX_PLAYERS];
- new Float:fOldVels[MAX_PLAYERS][3];
- new bool:bIsInAir[MAX_PLAYERS];
- new bool:bJumpPressed[MAX_PLAYERS];
- new Float:fMomentTouchedGround[MAX_PLAYERS];
- new Float:fBhopMaxDelays[MAX_PLAYERS];
- new iGroundEntities[MAX_PLAYERS];
- ////////////////////////////////////////////////////////////
- //
- // Mod description
- //
- ////////////////////////////////////////////////////////////
- public Plugin:myinfo =
- {
- name = "Physics Control",
- author = "thaCURSEDpie",
- description = "This plugin aims to give server admins more control over the game physics.",
- version = PLUGIN_VERSION,
- url = "http://www.sourcemod.net"
- };
- ////////////////////////////////////////////////////////////
- //
- // OnPluginStart
- //
- ////////////////////////////////////////////////////////////
- public OnPluginStart()
- {
- //-- Cmds
- RegAdminCmd("sm_phctrlreload", CmdReload, ADMFLAG_SLAY);
- //-- Convars
- CreateConVar("phctrl_version", PLUGIN_VERSION, SHORT_DESCRIPTION, FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
- hEnabled = CreateConVar("phctrl_enabled", "1", "Enable Physics Control", FCVAR_PLUGIN);
- hAirstrafeMult = CreateConVar("phctrl_airstrafemult", "1.0", "The multiplier to apply to airstrafing", FCVAR_PLUGIN);
- hBhopMult = CreateConVar("phctrl_bhopmult", "1.0", "Boost to apply to bunnyhopping", FCVAR_PLUGIN);
- hBhopMaxDelay = CreateConVar("phctrl_bhopmaxdelay", "1.0", "Maximum time after the player has touched the ground, that he still can get the bhop boost, in seconds", FCVAR_PLUGIN);
- hBhopZMult = CreateConVar("phctrl_bhopzmult", "1.0", "Boost to apply to Upward velocity when bunnyhopping", FCVAR_PLUGIN);
- HookConVarChange(hAirstrafeMult, OnAirstrafeMultChanged);
- HookConVarChange(hEnabled, OnEnabledChanged);
- HookConVarChange(hBhopMult, OnBhopMultChanged);
- HookConVarChange(hBhopMaxDelay, OnBhopMaxDelayChanged);
- HookConVarChange(hBhopZMult, OnBhopZMultChanged);
- Init();
- }
- public Init()
- {
- //-- Init some arrays and values
- for (new i = 1; i < MAX_PLAYERS; i++)
- {
- fAirstrafeMults[i] = fAirstrafeMult;
- fBhopMults[i] = fBhopMult;
- fBhopMaxDelays[i] = fBhopMaxDelay;
- fBhopZMults[i] = fBhopZMult;
- if (IsValidEntity(i) && IsClientConnected(i))
- {
- SDKHook(i, SDKHook_PostThink, OnPostThink);
- // SDKHook(i, SDKHook_GroundEntChangedPost, OnGroundEntChanged); // Causes crash!
- }
- }
- }
- public Action:CmdReload(client, args)
- {
- Init();
- PrintToChat(client, "Physics Control reloaded!");
- return Plugin_Handled;
- }
- ////////////////////////////////////////////////////////////
- //
- // OnClientPutInServer
- //
- ////////////////////////////////////////////////////////////
- public OnClientPutInServer(client)
- {
- SDKHook(client, SDKHook_PostThink, OnPostThink);
- // SDKHook(client, SDKHook_GroundEntChangedPost, OnGroundEntChanged); // Causes crash!
- }
- ////////////////////////////////////////////////////////////
- //
- // Convars Changed Hooks
- //
- ////////////////////////////////////////////////////////////
- public OnEnabledChanged(Handle:convar, const String:oldValue[], const String:newValue[])
- {
- bModEnabled = GetConVarBool(convar);
- }
- public OnAirstrafeMultChanged(Handle:convar, const String:oldValue[], const String:newValue[])
- {
- fAirstrafeMult = GetConVarFloat(convar);
- for (new i = 0; i < MAX_PLAYERS; i++)
- {
- fAirstrafeMults[i] = fAirstrafeMult;
- }
- }
- public OnBhopMultChanged(Handle:convar, const String:oldValue[], const String:newValue[])
- {
- fBhopMult = GetConVarFloat(convar);
- for (new i = 0; i < MAX_PLAYERS; i++)
- {
- fBhopMults[i] = fBhopMult;
- }
- }
- public OnBhopZMultChanged(Handle:convar, const String:oldValue[], const String:newValue[])
- {
- fBhopZMult = GetConVarFloat(convar);
- for (new i = 0; i < MAX_PLAYERS; i++)
- {
- fBhopZMults[i] = fBhopZMult;
- }
- }
- public OnBhopMaxDelayChanged(Handle:convar, const String:oldValue[], const String:newValue[])
- {
- new Float:oldMult = fBhopMaxDelay;
- fBhopMaxDelay = GetConVarFloat(convar);
- for (new i = 0; i < MAX_PLAYERS; i++)
- {
- if (fBhopMaxDelays[i] == oldMult)
- {
- fBhopMaxDelays[i] = fBhopMaxDelay;
- }
- }
- }
- ////////////////////////////////////////////////////////////
- //
- // OnPlayerRunCmd
- //
- ////////////////////////////////////////////////////////////
- public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
- {
- if (!bModEnabled)
- {
- return Plugin_Continue;
- }
- if (bIsInAir[client])
- {
- vel[0] *= fAirstrafeMults[client];
- vel[1] *= fAirstrafeMults[client];
- // PrintToConsole(client, "mult: %f", fAirstrafeMults[client]);
- // PrintToConsole(client, "new vel: x: %f y: %f", vel[0], vel[1]);
- }
- else
- {
- if (buttons & IN_JUMP)
- {
- bJumpPressed[client] = true;
- }
- }
- return Plugin_Continue;
- }
- ////////////////////////////////////////////////////////////
- //
- // OnPostThink
- //
- ////////////////////////////////////////////////////////////
- public OnPostThink(client)
- {
- if (!bModEnabled || !IsValidEntity(client) || !IsClientInGame(client) || !IsPlayerAlive(client))
- {
- return;
- }
- /*
- new iGroundEntity = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
- if (iGroundEntity == -1)
- {
- // PrintToConsole(client, "Ha! We are in the air!");
- // Air
- GetEntPropVector(client, Prop_Data, "m_vecVelocity", fOldVels[client]);
- bIsInAir[client] = true;
- }
- else
- {
- // Ground or entity
- if (bIsInAir[client])
- {
- fMomentTouchedGround[client] = GetTickedTime();
- bIsInAir[client] = false;
- }
- }
- */
- if (bJumpPressed[client])
- {
- bJumpPressed[client] = false;
- if (fBhopMults[client] != -1 && GetTickedTime() - fMomentTouchedGround[client] <= fBhopMaxDelays[client])
- {
- new Float:fNewVel[3];
- GetEntPropVector(client, Prop_Data, "m_vecVelocity", fNewVel);
- fNewVel[0] = fOldVels[client][0] * fBhopMults[client];
- fNewVel[1] = fOldVels[client][1] * fBhopMults[client];
- fNewVel[2] *= fBhopZMults[client];
- PrintToConsole(client, "bHop boost: mult: %f, zmult: %f, old: %f %f, new: %f %f", fBhopMults[client], fBhopZMults[client], fOldVels[client][0], fOldVels[client][1], fNewVel[0], fNewVel[1]);
- TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fNewVel);
- }
- else
- {
- PrintToConsole(client, "Not allowed to bHop! Current time: %f, last: %f, diff: %f", GetTickedTime(), fMomentTouchedGround[client], GetTickedTime() - fMomentTouchedGround[client]);
- }
- }
- }
- ////////////////////////////////////////////////////////////
- //
- // OnGroundEntChanged
- //
- ////////////////////////////////////////////////////////////
- public OnGroundEntChanged(client)
- {
- iGroundEntities[client] = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
- if (iGroundEntities[client] == -1)
- {
- // PrintToConsole(client, "Ha! We are in the air!");
- // Air
- GetEntPropVector(client, Prop_Data, "m_vecVelocity", fOldVels[client]);
- bIsInAir[client] = true;
- }
- else
- {
- // Ground or entity
- if (bIsInAir[client])
- {
- fMomentTouchedGround[client] = GetTickedTime();
- bIsInAir[client] = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement