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

Need fixing Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rzrhome
Junior Member
Join Date: Sep 2016
Old 11-03-2019 , 07:25   Need fixing Help
Reply With Quote #1

Thanks for help me.

SM 1.10

Code:
#include <sourcemod>
#include <sdktools>

EngineVersion g_Game;

public Plugin myinfo = 
{
	name = "MultiCFG DM", 
	author = "SHiva", 
	description = "DM Config Changer", 
	version = "0.3", 
	url = "http://www.sourcemod.net/"
};

Handle hTimer;

ArrayList aGameModes;
char sCurrentGameName[52];
char sNextGameName[52];
int iCurrentGameTime;

int modeIndex;

bool isLoop = false;
bool isLastMode = false;
bool isH3busDM;

char CONFIG_PATH[255];
char SOUND_PATH[255] = "ui/bonus_alert_start";

public void OnPluginStart()
{
	g_Game = GetEngineVersion();
	if (g_Game != Engine_CSGO)
	{
		SetFailState("This plugin is for CSGO.");
	}
	
	BuildPath(Path_SM, CONFIG_PATH, sizeof(CONFIG_PATH), "configs/multicfg-dm.cfg");
	
	aGameModes = CreateArray();
	
	LoadConfig();
	LoadGameModes();
	
	HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}

public OnMapStart()
{
	hTimer = INVALID_HANDLE;
}

public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
	if (hTimer != INVALID_HANDLE)
	{
		KillTimer(hTimer, false);
		hTimer = INVALID_HANDLE;
	}
	
	modeIndex = 0;
	
	// First Load
	PrepareNextMode();
	ExecConfig(true);
	
	hTimer = CreateTimer(1.0, CycleControl, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}

public Action CycleControl(Handle timer)
{
	if(isLastMode)
		return Plugin_Stop;
	
	iCurrentGameTime--;
	
	if(iCurrentGameTime <= 0)
	{
		PrepareNextMode();
		
		ExecConfig(true);
	}
	
	if(iCurrentGameTime <= 10 && iCurrentGameTime > 0)
	{
		char sAdvertMessage[255];
		
		Format(sAdvertMessage, sizeof(sAdvertMessage), "<font color='#ff0000'>Warmup  Mod</font>\nChanging to <font color='#66ff66'>%s</font> in <font color='#66ff66'>%i</font> seconds", sNextGameName, iCurrentGameTime);		
	
		if(iCurrentGameTime >= 1)
		{
			PrintHintTextToAll(sAdvertMessage);
		}
	}
	
	return Plugin_Handled;
}

void ExecConfig(bool sound)
{
	char sCommand[255];
	char sConfigName[52];
	
	sConfigName = sCurrentGameName;
	
	if(!isH3busDM)
	{
		StrCat(sConfigName, sizeof(sConfigName), ".ini");
		Format(sCommand, sizeof(sCommand), "dm_load \"%s\" \"respawn\"", sConfigName);
	}
	else
	{
		Format(sCommand, sizeof(sCommand), "dm_load \"Game Modes\" \"%s\" \"respawn\"", sConfigName);
	}
	
	ServerCommand(sCommand);
	
	UpdateGameModeIndex();
	
	if(sound)
		PlaySound();	
}

void PrepareNextMode()
{	
	ArrayList aGameMode = new ArrayList(512);
	ArrayList aNextGameMode = new ArrayList(512);
	
	aGameMode = aGameModes.Get(modeIndex);
	
	if(modeIndex == (aGameModes.Length - 1))
		aNextGameMode = aGameModes.Get(0);
	else
		aNextGameMode = aGameModes.Get(modeIndex+1);
	
	iCurrentGameTime = aGameMode.Get(1);

	// sCurrentGameName = sNextGameName; <---- need a bit modification on initialisation to apply this
	aGameMode.GetString(0, sCurrentGameName, sizeof(sCurrentGameName));
	
	aNextGameMode.GetString(0, sNextGameName, sizeof(sNextGameName));
}

