Raised This Month: $32 Target: $400
 8% 

Modify Retakes by Splewis


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
decentLIVE
Junior Member
Join Date: Aug 2015
Old 09-19-2016 , 21:48   Modify Retakes by Splewis
Reply With Quote #1

First, I'm willing to pay/donate to anyone that can help me

The plugin I want to modify:
https://github.com/splewis/csgo-retakes

My sm plugins list
Code:
"Admin File Reader" (1.7.3-dev+5301) by AlliedModders LLC
"Admin Help" (1.7.3-dev+5301) by AlliedModders LLC
"Admin Menu" (1.7.3-dev+5301) by AlliedModders LLC
"Anti-Flood" (1.7.3-dev+5301) by AlliedModders LLC
"Basic Chat" (1.7.3-dev+5301) by AlliedModders LLC
"Basic Comm Control" (1.7.3-dev+5301) by AlliedModders LLC
"Basic Commands" (1.7.3-dev+5301) by AlliedModders LLC
"Basic Info Triggers" (1.7.3-dev+5301) by AlliedModders LLC
"Basic Votes" (1.7.3-dev+5301) by AlliedModders LLC
"Client Preferences" (1.7.3-dev+5301) by AlliedModders LLC
"[Source 2013] Custom Chat Colors" (3.1.0-CSGO) by Dr. McKay | Mitchell
"Dynamic" (0.0.16) by Neuro Toxin
"Fun Commands" (1.7.3-dev+5301) by AlliedModders LLC
"Fun Votes" (1.7.3-dev+5301) by AlliedModders LLC
"gameME Plugin" (4.7.2) by TTS Oetzel & Goerz GmbH
"High Ping Kicker - Lite Edition" (1.0.0.1) by Liam
"HANSE Reserved Slots | Mod by H3bus for redirect" (2.2) by red!| H3bus
"MapChooser Extended" (1.10.2) by Powerlord, Zuko, and AlliedModders LLC
"Nextmap" (1.7.3-dev+5301) by AlliedModders LLC
"Map Nominations Extended" (1.10.0) by Powerlord and AlliedModders LLC
"Block Report" (0.1) by SM9
"Player Commands" (1.7.3-dev+5301) by AlliedModders LLC
"Radio Spam Block" (1.0.1csgofix) by exvel,TonyBaretta
"Server Redirect" (0.2.6) by H3bus
"Server Redirect: Ask connect in console" (0.2.5) by H3bus
"CS:GO Retakes" (0.3.2) by splewis
"CS:GO Retakes: Customised Weapon Allocator for splewis retakes plugin" (0.3.2) by BatMen
"Rock The Vote Extended" (1.10.0) by Powerlord and AlliedModders LLC
"Server Advertisement" (2.4b) by ESK0
"Simple Chat Processor (Redux)" (1.1.5) by Simple Plugins, Mini
"SMACBANS: Block" (0.2.0) by SMACBANS Team
"Force HTML MOTDs" (1.0.5) by Twisted|Panda
How the plugin works:
9 Players play 'retakes' while two players sit in spectator in a waiting queue. When a 'player' leaves the game the first person in the waiting queue gets moved from spectator into the game.

The addition I want:
If a player with a specific admin flag (preferably controlled by a cvar) joines he gets placed into the waiting queue. At the end of the round, just before the plugin respawns all the players, a random player swaps places with the admin waiting in the queue. The admin is now a 'player' and the player that was swapped gets placed into 'spectator' and is now waiting in the queue.
It would also have to use sourcemods immunity values, so they didn't swap out another admin.

Hopefully I have explained what I am looking for clearly and given you all enough information. If anyone can do this I am willing to pay. Thanks for reading.
decentLIVE is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 09-20-2016 , 14:39   Re: Modify Retakes by Splewis
Reply With Quote #2

Check this, not tested through.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <smlib>

#include "priorityqueue.inc"
#include "queue.inc"
#include "restorecvars.inc"
#include "retakes.inc"

#undef REQUIRE_PLUGIN
#tryinclude <pugsetup>

#pragma semicolon 1
#pragma newdecls required


/***********************
 *                     *
 *   Global variables  *
 *                     *
 ***********************/

/**
 * The general way players are put on teams is using a system of
 * "round points". Actions during a round earn points, and at the end of the round,
 * players are put into a priority queue using their rounds as the value.
 */
#define POINTS_KILL 50
#define POINTS_DMG 1
#define POINTS_BOMB 50
#define POINTS_LOSS 5000

#define SITESTRING(%1) ((%1) == BombsiteA ? "A" : "B")
#define TEAMSTRING(%1) ((%1) == CS_TEAM_CT ? "CT" : "T")

bool g_Enabled true;
Handle g_SavedCvars INVALID_HANDLE;

/** Client variable arrays **/
int g_SpawnIndices[MAXPLAYERS 1] = 0;
int g_RoundPoints[MAXPLAYERS 1] = 0;
bool g_PluginTeamSwitch[MAXPLAYERS 1] = false;
int g_Team[MAXPLAYERS 1] = 0;

/** Queue Handles **/
Handle g_hWaitingQueue INVALID_HANDLE;
Handle g_hRankingQueue INVALID_HANDLE;

/** ConVar handles **/
ConVar g_EnabledCvar;
ConVar g_hAutoTeamsCvar;
ConVar g_hCvarVersion;
ConVar g_hEditorEnabled;
ConVar g_hMaxPlayers;
ConVar g_hRatioConstant;
ConVar g_hRoundsToScramble;
ConVar g_hRoundTime;
ConVar g_hUseRandomTeams;
ConVar g_WarmupTimeCvar;

