Raised This Month: $ Target: $400
 0% 

[Feature Request] Free For all Day update


Post New Thread Reply   
 
Thread Tools Display Modes
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-25-2013 , 19:57   Re: [Feature Request] Free For all Day update
Reply With Quote #31

updated version:
Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#include <sdkhooks>
#include <smlib>

#pragma semicolon 1

#define REFRESH_RATE 0.5

new bool:FFDON = false;
new String:weaponsinfo[][] = {

	"weapon_ak47", "AK47",
	"weapon_m4a1", "M4A1",
	"weapon_awp", "AWP",
	"weapon_scout", "SCOUT",
	"weapon_aug", "AUG",
	"weapon_sg550", "SG550",
	"weapon_famas", "FAMAS",
	"weapon_m3", "M3",
	"weapon_xm1014", "XM1014",
	"weapon_galil", "GALIL",
	"weapon_sg552", "SG552",
	"weapon_g3sg1", "G3SG1",
	"weapon_mac10", "MAC10",
	"weapon_tmp", "TMP",
	"weapon_mp5navy", "MP5",
	"weapon_ump45", "UMP45",
	"weapon_p90", "P90",
	"weapon_m249", "M249"

};
new Handle:Menu;
new Handle:countdownTimer = INVALID_HANDLE;
new Handle:startFFDRoundTimer = INVALID_HANDLE;
new Float:startGameTime;
new Handle:friendlyfireConvar;
new oldValue;
new Handle:autoFFDModeConvar;
new Handle:numberOfRoundsToFFDConvar;
new Handle:numberOfRoundsExpectedConvar;
new roundNumber;
new roundToFFD;
new playerTeam[MAXPLAYERS+1];

public OnMapStart(){

	roundNumber = 0;
	roundToFFD = 0;
	switch(GetConVarInt(autoFFDModeConvar)){

		case 1:{

			roundToFFD = GetConVarInt(numberOfRoundsToFFDConvar);

		}case 2:{

			roundToFFD = GetRandomInt(2, GetConVarInt(numberOfRoundsExpectedConvar));

		}

	}

}

public OnPluginStart(){

	RegAdminCmd("sm_ffd", OnFFD, ADMFLAG_ROOT);
	HookEvent("round_start", OnRoundStart);
	Menu = CreateMenu(WeaponsHandler);
	for(new i = 0; i < sizeof(weaponsinfo); i+= 2){

		AddMenuItem(Menu, weaponsinfo[i], weaponsinfo[i+1]);

	}
	SetMenuTitle(Menu, "Weapon Menu");
	SetMenuExitButton(Menu, true);
	for(new i = 1; i <= MaxClients; i++){

		if(IsClientInGame(i)){

			SDKHook(i, SDKHook_OnTakeDamage, OnTakeDamage);

		}

	}
	friendlyfireConvar = FindConVar("mp_friendlyfire");
	HookUserMessage(GetUserMessageId("TextMsg"), Hook_TextMsg, true);
	HookUserMessage(GetUserMessageId("HintText"), Hook_HintText, true);
	autoFFDModeConvar = CreateConVar("auto_ffd_mode", "0", "0 = disabled; 1 = ffd at a defined number of rounds; 2 = ffd at a random round");
	numberOfRoundsToFFDConvar = CreateConVar("number_of_rounds_to_ffd", "0", "number of rounds to ffd if auto_ffd_mode is set to 1");
	numberOfRoundsExpectedConvar = CreateConVar("number_of_rounds_expected", "0", "number of rounds expected at a map. if auto_ffd_mode is set to 2, a ffd round will happen in a round before this number, excluding the first round(ffd at the first round doesn't sound like a good idea).");
	RegConsoleCmd("sm_ffdteam", OnFFDTeam);
	RegConsoleCmd("sm_ffdaccept", OnFFDAccept);
	RegConsoleCmd("sm_ffdleaveteam", OnFFDLeaveTeam);
	HookEvent("player_death", OnPlayerDeath);
	RegConsoleCmd("sm_ffdhelp", OnFFDHelp);

}

public Action:OnFFDHelp(client, args){

	OpenFFDHelpMenu(client);

}

OpenFFDHelpMenu(client){

	new Handle:menu = CreateMenu(HelpMenuHandler);
	SetMenuTitle(menu, "Free For all Day");
	AddMenuItem(menu, "30to1", "Information about the 30 seconds between activation and countdown reaching 0");
	AddMenuItem(menu, "teams", "Information about the teams system");
	AddMenuItem(menu, "after0", "Information about the ffd after the countdown reaches 0");
	SetMenuExitButton(menu, true);
	SetMenuExitBackButton(menu, false);
	DisplayMenu(menu, client, MENU_TIME_FOREVER);

}

