Jump to content
Official BF Editor Forums

Need Quick Help For My Server


Elifrak2
 Share

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

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...