/** Editing global variables **/
bool g_EditMode false;
bool g_DirtySpawns false// whether the spawns have been edited since loading from the file

/** Win-streak data **/
bool g_ScrambleSignal false;
int g_WinStreak 0;
int g_RoundCount 0;

/** Stored info from the spawns config file **/
#define MAX_SPAWNS 256
int g_NumSpawns 0;
bool g_SpawnDeleted[MAX_SPAWNS];
float g_SpawnPoints[MAX_SPAWNS][3];
float g_SpawnAngles[MAX_SPAWNS][3];
Bombsite g_SpawnSites[MAX_SPAWNS];
int g_SpawnTeams[MAX_SPAWNS];
SpawnType g_SpawnTypes[MAX_SPAWNS];

/** Spawns being edited per-client **/
int g_EditingSpawnTeams[MAXPLAYERS 1];
SpawnType g_EditingSpawnTypes[MAXPLAYERS 1];

/** Bomb-site stuff read from the map **/
ArrayList g_SiteMins;
ArrayList g_SiteMaxs;

/** Data created for the current retake scenario **/
Bombsite g_Bombsite;
bool g_SpawnTaken[MAX_SPAWNS];
char g_PlayerPrimary[MAXPLAYERS 1][WEAPON_STRING_LENGTH];
char g_PlayerSecondary[MAXPLAYERS 1][WEAPON_STRING_LENGTH];
char g_PlayerNades[MAXPLAYERS 1][NADE_STRING_LENGTH];
int g_PlayerHealth[MAXPLAYERS 1];
int g_PlayerArmor[MAXPLAYERS 1];
bool g_PlayerHelmet[MAXPLAYERS 1];
bool g_PlayerKit[MAXPLAYERS 1];

/** Per-round information about the player setup **/
bool g_bombPlantSignal false;
bool g_bombPlanted false;
int g_BombOwner = -1;
int g_NumCT 0;
int g_NumT 0;
int g_ActivePlayers 0;
bool g_RoundSpawnsDecided false// spawns are lazily decided on the first player spawn event

/** Forwards **/
Handle g_hOnGunsCommand INVALID_HANDLE;
Handle g_hOnPostRoundEnqueue INVALID_HANDLE;
Handle g_hOnPreRoundEnqueue INVALID_HANDLE;
Handle g_hOnTeamSizesSet INVALID_HANDLE;
Handle g_hOnTeamsSet INVALID_HANDLE;
Handle g_OnFailToPlant INVALID_HANDLE;
Handle g_OnRoundWon INVALID_HANDLE;
Handle g_OnSitePicked INVALID_HANDLE;
Handle g_OnWeaponsAllocated INVALID_HANDLE;

#include "retakes/generic.sp"
#include "retakes/editor.sp"
#include "retakes/editor_commands.sp"
#include "retakes/editor_menus.sp"
#include "retakes/natives.sp"
#include "retakes/spawns.sp"



/***********************
 *                     *
 * Sourcemod functions *
 *                     *
 ***********************/

public Plugin myinfo =  {
    
name "CS:GO Retakes"
    
author "splewis"
    
description "CS:GO Retake practice"
    
version PLUGIN_VERSION
    
url "https://github.com/splewis/csgo-retakes"
};