public HelpMenuHandler(Handle:menu, MenuAction:action, param1, param2){

	if(action == MenuAction_Select){

		decl String:buffer[128];
		GetMenuItem(menu, param2, buffer, 128);
		new Handle:submenu = CreateMenu(HelpSubmenuHandler);
		if(StrEqual(buffer, "30to1", false)){

			SetMenuTitle(submenu, "When the ffd is activated by an admin or\nautomatically you got 30 seconds to team up\nand find a location.\nDuring these 30 seconds you can\nmake teams with the teamsystem.\nDuring these 30 seconds the damage is off\nso you can't kill anyone untill the countdown\nreaches 0.");
			AddMenuItem(submenu, "", "", ITEMDRAW_DISABLED);

		}else if(StrEqual(buffer, "teams", false)){

			SetMenuTitle(submenu, "During the 30 seconds countdown you can\nrequest someone to team up with that\nplayer by typing !ffdteam \"player's name\"\nThat player has to type !ffdaccept\nto accept the request.\nThese teams exist of max 2 players.\nWhen you team up with someone you\ncan't deal that player any damage.\nTeams last for the rest of the map or untill one of\nthe teammates does !ffdleaveteam.\nYou can only join a team during the 30secondscountdown.\nLeaving a team can be done at any moment you want.");
			AddMenuItem(submenu, "", "", ITEMDRAW_DISABLED);

		}else{

			SetMenuTitle(submenu, "When the countdown reaches 0 the ffd will start.\nIt's then free for all. You can now kill everybody\nincluding your teammates. The teammates that made a\nteam using !ffdteam can't deal damage to eachother\nuntill one of them leaves the team by\ntyping !ffdleaveteam. Your goal during the ffd is\nofcourse killing everybody and be the only\nsurvivor or survive with your team. After\nthe countdown reached 0 you can't make teams anymore.\nYou can leave a team anytime you want.");
			AddMenuItem(submenu, "", "", ITEMDRAW_DISABLED);

		}
		SetMenuPagination(submenu, 1);
		SetMenuExitButton(submenu, true);
		SetMenuExitBackButton(submenu, true);
		DisplayMenu(submenu, param1, MENU_TIME_FOREVER);

	}else if(action == MenuAction_End){
		
		CloseHandle(menu);
		
	}

}

public HelpSubmenuHandler(Handle:menu, MenuAction:action, param1, param2){

	if(action == MenuAction_End){

		CloseHandle(menu);

	}else if(action == MenuAction_Cancel && param2 == MenuCancel_ExitBack){

		OpenFFDHelpMenu(param1);

	}

}

public Action:OnFFDAccept(client, args){

	new target = -1;
	for(new i = 1; i <= MaxClients; i++){

		if(playerTeam[i] == client){

			target = i;
			break;

		}

	}
	if(target > 0){

		playerTeam[client] = target;
		PrintToChat(client, "You're now teamed with %N.", target);
		PrintToChat(target, "Your friend %N accepted your request for teaming up.", client);

	}else{

		PrintToChat(client, "Sorry, I couldn't find any person who invited you to a team.");

	}

}

public Action:OnFFDLeaveTeam(client, args){

	purgePlayerTeam(client);
	PrintToChat(client, "You've left your team, if you had one.");

}

public Action:OnFFDTeam(client, arsgs){

	if(!FFDON || GetEngineTime() > startGameTime){

		PrintToChat(client, "Sorry, you can only do !ffdteam request during the 30 seconds countdown when ffd is activated.");
		return Plugin_Handled;

	}
	if(playerTeam[client] > 0 && playerTeam[playerTeam[client]] == client && IsClientInGame(playerTeam[client])){

		PrintToChat(client, "You have to leave your team with %N before trying to make another one(!ffdleaveteam).", playerTeam[client]);
		return Plugin_Handled;

	}
	if(GetCmdArgs() != 1){

		PrintToChat(client, "Usage of the command: !ffdteam \"name of your friend\"");
		return Plugin_Handled;

	}
	decl String:name[MAX_NAME_LENGTH];
	GetCmdArg(1, name, MAX_NAME_LENGTH);
	new target = FindTarget(client, name, true, false);
	if(target > 0){

		if(playerTeam[target] > 0 && playerTeam[playerTeam[target]] == target && IsClientInGame(playerTeam[target])){

			PrintToChat(client, "You can't invite %N to team up with you because he's already joined a team.", target);
			return Plugin_Handled;

		}else{

			PrintToChat(client, "You invited %N to team up with you.", target);
			PrintToChat(target, "You have been invited by %N to team up with him/her.", client);
			playerTeam[client] = target;

		}


	}
	return Plugin_Handled;

}

