Skip to content

Commit

Permalink
Prevent perk removal on class change without suicide (fixes #56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil25 committed Oct 6, 2023
1 parent 1e1569c commit 5c5b550
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions scripting/rtd.sp
Original file line number Diff line number Diff line change
Expand Up @@ -778,17 +778,39 @@ public Action Event_PlayerDeath(Handle hEvent, const char[] sEventName, bool don
}

public Action Event_ClassChange(Handle hEvent, const char[] sEventName, bool dontBroadcast){
int client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
int iUserId = GetEventInt(hEvent, "userid");
int client = GetClientOfUserId(iUserId);
if(client == 0)
return Plugin_Continue;

int iClass = GetEventInt(hEvent, "class");
if(view_as<int>(TF2_GetPlayerClass(client)) == iClass)
return Plugin_Continue; // no actual class change in effect

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

ForceRemovePerk(client, RTDRemove_ClassChange);
DataPack hData = new DataPack();
hData.WriteCell(iUserId);
hData.WriteCell(iClass);
CreateTimer(0.0, Timer_ClassChangePost, hData);

return Plugin_Continue;
}

public Action Timer_ClassChangePost(Handle hTimer, DataPack hData){
hData.Reset();
int client = GetClientOfUserId(hData.ReadCell());
int iDesiredClass = hData.ReadCell();
CloseHandle(hData);

if(client > 0)
if(view_as<int>(TF2_GetPlayerClass(client)) == iDesiredClass)
ForceRemovePerk(client, RTDRemove_ClassChange);

return Plugin_Stop;
}

public Action Event_RoundActive(Handle hEvent, const char[] sEventName, bool dontBroadcast){
if(g_bCvarPluginEnabled && (g_iCvarChat & CHAT_AD) && IsRTDInRound())
RTDPrintAll("%T", "RTD2_Ad", LANG_SERVER, 0x03, 0x01);
Expand Down

0 comments on commit 5c5b550

Please sign in to comment.