Results 1 to 20 of 20

Thread: SM Plugin: Empty Server Map Change

  1. #1
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2

    SM Plugin: Empty Server Map Change

    Thread for recording things I find when developing a sourcemod plugin:
    Empty Server Map Change

    Thought there was need for this after reading this: http://playstuff.net/showthread.php?t=172&page=4

    So, what should this plugin do?

    When a server is empty, it should change map after n minutes to a random map specified in its config-file.
    Why do we want a map change? Because it might be stuck on a custom map nobody wants to play.

    ------------------------------------
    Functional Specifications (...ahem...):

    Timer should be created:
    - last client disconnects from the server
    - OnMapStart

    Timer should be killed:
    - when client joins the server

    Things in config file:
    - number of minutes to set a timer for a map change (default: 30 minutes)
    - mapnames (default: ?)

    ------------------------------------

    Useful links:


    Feel free to give any random shouts of awesomeness or disapproval.
    Also, I'm open for suggestions too of course, else I wouldn't start a thread
    Last edited by MacNetron; 03-05-2009 at 22:13. Reason: changed Timer create specs
    2 People have given a Cookie to MacNetron: Boylee.ps, grom.ps

  2. #2
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Ai, should not create timer on OnPluginStart, but on new map start (= OnMapStart)

  3. #3
    ლ(ಠ益ಠლ) Logan's Avatar
    Join Date
    Nov 2008
    Posts
    6,323
    Cookies Given
    4,689
    Cookies Received
    3,320
    Blog Entries
    15
    Sounds like one of the most useful plug ins I can imagine - so many time this is an issue, and having the ability to program the server to respond to it's traffic would be epic!!!

  4. #4
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Updated top specs with OnMapStart note.

    Note to all developers: if a certain function (like OnClientConnected) is not triggered, check version of function in api specs (so called: version added) and the version of the software used. You might need to update your software

    Current output on my laptop (perfect for debugging):
    Code:
    sm plugins reload emptyservermapchange
    [ESMC] No clients ingame and no clients connecting
    [ESMC] Timer created, map change after 1800.000000 seconds, 30 minutes
    [SM] Plugin Empty Server Map Change reloaded successfully.
    Client "MacNetron" connected (192.168.1.103:27005).
    [ESMC] Client connected to the server
    [ESMC] Kill timer, we have a customer
    [ESMC] Client disconnected from the server
    [ESMC] No clients ingame and no clients connecting
    [ESMC] Timer created, map change after 1800.000000 seconds, 30 minutes
    Dropped MacNetron from server (Disconnect by user.)
    Starting to look useful

  5. #5
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Couldn't find any documentation about arrays of Strings. A bit of trying reveals:

    Code:
    	new String:array[][] = {"one","two"}
    	PrintToServer(array[0])
    	PrintToServer(array[1])
    gives the output:

    Code:
    one
    two

  6. #6
    Administrator jim's Avatar
    Join Date
    Nov 2008
    Posts
    2,664
    Cookies Given
    337
    Cookies Received
    2,712
    i've not been keeping track of the forums much lately, didn't see the post, making it yourself then? Gimme a shout if you need any help

  7. #7
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Thnx! Will do that if I run into serious trouble.
    For me, SourcePawn and the SourceMod API is just another language but quite well documented for a community project.

  8. #8
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Version 0.6.6.6: emptyservermapchange-0.6.6.6.zip (contains source + plugin itself).

    What is in this version:
    - will change map to default map (sm_esmc_defaultmapname = "pl_goldrush") after n minutes (sm_esmc_minutesmapchange = "30").
    - writes config file with default settings if none is there ( ...\tf\cfg\sourcemod\emptyservermapchange.cfg)

    Why is this one not final if it does what you want?
    - This code is not having yet the amount of comments I would like to see in any code produced by me.
    - Want to explore the possibility to choose random from the mapcycle or just nextmap, instead of one default map.

  9. #9
    Badministrator grom's Avatar
    Join Date
    Nov 2008
    Posts
    4,256
    Cookies Given
    2,297
    Cookies Received
    4,806
    Quote Originally Posted by MacNetron View Post
    - This code is not having yet the amount of comments I would like to see in any code produced by me.
    You sir, rock.
    That's a great attitude and pretty rare to see unfortunately.
    ---
    (aka JennyCide.ps)
    putting the Rage in Average
    gromblog (inactive at present)
    Twitter

  10. #10
    I accidentally a whole post. Carbon's Avatar
    Join Date
    Dec 2008
    Posts
    844
    Cookies Given
    84
    Cookies Received
    72
    awesome!


  11. #11
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Version 0.9.0.0: servermapchange-0.9.0.0.zip (contains source + plugin itself).

    What is new in this version:
    - Added 'sm_esmc_mapchangemode'. Sets the map changing mode. Possible values: [default|nextmap]. 'default' will use the sm_esmc_defaultmapname convar. 'nextmap' will use the current next map.
    - Added loads of comment

    But Mac, it is still not final, and what about that random thingy?
    - 'random' seems a bit more complicated. Will not make 1.0, but definitely something worth investigating for a future version.
    - Currently compiling gives a warning. That is because I have got a function returning a String. While this seems quite normal, in SourcePawn (and I quote documentation): "A function can accept any type of input. It can return any cell, but not arrays or strings."
    Of course, I don't follow documentation and just return a String and voila, it works but does give a warning when compiling. Just want to do a little bit more research on this issue.


    As I've been monitoring my laptop with TF2 server running for while and don't see any problems, I think it is safe to try it on the MapLab on "nextmap" mode.


    EDIT: for people interested in the code, just load it in your favorite editor (notepad++, editplus2, ...) and put it onto C/C++ mode.

  12. #12
    Playstuff Member .ps
    Join Date
    Dec 2008
    Posts
    119
    Cookies Given
    35
    Cookies Received
    48
    don't know, perhaps I'm wrong (never wrote code for sourcemod)
    but string and array parameters should be passed by reference, so perhaps add a string parameter to the GetMapChangeName() - function as "return-pointer" (C-like)
    -> avoid returning a string and no need to use strcopy()


    looks like I fail at putting my ideas on paper :cry:
    2 People have given a Cookie to master85: Logan.ps, MacNetron.ps

  13. #13
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    no no, I do understand it

    I thought all parameters were passed as value, but after rereading the SourcePawn introduction again it appears for arrays and String it is indeed by reference.
    Although I hate those constructs, the current one is more awkward. Thanks for the tip!

  14. #14
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Updated to 0.9.9.

    Have put it onto the maplab for the final test.
    If it doesn't break, it will be renamed 1.0.0

    emptyservermapchange-0.9.9.zip (src + plugin)

    Current top comment:
    Code:
    /*
    * Empty Server Map Change [ESMC]
    *
    * ESMC is a SourceMod plugin that allows an empty server to change map after
    * n minutes. This makes sure a server doesn't gets stuck on a not popular map,
    * so nobody will join the server anymore.
    *
    * ConVars (will be created if no configuration file exists):
    * sm_esmc_minutesmapchange <minutes>
    * sm_esmc_defaultmapname <mapname>
    * sm_esmc_mapchangemode [default|nextmap]
    *
    * Admin Commands:
    * sm_esmc_info (ADMFLAG_CHANGEMAP)
    * 
    * This plugin is written by Marco 'MacNetron' de Reus for the playstuff.net
    * community.
    * It is compiled with the SourcePawn Compiler 1.2.0.
    *
    * www.macnetron.nl / www.playstuff.net
    *
    */

  15. #15
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    Note to self:
    - Boylee proposed 'double rotation' in http://www.playstuff.net/showthread.php?t=172&page=5 , post 89.
    Try to find out if it is possible to have the rotation fall back to a default rotation after a couple of empty server map changes (and also if we would really want that ).

    - Is SourceTV also a person? ie, is the maplab empty now with tv on?

  16. #16
    ლ(ಠ益ಠლ) Logan's Avatar
    Join Date
    Nov 2008
    Posts
    6,323
    Cookies Given
    4,689
    Cookies Received
    3,320
    Blog Entries
    15
    source tv takes a player slot. it's not the default config for the server. we shouldn't leave it on all the time as it records whenever anyone joins. best to work on the basis that it will be off.

  17. #17
    I accidentally a whole post. Carbon's Avatar
    Join Date
    Dec 2008
    Posts
    844
    Cookies Given
    84
    Cookies Received
    72
    Most useful. Starting to get an understnding of how this works.


  18. #18
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2
    updated to 0.9.9b:

    added feature: plugin now detects and handles SourceTV. As SourceTV is seen as a Client, an empty server with sourcetv enabled was not seen as empty.

    uploaded to teamplay, maplab and koth

  19. #19
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2

    Re: SM Plugin: Empty Server Map Change

    potential bug, should check this out:

    Code:
    exec: couldn't exec ctf_soda_a7.cfg
    [...]
    SourceTV broadcast active.
    [ESMC] No clients ingame and no clients connecting
    [ESMC] Timer created, map change after 30 minutes, based on mode nextmap, going
    to ctf_soda_a7
    [MAPRATE] Using table name "map_ratings"
    L 03/27/2010 - 11:21:44: server_cvar: "sm_nextmap" "ctf_chicane_a9b"
    Seen on maplab.
    current map was soda, so ...

  20. #20
    Windows Only MacNetron's Avatar
    Join Date
    Dec 2008
    Posts
    6,530
    Cookies Given
    4,433
    Cookies Received
    4,007
    Blog Entries
    2

    Re: SM Plugin: Empty Server Map Change

    Noted some strange behaviour this weekend on the maplab, as the plugin started seeing the SourceTV client as a real client/player instead of... SourceTV.

    Due to the fact of the real life project madness and the fact that I code SourceMod in Eclipse, I've updated the IsSourceTvEnabled function to use tv_enable convar. Strangely enough this convar seems to function correctly now where it was not while coding version 0.9.9.
    Also added a line to see the status of sourcetv as seen by EmptyServerMapChange, to see type in console: sm_esmc_info

    Current version on both Teamplay as MapLab: 1.0.0.RC1
    Source and plugin: http://dl.dropbox.com/u/2874556/play...e-1.0.0.RC1.7z

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •