Raised This Month: $ Target: $400
 0% 

Scripting help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
BigMac
Member
Join Date: Jul 2009
Old 08-02-2009 , 09:22   Scripting help
Reply With Quote #1

Making rock the template for more configs but i don't know how to make it so it loads the new config that i want it to load.

Code:
#include <amxmodx>

#define ADMIN_RTT	ADMIN_KICK

new g_iRocks;
new g_iPlayers;
new bool:g_bCanRock
new bool:g_bRocked[33];
new bool:g_bTemplateEnded;
new bool:g_bRockedTemplate;
new Float:g_fRockDelay;

new rtt_enabled;
new rtt_percentage;
new rtt_wait;
new rtt_enddelay;
new rtt_who;
new rtt_showcmd;

public plugin_init()
{
	register_plugin("Rock The Template", "0.1", "Random");
	register_clcmd("say", "clcmd_Say");
	register_clcmd("say_team", "clcmd_Say");
	register_concmd("amx_rockthetemplate", "concmd_Rockthetemplate", ADMIN_RTT, "-- Rocks the template automatically.");
	register_concmd("amx_rtt", "concmd_Rockthetemplate", ADMIN_RTT, "-- Rocks the template automatically.");
	register_event("HLTV", "event_NewTemplate", "a", "1=0", "2=0");
	register_logevent("logevent_TemplateEnd", 2, "1=Template_End");
	
	rtt_enabled =		register_cvar("rtt_enabled", "1");
	rtt_percentage =	register_cvar("rtt_percentage", "60");
	rtt_wait =		register_cvar("rtt_wait", "180");
	rtt_enddelay =		register_cvar("rtt_enddelay", "10");
	rtt_who =		register_cvar("rtt_who", "0");
	rtt_showcmd =		register_cvar("rtt_showcmd", "0");
}

public client_putinserver(id)
{
	g_iPlayers++;
}

public client_disconnect(id)
{
	g_iPlayers--;
	
	if(g_bRocked[id] && !g_bRockedTemplate)
	{
		new sName[32];
		get_user_name(id, sName, sizeof(sName) - 1);
		client_print(0, print_chat, "[RTT] %s has left, so his/her rock does not count!", sName);
		g_bRocked[id] = false;
		g_iRocks--;
	}
}

public clcmd_Say(id)
{
	static sMessage[192];
	static const iMsgLen = sizeof(sMessage) - 1;
	read_args(sMessage, iMsgLen);
	remove_quotes(sMessage);
	if(equali(sMessage, "rtt") || equali(sMessage, "rockthetemplate"))
	{
		clcmd_Rockthetemplate(id);
		if(!get_pcvar_num(rtt_showcmd))
		{
			return PLUGIN_HANDLED;
		}
	}
	return PLUGIN_CONTINUE;
}

public clcmd_Rockthetemplate(id)
{
	if(!get_pcvar_num(rtt_enabled))
	{
		client_print(id, print_chat, "[RTT] Rock the Template is currently disabled.");
		return PLUGIN_HANDLED;
	}
	
	if(g_bTemplateEnded)
	{
		client_print(id, print_chat, "[RTT] The Template has already ended!");
		return PLUGIN_HANDLED;
	}
	
	if(g_bRockedTemplate)
	{
		client_print(id, print_chat, "[RTT] The Template has already been rocked!");
		return PLUGIN_HANDLED;
	}
	
	if(!g_bCanRock)
	{
		if(!task_exists(112233))
		{
			// in case the plugin is stupid
			g_bCanRock = true;
			goto canrock;
		}
		
		new iTotal = floatround(g_fRockDelay - get_gametime());
		new iSeconds = (iTotal % 60);
		new iMinutes = (iTotal - iSeconds) / 60;
		
		new sTime[32];
		new iTimeLen = sizeof(sTime) - 1;
		
		if(iMinutes > 0)
		{
			formatex(sTime, iTimeLen, "%d minute%s", iMinutes, (iMinutes != 1) ? "s" : "");
		}
		if(iSeconds > 0)
		{
			if(!strlen(sTime))
			{
				formatex(sTime, iTimeLen, "%d second%s", iSeconds, (iSeconds != 1) ? "s" : "");
			}
			else
			{
				format(sTime, iTimeLen, "%s and %d second%s", sTime, iSeconds, (iSeconds != 1) ? "s" : "");
			}
		}
		
		client_print(id, print_chat, "[RTT] You must wait %s before you can rock the Template.", sTime);
		return PLUGIN_HANDLED;
	}
	
	canrock:
	switch(get_pcvar_num(rtt_who))
	{
		case 0:
		{
			if(is_user_alive(id))
			{
				client_print(id, print_chat, "[RTT] You must be dead to rock the Template!");
				return PLUGIN_HANDLED;
			}
		}
		case 1:
		{
			if(!is_user_alive(id))
			{
				client_print(id, print_chat, "[RTT] You must be alive to rock the Template!");
				return PLUGIN_HANDLED;
			}
		}
		case 2:
		{
			/* anyone can rock it */
		}
		default:
		{
			set_pcvar_num(rtt_who, 2);
		}
	}
	
	if(g_bRocked[id])
	{
		client_print(id, print_chat, "[RTT] You have already rocked the Template.");
	}
	else
	{
		g_iRocks++;
		g_bRocked[id] = true;
		
		new sName[32];
		get_user_name(id, sName, sizeof(sName) - 1);
		client_print(0, print_chat, "[RTT] %s has rocked the Template.", sName);
		
		new iNeeded = floatround((float(g_iPlayers) * (get_pcvar_float(rtt_percentage) / 100.0)) + 0.49);
		if(g_iRocks >= iNeeded)
		{
			client_print(0, print_chat, "[RTT] Enough (%d) people have rocked the Template.", g_iRocks);
			rock_the_template();
		}
		else
		{
			iNeeded -= g_iRocks;
			client_print(0, print_chat, "[RTT] Only %d more %s need%s to rock the Template!", iNeeded, (iNeeded != 1) ? "people" : "person", (iNeeded == 1) ? "s" : "");
		}
	}
	return PLUGIN_HANDLED;
}

