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

DR script causes server to crash on slay


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
RealMessiah
New Member
Join Date: Dec 2017
Location: England
Old 08-10-2018 , 11:32   DR script causes server to crash on slay
Reply With Quote #1

Hello friends,

Context: The code is a deathrun plugin for one of my servers. The code selects T's and starts/stops the gamemode as planned until the issue below.

My issue: upon Slaying or Kicking a client the server crashes. I am unsure what is causing the crash because no error message is outputted in console, but I have a feeling it is to do with the round_prestart hook and the T selection.

What I am looking for: I was mainly hoping that somebody could point out a flaw or give me some direction as to what is causing it. I have tried to troubleshoot the issue through commenting out certain aspects of the code until I found the area that is causing the issue: the round_prestart hook and T selection. I attempted changing when I performed the code in round_prestart to round_end and player_death but it never worked, I always had the slay issue.

BELOW IS SOURCECODE FOR DR PLUGIN:::

Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <cstrike>
#include <colors>

// Global variables

bool activeClients[MAXPLAYERS+1] = false;
bool bActive = false;
bool bAllowSpawns = true;

int iRoundCount = 0;
int iCurrentT = 0;

// Plugin info

public Plugin myinfo = {
	name = "Messiah's deathrun",
	author = "Messiah",
	description = "Deathrun Manager",
	version = "v1.0",
	url = "www.newworldorder.group/forums/"
}

// Voids

public void OnPluginStart() {
	AddCommandListener(OnPlayerJoinTeam, "jointeam");
	HookEvent("round_start", OnRoundStart); // To create afk timer
	HookEvent("round_prestart", OnRoundPreStart); // To allocate teams
	HookEvent("player_spawned", OnPlayerSpawned); // To set activeClient state to true or start Deathrun GM
	HookEvent("player_disconnect", OnPlayerDisconnect); // To set activeClient state to false
}

public void CheckDeactivate() { // Called to check if Deathrun GM needs to be disabled.
	if (bActive && GetActiveClientCount() == 1) {
		bActive = false; // DR is disabled
		ChangeClientTeam(iCurrentT, 3); // Make Current T CT
		iCurrentT = 0; // States there is no T
		CS_TerminateRound(3.0, CSRoundEnd_GameStart, true); // Starts new round on DR de-activating
		CPrintToChatAll("{default}[{lime}NWO{default}] Deathrun gamemode has been disabled.");
	}
}

stock void SetCvar(char[] scvar, char[] svalue) {
	Handle cvar = FindConVar(scvar);
	if (cvar != INVALID_HANDLE) {
		SetConVarString(cvar, svalue, true);
	}
}

public void SelectTerrorist() {
	int newTR = 0;

	if (iRoundCount == 0 || iCurrentT == 0) {
		while (!IsValidClient(newTR) || GetClientTeam(newTR) == 1) {
			newTR = GetRandomInt(1, MaxClients);
		}
		ChangeClientTeam(newTR, 3);
		iCurrentT = newTR;
	} else {
		if (GetActiveClientCount() != 1) {
			while (!IsValidClient(newTR) || GetClientTeam(newTR) == 1 || iCurrentT == newTR) {
				newTR = GetRandomInt(1, MaxClients);
			}
			ChangeClientTeam(iCurrentT, 3);
			ChangeClientTeam(newTR, 2);
			iCurrentT = newTR;
		}
	}
}

// Actions

public Action OnRoundStart(Handle event, const char[] name, bool dontBroadcast) {
	if (bActive) {
		CreateTimer(7.0, StopPlayerSpawns);	
	}
}

public Action OnRoundPreStart(Handle event, const char[] name, bool dontBroadcast) {
	if (bActive) {
		SelectTerrorist();
	}
	bAllowSpawns = true;
	iRoundCount++; 
	return Plugin_Continue;
}

public Action OnPlayerSpawned(Handle event, const char[] name, bool dontBroadcast) {
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	activeClients[client] = true;
	if (!bAllowSpawns) {
		ForcePlayerSuicide(client);
	}
	if (!bActive && GetActiveClientCount() == 2) {
		bActive = true
		CS_TerminateRound(3.0, CSRoundEnd_GameStart, true);
		CPrintToChatAll("{default}[{lime}NWO{default}] Deathrun gamemode has been enabled.");
	}
}

public Action OnPlayerDisconnect(Handle event, const char[] name, bool dontBroadcast) {
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	activeClients[client] = false;
	CheckDeactivate();
}

public Action OnPlayerJoinTeam(int client, const char[] command, int args) {
	char argz[32];
	GetCmdArg(1, argz, sizeof(argz));
	int arg = StringToInt(argz);

	if (bActive) {
		if (GetClientTeam(client) == 1) { // Spectator Team
			if (arg == 2) { // Trying To join T
				return Plugin_Handled;
			} else if (arg == 3) { // Trying to join CT
				ChangeClientTeam(client, 3);
				return Plugin_Handled;
			}
		} else if (GetClientTeam(client) == 2) { // Terrorist Team
			if (arg == 1) { // Trying to join spec
				return Plugin_Handled;
			} else if (arg == 3) { // Trying to join CT
				return Plugin_Handled;
			}
		} else if (GetClientTeam(client) == 3) { // Counter-Terrorist Team
			if (arg == 1) { // Trying to join spec
				activeClients[client] = false;
				CheckDeactivate();
				ChangeClientTeam(client, 1);
				return Plugin_Handled;
			} else if (arg == 2) { // Trying to join T
				return Plugin_Handled;
			}
		} else {
			if (arg == 1) { // Trying to join spec
				activeClients[client] = false;
				ChangeClientTeam(client, 1);
				CheckDeactivate();
				return Plugin_Handled;
			} else if (arg == 2) { // Trying to join T
				return Plugin_Handled;
			} else if (arg == 3) { // Trying to join CT
				ChangeClientTeam(client, 3);
				return Plugin_Handled;
			}
		}
	} else {
		if (arg == 1) { // Trying to join spec
			activeClients[client] = false;
			ChangeClientTeam(client, 1);
			return Plugin_Handled;
		} else if (arg == 2) { // Trying to join T
			return Plugin_Handled;
		} else if (arg == 3) { // Trying to join CT
			ChangeClientTeam(client, 3);
			return Plugin_Handled;
		}
	}
	return Plugin_Continue;
}

public Action StopPlayerSpawns(Handle time) {
	bAllowSpawns = false;
}

// Functions

int GetActiveClientCount() {
	int count = 0;
	for (int i = 1; i <= MaxClients; i++) {
		if (activeClients[i] == true) {
			count++;
		}
	}
	return count;
}

bool IsValidClient(int client) {
	if (client <= 0 || client > MaxClients || !IsClientConnected(client)) return false;
	return IsClientInGame(client);
}
Any help would be appreciated and I will continue to troubleshoot!
RealMessiah is offline
 



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 11:10.


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