Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 51 additions & 53 deletions addons/sourcemod/scripting/shavit-unreal.sp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma semicolon 1
#pragma newdecls required

#define UNREALPHYS_VERSION "1.2"

Expand All @@ -11,6 +12,8 @@
#undef REQUIRE_PLUGIN
#include <shavit>

chatstrings_t gS_ChatStrings;

enum struct GunJumpConfig
{
char Weapon[64];
Expand All @@ -28,6 +31,7 @@ int g_TotalGuns;

// Dodging
float g_LastSideMove[MAXPLAYERS + 1][2];
float g_LastBoostPos[MAXPLAYERS + 1][3];
int g_LastDodgeTick[MAXPLAYERS + 1];
int g_LandingTick[MAXPLAYERS + 1];
int g_LastTapTick[MAXPLAYERS + 1];
Expand Down Expand Up @@ -92,9 +96,16 @@ public void OnPluginStart()
g_bUnrealClients[i] = IsStyleUnreal(Shavit_GetBhopStyle(i));
}
}

Shavit_OnChatConfigLoaded();
}

public void Shavit_OnChatConfigLoaded()
{
Shavit_GetChatStringsStruct(gS_ChatStrings);
}

public Action Command_Glock(int client, int args)
Action Command_Glock(int client, int args)
{
if(!IsValidClient(client))
return Plugin_Handled;
Expand All @@ -104,11 +115,11 @@ public Action Command_Glock(int client, int args)
IntToString(view_as<int>(g_USPUsers[client]), sCookie, 4);
SetClientCookie(client, gH_USPCookie, sCookie);

Shavit_PrintToChat(client, "Using Glock for Unreal.");
Shavit_PrintToChat(client, "Using %sglock %sfor Unreal", gS_ChatStrings.sVariable, gS_ChatStrings.sText);
return Plugin_Handled;
}

public Action Command_USP(int client, int args)
Action Command_USP(int client, int args)
{
if(!IsValidClient(client))
return Plugin_Handled;
Expand All @@ -118,7 +129,7 @@ public Action Command_USP(int client, int args)
IntToString(view_as<int>(g_USPUsers[client]), sCookie, 4);
SetClientCookie(client, gH_USPCookie, sCookie);

Shavit_PrintToChat(client, "Using USP for Unreal.");
Shavit_PrintToChat(client, "Using %sUSP %sfor Unreal", gS_ChatStrings.sVariable, gS_ChatStrings.sText);
return Plugin_Handled;
}

Expand Down Expand Up @@ -163,7 +174,7 @@ bool IsPlayerUsingUnreal(int client)
return g_bUnrealClients[client];
}

public void OnModifiedUnrealChanged(ConVar convar, const char[] oldValue, const char[] newValue)
void OnModifiedUnrealChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_bModifiedUnreal = GetConVarBool(g_hModifiedUnreal);
}
Expand Down Expand Up @@ -203,7 +214,7 @@ public void OnEntityCreated(int entity, const char[] classname)
}

// counter-act bhoptimer !Hud setting that you can use to make glocks burst fire
public Action Hook_GunTouchPost(int entity, int client)
Action Hook_GunTouchPost(int entity, int client)
{
if (1 <= client <= MaxClients && g_bUnrealClients[client])
{
Expand Down Expand Up @@ -234,24 +245,14 @@ void givegunstuff(int client)
GivePlayerItem(client, (GetEngineVersion() == Engine_CSGO) ? "weapon_usp_silencer" : "weapon_usp");
else
GivePlayerItem(client, "weapon_glock");

/*
if(weaponIndex != -1)
{
Handle hPack = CreateDataPack();
WritePackCell(hPack, GetClientUserId(client));
WritePackCell(hPack, EntIndexToEntRef(weaponIndex));
RequestFrame(NextFrame_EquipWeapon, hPack);
}
*/
}
}

public void Shavit_OnStyleChanged(int client, int oldStyle, int newStyle)
{
if(IsStyleUnreal(newStyle))
{
Shavit_PrintToChat(client, "Use !unrealglock or !unrealusp to set your default pistol.");
Shavit_PrintToChat(client, "Use %s!unrealglock %sor %s!unrealusp %sto set your default pistol", gS_ChatStrings.sVariable, gS_ChatStrings.sText, gS_ChatStrings.sVariable, gS_ChatStrings.sText);
g_bUnrealClients[client] = true;
givegunstuff(client);
}
Expand All @@ -261,22 +262,7 @@ public void Shavit_OnStyleChanged(int client, int oldStyle, int newStyle)
}
}

public void NextFrame_EquipWeapon(Handle pack)
{
ResetPack(pack);
int client = GetClientOfUserId(ReadPackCell(pack));
if(client != 0)
{
int weaponIndex = EntRefToEntIndex(ReadPackCell(pack));
if(weaponIndex != INVALID_ENT_REFERENCE)
{
EquipPlayerWeapon(client, weaponIndex);
}
}
delete pack;
}

public Action SM_ReloadGJ(int client, int args)
Action SM_ReloadGJ(int client, int args)
{
LoadGunJumpConfig();

Expand All @@ -285,9 +271,9 @@ public Action SM_ReloadGJ(int client, int args)
return Plugin_Handled;
}

