Announcement

Collapse
No announcement yet.

Help: Auto-resize maps/Python syntax

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help: Auto-resize maps/Python syntax

    I'm trying to figure out how to have the server recognize when a population threshold has been crossed and rebuild the maplist.con so that when the next map gets loaded, BAM! it's bigger or smaller to suit the population. It would require launching the server with bf2_w32ded.exe instead of BF2Launcher so that the max population could be set at 64 but mapsizes could be set to 16, 32 or 64.

    So, my question is, to those that have done mods, particularly with Python, is this syntatically correct, at least, and if so, does it look workable. Don't take off points for style. I'm at work and hobbling this together from other forum posts and wiki entries and object model lists. I have never touched Python before, and never seen the BF object model before now.
    This file would be imported and initialized in the __init__.py file(I think).
    It's definitely NOT elegant OR efficient - I need a couple more variables to prevent repeated rebuilding of the maplist when unnecessary, but you get the idea.

    What think you?

    Edit:Looks like I missed "bf2.playerManager.getNumberOfPlayers()" which should be used instead of that wretched global variable every time I player connects or disconnects. I still think the maplist needs to be modified before End of Round in order for the change to happen before anyone starts loading a new map.
    Thoughts?
    Code:
    import bf2
    import host
    from bf2 import g_debug
    
    numPlayers = 0
    
    def init():
    	if g_debug: print 'initialising Dynamic Maplist script'
    
    	host.registerHandler('PlayerConnect', onPlayerConnect, 1)
    	host.registerHandler('PlayerDisconnect', onPlayerDisconnect, 1) 
    	host.registerHandler('EndRound', onEndRound, 1)
    	host.rcon_invoke('echo "events.py loaded"')
    
    def onPlayerConnect(player):
    	global numPlayers
    	host.rcon_invoke('echo "Connected: %s"' % (player.getName())) 
    	numPlayers = numPlayers + 1
    	if numPlayers > bf2.gameLogic.getWorldSize(): increaseWorldSize()
    
    def onPlayerDisconnect(player):
    	global numPlayers
    	host.rcon_invoke('echo "Disconnected: %s"' % (player.getName())) 
    	numPlayers = numPlayers - 1
    	if numPlayers < bf2.gameLogic.getWorldSize(): decreaseWorldSize()
    
    def increaseWorldSize(): 
    	global numPlayers 
    	if numPlayers > 40: changeMaplist(64) 
    	if numPlayers > 18 && numPlayers < 41: changeMaplist(32) 
    
    def decreaseWorldSize(): 
    	global numPlayers 
    	if numPlayers < 40 && numPlayers > 18: changeMaplist(32) 
    	if numPlayers < 19: changeMaplist(16) 
    
    def changeMaplist(myMapSize): 
    	host.rcon_invoke('mapList.clear')
    	host.rcon_invoke('mapList.append strike_at_karkand gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append dalian_plant gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append daqing_oilfields gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append dragon_valley gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append fushe_pass gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append gulf_of_oman gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append kubra_dam gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append mashtuur_city gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append operation_clean_sweep gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append sharqi_peninsula gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append songhua_stalemate gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.append zatar_wetlands gpm_cq %s"' % myMapSize)
    	host.rcon_invoke('mapList.save')
    Last edited by duckilama; 07-12-2005, 05:36 PM.

  • #2
    Re: Help: Auto-resize maps/Python syntax

    Check out the BF2 wiki's Python section: http://bf2.fun-o-matic.org/index.php/Python

    There's documentation on hooking the game status events. You'll be able to change your code to run the checks when the map ends. You can even get the map name and continue the rotation with the larger game size.

    - It's who you game with.

    Comment


    • #3
      Re: Help: Auto-resize maps/Python syntax

      I was under the impression that server settings like this couldn't be modified on the fly.
      [volun2]
      NS Game Officer. TF2 Admin. BF2 Admin / Scripter. PM with issues.
      Tempus: Pokerface is nailing it right on the head. Everyone who is arguing against him is simply arguing against reality.
      <anmuzi> it is not permitted to have privacy or anonymity
      <LazyEye> yeah when I play on TG the server digs though my trash

      Arm yourself with knowledge: TG NS TF2 BF2

      Comment


      • #4
        Re: Help: Auto-resize maps/Python syntax

        If you launch using bf2_w32ded.exe instead of bf2launcher, you can change the maplist, clear it, reload it, etc. What you can't do to a server on the fly, I think, is change the max population.

        Which is why I want to be able to set the max pop at, say, 64 when the server starts, then adjust the maplist.con file as the server pop changes...
        Once a new map is loaded, it will be the next one in the "new" maplist.con file.
        And an admin or a player vote can switch the map immediately.

        Comment


        • #5
          Re: Help: Auto-resize maps/Python syntax

          Originally posted by duckilama
          If you launch using bf2_w32ded.exe instead of bf2launcher, you can change the maplist, clear it, reload it, etc. What you can't do to a server on the fly, I think, is change the max population.
          Maybe that's it then... the SERVER settings (IE, everything you'd see on the "server" part of the launcher) get fixed into place on launch, and other things (such as the maplist.con file) do not.[/QUOTE]
          [volun2]
          NS Game Officer. TF2 Admin. BF2 Admin / Scripter. PM with issues.
          Tempus: Pokerface is nailing it right on the head. Everyone who is arguing against him is simply arguing against reality.
          <anmuzi> it is not permitted to have privacy or anonymity
          <LazyEye> yeah when I play on TG the server digs though my trash

          Arm yourself with knowledge: TG NS TF2 BF2

          Comment


          • #6
            Re: Help: Auto-resize maps/Python syntax

            Make it happen Poker! We know you can do it!
            Telorn

            Comment


            • #7
              Re: Help: Auto-resize maps/Python syntax

              I think just going with registering a new handler for "EndRound" that checks "bf2.playerManager.getNumberOfPlayers()" and compares it to both the current size in the maplist and your threshholds would be a lot cleaner... assuming getNumberOfPlayers() actually works AND "EndRound" occurs early enough to swap out the maplist before loading the next map.

              Comment


              • #8
                Re: Help: Auto-resize maps/Python syntax

                I believe bf2cc does this. Check their forums for more information.

                3) Support game play in a near-simulation environment. Where the focus of play would not be solely on doing what it takes to win, but doing so utilizing real-world combat strategy and tactics rather than leveraging exploits provided to players by the design of the game engine.

                Comment


                • #9
                  Re: Help: Auto-resize maps/Python syntax

                  Automatically changing maplists based on how many folks are on at a given time? I know I can manually alt+tab out and change the maplist, but I didn't see anything about auto-swapping the maps out when more folks log in or out... hmm...

                  Comment


                  • #10
                    Re: Help: Auto-resize maps/Python syntax

                    Only problem I see are the amount of players that drop between rounds are not taken into consideration, but I don't think that is possible. Can't have everything. ;)

                    Comment


                    • #11
                      Re: Help: Auto-resize maps/Python syntax

                      Originally posted by Edwin
                      Only problem I see are the amount of players that drop between rounds are not taken into consideration, but I don't think that is possible. Can't have everything. ;)
                      It would only be taken into consideration when a round ends and a new one begins. But that is a huge advantage when servers are low in population and a nice feature.
                      Telorn

                      Comment


                      • #12
                        Re: Help: Auto-resize maps/Python syntax

                        Hi see this post i think that with getsizeworld you can't read the map size
                        http://forums.totalbf2.com/showthread.php?t=12252

                        Comment


                        • #13
                          Re: Help: Auto-resize maps/Python syntax

                          Yeah, I saw a similar post somewhere. I'm sure I can get the mapname, though, and surely Python has enough text munging capability to let me do either a regex or an indexof on 16, 32, 64, which is just as good, almost.

                          Comment


                          • #14
                            Re: Help: Auto-resize maps/Python syntax

                            hi i was finished a similar script working
                            http://forums.totalbf2.com/showthread.php?t=16638

                            Comment


                            • #15
                              Re: Help: Auto-resize maps/Python syntax

                              Thanks for the link, im sure duckilama and you can help each other.
                              Oyee

                              Comment

                              Connect

                              Collapse

                              TeamSpeak 3 Server

                              Collapse

                              Advertisement

                              Collapse

                              Twitter Feed

                              Collapse

                              Working...
                              X