Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Third attempt for cmd_targetex #515

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

OciXCrom
Copy link
Contributor

@OciXCrom OciXCrom commented Aug 9, 2018

First attempt was made by HamletEagle.
Second attempt is over here and looks abandoned - #368
So, here's the third attempt to add this stock into AMXX.

For those of you that don't know, the goal of this stock is to allow admins to use arguments such as @ALL, @ct, @t and so on with player targeting commands. Here's a list of all arguments that I made for the stock:

  • @aim - targets the player that the admin is aiming at
  • @ALL - targets all players
  • @alive - targets alive players
  • @Bots - targets all bots
  • @dead - targets dead players
  • @humans - targets all humans
  • @me - targets the admin himself
  • @Spectating - targets the client that the admin is spectating
  • @view - targets all clients in the admin's field of view

In addition, a team name can be passed into any argument that is supposed to target a group of players. For example, @alivect will target all alive players.

Another addition is the option to exclude yourself from the command by adding the "!" symbol right after the "@". For example, @!all will target everyone except the admin who used the command.

I decided to create a separate .inc file because it requires engine.inc. I'm not sure if the compiler will actually read any of the natives in engine.inc if cmd_targetex isn't used in the plugin, if not, we may move it in amxmisc.inc where the original cmd_target is.

Let me know if there's something that can be optimized (there probably is) and if you have any ideas about adding additional arguments (@closest and @radius are ones I have in mind).

Here's an example usage for amx_slap:

new szArg[MAX_NAME_LENGTH], iPlayers[MAX_PLAYERS], szName[MAX_NAME_LENGTH]
read_argv(1, szArg, charsmax(szArg))

new iPnum = cmd_targetex(id, szArg, iPlayers, szName, charsmax(szName), TARGETEX_OBEY_IMM_SINGLE)

if(!iPnum)
    return

for(new i; i < iPnum; i++)
    user_slap(iPlayers[i], 0)

client_print(0, print_chat, "ADMIN %n slapped %s", id, szName)

@rsKliPPy
Copy link
Contributor

rsKliPPy commented Aug 9, 2018

This can probably just be in amxmisc.inc, we don't need a new file.
I haven't checked thoroughly, but because this is in "core" it shouldn't work only for CS teams, it should be game independent. Either through some configuration file, somehow, or with natives to register a new @selector. With that in mind, it's would probably be better if this was a native implemented in the amxmodx core dll.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Aug 9, 2018

@rsKliPPy I made a new file because it includes engine.inc as well, I don't know if that's a big deal or not.

It won't be only for CS. I didn't make the team names hardcoded, instead I added them in an enum list which can be filled with the team names for other games and it will work just fine. I don't know the names for the other games, so a list of them would be appreciated.

I agree it's better if it was a native, but my C++ "skills" aren't too good, I even struggled doing it in Pawn and we can see that other people did too (the previous attempts).

@Arkshine Arkshine mentioned this pull request Aug 21, 2018
@OciXCrom OciXCrom changed the title [WIP] Third attempt for cmd_targetex Third attempt for cmd_targetex Aug 26, 2018
@OciXCrom
Copy link
Contributor Author

OciXCrom commented Aug 26, 2018

I removed the [WIP] tag since I think it's pretty much good to go from coding perspective. I'll just need a list of all the team names used in AMXX games so I can add them in the file.

static const Targetex_Teams[][TargetexTeams] =
{
	{ "ct", "CT" },
	{ "t", "TERRORIST" },
	{ "spec", "SPECTATOR" }
}

I did a bunch of testing and no problems were found.

@rsKliPPy
Copy link
Contributor

There isn't such a list, that's the thing. That's why I think the ability to target teams shouldn't be in the core.

@OciXCrom
Copy link
Contributor Author

@rsKliPPy There won't be any problem if an invalid team name is used. It will simply print in the console that no players were found. It uses get_players_ex to find the players and this function doesn't produce errors or any kind of problems if the team name doesn't exist. With that being said, if you try using a CS team in DoD for example, it will simply tell you that no players were found.

@WPMGPRoSToTeMa
Copy link
Contributor

WPMGPRoSToTeMa commented Aug 30, 2018

@OciXCrom for team filters I see two approaches:

  1. If text after @ can't be matched with any pattern, then treat it as a team name and pass it to get_players_ex.
  2. Add prefix for team patterns like @team_%teamname% or @team%teamname%, where %teamname% is a team name.

@rsKliPPy
Copy link
Contributor

I like the second suggestion the most and provided that no errors are produced when matching team names, it seems like the best solution which can stay in core.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Aug 30, 2018

@WPMGPRoSToTeMa @rsKliPPy Right now it's working like this:

  1. It's looping the entire array that holds the teams and if it finds a match it adds _TEAM to the language key (e.g. ct).
  2. It checks if any other argument is specified (e.g. @alivect). If not (it's only @ct), it proceeds directly to affecting the entire team.

This way there's no errors or wrong matches. The group argument names don't collide with the team names. The only reason I don't like the second approach is because the patterns are longer and admins will need to write more text (e.g. @team_ct), whereas typing only @ct is much convenient and used in custom plugins at the moment so people are already used to it.

What can also be done is to check the modname on first call and add the team names to the array according to the game (e.g. add t, ct and spec if the game is cstrike). This way it won't have to loop the teams from all games.

@WPMGPRoSToTeMa
Copy link
Contributor

@OciXCrom IIRC Half-Life has dynamic teams, so I think it's not possible to store teams for all the games.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Aug 30, 2018

@WPMGPRoSToTeMa Weren't the teams in HL named RED and BLUE? If they can't be added we'll just ignore them, not a big deal. It's fine as long as they're working for CS and other games that have valid team names. We just need to dig out the list.

I found this:

"mp_teamlist: This defines the team names in HLDM depending of the models. Put nothing to allow all teams. List of valid team names: barney, gina, gman, gordon, helmet, hgrunt, recon, robo, scientist, zombie"

@Nord1cWarr1or
Copy link

Any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants