AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Move player to spectator. (https://forums.alliedmods.net/showthread.php?t=61717)

fysiks 10-07-2007 21:20

Move player to spectator.
 
I was just messing around and I thought of writing a plugin that would move a player to spectator if maybe they were afk and didn't want to kick them. I was wondering if you anyone might have some suggestions to improve my script. I it works fine on my server (linux fc6) but any thoughts would be great.

Code:
  // Plugin for moving a player to spectator.   #include <amxmodx> #include <amxmisc> #include <dodfun>   #define PLUGIN "mv_spec" #define VERSION "1.0" #define AUTHOR "Fysiks"   public plugin_init() {   register_plugin(PLUGIN,VERSION,AUTHOR)   register_concmd("admin_spec", "cmdMvSpec", ADMIN_KICK, "<player> - Moves player to spectator.") }   public cmdMvSpec(id, level, cid) {   if (!cmd_access(id, level, cid, 2))     return PLUGIN_HANDLED     new arg[32]   read_argv(1, arg, 31)   new player = cmd_target(id, arg, 2)     if (!player)     return PLUGIN_HANDLED     new authid[32], name[32], userid   get_user_authid(player, authid, 31)   get_user_name(player, name, 31)   userid = get_user_userid(player)     new teamname[12]   get_user_team(player, teamname, 11)     if (is_user_bot(player))  {    console_print(id, "Kicking a bot is BAD, Action denied.")    return PLUGIN_HANDLED  }     if (teamname[0])   {     dod_set_user_team(player, 3, 1)     return PLUGIN_HANDLED   } else {     console_print(id, "No such player.")     return PLUGIN_HANDLED   } }

M249-M4A1 10-07-2007 21:53

Re: Move player to spectator.
 
I'm pretty sure there are a few plugins that already do this

And when posting code, use [php] tags instead of [code] tags

fysiks 10-08-2007 01:07

Re: Move player to spectator.
 
Quote:

Originally Posted by M249-M4A1 (Post 539836)
I'm pretty sure there are a few plugins that already do this

I only want the one command though. I was just wondering if there were any potential problems that might come up that I haven't thought of that might crash the server or cause unwelcomed side effects.

Wilson [29th ID] 10-08-2007 03:30

Re: Move player to spectator.
 
Quite concisely written and to the point. Doesn't seem to be any improvements I can think of. I've never used cmd_target() so it seems that having get_user_userid() afterward is redundant, but like I said I've never used it before - it might return something else - if it works, it works.

And M249, you can use the [small] tag for the real coding tag ;)

M249-M4A1 10-08-2007 07:24

Re: Move player to spectator.
 
Quote:

Originally Posted by Wilson [29th ID] (Post 539910)
Quite concisely written and to the point. Doesn't seem to be any improvements I can think of. I've never used cmd_target() so it seems that having get_user_userid() afterward is redundant, but like I said I've never used it before - it might return something else - if it works, it works.

And M249, you can use the [small] tag for the real coding tag ;)

Lies :D

fysiks 10-08-2007 21:00

Re: Move player to spectator.
 
Quote:

Originally Posted by Wilson [29th ID] (Post 539910)
I've never used cmd_target() so it seems that having get_user_userid() afterward is redundant, but like I said I've never used it before - it might return something else - if it works, it works.

When I was writing the code my refernce scripts had those commands in them so I just wrote serveral things in that I didn't end up using. (e.g I assign the get_user_userid() to a var that I don't use because I didn't know if I would end up needing it in the end.

Wilson,

What do you use instead of cmd_target()?

Thanks for your thoughts.

Wilson [29th ID] 10-09-2007 03:35

Re: Move player to spectator.
 
The only time I've ever needed to get a username's userid, I used:

new id = get_user_index(szUsername);

Vet 11-04-2007 13:57

Re: Move player to spectator.
 
Sup fysiks? There's many ways to skin a cat (personally, I like pliers). Here's a couple things...

This code in your plugin isn't used anywhere else. Thus, unnecessary.
Code:


  new authid[32], name[32], userid
  get_user_authid(player, authid, 31)
  get_user_name(player, name, 31)
  userid = get_user_userid(player)

There's no real harm in sending a bot to spectator. Of course he'll stay there until the map changes or you kick him.

If you use the 'engclient_cmd' function, you don't need the 'dodfun' module. So instead of this...
Code:


    dod_set_user_team(player, 3, 1)

you could use this...
Code:


    engclient_cmd(player, "jointeam", "3")

This part is unnecessary
Code:


  } else {
    console_print(id, "No such player.")
    return PLUGIN_HANDLED

because it will never be reached. If the cmd_target function can't differentiate a player, it will issue a statement saying so. Then the
Code:


  if (!player)
    return PLUGIN_HANDLED

will cause the plugin to exit.

Here's an example of a super simple 'move-to-spectator' plugin for DOD.
Code:

/*
* Send player to spectator
*/
#include <amxmodx>
#include <amxmisc>
 
#define PLUGIN "AMXX_Spec"
#define VERSION "1.0"
#define AUTHOR "Vet(3TT3V)"
 
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_concmd("admin_spec", "playerspec", ADMIN_KICK, "<name or #userid> Send player to Spectator")
}
 
public playerspec(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED
    new arg[32]
    read_argv(1, arg, 31)
    new player = cmd_target(id, arg, 1)
    if (!player)
        return PLUGIN_HANDLED
 
    new curteam[16]
    get_user_team(player, curteam, 15)
    if (curteam[0])
        engclient_cmd(player, "jointeam", "3")
 
    return PLUGIN_HANDLED
}


fysiks 12-03-2007 17:37

Re: Move player to spectator.
 
Code:


engclient_cmd(player, "jointeam", "3")

Where can I get a list of command constants (e.g. "jointeam")?

Alka 12-04-2007 00:19

Re: Move player to spectator.
 
lol ?! that are cs client commands. Just look in cs...


All times are GMT -4. The time now is 16:15.

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