void LoadGameModes()
{
	KeyValues kvGameModes = new KeyValues("MultiCFG");
	if (!FileExists(CONFIG_PATH))
	{
		SetFailState("Unable to find multicfg-dm.cfg in %s", CONFIG_PATH);
		return;
	}
	
	kvGameModes.ImportFromFile(CONFIG_PATH);
	
	if (kvGameModes.JumpToKey("Game Modes"))
	{
		kvGameModes.GotoFirstSubKey();
		AddGameModeToArray(kvGameModes);
		
		while (kvGameModes.GotoNextKey())
		{
			AddGameModeToArray(kvGameModes);
		}
	}
	else
	{
		SetFailState("Unable to find Game Modes in %s", CONFIG_PATH);
		return;
	}
	
	delete kvGameModes;
}

void LoadConfig()
{
	KeyValues kvConfig = new KeyValues("MultiCFG");
	if (!FileExists(CONFIG_PATH))
	{
		SetFailState("Unable to find multicfg-dm.cfg in %s", CONFIG_PATH);
		return;
	}
	
	kvConfig.ImportFromFile(CONFIG_PATH);
	
	if (kvConfig.JumpToKey("Config"))
	{
		isLoop = view_as<bool>(KvGetNum(kvConfig, "Loop"));
		isH3busDM = view_as<bool>(KvGetNum(kvConfig, "H3busCompatibility"));
	}
	else
	{
		SetFailState("Unable to find Config in %s", CONFIG_PATH);
		return;
	}

	
	delete kvConfig;
}


void AddGameModeToArray(Handle kv)
{
	char sGameModeName[255];
	int sGameModeTime = 0;
	
	KvGetString(kv, "name", sGameModeName, sizeof(sGameModeName));
	sGameModeTime = KvGetNum(kv, "time");
	
	ArrayList aGameMode = new ArrayList(512);
	aGameMode.PushString(sGameModeName);
	aGameMode.Push(sGameModeTime);
	
	aGameModes.Push(aGameMode);
}

void UpdateGameModeIndex()
{
	if (modeIndex < aGameModes.Length)
	{
		if (modeIndex == (aGameModes.Length - 1))
		{
			if (isLoop)
				modeIndex = 0;
			else
				isLastMode = true;
		}
		else
		{
			modeIndex++;
		}
	}
}

void PlaySound()
{
	for (int i = 1; i <= GetClientCount(true); i++)
	{
		if (!IsFakeClient(i) && !IsClientObserver(i))
			ClientCommand(i, "play *%s", SOUND_PATH);
	}
}

Error:
L 11/03/2019 - 13:07:26: [SM] Exception reported: Client 2 is not in game
L 11/03/2019 - 13:07:26: [SM] Blaming: MultiCFG-DM.smx
L 11/03/2019 - 13:07:26: [SM] Call stack trace:
L 11/03/2019 - 13:07:26: [SM] [0] IsClientObserver
L 11/03/2019 - 13:07:26: [SM] [1] Line 239, MultiCFG-DM.sp:: PlaySound
L 11/03/2019 - 13:07:26: [SM] [2] Line 122, MultiCFG-DM.sp::ExecConfig
L 11/03/2019 - 13:07:26: [SM] [3] Line 66, MultiCFG-DM.sp::Event_RoundStart
L 11/03/2019 - 13:07:48: [SM] Exception reported: Client 4 is not connected
L 11/03/2019 - 13:07:48: [SM] Blaming: MultiCFG-DM.smx
L 11/03/2019 - 13:07:48: [SM] Call stack trace:
L 11/03/2019 - 13:07:48: [SM] [0] IsFakeClient
L 11/03/2019 - 13:07:48: [SM] [1] Line 239, MultiCFG-DM.sp:: PlaySound
L 11/03/2019 - 13:07:48: [SM] [2] Line 122, MultiCFG-DM.sp::ExecConfig
L 11/03/2019 - 13:07:48: [SM] [3] Line 66, MultiCFG-DM.sp::Event_RoundStart

Last edited by rzrhome; 11-03-2019 at 08:24.
rzrhome is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 11-03-2019 , 07:38   Re: Need fixing Help
Reply With Quote #2

Your PlaySound loop never checks if the player is ingame. Also you should be using MaxClients instead of GetClientCount. So add IsClientInGame before any other checks.
xerox8521 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 11-03-2019 , 08:03   Re: Need fixing Help
Reply With Quote #3