public OnClientDisconnect(client){

	purgePlayerTeam(client);
	if(FFDON){

		evaluateRound();

	}

}

purgePlayerTeam(client){

	playerTeam[client] = -1;
	for(new i = 1; i <= MAXPLAYERS; i++){

		if(playerTeam[i] == client){

			playerTeam[i] = -1;

		}

	}

}

//thanks to lambdalambda
public Action:OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast){

	if(FFDON){

		new victim = GetClientOfUserId(GetEventInt(event, "userid"));
		new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
		if(attacker > 0 && victim != attacker && GetClientTeam(victim) == GetClientTeam(attacker)){

			SetEntProp(attacker, Prop_Data, "m_iFrags", GetClientFrags(attacker) + 2);

		}
		evaluateRound();

	}

}

evaluateRound(){

	CS_TerminateRound(6.0, CSRoundEnd_Draw, false);

}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3]){

	if(!FFDON || attacker <= 0 || attacker > MaxClients || victim <= 0 || victim > MaxClients){

		return Plugin_Continue;

	}else if(countdownTimer != INVALID_HANDLE){

		damage = 0.0;
		return Plugin_Changed;

	}else if(playerTeam[victim] == attacker && playerTeam[attacker] == victim){

		new count = 0;
		for(new i = 1; i <= MaxClients; i++){

			if(IsClientInGame(i) && IsPlayerAlive(i)){

				count++;

			}

		}
		if(count > 2){

			damage = 0.0;
			return Plugin_Changed;

		}

	}else if(GetClientTeam(victim) && GetClientTeam(attacker) && inflictor == attacker){

		damage /= 0.35;
		return Plugin_Changed;

	}
	return Plugin_Continue;

}

public Action:OnFFD(client, args){

	if(FFDON){

		PrintToChat(client, "Sorry, it's already free for all day. You can't trigger it again.");
		return Plugin_Continue;

	}
	turnFFDOn();
	return Plugin_Continue;

}

turnFFDOn(){

	for(new i = 1; i <= MaxClients; i++){

		if(IsClientInGame(i) && IsPlayerAlive(i)){

			GivePlayerItem(i, "weapon_deagle");
			DisplayMenu(Menu, i, MENU_TIME_FOREVER);

		}

	}
	FFDON = true;
	oldValue = GetConVarInt(friendlyfireConvar);
	SetConVarInt(friendlyfireConvar, 1);
	countdownTimer = CreateTimer(REFRESH_RATE, refreshCountdown, _, TIMER_REPEAT);
	startGameTime = GetEngineTime() + 30.0;
	PrintCenterTextAll("You got 30 seconds to team up and find a location");

}

public Action:refreshCountdown(Handle:timer, any:data){

	new remainingTime = RoundFloat(startGameTime - GetEngineTime());
	if(remainingTime > 0){

		PrintCenterTextAll("You got %d seconds to team up and find a location", remainingTime);
		return Plugin_Continue;

	}else{

		PrintCenterTextAll("Kill your enemies!");
		countdownTimer = INVALID_HANDLE;
		return Plugin_Stop;

	}

}

public Action:CS_OnTerminateRound(&Float:delay, &CSRoundEndReason:reason){

	if(FFDON){

		new ctcount = 0;
		new trcount = 0;
		for(new i = 1; i <= MaxClients; i++){

			if(IsClientInGame(i) && IsPlayerAlive(i)){

				switch(GetClientTeam(i)){

					case 2:{

						trcount++;

					}case 3:{

						ctcount++;

					}

				}

			}

		}
		if(trcount + ctcount > 1){

			return Plugin_Handled;

		}
		if(trcount == 0){

			if(countdownTimer != INVALID_HANDLE){

				KillTimer(countdownTimer);
				countdownTimer = INVALID_HANDLE;

			}
			FFDON = false;
			SetConVarInt(friendlyfireConvar, oldValue);
			reason = CSRoundEnd_CTWin;
			return Plugin_Changed;

		}else if(ctcount == 0){

			if(countdownTimer != INVALID_HANDLE){

				KillTimer(countdownTimer);
				countdownTimer = INVALID_HANDLE;

			}
			FFDON = false;
			SetConVarInt(friendlyfireConvar, oldValue);
			reason = CSRoundEnd_TerroristWin;
			return Plugin_Changed;

		}
		return Plugin_Handled;

	}
	return Plugin_Continue;

}

