Jump to content
Official BF Editor Forums
Sign in to follow this  
Elifrak2

Need Quick Help For My Server

Recommended Posts

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? :(

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×