Quote:
Originally Posted by rzrhome View Post
Thanks for help me.

SM 1.10

Code:
#include <sourcemod>
#include <sdktools>

EngineVersion g_Game;

public Plugin myinfo = 
{
	name = "", 
	author = "", 
	description = "", 
	version = "", 
	url = ""
};

Handle hTimer;

ArrayList aGameModes;
char sCurrentGameName[52];
char sNextGameName[52];
int iCurrentGameTime;

int modeIndex;

bool isLoop = false;
bool isLastMode = false;
bool isH3busDM;

char CONFIG_PATH[255];
char SOUND_PATH[255] = "ui/bonus_alert_start";

public void OnPluginStart()
{
	g_Game = GetEngineVersion();
	if (g_Game != Engine_CSGO)
	{
		SetFailState("This plugin is for CSGO.");
	}
	
	BuildPath(Path_SM, CONFIG_PATH, sizeof(CONFIG_PATH), "configs/multicfg-dm.cfg");
	
	aGameModes = CreateArray();
	
	LoadConfig();
	LoadGameModes();
	
	HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}

public OnMapStart()
{
	hTimer = INVALID_HANDLE;
}

public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
	if (hTimer != INVALID_HANDLE)
	{
		KillTimer(hTimer, false);
		hTimer = INVALID_HANDLE;
	}
	
	modeIndex = 0;
	
	// First Load
	PrepareNextMode();
	ExecConfig(true);
	
	hTimer = CreateTimer(1.0, CycleControl, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}

public Action CycleControl(Handle timer)
{
	if(isLastMode)
		return Plugin_Stop;
	
	iCurrentGameTime--;
	
	if(iCurrentGameTime <= 0)
	{
		PrepareNextMode();
		
		ExecConfig(true);
	}
	
	if(iCurrentGameTime <= 10 && iCurrentGameTime > 0)
	{
		char sAdvertMessage[255];
		
		Format(sAdvertMessage, sizeof(sAdvertMessage), "<font color='#ff0000'>Warmup  Mod</font>\nChanging to <font color='#66ff66'>%s</font> in <font color='#66ff66'>%i</font> seconds", sNextGameName, iCurrentGameTime);		
	
		if(iCurrentGameTime >= 1)
		{
			PrintHintTextToAll(sAdvertMessage);
		}
	}
	
	return Plugin_Handled;
}

void ExecConfig(bool sound)
{
	char sCommand[255];
	char sConfigName[52];
	
	sConfigName = sCurrentGameName;
	
	if(!isH3busDM)
	{
		StrCat(sConfigName, sizeof(sConfigName), ".ini");
		Format(sCommand, sizeof(sCommand), "dm_load \"%s\" \"respawn\"", sConfigName);
	}
	else
	{
		Format(sCommand, sizeof(sCommand), "dm_load \"Game Modes\" \"%s\" \"respawn\"", sConfigName);
	}
	
	ServerCommand(sCommand);
	
	UpdateGameModeIndex();
	
	if(sound)
		PlaySound();	
}

void PrepareNextMode()
{	
	ArrayList aGameMode = new ArrayList(512);
	ArrayList aNextGameMode = new ArrayList(512);
	
	aGameMode = aGameModes.Get(modeIndex);
	
	if(modeIndex == (aGameModes.Length - 1))
		aNextGameMode = aGameModes.Get(0);
	else
		aNextGameMode = aGameModes.Get(modeIndex+1);
	
	iCurrentGameTime = aGameMode.Get(1);

	// sCurrentGameName = sNextGameName; <---- need a bit modification on initialisation to apply this
	aGameMode.GetString(0, sCurrentGameName, sizeof(sCurrentGameName));
	
	aNextGameMode.GetString(0, sNextGameName, sizeof(sNextGameName));
}

