AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Execute on Dead Players But Not Spectate (https://forums.alliedmods.net/showthread.php?t=237440)

bobbobagan 03-24-2014 05:15

Execute on Dead Players But Not Spectate
 
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?

Bacardi 03-24-2014 05:42

Re: Execute on Dead Players But Not Spectate
 
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;
}


bobbobagan 03-25-2014 04:13

Re: Execute on Dead Players But Not Spectate
 
Thanks for the detailed explanation Bacardi

I may have to drink you some time :wink:

Bacardi 03-25-2014 06:21

Re: Execute on Dead Players But Not Spectate
 
Cuba libre!


All times are GMT -4. The time now is 13:25.

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