-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjmod.py
More file actions
148 lines (112 loc) · 4.16 KB
/
objmod.py
File metadata and controls
148 lines (112 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# --------------------------------------------------------------------------
# objmod by rpoxo
#
# Description:
#
# module for changing various object templates properties on flight
#
# Credits:
# alon&mats&pr sources for various code help
# -------------------------------------------------------------------------
# importing python system modules
import sys
import time
import math
# importing modules from standart bf2 package
import bf2
import host
# importing custom modules
import constants as C
G_TWEAKER = None
class Tweaker:
def __init__(self):
self.__queries = []
def setupDefaultTweaks(self):
del self.__queries
self.__queries = []
for objectTemplate in C.TWEAKS:
activeSafe = ('ObjectTemplate.active %s' % (str(objectTemplate)))
host.rcon_invoke(activeSafe)
debugMessage(activeSafe)
for tweak in C.TWEAKS[objectTemplate]:
host.rcon_invoke(tweak)
debugMessage(tweak)
# ------------------------------------------------------------------------
# Init
# ------------------------------------------------------------------------
def init():
global G_TWEAKER
G_TWEAKER = Tweaker()
G_TWEAKER.setupDefaultTweaks()
host.registerGameStatusHandler(onGameStatusChanged)
# ------------------------------------------------------------------------
# DeInit
# ------------------------------------------------------------------------
def deinit():
host.unregisterGameStatusHandler(onGameStatusChanged)
# ------------------------------------------------------------------------
# onGameStatusChanged
# ------------------------------------------------------------------------
def onGameStatusChanged(status):
if status == bf2.GameStatus.Playing:
# registering chatMessage handler
host.registerHandler('ChatMessage', onChatMessage, 1)
if G_TWEAKER is not None:
G_TWEAKER.setupDefaultTweaks()
debugMessage('===== FINISHED OBJMOD INIT =====')
# ------------------------------------------------------------------------
# onChatMessage
# Callback that managing chat messages.
##########################################################################
# !NEVER call any messages directly from onChatMessage handler
# It causing inifite loop and game hangs
##########################################################################
# ------------------------------------------------------------------------
def onChatMessage(playerId, text, channel, flags):
# fix for local non-dedicated servers
if playerId == -1:
playerId = 255
# getting player object by player index
player = bf2.playerManager.getPlayerByIndex(playerId)
# standart check for invalid players
if player is None or player.isValid() is False:
return
# common way to filter chat message
# clearing text as any channel except Global are prefixed
text = text.replace('HUD_TEXT_CHAT_COMMANDER', '')
text = text.replace('HUD_TEXT_CHAT_TEAM', '')
text = text.replace('HUD_TEXT_CHAT_SQUAD', '')
text = text.replace('HUD_CHAT_DEADPREFIX', '')
text = text.replace('* ', '')
text = text.strip()
# splitting filtered message text to arguments
args = text.split(' ')
if args[0] == C.COMMANDKEY:
del args[0]
if len(args) == 0:
debugMessage('NO ARGS IN CHAT MSG')
return
commandHandler(player, args)
else:
pass
# ------------------------------------------------------------------------
# commandHandler
# wrapper around function calls
# ------------------------------------------------------------------------
def commandHandler(player, args):
"""
commandHandler
handling functions calls for ingame debug
"""
if args[0] == C.KEYWORD_RELOAD:
reload(C) # reloading constant file
return G_TWEAKER.setupDefaultTweaks()
# Debug
def debugMessage(msg):
host.rcon_invoke('echo "%s"' % (str(msg)))
def debugIngame(msg):
#debugMessage(msg)
try:
host.rcon_invoke('game.sayAll "%s"' % (str(msg)))
except:
host.rcon_invoke('echo "debugIngame(FAIL): %s"' % (str(msg)))