void LoadGameModes()
{
	KeyValues kvGameModes = new KeyValues("MultiCFG");
	if (!FileExists(CONFIG_PATH))
	{
		SetFailState("Unable to find multicfg-dm.cfg in %s", CONFIG_PATH);
		return;
	}
	
	kvGameModes.ImportFromFile(CONFIG_PATH);
	
	if (kvGameModes.JumpToKey("Game Modes"))
	{
		kvGameModes.GotoFirstSubKey();
		AddGameModeToArray(kvGameModes);
		
		while (kvGameModes.GotoNextKey())
		{
			AddGameModeToArray(kvGameModes);
		}
	}
	else
	{
		SetFailState("Unable to find Game Modes in %s", CONFIG_PATH);
		return;
	}
	
	delete kvGameModes;
}

void LoadConfig()
{
	KeyValues kvConfig = new KeyValues("MultiCFG");
	if (!FileExists(CONFIG_PATH))
	{
		SetFailState("Unable to find multicfg-dm.cfg in %s", CONFIG_PATH);
		return;
	}
	
	kvConfig.ImportFromFile(CONFIG_PATH);
	
	if (kvConfig.JumpToKey("Config"))
	{
		isLoop = view_as<bool>(KvGetNum(kvConfig, "Loop"));
		isH3busDM = view_as<bool>(KvGetNum(kvConfig, "H3busCompatibility"));
	}
	else
	{
		SetFailState("Unable to find Config in %s", CONFIG_PATH);
		return;
	}

	
	delete kvConfig;
}


void AddGameModeToArray(Handle kv)
{
	char sGameModeName[255];
	int sGameModeTime = 0;
	
	KvGetString(kv, "name", sGameModeName, sizeof(sGameModeName));
	sGameModeTime = KvGetNum(kv, "time");
	
	ArrayList aGameMode = new ArrayList(512);
	aGameMode.PushString(sGameModeName);
	aGameMode.Push(sGameModeTime);
	
	aGameModes.Push(aGameMode);
}

void UpdateGameModeIndex()
{
	if (modeIndex < aGameModes.Length)
	{
		if (modeIndex == (aGameModes.Length - 1))
		{
			if (isLoop)
				modeIndex = 0;
			else
				isLastMode = true;
		}
		else
		{
			modeIndex++;
		}
	}
}

void PlaySound()
{
	for (int i = 1; i <= GetClientCount(true); i++)
	{
		if (!IsFakeClient(i) && !IsClientObserver(i))
			ClientCommand(i, "play *%s", SOUND_PATH);
	}
}

Error:
L 11/03/2019 - 13:07:26: [SM] Exception reported: Client 2 is not in game
L 11/03/2019 - 13:07:26: [SM] Blaming: MultiCFG-DM.smx
L 11/03/2019 - 13:07:26: [SM] Call stack trace:
L 11/03/2019 - 13:07:26: [SM] [0] IsClientObserver
L 11/03/2019 - 13:07:26: [SM] [1] Line 239, MultiCFG-DM.sp:: PlaySound
L 11/03/2019 - 13:07:26: [SM] [2] Line 122, MultiCFG-DM.sp::ExecConfig
L 11/03/2019 - 13:07:26: [SM] [3] Line 66, MultiCFG-DM.sp::Event_RoundStart
L 11/03/2019 - 13:07:48: [SM] Exception reported: Client 4 is not connected
L 11/03/2019 - 13:07:48: [SM] Blaming: MultiCFG-DM.smx
L 11/03/2019 - 13:07:48: [SM] Call stack trace:
L 11/03/2019 - 13:07:48: [SM] [0] IsFakeClient
L 11/03/2019 - 13:07:48: [SM] [1] Line 239, MultiCFG-DM.sp:: PlaySound
L 11/03/2019 - 13:07:48: [SM] [2] Line 122, MultiCFG-DM.sp::ExecConfig
L 11/03/2019 - 13:07:48: [SM] [3] Line 66, MultiCFG-DM.sp::Event_RoundStart
why blank out the original author?

https://github.com/Shivaah/multicfg-...MultiCFG-DM.sp
__________________
8guawong is offline
Balimbanana
Member
Join Date: Jan 2017
Old 11-05-2019 , 12:45   Re: Need fixing Help
Reply With Quote #4

I made a pull request with a couple fixes/adjustments. I don't have a CSGO server to test it on, but it *should* work.
Balimbanana 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 00:41.


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