Elifrak2 Posted November 19, 2013 Report Share Posted November 19, 2013 Hey guys, I'm sorry for asking a question about an old game but I have a issue that I've been trying to fix for so long but can't make it work while it's probably a stupid mistake I'm overseeing. I used to have automatic messages on my BF2 server every 45 seconds or so (without the Punkbuster system). This is the content of the file I used: import bf2 import bf2.Timer import host interval=60 # Number of seconds between announcements message1="This is an unranked server" message2="Modified by Belgian_hero and =hero= Shoota{BE}" message3="Grenadelaunchers and C4 have 0 damage" def onTimer(data): global message host.rcon_invoke('game.sayall "%s"' % message1) host.rcon_invoke('game.sayall "%s"' % message2) host.rcon_invoke('game.sayall "%s"' % message3) timer=bf2.Timer(onTimer, interval, 1) timer.setRecurring(interval) Now my question: Is this content correct? And more important: where do I place this file? I can't seem to make it work, I put it in the EA Games/Battlefield2/Admin/standardadmin file and the EA Games/Battlefield2/mods/python file (while adding the name of the file in the _init_folder but it won't work anymore.. As you can see I'm a newb in modding, haven't made this myself, so can anyone help me? Quote Link to comment Share on other sites More sharing options...
mschoeldgen[Xww2] Posted December 6, 2013 Report Share Posted December 6, 2013 I moved your thread to the python section as i can't see any relation to Mod Recruitment. Here's the chance that the few remaining python gurus will find your question. Quote Link to comment Share on other sites More sharing options...
Frankelstner Posted December 19, 2013 Report Share Posted December 19, 2013 You could place the script in just about any Python folder. Common practice is to make a new script and place it in such a folder, then add two lines to the __init__.py in the same folder (which is empty by default): import myscriptname myscriptname.init() When a round starts this will then call the init function of your script. In your script, set up the timer in the init function. The rest of the script should work out. import bf2 import bf2.Timer import host def init(): timer = bf2.Timer(onTimer, 60, 1) timer.setRecurring(60) messages=("This is an unranked server", "Modified by Belgian_hero and =hero= Shoota{BE}", "Grenadelaunchers and C4 have 0 damage") def onTimer(data): global messages #not sure if this is even needed for message in messages: #just tidying things up a bit host.rcon_invoke('game.sayall "%s"' % message) I haven't tested it, but I hope you get the idea. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.