Raised This Month: $ Target: $400
 0% 

Move player to spectator.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-07-2007 , 21:20   Move player to spectator.
Reply With Quote #1

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   } }

Last edited by fysiks; 11-04-2007 at 01:33.
fysiks is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 10-07-2007 , 21:53   Re: Move player to spectator.
Reply With Quote #2

I'm pretty sure there are a few plugins that already do this

And when posting code, use [php] tags instead of [code] tags
__________________
M249-M4A1 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-08-2007 , 01:07   Re: Move player to spectator.
Reply With Quote #3

Quote:
Originally Posted by M249-M4A1 View Post
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.
fysiks is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-08-2007 , 03:30   Re: Move player to spectator.
Reply With Quote #4

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 ;)
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 10-08-2007 , 07:24   Re: Move player to spectator.
Reply With Quote #5

Quote:
Originally Posted by Wilson [29th ID] View Post
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
__________________
M249-M4A1 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-08-2007 , 21:00   Re: Move player to spectator.
Reply With Quote #6

Quote:
Originally Posted by Wilson [29th ID] View Post
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.
fysiks is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-09-2007 , 03:35   Re: Move player to spectator.
Reply With Quote #7

The only time I've ever needed to get a username's userid, I used:

new id = get_user_index(szUsername);
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
Vet
Veteran Member
Join Date: Jul 2006
Location: I|O wa
Old 11-04-2007 , 13:57   Re: Move player to spectator.
Reply With Quote #8

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
}
__________________
=====================================
- My Plugins -
=====================================

Last edited by Vet; 12-04-2007 at 02:41.
Vet is offline
Send a message via MSN to Vet
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-03-2007 , 17:37   Re: Move player to spectator.
Reply With Quote #9

Code:
 
engclient_cmd(player, "jointeam", "3")
Where can I get a list of command constants (e.g. "jointeam")?
fysiks is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 12-04-2007 , 00:19   Re: Move player to spectator.
Reply With Quote #10

lol ?! that are cs client commands. Just look in cs...
__________________
Still...lovin' . Connor noob! Hello
Alka 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 16:15.


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