FindWeaponConfigByWeaponName(const char[] sWeapon)
int FindWeaponConfigByWeaponName(const char[] sWeapon)
{
for(new i; i < g_TotalGuns; i++)
for(int i; i < g_TotalGuns; i++)
{
if(StrEqual(sWeapon, g_GunJumpConfig[i].Weapon))
{
Expand All @@ -300,15 +286,17 @@ FindWeaponConfigByWeaponName(const char[] sWeapon)

void LoadGunJumpConfig()
{
decl String:sPath[PLATFORM_MAX_PATH];
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/shavit-unreal.cfg");

new Handle:kv = CreateKeyValues("Gun Jump Settings");
Handle kv = CreateKeyValues("Gun Jump Settings");
FileToKeyValues(kv, sPath);

if(kv != INVALID_HANDLE)
{
new Key, bool:KeyExists = true, String:sKey[32];
int Key;
bool KeyExists = true;
char sKey[32];

do
{
Expand Down Expand Up @@ -348,33 +336,40 @@ void LoadGunJumpConfig()
}
}

public void Event_WeaponFire(Event event, const char[] name, bool dontBroadcast)
Action Event_WeaponFire(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));

if(!(0 < client <= MaxClients))
{
return;
return Plugin_Continue;
}

if(IsFakeClient(client))
{
return;
return Plugin_Continue;
}

if(!IsPlayerUsingUnreal(client))
{
return;
return Plugin_Continue;
}

float vPos[3];
GetClientEyePosition(client, vPos);

// Stop boost if position same as last boost (prevent the noclip in ground vel storage exploit)
if(g_LastBoostPos[client][0] == vPos[0] && g_LastBoostPos[client][1] == vPos[1] && g_LastBoostPos[client][2] == vPos[2])
return Plugin_Continue;

// Stop boost if invalid weapon
char sWeapon[64];
GetEventString(event, "weapon", sWeapon, sizeof(sWeapon));
if (StrContains(sWeapon, "weapon_") == -1)
Format(sWeapon, sizeof(sWeapon), "weapon_%s", sWeapon);
int GunConfig = FindWeaponConfigByWeaponName(sWeapon);
if(GunConfig == -1)
return;
return Plugin_Continue;

int slot2 = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
if (IsValidEntity(slot2))
Expand All @@ -385,9 +380,6 @@ public void Event_WeaponFire(Event event, const char[] name, bool dontBroadcast)
}
}

float vPos[3];
GetClientEyePosition(client, vPos);

float vAng[3];
GetClientEyeAngles(client, vAng);

Expand Down Expand Up @@ -419,13 +411,17 @@ public void Event_WeaponFire(Event event, const char[] name, bool dontBroadcast)
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", vVel);
AddVectors(vPush, vVel, vResult);
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vResult);

g_LastBoostPos[client][0] = vPos[0];
g_LastBoostPos[client][1] = vPos[1];
g_LastBoostPos[client][2] = vPos[2];
}
}

return;
return Plugin_Continue;
}

public bool TraceRayDontHitSelf(entity, mask, any:data)
bool TraceRayDontHitSelf(int entity, int mask, any data)
{
if(entity == data)
{
Expand Down Expand Up @@ -477,7 +473,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
g_LastButtons[client] = Unreal_GetButtons(client);
}

CheckForKeyTap(int client, float vel[3])
void CheckForKeyTap(int client, float vel[3])
{
if(GetEntityFlags(client) & FL_ONGROUND)
{
Expand Down Expand Up @@ -506,7 +502,7 @@ CheckForKeyTap(int client, float vel[3])
OnClientTappedKey(client, IN_BACK);
}

OnClientTappedKey(int client, int Key)
void OnClientTappedKey(int client, int Key)
{
if(g_LastTapKey[client] == Key && (float(GetGameTickCount())*GetTickInterval() - float(g_LastTapTick[client])*GetTickInterval() < 0.2))
{
Expand All @@ -517,7 +513,7 @@ OnClientTappedKey(int client, int Key)
g_LastTapTick[client] = GetGameTickCount();
}

OnClientDoubleTappedKey(int client, int Key)
void OnClientDoubleTappedKey(int client, int Key)
{
float vAng[3];
GetClientEyeAngles(client, vAng);
Expand Down Expand Up @@ -606,7 +602,7 @@ OnClientDoubleTappedKey(int client, int Key)
}
}

public Action Timer_Dodge(Handle timer, DataPack data)
Action Timer_Dodge(Handle timer, DataPack data)
{
ResetPack(data);
int client = ReadPackCell(data);
Expand All @@ -620,9 +616,11 @@ public Action Timer_Dodge(Handle timer, DataPack data)

g_bWaitingForGround[client] = true;
g_bCanDodge[client] = false;

return Plugin_Handled;
}

CheckForJumpTap(int client, int buttons)
void CheckForJumpTap(int client, int buttons)
{
if(!(GetEntityFlags(client) & FL_ONGROUND))
{
Expand Down