public 
void OnPluginStart() {
    
LoadTranslations("common.phrases");
    
LoadTranslations("retakes.phrases");
    
    
/** ConVars **/
    
g_EnabledCvar CreateConVar("sm_retakes_enabled""1""Whether the plugin is enabled");
    
g_hAutoTeamsCvar CreateConVar("sm_retakes_auto_set_teams""1""Whether retakes is allowed to automanage team balance");
    
g_hEditorEnabled CreateConVar("sm_retakes_editor_enabled""1""Whether the editor can be launched by admins");
    
g_hMaxPlayers CreateConVar("sm_retakes_maxplayers""9""Maximum number of players allowed in the game at once."_true2.0);
    
g_hRatioConstant CreateConVar("sm_retakes_ratio_constant""0.425""Ratio constant for team sizes.");
    
g_hRoundsToScramble CreateConVar("sm_retakes_scramble_rounds""10""Consecutive terrorist wins to cause a team scramble.");
    
g_hRoundTime CreateConVar("sm_retakes_round_time""12""Round time left in seconds.");
    
g_hUseRandomTeams CreateConVar("sm_retakes_random_teams""0""If set to 1, this will randomize the teams every round.");
    
g_WarmupTimeCvar CreateConVar("sm_retakes_warmuptime""25""Warmup time on map starts");
    
    
HookConVarChange(g_EnabledCvarEnabledChanged);
    
    
/** Create/Execute retakes cvars **/
    
AutoExecConfig(true"retakes""sourcemod/retakes");
    
    
g_hCvarVersion CreateConVar("sm_retakes_version"PLUGIN_VERSION"Current retakes version"FCVAR_SPONLY FCVAR_REPLICATED FCVAR_NOTIFY FCVAR_DONTRECORD);
    
g_hCvarVersion.SetString(PLUGIN_VERSION);
    
    
/** Command hooks **/
    
AddCommandListener(Command_JoinTeam"jointeam");
    
    
/** Admin/editor commands **/
    
RegAdminCmd("sm_scramble"Command_ScrambleTeamsADMFLAG_CHANGEMAP"Sets teams to scramble on the next round");
    
RegAdminCmd("sm_scrambleteams"Command_ScrambleTeamsADMFLAG_CHANGEMAP"Sets teams to scramble on the next round");
    
    
RegAdminCmd("sm_edit"Command_EditSpawnsADMFLAG_CHANGEMAP"Launches the retakes spawn editor mode");
    
RegAdminCmd("sm_spawns"Command_EditSpawnsADMFLAG_CHANGEMAP"Launches the retakes spawn editor mode");
    
    
RegAdminCmd("sm_new"Command_AddSpawnADMFLAG_CHANGEMAP"Creates a new retakes spawn");
    
RegAdminCmd("sm_newspawn"Command_AddSpawnADMFLAG_CHANGEMAP"Creates a new retakes spawn");
    
RegAdminCmd("sm_delete"Command_DeleteSpawnADMFLAG_CHANGEMAP"Deletes the nearest retakes spawn");
    
RegAdminCmd("sm_deletespawn"Command_DeleteSpawnADMFLAG_CHANGEMAP"Deletes the nearest retakes spawn"); \
    
RegAdminCmd("sm_deletemapspawns"Command_DeleteMapSpawnsADMFLAG_CHANGEMAP"Deletes all retakes spawns for the current map");
    
    
RegAdminCmd("sm_show"Command_ShowADMFLAG_CHANGEMAP"Shows all retakes spawns in a bombsite");
    
RegAdminCmd("sm_goto"Command_GotoSpawnADMFLAG_CHANGEMAP"Goes to a retakes spawn");
    
RegAdminCmd("sm_nearest"Command_GotoNearestSpawnADMFLAG_CHANGEMAP"Goes to nearest retakes spawn");
    
    
RegAdminCmd("sm_iteratespawns"Command_IterateSpawnsADMFLAG_CHANGEMAP);
    
RegAdminCmd("sm_reloadspawns"Command_ReloadSpawnsADMFLAG_CHANGEMAP"Reloads retakes spawns for the current map, discarding changes");
    
RegAdminCmd("sm_savespawns"Command_SaveSpawnsADMFLAG_CHANGEMAP"Saves retakes spawns for the current map");
    
    
/** Player commands **/
    
RegConsoleCmd("sm_guns"Command_Guns);
    
    
/** Event hooks **/
    
HookEvent("player_connect_full"Event_PlayerConnectFull);
    
HookEvent("player_team"Event_PlayerTeamEventHookMode_Pre);
    
HookEvent("player_spawn"Event_PlayerSpawn);
    
HookEvent("player_hurt"Event_DamageDealt);
    
HookEvent("player_death"Event_PlayerDeath);
    
HookEvent("round_prestart"Event_RoundPreStart);
    
HookEvent("round_poststart"Event_RoundPostStart);
    
HookEvent("round_freeze_end"Event_RoundFreezeEnd);
    
HookEvent("bomb_planted"Event_BombPlant);
    
HookEvent("bomb_exploded"Event_Bomb);
    
HookEvent("bomb_defused"Event_Bomb);
    
HookEvent("round_end"Event_RoundEnd);
    
    
g_hOnGunsCommand CreateGlobalForward("Retakes_OnGunsCommand"ET_IgnoreParam_Cell);
    
g_hOnPostRoundEnqueue CreateGlobalForward("Retakes_OnPostRoundEnqueue"ET_IgnoreParam_Cell);
    
g_hOnPreRoundEnqueue CreateGlobalForward("Retakes_OnPreRoundEnqueue"ET_IgnoreParam_CellParam_Cell);
    
g_hOnTeamSizesSet CreateGlobalForward("Retakes_OnTeamSizesSet"ET_IgnoreParam_CellByRefParam_CellByRef);
    
g_hOnTeamsSet CreateGlobalForward("Retakes_OnTeamsSet"ET_IgnoreParam_CellParam_CellParam_Cell);
    
g_OnFailToPlant CreateGlobalForward("Retakes_OnFailToPlant"ET_IgnoreParam_Cell);
    
g_OnRoundWon CreateGlobalForward("Retakes_OnRoundWon"ET_IgnoreParam_CellParam_CellParam_Cell);
    
g_OnSitePicked CreateGlobalForward("Retakes_OnSitePicked"ET_IgnoreParam_CellByRef);
    
g_OnWeaponsAllocated CreateGlobalForward("Retakes_OnWeaponsAllocated"ET_IgnoreParam_CellParam_CellParam_Cell);
    
    
g_SiteMins = new ArrayList(3);
    
g_SiteMaxs = new ArrayList(3);
    
g_hWaitingQueue Queue_Init();
    
g_hRankingQueue PQ_Init();
    
    
// Set inital spawn types.
    
for (int i 0MAX_SPAWNSi++) {
        
g_SpawnTypes[i] = SpawnType_Normal;
    }
}

public 
void OnPluginEnd() {
    if (
g_SavedCvars != INVALID_HANDLE) {
        
RestoreCvars(g_SavedCvarstrue);
    }
}

