Skip to content

Commit

Permalink
Rebalance Godmode
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil25 committed Oct 6, 2023
1 parent 7b553af commit 3562e02
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 39 deletions.
7 changes: 5 additions & 2 deletions scripting/rtd.sp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ public void OnClientDisconnect(int client){
ForceRemovePerk(client, RTDRemove_Disconnect);

g_hRollers.Reset(client);

Forward_OnClientDisconnect(client);
}

public void OnAllPluginsLoaded(){
Expand Down Expand Up @@ -763,10 +765,11 @@ public Action Event_PlayerDeath(Handle hEvent, const char[] sEventName, bool don
if(client == 0)
return Plugin_Continue;

int flags = GetEventInt(hEvent, "death_flags");
if(flags & FLAG_FEIGNDEATH)
if(GetEventInt(hEvent, "death_flags") & FLAG_FEIGNDEATH)
return Plugin_Continue;

Forward_OnPlayerDeath(client);

if(!g_hRollers.GetInRoll(client))
return Plugin_Continue;

Expand Down
23 changes: 23 additions & 0 deletions scripting/rtd/manager.sp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ void Forward_OnClientPutInServer(int client){
}


/*
• Editing Forward_OnClientDisconnect() is OPTIONAL
• This is a forward of OnClientDisconnect() from rtd.sp
*/
void Forward_OnClientDisconnect(int client){
Godmode_OnClientDisconnect(client);
}


/*
• Editing Forward_Voice() is OPTIONAL
• This is a forward of Listener_Voice() from rtd.sp
Expand Down Expand Up @@ -127,6 +136,17 @@ void Forward_OnEntityCreated(int iEntity, const char[] sClassname){
}


/*
• Editing Forward_OnPlayerDeath() is OPTIONAL
• This is a forward of Event_PlayerDeath() from rtd.sp
• Client is guaranteed to be valid.
• Actual death, Dead Ringer feign does not count.
*/
void Forward_OnPlayerDeath(int client){
Godmode_OnPlayerDeath(client);
}


/*
• Editing Forward_Resupply() is OPTIONAL
• Client is guaranteed to be valid
Expand All @@ -144,6 +164,7 @@ void Forward_Resupply(int client){
• Client is guaranteed to be valid
*/
void Forward_PlayerHurt(int client, Handle hEvent){
Godmode_PlayerHurt(client, hEvent);
Blind_PlayerHurt(hEvent);
ScaryBullets_PlayerHurt(client, hEvent);
EyeForAnEye_PlayerHurt(hEvent);
Expand All @@ -166,6 +187,7 @@ void Forward_OnGameFrame(){
• It's a forward of TF2_OnConditionAdded() from rtd.sp
*/
void Forward_OnConditionAdded(int client, TFCond condition){
Godmode_OnConditionAdded(client, condition);
FullRifleCharge_OnConditionAdded(client, condition);
ForcedTaunt_OnConditionAdded(client, condition);
}
Expand All @@ -176,6 +198,7 @@ void Forward_OnConditionAdded(int client, TFCond condition){
• It's a forward of TF2_OnConditionRemoved() from rtd.sp
*/
void Forward_OnConditionRemoved(int client, TFCond condition){
Godmode_OnConditionRemoved(client, condition);
FullUbercharge_OnConditionRemoved(client, condition);
FunnyFeeling_OnConditionRemoved(client, condition);
ForcedTaunt_OnConditionRemoved(client, condition);
Expand Down
35 changes: 10 additions & 25 deletions scripting/rtd/perks/blind.sp
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,19 @@ public void Blind_ApplyPerk(int client, int iAlpha){

int iOtherTeam = GetOppositeTeamOf(client);

for(int i = 1; i <= MaxClients; ++i){
Handle hAnnotation = Blind_CreateEventForPlayer("show_annotation", client, i, iOtherTeam);
if (hAnnotation == INVALID_HANDLE)
continue;

SetEventInt(hAnnotation, "follow_entindex", i);
SetEventInt(hAnnotation, "id", GetUniqueId(client, i));
SetEventFloat(hAnnotation, "lifetime", 99999.0);
SetEventBool(hAnnotation, "show_distance", false);
SetEventString(hAnnotation, "text", "!");
SetEventInt(hAnnotation, "visibilityBitfield", (1 << client));
FireEvent(hAnnotation);
}
for(int i = 1; i <= MaxClients; ++i)
if(Blind_IsValidTarget(client, i, iOtherTeam))
ShowAnnotationFor(client, i, "<!>");
}

public void Blind_RemovePerk(int client){
Blind_SendFade(client, 0);

int iOtherTeam = GetOppositeTeamOf(client);

for(int i = 1; i <= MaxClients; ++i){
Handle hAnnotation = Blind_CreateEventForPlayer("hide_annotation", client, i, iOtherTeam);
if (hAnnotation == INVALID_HANDLE)
continue;

SetEventInt(hAnnotation, "id", GetUniqueId(client, i));
FireEvent(hAnnotation);
}
for(int i = 1; i <= MaxClients; ++i)
if(Blind_IsValidTarget(client, i, iOtherTeam))
HideAnnotationFor(client, i);
}

void Blind_PlayerHurt(Handle hEvent){
Expand All @@ -83,14 +68,14 @@ void Blind_PlayerHurt(Handle hEvent){
Blind_SendFade(iAttacker, GetIntCache(iAttacker), true);
}

Handle Blind_CreateEventForPlayer(char sEvent[32], int client, int iTarget, int iTargetTeam){
bool Blind_IsValidTarget(int client, int iTarget, int iTargetTeam){
if(iTarget == client || !IsClientInGame(iTarget))
return INVALID_HANDLE;
return false;

if(GetClientTeam(iTarget) != iTargetTeam)
return INVALID_HANDLE;
return false;

return CreateEvent(sEvent);
return true;
}

void Blind_SendFade(const int client, const int iAlpha, const bool bFast=false){
Expand Down
184 changes: 173 additions & 11 deletions scripting/rtd/perks/godmode.sp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,96 @@

#define GODMODE_PARTICLE "powerup_supernova_ready"

#define GODMODE_DOWN_TEXT "(⋆⭒˚。⋆) ⬇"
#define GODMODE_DOWN_SOUND "misc/doomsday_cap_close_start.wav"
#define GODMODE_WARN_TEXT "<!>"
#define GODMODE_WARN_SOUND "replay/snip.wav"

#define GODMODE_BULLET_HIT "versus_door_sparks_floaty"

#define UBER_MODE 0
#define ENEMIES 1

int g_iInGodmode = 0;
int g_iGodmodeId = 0;

methodmap GodmodeEnemies{
public GodmodeEnemies(const int client=0){
return view_as<GodmodeEnemies>(GetIntCache(client, ENEMIES));
}

public GodmodeEnemies Add(const int client, const int iEnemy){
if(client == iEnemy || this.Contains(iEnemy))
return this;

ShowAnnotationFor(iEnemy, client, GODMODE_DOWN_TEXT, GODMODE_DOWN_SOUND);

if(!TF2_IsPlayerInCondition(iEnemy, TFCond_Cloaked) && !TF2_IsPlayerInCondition(iEnemy, TFCond_Disguised)){
ShowAnnotationFor(client, iEnemy, GODMODE_WARN_TEXT, GODMODE_WARN_SOUND);

int iBeam = ConnectWithBeam(iEnemy, client, 150, 255, 150, 1.0, 1.0, 10.0);
if(iBeam > MaxClients){
KILL_ENT_IN(iBeam,0.2)
}
}

return view_as<GodmodeEnemies>(view_as<int>(this) | (1 << iEnemy));
}

public GodmodeEnemies Remove(const int client, const int iEnemy){
if(!this.Contains(iEnemy))
return this;

this.RemoveAnnotation(client, iEnemy);
return view_as<GodmodeEnemies>(view_as<int>(this) & ~(1 << iEnemy));
}

public void RemoveForAll(const int iEnemy){
for(int client = 1; client <= MaxClients; ++client)
if(CheckClientPerkCache(client, g_iGodmodeId))
GodmodeEnemies(client).Remove(client, iEnemy).Save(client);
}

public void RemoveAnnotation(const int client, const int iEnemy){
HideAnnotationFor(client, iEnemy);
HideAnnotationFor(iEnemy, client);
}

public void HideAnnotationForAll(const int iEnemy){
for(int client = 1; client <= MaxClients; ++client)
if(CheckClientPerkCache(client, g_iGodmodeId)) // checking for enemy unnecesary here
HideAnnotationFor(client, iEnemy);
}

public void ShowAnnotationForAll(const int iEnemy){
for(int client = 1; client <= MaxClients; ++client)
if(CheckClientPerkCache(client, g_iGodmodeId) && GodmodeEnemies(client).Contains(iEnemy))
ShowAnnotationFor(client, iEnemy, GODMODE_WARN_TEXT);
}

public bool Contains(const int iEnemy){
return view_as<bool>(view_as<int>(this) & (1 << iEnemy));
}

public void Init(const int client){
SetIntCache(client, 0, ENEMIES);
}

public void Save(const int client){
SetIntCache(client, view_as<int>(this), ENEMIES);
}
}

public void Godmode_Call(int client, Perk perk, bool bApply){
if(bApply) Godmode_ApplyPerk(client, perk);
else Godmode_RemovePerk(client);
}

void Godmode_ApplyPerk(int client, Perk perk){
g_iGodmodeId = perk.Id;
SetClientPerkCache(client, g_iGodmodeId);
SetFloatCache(client, 0.0);

float fParticleOffset[3] = {0.0, 0.0, 12.0};

SetEntCache(client, CreateParticle(client, GODMODE_PARTICLE, _, _, fParticleOffset));
Expand All @@ -42,37 +124,117 @@ void Godmode_ApplyPerk(int client, Perk perk){
}

int iUber = perk.GetPrefCell("uber");
SetIntCache(client, iUber);
SetIntCache(client, iUber, UBER_MODE);
if(iUber) TF2_AddCondition(client, TFCond_UberchargedCanteen);

GodmodeEnemies(client).Init(client);

g_iInGodmode |= client;
}

void Godmode_RemovePerk(int client){
UnsetClientPerkCache(client, g_iGodmodeId);

KillEntCache(client);

SDKUnhook(client, SDKHook_OnTakeDamage, Godmode_OnTakeDamage_NoSelf);
SDKUnhook(client, SDKHook_OnTakeDamage, Godmode_OnTakeDamage_Pushback);
SDKUnhook(client, SDKHook_OnTakeDamage, Godmode_OnTakeDamage_Self);

if(GetIntCacheBool(client))
if(GetIntCacheBool(client, UBER_MODE))
TF2_RemoveCondition(client, TFCond_UberchargedCanteen);

GodmodeEnemies hEnemies = GodmodeEnemies(client);
for(int i = 1; i <= MaxClients; ++i)
if(IsClientInGame(i) && hEnemies.Contains(i))
hEnemies.RemoveAnnotation(client, i);

g_iInGodmode &= ~client;
}

public Action Godmode_OnTakeDamage_NoSelf(int client, int &iAttacker){
return Plugin_Handled;
void Godmode_SpawnDeflectEffect(int client, int iType, float fPos[3]){
float fTime = GetEngineTime();
if(fTime < GetFloatCache(client) + 0.1)
return;

SetFloatCache(client, fTime);

if(iType & (DMG_BULLET | DMG_CLUB)){
CreateEffect(fPos, GODMODE_BULLET_HIT, 0.2);
return;
}

if(iType & (DMG_BUCKSHOT)){
float fShotPos[3];
for(int i = 0; i < 3; ++i){
fShotPos[0] = fPos[0] + GetRandomFloat(-10.0, 10.0);
fShotPos[1] = fPos[1] + GetRandomFloat(-10.0, 10.0);
fShotPos[2] = fPos[2] + GetRandomFloat(-10.0, 10.0);
CreateEffect(fShotPos, GODMODE_BULLET_HIT, 0.2);
}
}
}

Action Godmode_OnTakeDamage_Common(const int client, iAttacker, const int iType, float fPos[3]){
if(GodmodeEnemies(client).Contains(iAttacker)){
return Plugin_Continue;
}

Godmode_SpawnDeflectEffect(client, iType, fPos);
return Plugin_Handled
}

public Action Godmode_OnTakeDamage_NoSelf(int client, int &iAttacker, int &iInflictor, float &fDamage, int &iType, int &iWeapon, float fForce[3], float fPos[3], int iCustom){
return client == iAttacker ? Plugin_Handled : Godmode_OnTakeDamage_Common(client, iAttacker, iType, fPos);
}

public Action Godmode_OnTakeDamage_Pushback(int client, int &iAttacker, int &iInflictor, float &fDamage, int &iType, int &iWeapon, float fForce[3], float fPos[3], int iCustom){
if(client == iAttacker){
TF2_AddCondition(client, TFCond_Bonked, 0.01);
return Plugin_Continue;
}
return Godmode_OnTakeDamage_Common(client, iAttacker, iType, fPos);
}

public Action Godmode_OnTakeDamage_Self(int client, int &iAttacker, int &iInflictor, float &fDamage, int &iType, int &iWeapon, float fForce[3], float fPos[3], int iCustom){
return client == iAttacker ? Plugin_Continue : Godmode_OnTakeDamage_Common(client, iAttacker, iType, fPos);
}

public Action Godmode_OnTakeDamage_Pushback(int client, int &iAttacker){
if(client != iAttacker)
return Plugin_Handled;
void Godmode_OnClientDisconnect(const int client){
GodmodeEnemies().RemoveForAll(client);
}

TF2_AddCondition(client, TFCond_Bonked, 0.01);
return Plugin_Continue;
void Godmode_OnPlayerDeath(const int client){
GodmodeEnemies().RemoveForAll(client);
}

public Action Godmode_OnTakeDamage_Self(int client, int &iAttacker){
return client == iAttacker ? Plugin_Continue : Plugin_Handled;
void Godmode_OnConditionAdded(const int client, const TFCond condition){
switch(condition){
case TFCond_Cloaked, TFCond_Disguised:
GodmodeEnemies().HideAnnotationForAll(client);
}
}

void Godmode_OnConditionRemoved(const int client, const TFCond condition){
switch(condition){
case TFCond_Cloaked, TFCond_Disguised:
GodmodeEnemies().ShowAnnotationForAll(client);
}
}

void Godmode_PlayerHurt(const int client, Handle hEvent){
int iAttacker = GetClientOfUserId(GetEventInt(hEvent, "attacker"));
if(0 < iAttacker <= MaxClients && CheckClientPerkCache(iAttacker, g_iGodmodeId) && GetEventInt(hEvent, "health") > 1){
GodmodeEnemies(iAttacker).Add(iAttacker, client).Save(iAttacker);
}
}

#undef GODMODE_DOWN_TEXT
#undef GODMODE_DOWN_SOUND
#undef GODMODE_WARN_TEXT
#undef GODMODE_WARN_SOUND

#undef GODMODE_BULLET_HIT

#undef UBER_MODE
#undef ENEMIES
Loading

0 comments on commit 3562e02

Please sign in to comment.