Raised This Month: $51 Target: $400
 12% 

DR script causes server to crash on slay


Post New Thread Reply   
 
Thread Tools Display Modes
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
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-10-2018 , 13:51   Re: DR script causes server to crash on slay
Reply With Quote #2

update sourcemod to the latest version

and another way to get a random terrorist:

PHP Code:


public int SelectTerrorist() {

    
ArrayList Terrorists = new ArrayList();

    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i))
        {
            if(
GetClientTeam(i) == CS_TEAM_CT)
            {
                
Terrorists.Push(i);
            }
        }
    }

    
int index Terrorists.Get(GetRandomInt(0Terrorists.Length 1));
    
delete Terrorists;

    return 
index;

You can get an infinite loop with while and getrandomint.
__________________

Last edited by Ilusion9; 08-10-2018 at 17:15.
Ilusion9 is offline
RealMessiah
New Member
Join Date: Dec 2017
Location: England
Old 08-11-2018 , 11:22   Re: DR script causes server to crash on slay
Reply With Quote #3

Quote:
Originally Posted by Ilusion9 View Post
update sourcemod to the latest version

and another way to get a random terrorist:

PHP Code:


public int SelectTerrorist() {

    
ArrayList Terrorists = new ArrayList();

    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i))
        {
            if(
GetClientTeam(i) == CS_TEAM_CT)
            {
                
Terrorists.Push(i);
            }
        }
    }

    
int index Terrorists.Get(GetRandomInt(0Terrorists.Length 1));
    
delete Terrorists;

    return 
index;

You can get an infinite loop with while and getrandomint.
I updated SM and used your selection function, thank you for that <3, but I am still experiencing the server crash after slaying a player who is last alive. Any other ideas would be greatly appreciated!
__________________
There are no accidents
RealMessiah is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-11-2018 , 12:44   Re: DR script causes server to crash on slay
Reply With Quote #4

maybe it's not this script that cause the problem? try to remove other custom plugins.
__________________
Ilusion9 is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 08-10-2018 , 14:16   Re: DR script causes server to crash on slay
Reply With Quote #5

It shouldn't be void, it returns INT
__________________


Max-Play.pl - the best polish servers

Last edited by CamerDisco; 08-10-2018 at 14:52.
CamerDisco is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-10-2018 , 17:26   Re: DR script causes server to crash on slay
Reply With Quote #6

Quote:
Originally Posted by CamerDisco View Post
It shouldn't be void, it returns INT
i have copied his header function

also, make terrorist a global variable and in jointeam hook function:

PHP Code:

public Action Event_PlayerJoin(int Client, const char[] Commandint Args)
{    
    if(
Client == Terrorist) - create a global variable or check his team.
    {
        return 
Plugin_Handled;
    }

    if(
Client != 0)
    {
        if(
Args != 0)
        {
            
char Buffer[65];    
            
GetCmdArg(1Buffersizeof(Buffer));
            
            
int Team StringToInt(Buffer);
            
            if(
Team == CS_TEAM_SPECTATOR || Team == CS_TEAM_CT)  - let the player move to spec or ct
            
{
                
ChangeClientTeam(ClientTeam);
            }
        }
    }
    
    return 
Plugin_Handled;

that code is very ugly and this is doing the same thing
__________________
Ilusion9 is offline
RealMessiah
New Member
Join Date: Dec 2017
Location: England
Old 08-10-2018 , 20:47   Re: DR script causes server to crash on slay
Reply With Quote #7

Thankyou for the suggestions! I'll test them tomorrow when I get off work and let you know if they work. <3
__________________
There are no accidents
RealMessiah 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 11:56.


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