public WeaponsHandler(Handle:menu, MenuAction:action, param1, param2){

	if(action == MenuAction_Select && FFDON){

		decl String:weapon[32];
		GetMenuItem(menu, param2, weapon, 32);
		if(IsPlayerAlive(param1)){

			GivePlayerItem(param1, weapon);

		}

	}

}

public Action:OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast){

	if(startFFDRoundTimer != INVALID_HANDLE){

		KillTimer(startFFDRoundTimer);
		startFFDRoundTimer = INVALID_HANDLE;

	}
	roundNumber++;
	if(roundNumber == roundToFFD - 1){

		PrintCenterTextAll("Next round will be a Free For all Day. For more info about ffd type !ffdhelp");
		PrintToChatAll("Next round will be a Free For all Day. For more info about ffd type !ffdhelp");

	}else if(roundNumber == roundToFFD){

		PrintCenterTextAll("This round is going to be a Free For all Day, expect for it in 30s");
		PrintToChatAll("This round is going to be a Free For all Day, expect for it in 30s");
		if(startFFDRoundTimer != INVALID_HANDLE){

			KillTimer(startFFDRoundTimer);
			startFFDRoundTimer = INVALID_HANDLE;

		}
		startFFDRoundTimer = CreateTimer(30.0, startFFDRound);

	}
	FFDON = false;
	if(countdownTimer != INVALID_HANDLE){

		KillTimer(countdownTimer);
		countdownTimer = INVALID_HANDLE;

	}
	SetConVarInt(friendlyfireConvar, oldValue);

}

public Action:startFFDRound(Handle:timer, any:data){

	startFFDRoundTimer = INVALID_HANDLE;
	turnFFDOn();

}

public Action:Hook_TextMsg(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
{
	/* Block team-attack messages from being shown to players. */ 
	decl String:message[256];
	BfReadString(bf, message, sizeof(message));

	if (StrContains(message, "teammate_attack") != -1)
		return Plugin_Handled;

	if (StrContains(message, "Killed_Teammate") != -1)
		return Plugin_Handled;
		
	return Plugin_Continue;
}

public Action:Hook_HintText(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
{
	/* Block team-attack "tutorial" messages from being shown to players. */ 
	decl String:message[256];
	BfReadString(bf, message, sizeof(message));
	
	if (StrContains(message, "spotted_a_friend") != -1)
		return Plugin_Handled;

	if (StrContains(message, "careful_around_teammates") != -1)
		return Plugin_Handled;
	
	if (StrContains(message, "try_not_to_injure_teammates") != -1)
		return Plugin_Handled;
		
	return Plugin_Continue;
}

public OnClientPutInServer(client){

	SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
	purgePlayerTeam(client);

}
i don't know why it's not working. change the convars and, then, change the map. it should be working...
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
tommie113
AlliedModders Donor
Join Date: Oct 2013
Old 11-26-2013 , 05:41   Re: [Feature Request] Free For all Day update
Reply With Quote #32

It's working now
Thanks for your help.
__________________
No longer taking requests due to lack of time and interrest.
Only helping out with minor things through forum.
tommie113 is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-26-2013 , 06:28   Re: [Feature Request] Free For all Day update
Reply With Quote #33

bitte, but it was already working before my last update, though. at my last update i only corrected an issue that would happen in a very rare and specific case, nothing related to the cvars.
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
tommie113
AlliedModders Donor
Join Date: Oct 2013
Old 11-26-2013 , 06:31   Re: [Feature Request] Free For all Day update
Reply With Quote #34

Weird that it wasn't working first then, but it works now.
If there is any way I could help you in return, please send me a pm.
__________________
No longer taking requests due to lack of time and interrest.
Only helping out with minor things through forum.
tommie113 is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-26-2013 , 06:53   Re: [Feature Request] Free For all Day update
Reply With Quote #35

so, u could gimme a hug and invite me to play on your server.
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
tommie113
AlliedModders Donor
Join Date: Oct 2013
Old 11-26-2013 , 06:54   Re: [Feature Request] Free For all Day update
Reply With Quote #36

If you want to play on my servers you can add me on steam
Search liquidkillsx
You will find me with the ingame name i[B]eaSt.
__________________
No longer taking requests due to lack of time and interrest.
Only helping out with minor things through forum.
tommie113 is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 11-26-2013 , 06:56   Re: [Feature Request] Free For all Day update
Reply With Quote #37

danke
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 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 20:27.


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