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

Execute on Dead Players But Not Spectate


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bobbobagan
SourceMod Donor
Join Date: May 2007
Location: New Zealand
Old 03-24-2014 , 05:15   Execute on Dead Players But Not Spectate
Reply With Quote #1

Hi all,

What would be the best way to execute a command on dead players but not execute on spectators?

The following will not execute if a client is in spectate and an admin uses sm_respawn @all. If I remove the code relating to spectate then the plugin works, but if an admin executes on a single client in spectate it says that they were respawned (they weren't actually respawned, plugin just reports in chat that they were)

Code:
public Action:Command_Respawn(client, args)
{
	if (args < 1)
	{
		ReplyToCommand(client, "[SM] Usage: sm_respawn <#userid|name>");
		return Plugin_Handled;
	}

	decl String:arg[65];
	GetCmdArg(1, arg, sizeof(arg));

	decl String:target_name[MAX_TARGET_LENGTH];
	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;

	if ((target_count = ProcessTargetString(
	arg,
	client,
	target_list,
	MAXPLAYERS,
	COMMAND_FILTER_DEAD,
	target_name,
	sizeof(target_name),
	tn_is_ml)) <= 0)
	{
		ReplyToTargetError(client, target_count);
		return Plugin_Handled;
	}

	for (new i = 0; i < target_count; i++)
	{
		new team = GetClientTeam(target_list[i]);
		if (team == TEAM_1 || team == TEAM_2)
			RespawnPlayer(client, target_list[i]);
		if (team == SPECTATOR_TEAM || team == TEAM_SPEC)
		{
			PrintToChat(client, "[SM] %t", "Client not on active team");
			return Plugin_Handled;
		}
	}

	if (tn_is_ml)
	{
		ShowActivity2(client, "[SM] ", "%t", "Toggled respawn on target", target_name);
	}
	else
	{
		ShowActivity2(client, "[SM] ", "%t", "Toggled respawn on target", "_s", target_name);
	}

	return Plugin_Handled;
}
How can I allow the use of @all but not have it execute on spectators?
__________________
bobbobagan is offline
Send a message via Skype™ to bobbobagan
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-24-2014 , 05:42   Re: Execute on Dead Players But Not Spectate
Reply With Quote #2

this look funny... re-order your target_list array
Code:
public Action:Command_Respawn(client, args)
{
	if (args < 1)
	{
		ReplyToCommand(client, "[SM] Usage: sm_respawn <#userid|name>");
		return Plugin_Handled;
	}

	new String:arg[65];
	GetCmdArg(1, arg, sizeof(arg));

	new String:target_name[MAX_TARGET_LENGTH];
	new target_list[MaxClients], target_count, bool:tn_is_ml;

	target_count = ProcessTargetString(
					arg,
					client,
					target_list,
					MaxClients,
					COMMAND_FILTER_DEAD,
					target_name,
					sizeof(target_name),
					tn_is_ml);


	if(target_count <= COMMAND_TARGET_NONE) 	// If we don't have dead players
	{
		ReplyToTargetError(client, target_count);
		return Plugin_Handled;
	}

	// Team filter dead players, re-order target_list array with new_target_count
	new target, team, new_target_count;

	for (new i = 0; i < target_count; i++)
	{
		target = target_list[i];
		team = GetClientTeam(target);

		if(team >= 2)
		{
			target_list[new_target_count] = target; // re-order
			new_target_count++;
		}
	}

	if(new_target_count == COMMAND_TARGET_NONE) // No dead players from  team 2 and 3
	{
		ReplyToTargetError(client, new_target_count);
		return Plugin_Handled;
	}

	target_count = new_target_count; // re-set new value.

	if (tn_is_ml)
	{
		ShowActivity2(client, "[SM] ", "%t", "Toggled respawn on target", target_name);
	}
	else
	{
		ShowActivity2(client, "[SM] ", "%t", "Toggled respawn on target", "_s", target_name);
	}

	for (new i = 0; i < target_count; i++)
	{
		RespawnPlayer(client, target_list[i]);
	}

	return Plugin_Handled;
}
Bacardi is offline
bobbobagan
SourceMod Donor
Join Date: May 2007
Location: New Zealand
Old 03-25-2014 , 04:13   Re: Execute on Dead Players But Not Spectate
Reply With Quote #3

Thanks for the detailed explanation Bacardi

I may have to drink you some time
__________________

Last edited by bobbobagan; 03-25-2014 at 04:14.
bobbobagan is offline
Send a message via Skype™ to bobbobagan
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-25-2014 , 06:21   Re: Execute on Dead Players But Not Spectate
Reply With Quote #4

Cuba libre!
Bacardi is offline
Reply


Thread Tools
Display Modes

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