Starting A Python Script?
Posted: 2021-10-18 20:36
Greetings, not sure if its the right place to ask since this is for 'vanilla' bf2 and not PR,
but I really don't know where to ask else and Im trying get a 'Hello World' python script done.
First I created a folder inside the mods/bf2mod/python/game/gamemodes/helloworld
threw '__init__.py' and 'helloworld.py' into it,
then edited the 'gpm_coop.py' in the parent folder 'gamemodes'
added 2 lines to it, 'import helloworld' under line 'from bf2 import g_debug'
and 'helloworld.init()' at the top in the 'def init()' function
__init__.py
helloworld.py
Now if I start a game nothing, in the console will show up, first I thought it was a
'rcon' error since I wasnt logged in as an admin but that wasn't the case,
I suspect my script wont even load since my game wont crash on load if
I place a wrong Tabulator in the script for example.
What did I missed? Thanks in advance.
but I really don't know where to ask else and Im trying get a 'Hello World' python script done.
First I created a folder inside the mods/bf2mod/python/game/gamemodes/helloworld
threw '__init__.py' and 'helloworld.py' into it,
then edited the 'gpm_coop.py' in the parent folder 'gamemodes'
added 2 lines to it, 'import helloworld' under line 'from bf2 import g_debug'
and 'helloworld.init()' at the top in the 'def init()' function
__init__.py
Code: Select all
import helloworld
def init():
helloworld.init()
def deinit():
helloworld.deinit()
Code: Select all
import host
import bf2
from bf2 import g_debug
def init():
host.registerGameStatusHandler(gameStatusChanged)
global g_debug
g_debug = 1
if g_debug:
print "helloworld.py initialized"
def deinit():
host.unregisterGameStatusHandler(gameStatusChanged)
print "testrotz.py deinitialized"
def gameStatusChanged(status):
if status == bf2.GameStatus.Playing:
host.rcon_invoke("echo HelloWorld")
'rcon' error since I wasnt logged in as an admin but that wasn't the case,
I suspect my script wont even load since my game wont crash on load if
I place a wrong Tabulator in the script for example.
What did I missed? Thanks in advance.