public 
void OnMapStart() {
    
PQ_Clear(g_hRankingQueue);
    
PQ_Clear(g_hWaitingQueue);
    
g_ScrambleSignal false;
    
g_WinStreak 0;
    
g_RoundCount 0;
    
g_RoundSpawnsDecided false;
    
    
g_bombPlanted false;
    
g_bombPlantSignal false;
    
    
FindSites();
    
g_NumSpawns ParseSpawns();
    
    
g_EditMode false;
    
CreateTimer(1.0Timer_ShowSpawns_TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
    
    if (!
g_Enabled)
        return;
    
    
ExecConfigs();
    
    
// Restart warmup for players to connect.
    
StartTimedWarmup(g_WarmupTimeCvar.IntValue);
}

public 
void OnMapEnd() {
    if (!
g_Enabled) {
        return;
    }
    
    if (
g_DirtySpawns) {
        
WriteSpawns();
    }
}

public 
int EnabledChanged(Handle cvar, const char[] oldValue, const char[] newValue) {
    
bool wasEnabled = !StrEqual(oldValue"0");
    
g_Enabled = !StrEqual(newValue"0");
    
    if (
wasEnabled && !g_Enabled) {
        if (
g_SavedCvars != INVALID_HANDLE)
            
RestoreCvars(g_SavedCvarstrue);
        
    } else if (!
wasEnabled && g_Enabled) {
        
Queue_Clear(g_hWaitingQueue);
        
ExecConfigs();
        for (
int i 1<= MaxClientsi++) {
            if (
IsClientConnected(i) && !IsFakeClient(i)) {
                
OnClientConnected(i);
                if (
IsClientInGame(i) && IsOnTeam(i)) {
                    
SwitchPlayerTeam(iCS_TEAM_SPECTATOR);
                    
Queue_Enqueue(g_hWaitingQueuei);
                    
FakeClientCommand(i"jointeam 2");
                }
            }
        }
    }
}

public 
void ExecConfigs() {
    if (
g_SavedCvars != INVALID_HANDLE) {
        
CloseCvarStorage(g_SavedCvars);
    }
    
g_SavedCvars ExecuteAndSaveCvars("sourcemod/retakes/retakes_game.cfg");
}

public 
void OnClientConnected(int client) {
    
ResetClientVariables(client);
}

public 
void OnClientDisconnect(int client) {
    
ResetClientVariables(client);
    
CheckRoundDone();
}

/**
 * Helper functions that resets client variables when they join or leave.
 */
public void ResetClientVariables(int client) {
    if (
client == g_BombOwner)
        
g_BombOwner = -1;
    
Queue_Drop(g_hWaitingQueueclient);
    
g_Team[client] = CS_TEAM_SPECTATOR;
    
g_PluginTeamSwitch[client] = false;
    
g_RoundPoints[client] = -POINTS_LOSS;
}

public 
Action Command_ScrambleTeams(int clientint args) {
    if (
g_Enabled) {
        
g_ScrambleSignal true;
        
Retakes_MessageToAll("%t""AdminScrambleTeams"client);
    }
}

public 
Action Command_Guns(int clientint args) {
    if (
g_Enabled) {
        
Call_StartForward(g_hOnGunsCommand);
        
Call_PushCell(client);
        
Call_Finish();
    }
    return 
Plugin_Handled;
}

public 
Action OnClientSayCommand(int client, const char[] command, const char[] args) {
    if (!
g_Enabled) {
        return 
Plugin_Continue;
    }
    
    static 
char gunsChatCommands[][] =  { "gun""guns"".gun"".guns""!gun""gnus" };
    for (
int i 0sizeof(gunsChatCommands); i++) {
        if (
strcmp(args[0], gunsChatCommands[i], false) == 0) {
            
Call_StartForward(g_hOnGunsCommand);
            
Call_PushCell(client);
            
Call_Finish();
            break;
        }
    }
    
    return 
Plugin_Continue;
}


/***********************
 *                     *
 *    Command Hooks    *
 *                     *
 ***********************/

public Action Command_JoinTeam(int client, const char[] commandint argc) {
    if (!
g_Enabled || g_hAutoTeamsCvar.IntValue == 0) {
        return 
Plugin_Continue;
    }
    
    if (!
IsValidClient(client) || argc 1)
        return 
Plugin_Handled;
    
    if (
g_EditMode) {
        
MovePlayerToEditMode(client);
        return 
Plugin_Handled;
    }
    
    
char arg[4];
    
GetCmdArg(1argsizeof(arg));
    
int team_to StringToInt(arg);
    
int team_from GetClientTeam(client);
    
    
// if same team, teamswitch controlled by the plugin
    // note if a player hits autoselect their team_from=team_to=CS_TEAM_NONE
    
if ((team_from == team_to && team_from != CS_TEAM_NONE) || g_PluginTeamSwitch[client] || IsFakeClient(client)) {
        return 
Plugin_Continue;
    } else {
        
// ignore switches between T/CT team
        
if ((team_from == CS_TEAM_CT && team_to == CS_TEAM_T)
             || (
team_from == CS_TEAM_T && team_to == CS_TEAM_CT)) {
            return 
Plugin_Handled;
            
        } else if (
team_to == CS_TEAM_SPECTATOR) {
            
// voluntarily joining spectator will not put you in the queue
            
SwitchPlayerTeam(clientCS_TEAM_SPECTATOR);
            
Queue_Drop(g_hWaitingQueueclient);
            
            
// check if a team is now empty
            
CheckRoundDone();
            
            return 
Plugin_Handled;
        } else {
            return 
PlacePlayer(client);
        }
    }
}

/**
 * Generic logic for placing a player into the correct team when they join.
 */
public Action PlacePlayer(int client) {
    
int tHumanCount 0ctHumanCount 0nPlayers 0;
    
GetTeamsClientCounts(tHumanCountctHumanCount);
    
nPlayers tHumanCount ctHumanCount;
    
    if (
Retakes_InWarmup() && nPlayers g_hMaxPlayers.IntValue) {
        return 
Plugin_Continue;
    }
    
    if (
nPlayers 2) {
        
ChangeClientTeam(clientCS_TEAM_SPECTATOR);
        
Queue_Enqueue(g_hWaitingQueueclient);
        
CS_TerminateRound(0.0CSRoundEnd_CTWin);
        return 
Plugin_Handled;
    }
    
    
    if (
CheckCommandAccess(client"HAVE_'A'_FLAG"ADMFLAG_GENERICtrue))
    {
        
Handle UnluckyGuys CreateArray();
        
int unluckyGuy = -1;
        
int previousUnluckyGuy = -1;
        do
        {
            if(
nPlayers == GetArraySize(UnluckyGuys))
            {
                
unluckyGuy = -1;
                break;
            }
            
            
previousUnluckyGuy unluckyGuy;
            while(
previousUnluckyGuy == unluckyGuy && FindValueInArray(UnluckyGuysunluckyGuy) == -1)
                
unluckyGuy GetRandomInt(1MaxClients);
            
PushArrayCell(UnluckyGuysunluckyGuy);
        }
        while (!
IsClientInGame(unluckyGuy) && CheckCommandAccess(unluckyGuy"HAVE_'A'_FLAG"ADMFLAG_GENERICtrue) && (GetClientTeam(unluckyGuy) == CS_TEAM_CT || GetClientTeam(unluckyGuy) == CS_TEAM_T));
        
        
        if(
unluckyGuy == -1)
        {
            
ChangeClientTeam(unluckyGuyCS_TEAM_SPECTATOR);
            
Queue_Enqueue(g_hWaitingQueueunluckyGuy);
            
Retakes_Message(unluckyGuy"%t""JoinedQueueMessage");
            return 
Plugin_Continue;
        }
        else
        {
            
PrintToChat(client"No place available now.");
            return 
Plugin_Continue;
        }
    }
    else
    {
        
ChangeClientTeam(clientCS_TEAM_SPECTATOR);
        
Queue_Enqueue(g_hWaitingQueueclient);
        
Retakes_Message(client"%t""JoinedQueueMessage");
        return 
Plugin_Handled;
    }
}



/***********************
 *                     *
 *     Event Hooks     *
 *                     *
 ***********************/

/**
 * Called when a player joins a team, silences team join events
 */
public Action Event_PlayerTeam(Handle event, const char[] namebool dontBroadcast) {
    if (!
g_Enabled) {
        return 
Plugin_Continue;
    }
    
    
SetEventBroadcast(eventtrue);
    return 
Plugin_Continue;
}

/**
 * Full connect event right when a player joins.
 * This sets the auto-pick time to a high value because mp_forcepicktime is broken and
 * if a player does not select a team but leaves their mouse over one, they are
 * put on that team and spawned, so we can't allow that.
 */
public Action Event_PlayerConnectFull(Handle event, const char[] namebool dontBroadcast) {
    if (!
g_Enabled) {
        return;
    }
    
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
SetEntPropFloat(clientProp_Send"m_fForceTeam"3600.0);
}

/**
 * Called when a player spawns.
 * Gives default weapons. (better than mp_ct_default_primary since it gives the player the correct skin)
 */
public Action Event_PlayerSpawn(Handle event, const char[] namebool dontBroadcast) {
    if (!
g_Enabled) {
        return;
    }
    
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if (!
IsValidClient(client) || !IsOnTeam(client) || g_EditMode || Retakes_InWarmup())
        return;
    
    if (!
g_RoundSpawnsDecided) {
        if (
IsPlayer(g_BombOwner)) {
            
g_SpawnIndices[g_BombOwner] = SelectSpawn(CS_TEAM_Ttrue);
        }
        
        for (
int i 1<= MAXPLAYERSi++) {
            if (
IsPlayer(i) && IsOnTeam(i) && != g_BombOwner) {
                
g_SpawnIndices[i] = SelectSpawn(g_Team[i], false);
            }
        }
        
g_RoundSpawnsDecided true;
    }
    
    
SetupPlayer(client);
}

/**
 * Called when a player dies - gives points to killer, and does database stuff with the kill.
 */
public Action Event_PlayerDeath(Handle event, const char[] namebool dontBroadcast) {
    if (!
Retakes_Live()) {
        return;
    }
    
    
int victim GetClientOfUserId(GetEventInt(event"userid"));
    
int attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    
bool validAttacker IsValidClient(attacker);
    
bool validVictim IsValidClient(victim);
    
    if (
validAttacker && validVictim) {
        if (
HelpfulAttack(attackervictim)) {
            
g_RoundPoints[attacker] += POINTS_KILL;
        } else {
            
g_RoundPoints[attacker] -= POINTS_KILL;
        }
    }
}

/**
 * Called when a player deals damage to another player - ads round points if needed.
 */
public Action Event_DamageDealt(Handle event, const char[] namebool dontBroadcast) {
    if (!
Retakes_Live()) {
        return 
Plugin_Continue;
    }
    
    
int attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
int victim GetClientOfUserId(GetEventInt(event"userid"));
    
bool validAttacker IsValidClient(attacker);
    
bool validVictim IsValidClient(victim);
    
    if (
validAttacker && validVictim && HelpfulAttack(attackervictim)) {
        
int damage GetEventInt(event"dmg_PlayerHealth");
        
g_RoundPoints[attacker] += (damage POINTS_DMG);
    }
    return 
Plugin_Continue;
}

/**
 * Called when the bomb explodes or is defuser, gives ponts to the one that planted/defused it.
 */
public Action Event_BombPlant(Handle event, const char[] namebool dontBroadcast) {
    if (!
g_Enabled) {
        return;
    }
    
    
g_bombPlanted true;
    
g_bombPlantSignal false;
}

/**
 * Called when the bomb explodes or is defused, gives ponts to the one that planted/defused it.
 */
public Action Event_Bomb(Handle event, const char[] namebool dontBroadcast) {
    if (!
Retakes_Live()) {
        return;
    }
    
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if (
IsValidClient(client)) {
        
g_RoundPoints[client] += POINTS_BOMB;
    }
}

/**
 * Called before any other round start events. This is the best place to change teams
 * since it should happen before respawns.
 */
public Action Event_RoundPreStart(Handle event, const char[] namebool dontBroadcast) {
    if (!
Retakes_Live()) {
        return;
    }
    
    
g_RoundSpawnsDecided false;
    
RoundEndUpdates();
    
UpdateTeams();
    
    
ArrayList ts = new ArrayList();
    for (
int i 1MaxClientsi++) {
        if (
IsValidClient(i) && IsOnTeam(i)) {
            
Client_RemoveAllWeapons(i);
            if (
GetClientTeam(i) == CS_TEAM_T) {
                
ts.Push(i);
            }
        }
    }
    
    if (
ts.Length >= 1) {
        
int player RandomElement(ts);
        
g_BombOwner player;
    }
    
delete ts;
}

public 
Action Event_RoundPostStart(Handle event, const char[] namebool dontBroadcast) {
    if (!
Retakes_Live()) {
        return;
    }
    
    if (!
g_EditMode) {
        
GameRules_SetProp("m_iRoundTime"g_hRoundTime.IntValue40true);
        
Retakes_MessageToAll("%t""RetakeSiteMessage"SITESTRING(g_Bombsite), g_NumTg_NumCT);
    }
    
    
g_bombPlanted false;
}

/**
 * Round freezetime end, resets the round points and unfreezes the players.
 */
public Action Event_RoundFreezeEnd(Handle event, const char[] namebool dontBroadcast) {
    for (
int i 1<= MaxClientsi++) {
        
g_RoundPoints[i] = 0;
    }
}

/**
 * Round end event, calls the appropriate winner (T/CT) unction and sets the scores.
 */
public Action Event_RoundEnd(Handle event, const char[] namebool dontBroadcast) {
    if (!
Retakes_Live()) {
        return;
    }
    
    if (
g_ActivePlayers >= 2) {
        
g_RoundCount++;
        
int winner GetEventInt(event"winner");
        
        
ArrayList ts = new ArrayList();
        
ArrayList cts = new ArrayList();
        
        for (
int i 1<= MaxClientsi++) {
            if (
IsPlayer(i)) {
                if (
GetClientTeam(i) == CS_TEAM_CT)
                    
cts.Push(i);
                else if (
GetClientTeam(i) == CS_TEAM_T)
                    
ts.Push(i);
            }
        }
        
        
Call_StartForward(g_OnRoundWon);
        
Call_PushCell(winner);
        
Call_PushCell(ts);
        
Call_PushCell(cts);
        
Call_Finish();
        
        
delete ts;
        
delete cts;
        
        for (
int i 1<= MaxClientsi++) {
            if (
IsPlayer(i) && GetClientTeam(i) != winner) {
                
g_RoundPoints[i] -= POINTS_LOSS;
            }
        }
        
        if (
winner == CS_TEAM_T) {
            
TerroristsWon();
        } else if (
winner == CS_TEAM_CT) {
            
CounterTerroristsWon();
        }
    }
}



/***********************
 *                     *
 *    Retakes logic    *
 *                     *
 ***********************/

/**
 * Called at the end of the round - puts all the players into a priority queue by
 * their score for placing them next round.
 */
public void RoundEndUpdates() {
    
PQ_Clear(g_hRankingQueue);
    
    
Call_StartForward(g_hOnPreRoundEnqueue);
    
Call_PushCell(g_hRankingQueue);
    
Call_PushCell(g_hWaitingQueue);
    
Call_Finish();
    
    for (
int client 1client <= MaxClientsclient++) {
        if (
IsPlayer(client) && IsOnTeam(client)) {
            
PQ_Enqueue(g_hRankingQueueclientg_RoundPoints[client]);
        }
    }
    
    while (!
Queue_IsEmpty(g_hWaitingQueue) && PQ_GetSize(g_hRankingQueue) < g_hMaxPlayers.IntValue) {
        
int client Queue_Dequeue(g_hWaitingQueue);
        if (
IsPlayer(client)) {
            
PQ_Enqueue(g_hRankingQueueclient, -POINTS_LOSS);
        } else {
            break;
        }
    }
    
    
Call_StartForward(g_hOnPostRoundEnqueue);
    
Call_PushCell(g_hRankingQueue);
    
Call_Finish();
}

/**
 * Places players onto the correct team.
 * This assumes the priority queue has already been built (e.g. by RoundEndUpdates).
 */
public void UpdateTeams() {
    for (
int i 0MAX_SPAWNSi++) {
        
g_SpawnTaken[i] = false;
    }
    
    if (
g_NumSpawns g_hMaxPlayers.IntValue) {
        
LogError("This map does not have enough spawns!");
        return;
    }
    
    
g_Bombsite GetRandomBool() ? BombsiteA BombsiteB;
    
Call_StartForward(g_OnSitePicked);
    
Call_PushCellRef(g_Bombsite);
    
Call_Finish();
    
    
g_ActivePlayers PQ_GetSize(g_hRankingQueue);
    if (
g_ActivePlayers g_hMaxPlayers.IntValue)
        
g_ActivePlayers g_hMaxPlayers.IntValue;
    
    
g_NumT RoundToNearest(g_hRatioConstant.FloatValue float(g_ActivePlayers));
    if (
g_NumT 1)
        
g_NumT 1;
    
    
g_NumCT g_ActivePlayers g_NumT;
    
    
Call_StartForward(g_hOnTeamSizesSet);
    
Call_PushCellRef(g_NumT);
    
Call_PushCellRef(g_NumCT);
    
Call_Finish();
    
    if (
g_ScrambleSignal || g_hUseRandomTeams.IntValue != 0) {
        
int n GetArraySize(g_hRankingQueue);
        for (
int i 0ni++) {
            
int value GetRandomInt(11000);
            
SetArrayCell(g_hRankingQueueivalue1);
        }
        
g_ScrambleSignal false;
    }
    
    
ArrayList ts = new ArrayList();
    
ArrayList cts = new ArrayList();
    
    if (
g_hAutoTeamsCvar.IntValue != 0) {
        
// Ordinary team switching by retakes
        
for (int i 0g_NumTi++) {
            
int client PQ_Dequeue(g_hRankingQueue);
            if (
IsValidClient(client)) {
                
ts.Push(client);
            }
        }
        
        for (
int i 0g_NumCTi++) {
            
int client PQ_Dequeue(g_hRankingQueue);
            if (
IsValidClient(client)) {
                
cts.Push(client);
            }
        }
    } else {
        
// Use the already set teams
        
for (int i 1<= MaxClientsi++) {
            if (
IsValidClient(i)) {
                if (
GetClientTeam(i) == CS_TEAM_CT)
                    
cts.Push(i);
                else if (
GetClientTeam(i) == CS_TEAM_T)
                    
ts.Push(i);
            }
        }
        
g_NumCT cts.Length;
        
g_NumT ts.Length;
        
g_ActivePlayers g_NumCT g_NumT;
    }
    
    
Call_StartForward(g_hOnTeamsSet);
    
Call_PushCell(ts);
    
Call_PushCell(cts);
    
Call_PushCell(g_Bombsite);
    
Call_Finish();
    
    for (
int i 0GetArraySize(ts); i++) {
        
int client GetArrayCell(tsi);
        if (
IsValidClient(client)) {
            
SwitchPlayerTeam(clientCS_TEAM_T);
            
g_Team[client] = CS_TEAM_T;
            
g_PlayerPrimary[client] = "weapon_ak47";
            
g_PlayerSecondary[client] = "weapon_glock";
            
g_PlayerNades[client] = "";
            
g_PlayerKit[client] = false;
            
g_PlayerHealth[client] = 100;
            
g_PlayerArmor[client] = 100;
            
g_PlayerHelmet[client] = true;
        }
    }
    
    for (
int i 0GetArraySize(cts); i++) {
        
int client GetArrayCell(ctsi);
        if (
IsValidClient(client)) {
            
SwitchPlayerTeam(clientCS_TEAM_CT);
            
g_Team[client] = CS_TEAM_CT;
            
g_PlayerPrimary[client] = "weapon_m4a1";
            
g_PlayerSecondary[client] = "weapon_hkp2000";
            
g_PlayerNades[client] = "";
            
g_PlayerKit[client] = true;
            
g_PlayerHealth[client] = 100;
            
g_PlayerArmor[client] = 100;
            
g_PlayerHelmet[client] = true;
        }
    }
    
    
// if somebody didn't get put in, put them back into the waiting queue
    
while (!PQ_IsEmpty(g_hRankingQueue)) {
        
int client PQ_Dequeue(g_hRankingQueue);
        if (
IsPlayer(client)) {
            
Queue_EnqueueFront(g_hWaitingQueueclient);
        }
    }
    
    
Call_StartForward(g_OnWeaponsAllocated);
    
Call_PushCell(ts);
    
Call_PushCell(cts);
    
Call_PushCell(g_Bombsite);
    
Call_Finish();
    
    
int length Queue_Length(g_hWaitingQueue);
    for (
int i 0lengthi++) {
        
int client GetArrayCell(g_hWaitingQueuei);
        if (
IsValidClient(client)) {
            
Retakes_Message(client"%t""WaitingQueueMessage"g_hMaxPlayers.IntValue);
        }
    }
    
    
delete ts;
    
delete cts;
}

static 
bool ScramblesEnabled() {
    return 
g_hRoundsToScramble.IntValue >= 1;
}

public 
void TerroristsWon() {
    
int toScramble g_hRoundsToScramble.IntValue;
    
g_WinStreak++;
    
    if (
g_WinStreak >= toScramble) {
        if (
ScramblesEnabled()) {
            
g_ScrambleSignal true;
            
Retakes_MessageToAll("%t""ScrambleMessage"g_WinStreak);
        }
        
g_WinStreak 0;
    } else if (
g_WinStreak >= toScramble && ScramblesEnabled()) {
        
Retakes_MessageToAll("%t""WinStreakAlmostToScramble"g_WinStreaktoScramble g_WinStreak);
    } else if (
g_WinStreak >= 3) {
        
Retakes_MessageToAll("%t""WinStreak"g_WinStreak);
    }
}

public 
void CounterTerroristsWon() {
    if (!
g_bombPlanted && IsValidClient(g_BombOwner) && g_RoundCount >= 3) {
        
Retakes_MessageToAll("%t""FailedToPlant"g_BombOwner);
        
Call_StartForward(g_OnFailToPlant);
        
Call_PushCell(g_BombOwner);
        
Call_Finish();
    }
    
    if (
g_WinStreak >= 3) {
        
Retakes_MessageToAll("%t""WinStreakOver"g_WinStreak);
    }
    
    
g_WinStreak 0;
}

void CheckRoundDone() {
    
int tHumanCount 0ctHumanCount 0;
    
GetTeamsClientCounts(tHumanCountctHumanCount);
    if (
tHumanCount == || ctHumanCount == 0) {
        
CS_TerminateRound(0.1CSRoundEnd_TerroristWin);
    }
}

public 
int GetOtherTeam(int team) {
    return (
team == CS_TEAM_CT) ? CS_TEAM_T CS_TEAM_CT;
}

public 
Bombsite GetOtherSite(Bombsite site) {
    return (
site == BombsiteA) ? BombsiteB BombsiteA;
}

// pugsetup (github.com/splewis/csgo-pug-setup) integrations
#if defined _pugsetup_included
public Action PugSetup_OnSetupMenuOpen(int clientMenu menubool displayOnly) {
    
int leader PugSetup_GetLeader(false);
    if (!
IsPlayer(leader)) {
        
PugSetup_SetLeader(client);
    }
    
    
int style ITEMDRAW_DEFAULT;
    if (!
PugSetup_HasPermissions(clientPermission_Leader) || displayOnly) {
        
style ITEMDRAW_DISABLED;
    }
    
    if (
g_Enabled) {
        
AddMenuItem(menu"disable_retakes""Disable retakes"style);
    } else {
        
AddMenuItem(menu"enable_retakes""Enable retakes"style);
    }
    
    return 
Plugin_Continue;
}

public 
void PugSetup_OnSetupMenuSelect(Menu menuint client, const char[] selected_infoint selected_position) {
    if (
StrEqual(selected_info"disable_retakes")) {
        
SetConVarInt(g_EnabledCvar0);
        
PugSetup_GiveSetupMenu(clientfalseselected_position);
    } else if (
StrEqual(selected_info"enable_retakes")) {
        
SetConVarInt(g_EnabledCvar1);
        
PugSetup_GiveSetupMenu(clientfalseselected_position);
    }
}
#endif 
__________________
Want to check my plugins ?
Arkarr is offline
weeeishy
Senior Member
Join Date: Jul 2015
Location: Kuwait
Old 09-22-2016 , 19:00   Re: Modify Retakes by Splewis
Reply With Quote #3

Thanks Arkarr. However, I found a bug. I have 10 players that play actively but when I join we become 11 instead of moving a random guy to specs. It also breaks the balance in the retakes like 7vs3 instead of 6vs4. Also the chat keeps printing that I'm in the queue even though I'm playing.
__________________
weeeishy is offline
splewis
Veteran Member
Join Date: Feb 2014
Location: United States
Old 09-25-2016 , 12:42   Re: Modify Retakes by Splewis
Reply With Quote #4

You don't need to modify the plugin to do this

Retakes_OnPreRoundEnqueue https://github.com/splewis/csgo-reta...etakes.inc#L41

if there's an admin in waitingQueue move them to rankingQueue and move the evicted player to waitingQueue
__________________
splewis is offline
decentLIVE
Junior Member
Join Date: Aug 2015
Old 10-02-2016 , 04:15   Re: Modify Retakes by Splewis
Reply With Quote #5

Quote:
Originally Posted by splewis View Post
You don't need to modify the plugin to do this

Retakes_OnPreRoundEnqueue https://github.com/splewis/csgo-reta...etakes.inc#L41

if there's an admin in waitingQueue move them to rankingQueue and move the evicted player to waitingQueue
So your base plugin is already setup with priority queue? wow I never would have known
decentLIVE is offline
decentLIVE
Junior Member
Join Date: Aug 2015
Old 10-10-2016 , 04:09   Re: Modify Retakes by Splewis
Reply With Quote #6

Can anyone implement a priority queue using the methods splewis listed? I'm willing to pay someone for it, I just dont yet know enough sourcepawn to do it myself.
decentLIVE is offline
decentLIVE
Junior Member
Join Date: Aug 2015
Old 10-13-2016 , 23:19   Re: Modify Retakes by Splewis
Reply With Quote #7

Anyone? Or anyone able to explain how to do it for me? :/
decentLIVE is offline
Cooky
Veteran Member
Join Date: Jun 2010
Location: 127.0.0.1
Old 04-11-2017 , 14:13   Re: Modify Retakes by Splewis
Reply With Quote #8

Also interested in this.. could someone make this. $$$$$$$$$$$$$$$$$ of course...
Cooky is offline
TrappaTroopa
Senior Member
Join Date: Feb 2016
Old 04-30-2017 , 23:47   Re: Modify Retakes by Splewis
Reply With Quote #9

Anybody? Really need this!
TrappaTroopa is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 05-02-2017 , 01:32   Re: Modify Retakes by Splewis
Reply With Quote #10

Might work might not, if it doesn't please show the error log

If you feel like donating, use the donation button at the top right of the page to support SourceMod.

Default reservation flag is 'a', but feel free to change it using the overrides system with the command of "skip_queue"
Attached Files
File Type: sp Get Plugin or Get Source (hl_priorityqueue.sp - 997 views - 11.3 KB)

Last edited by headline; 05-04-2017 at 16:35.
headline is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode