[bfprog] announcement script

Forrest Thiessen thiessen at cyberscapearena.com
Thu Jul 14 20:15:57 PDT 2005


Ronald Pompa wrote:

> I’ve recently dived into the word of Python and tried to make a simple
> announcement script and this is what I’ve got so far:
>
> import bf2
>
> import host
>
> from bf2 import g_debug
>
> # announce every 5 min
>
> announceTime = 300
>
> # announce text
>
> announceText = "Hello world"
>
> def init():
>
> global announceTime
>
> if g_debug: print 'initialising announce script'
>
> # timer set to 5 min
>
> announcer = bf2.Timer(announceIt, announceTime, 1)
>
> announcer.setRecurring(10)
>
> host.rcon_invoke('echo "announce_le.py loaded"')
>
> def announceIt():
>
> global announceText
>
> host.rcon_invoke('game.sayAll "\" + announceText + "\"')
>
> The problem is it does not work. Anyone else got any ideas on how to
> make it work? What am I doing wrong ?
>
For a working script, check out:
http://bf2.fun-o-matic.org/index.php/Scripts:Automatic_Announcements

To answer your question about what you did wrong: in order to access
bf2.Timer, you have to import bf2.Timer; otherwise, Python has no idea
what you're talking about, and raises an exception. The way the BF2
embedded Python interpreter works is that (for some reason) many
uncaught exceptions just cause quiet failures--so your script silently
dies when you call it's init method, and you never see any announcements.

--Forrest (aka "Woody")




More information about the BFProg mailing list