public concmd_Rockthetemplate(id, level, cid)
{
	if(!(get_user_flags(id) & ADMIN_RTT))
	{
		console_print(id, "[RTT] You have no access to this command!");
		return PLUGIN_HANDLED;
	}
	
	if(!get_pcvar_num(rtt_enabled))
	{
		console_print(id, "[RTT] Rock the Template is currently disabled!");
		return PLUGIN_HANDLED;
	}
	
	if(g_bTemplateEnded)
	{
		console_print(id, "[RTT] The Template has already ended!");
		return PLUGIN_HANDLED;
	}
	
	if(g_bRockedTemplate)
	{
		console_print(id, "[RTT] The Template has already been rocked!");
		return PLUGIN_HANDLED;
	}
	
	new sName[32];
	get_user_name(id, sName, sizeof(sName) - 1);
	client_print(0, print_chat, "[RTT] ADMIN %s: has rocked the Template automatically!", sName);
	
	new sAuthid[35];
	get_user_authid(id, sAuthid, sizeof(sAuthid) - 1);
	log_amx("%s <%s> rocked the template!", sName, sAuthid);
	
	rock_the_template();
	return PLUGIN_HANDLED;
}

public event_NewTemplate()
{
	g_iRocks = 0;
	arrayset(g_bRocked, false, sizeof(g_bRocked));
	g_bTemplateEnded = false;
	g_bRockedTemplate = false;
	
	new Float:fWait = get_pcvar_float(rtt_wait);
	if(fWait > 0.0)
	{
		g_bCanRock = false;
		set_task(fWait, "task_AllowRock", 112233);
		g_fRockDelay = get_gametime() + fWait;
	}
	else
	{
		g_bCanRock = true;
	}
}

public task_AllowRock()
{
	g_bCanRock = true;
	client_print(0, print_chat, "[RTT] You can now rock the template!");
}

public logevent_TemplateEnd()
{
	g_bTemplateEnded = true;
	if(task_exists(112233))
	{
		remove_task(112233);
	}
	
	if(task_exists(223344))
	{
		remove_task(223344);
	}
}

public task_Timer(iTimer[])
{
	if(iTimer[0] > 0 || iTimer[1] > 0)
	{
		if(iTimer[0] == 0)
		{
			iTimer[1]--;
			iTimer[0] = 59;
		}
		else
		{
			iTimer[0]--;
		}
		
		set_hudmessage(255, 255, 255, -1.0, -1.0, 0, 0.0, 1.1, 0.1, 0.1, 1);
		show_hudmessage(0, "Round is Ending^nNew Config will start in:^n%d:%02d", iTimer[1], iTimer[0]);
		set_task(1.0, "task_Timer", 223344, iTimer, 2);
	}
}

rock_the_template()
{
	client_print(0, print_chat, "[RTT] New Config will start next round...");
	
	new iTotal = get_pcvar_num(rtt_enddelay) + 1;
	new iTimer[2];
	iTimer[0] = (iTotal % 60);
	iTimer[1] = (iTotal - iTimer[0]) / 60;
	task_Timer(iTimer);
	
	g_bRockedTemplate = true;
}
__________________

Last edited by BigMac; 08-02-2009 at 09:28. Reason: i fail
BigMac 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 18:31.


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