Skip to content

Instantly share code, notes, and snippets.

@splewis
Last active August 29, 2015 14:09
Show Gist options
  • Save splewis/d8bc91a6c47f1518b594 to your computer and use it in GitHub Desktop.
Save splewis/d8bc91a6c47f1518b594 to your computer and use it in GitHub Desktop.
#pragma semicolon 1
#include <cstrike>
#include <sdktools>
#include <sourcemod>
#define PLUGIN_VERSION "1.0.0"
new bool:g_ShouldBeT[MAXPLAYERS+1] = false;
public Plugin:myinfo = {
name = "CS:GO USP Ninjas",
author = "splewis",
description = "",
version = PLUGIN_VERSION,
url = "https://github.com/splewis/"
};
public OnPluginStart() {
AddNormalSoundHook(OnSoundPlayed);
HookEvent("round_end", Event_RoundEnd);
HookEvent("round_prestart", Event_RoundPreStart);
AddCommandListener(Command_TeamJoin, "jointeam");
}
public OnClientConnected(client) {
g_ShouldBeT[client] = false;
}
public Action:Command_TeamJoin(client, const String:command[], argc) {
if (!IsClientConnected(client) || IsFakeClient(client) || argc < 1)
return Plugin_Handled;
decl String:arg[4];
GetCmdArg(1, arg, sizeof(arg));
new team_to = StringToInt(arg);
// don't let people move themselves to T
if (team_to == CS_TEAM_T) {
SwitchPlayerTeam(client, CS_TEAM_CT);
return Plugin_Handled;
}
return Plugin_Continue;
}
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast) {
new winner = GetEventInt(event, "winner");
for (new i = 1; i <= MaxClients; i++) {
if (IsClientConnected(i) && IsClientInGame(i)) {
if (winner == GetClientTeam(i)) {
g_ShouldBeT[i] = true;
} else {
g_ShouldBeT[i] = false;
}
}
}
}
public Event_RoundPreStart(Handle:event, const String:name[], bool:dontBroadcast) {
new tCount, ctCount;
for (new i = 1; i <= MaxClients; i++) {
if (IsClientConnected(i) && IsClientInGame(i)) {
if (GetClientTeam(i) == CS_TEAM_T)
tCount++;
if (GetClientTeam(i) == CS_TEAM_CT)
ctCount++;
}
}
new allowedTs = (tCount + ctCount) / 2;
new moved = 0;
// move players that are maked as "should be T"
for (new i = 1; i <= MaxClients; i++) {
if (IsClientConnected(i) && IsClientInGame(i)) {
if (g_ShouldBeT[i] && moved+1 < allowedTs) {
moved++;
ChangeClientTeam(i, CS_TEAM_T);
} else {
ChangeClientTeam(i, CS_TEAM_CT);
}
}
}
// move any extra players needed
for (new i = 1; i <= MaxClients; i++) {
if (IsClientConnected(i) && IsClientInGame(i)) {
if (GetClientTeam(i) == CS_TEAM_CT && moved+1 < allowedTs) {
moved++;
ChangeClientTeam(i, CS_TEAM_T);
}
}
}
}
public Action:OnSoundPlayed(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags) {
if (entity && entity <= MaxClients && (StrContains(sample, "physics") != -1 || StrContains(sample, "footsteps") != -1)) {
return Plugin_Handled;
}
return Plugin_Continue;
}
public SwitchPlayerTeam(client, team) {
if (GetClientTeam(client) == team)
return;
if (team > CS_TEAM_SPECTATOR) {
CS_SwitchTeam(client, team);
CS_UpdateClientModel(client);
} else {
ChangeClientTeam(client, team);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment