Created
April 8, 2015 15:01
-
-
Save rootindex/332a70fd63ab0df17c22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sourcemod> | |
#include <sdktools> | |
#include <sdkhooks> | |
//#include <sendproxy> | |
#define WATER_LEVEL_DRY 0 | |
#define WATER_LEVEL_FEET 1 | |
#define WATER_LEVEL_HALF 2 | |
#define WATER_LEVEL_FULL 3 | |
new Handle:sv_airaccelerate | |
new Handle:sv_enablebunnyhopping | |
new Handle:sv_staminajumpcost | |
new Handle:sv_staminalandcost | |
new Handle:mp_flashlight | |
new Handle:surf_spawn_protect_time | |
new Float:fLastThinkUpdateAt | |
new Float:fClientLastSpawnedAt[MAXPLAYERS+1] | |
new Float:fClientLastJumpedAt[MAXPLAYERS+1] | |
new m_flStamina, m_nWaterLevel | |
new bool:bClientIsProtected[MAXPLAYERS+1] | |
new bool:bClientWaterLevelHooked[MAXPLAYERS+1] | |
public Plugin:myinfo = | |
{ | |
name = "Intoxicated Surf", | |
author = "bawNg", | |
description = "Makes CS:GO surfable", | |
version = "0.4", | |
url = "http://intoxicated.co.za" | |
} | |
public OnPluginStart() | |
{ | |
if ((m_nWaterLevel = FindSendPropOffs("CCSPlayer", "m_nWaterLevel")) == -1) SetFailState("Failed to find CCSPlayer::m_nWaterLevel offset") | |
if ((m_flStamina = FindSendPropOffs("CCSPlayer", "m_flStamina")) == -1) SetFailState("Failed to find CCSPlayer::m_flStamina offset") | |
surf_spawn_protect_time = CreateConVar("surf_spawn_protect_time", "0.2", "Time a player is protected after they spawn") | |
HookEvent("player_spawn", OnPlayerSpawn) | |
HookEvent("weapon_fire", OnWeaponFire) | |
Initialize() | |
} | |
public OnMapStart() | |
{ | |
new cs_player_manager = FindEntityByClassname(0, "cs_player_manager") | |
SDKHook(cs_player_manager, SDKHook_ThinkPost, OnThinkPost) | |
Initialize() | |
} | |
Initialize() | |
{ | |
sv_airaccelerate = FindConVar("sv_airaccelerate") | |
sv_enablebunnyhopping = FindConVar("sv_enablebunnyhopping") | |
sv_staminajumpcost = FindConVar("sv_staminajumpcost") | |
sv_staminalandcost = FindConVar("sv_staminalandcost") | |
mp_flashlight = FindConVar("mp_flashlight") | |
SetConVarInt(sv_airaccelerate, 150) | |
SetConVarInt(sv_enablebunnyhopping, 1) | |
SetConVarFloat(sv_staminajumpcost, 0) | |
SetConVarFloat(sv_staminalandcost, 0) | |
SetConVarFloat(mp_flashlight, 1) | |
for (new client = 1; client <= MaxClients; client++) { | |
if (!IsClientInGame(client) || bClientWaterLevelHooked[client]) continue | |
//SendProxy_Hook(client, "m_nWaterLevel", Prop_Int, OnClientWaterLevel) | |
bClientWaterLevelHooked[client] = true | |
} | |
} | |
public OnClientPutInServer(client) | |
{ | |
if (!bClientWaterLevelHooked[client]) { | |
//SendProxy_Hook(client, "m_nWaterLevel", Prop_Int, OnClientWaterLevel) | |
bClientWaterLevelHooked[client] = true | |
} | |
} | |
public OnClientDisconnect(client) | |
{ | |
//SendProxy_Unhook(client, "m_nWaterLevel", OnClientWaterLevel) | |
bClientWaterLevelHooked[client] = false | |
fClientLastJumpedAt[client] = 0.0 | |
fClientLastSpawnedAt[client] = 0.0 | |
} | |
public OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) | |
{ | |
new client = GetClientOfUserId(GetEventInt(event, "userid")) | |
if (!client || !IsClientInGame(client)) return | |
if (1 < GetClientTeam(client) <= 3) { | |
fClientLastSpawnedAt[client] = GetEngineTime() | |
SetEntProp(client, Prop_Data, "m_takedamage", 0, 1) | |
SetEntityRenderColor(client, 255, 0, 0, 200) | |
CreateTimer(GetConVarFloat(surf_spawn_protect_time), Timer_DisableSpawnProtection, client) | |
bClientIsProtected[client] = true | |
} | |
} | |
public OnWeaponFire(Handle:event, const String:name[], bool:dontBroadcast) | |
{ | |
new client = GetClientOfUserId(GetEventInt(event, "userid")) | |
if (!IsClientInGame(client) || !IsPlayerAlive(client)) return | |
if (bClientIsProtected[client]) { | |
fClientLastSpawnedAt[client] -= 10.0 | |
Timer_DisableSpawnProtection(INVALID_HANDLE, client) | |
} | |
} | |
public Action:Timer_DisableSpawnProtection(Handle:timer, any:client) | |
{ | |
if (!IsClientInGame(client) || !IsPlayerAlive(client)) return | |
SetEntProp(client, Prop_Data, "m_takedamage", 2, 1) | |
SetEntityRenderColor(client, 255, 255, 255, 255) | |
bClientIsProtected[client] = false | |
} | |
Float:TimeSincePlayerSpawned(client) | |
{ | |
return GetEngineTime() - fClientLastSpawnedAt[client] | |
} | |
public OnThinkPost(entity) | |
{ | |
if (fLastThinkUpdateAt && GetEngineTime() - fLastThinkUpdateAt < 0.05) return | |
fLastThinkUpdateAt = GetEngineTime() | |
new Float:spawn_protect_time = GetConVarFloat(surf_spawn_protect_time) | |
for (new client = 1; client <= MaxClients; client++) { | |
if (!IsClientInGame(client) || !IsPlayerAlive(client)) continue | |
if (fClientLastSpawnedAt[client]) { | |
if (bClientIsProtected[client]) | |
PrintCenterText(client, "Your spawn protection ends in %0.2f seconds", spawn_protect_time - TimeSincePlayerSpawned(client)) | |
else { | |
PrintCenterText(client, "You are no longer protected") | |
CreateTimer(0.5, Timer_ShowClientIsNoLongerProtected, client) | |
fClientLastSpawnedAt[client] = 0.0 | |
} | |
} | |
//if (GetEntData(client, iWaterLevel) == WATER_LEVEL_FEET) | |
// SetEntData(client, iWaterLevel, WATER_LEVEL_DRY, 4, true) | |
} | |
} | |
public Action:Timer_ShowClientIsNoLongerProtected(Handle:timer, any:client) | |
{ | |
if (!IsClientInGame(client) || !IsPlayerAlive(client)) return | |
if (fClientLastSpawnedAt[client]) return | |
PrintHintText(client, "You are no longer protected") | |
} | |
/*public OnGameFrame() | |
{ | |
new Float:now = GetEngineTime() | |
for (new i = 1; i <= MaxClients; i++) { | |
if (!fClientLastJumpedAt[i]) continue | |
if (now - fClientLastJumpedAt[i] < 0.3) { | |
if (GetEntData(client, m_nWaterLevel) == WATER_LEVEL_FEET) { | |
} | |
continue | |
} | |
fClientLastJumpedAt[i] = 0.0 | |
} | |
}*/ | |
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon) | |
{ | |
if (!IsPlayerAlive(client)) return Plugin_Continue | |
/*if (buttons & IN_JUMP) { | |
if (!(GetEntityFlags(client) & FL_ONGROUND)) { | |
// In air | |
if (!(GetEntityMoveType(client) & MOVETYPE_LADDER)) { | |
// Not on ladder | |
fClientLastJumpedAt[client] = GetEngineTime() | |
new water_level = GetEntData(client, m_nWaterLevel) | |
if (water_level <= WATER_LEVEL_FEET) { | |
// Not swimming | |
buttons &= ~IN_JUMP | |
return Plugin_Changed | |
} | |
} | |
} | |
}*/ | |
if ((GetEntityMoveType(client) & MOVETYPE_LADDER)) return Plugin_Continue | |
if (GetEntData(client, m_nWaterLevel) > WATER_LEVEL_FEET) return Plugin_Continue | |
new flags = GetEntityFlags(client) | |
new Float:now = GetEngineTime() | |
new bool:is_on_ground = flags & FL_ONGROUND | |
if (buttons & IN_JUMP) { | |
fClientLastJumpedAt[client] = now | |
if (is_on_ground) return Plugin_Continue | |
buttons &= ~IN_JUMP | |
} | |
else if (fClientLastJumpedAt[client]) { | |
if (now - fClientLastJumpedAt[client] < 0.25) { | |
// jump was down recently | |
if (is_on_ground) { | |
//PrintToChat(client, "[DEBUG] Hit ground after %f", now - fClientLastJumpedAt[client]) | |
buttons |= IN_JUMP | |
fClientLastJumpedAt[client] = 0.0 | |
} | |
else { | |
SetEntDataFloat(client, m_flStamina, 0.0, true) | |
buttons &= ~IN_JUMP | |
} | |
} | |
else | |
fClientLastJumpedAt[client] = 0.0 | |
} | |
return Plugin_Changed | |
} | |
public Action:OnClientWaterLevel(entity, const String:prop_name[], &value, element) | |
{ | |
if (value == WATER_LEVEL_FEET) { | |
value = WATER_LEVEL_DRY | |
return Plugin_Changed | |
} | |
return Plugin_Continue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment