Skip to content

Instantly share code, notes, and snippets.

@kiprasmel
Last active April 23, 2020 21:31
Show Gist options
  • Select an option

  • Save kiprasmel/e0e96bfdba68e7b7cfada4d390e836bc to your computer and use it in GitHub Desktop.

Select an option

Save kiprasmel/e0e96bfdba68e7b7cfada4d390e836bc to your computer and use it in GitHub Desktop.
#include <sourcemod>
#include <sdktools> /** ForcePlayerSuicide */
public Plugin myinfo = {
name = "Anti-respawn on reconnect",
author = "Kipras Melnikovas (https://kipras.org) <[email protected]>",
description = "Disallow clients from respawning after being spawned and reconnecting",
version = "0.1.0",
url = "https://kipras.org"
};
public void OnPluginStart() {
HookEvent("round_prestart", Event_RoundPreStart);
HookEvent("player_spawned", Event_PlayerSpawned);
}
/**
* Contains steam ids of clients (as strings) that have been spawned this round.
*
* The `ArrayList` is documented here: https://sm.alliedmods.net/new-api/adt_array/ArrayList
*/
public ArrayList g_spawnedClientsThisRound;
/**
* Clears the spawned client array before the round starts.
*
* https://wiki.alliedmods.net/Counter-Strike:_Global_Offensive_Events#round_prestart
*/
public void Event_RoundPreStart(Event event, const char[] eventName, bool dontBroadcast) {
ClearArray(g_spawnedClientsThisRound);
}
/**
* Kills the client if it has already been spawned,
* or adds it to the spawned client array.
*
* https://wiki.alliedmods.net/Counter-Strike:_Global_Offensive_Events#player_spawned
*/
public void Event_PlayerSpawned(Event event, const char[] eventName, bool dontBroadcast) {
/** used to get the `clientIndex` */
int clientUserId = GetEventInt(event, "userid");
/** used to get the `clientSteamId` & for `ForcePlayerSuicide` */
int clientIndex = GetClientOfUserId(clientUserId);
/** used for storing in the array */
const int maxlen = 32;
char clientSteamId[maxlen];
GetClientAuthId(clientIndex, AuthId_SteamID64, clientSteamId, maxlen); /** TODO - might not succeed */
bool hasAlreadyBeenSpawnedThisRound = (FindStringInArray(g_spawnedClientsThisRound, clientSteamId) != -1);
if (hasAlreadyBeenSpawnedThisRound) {
ForcePlayerSuicide(clientIndex);
/** TODO message the killed client? */
} else {
PushArrayString(g_spawnedClientsThisRound, clientSteamId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment