【发布时间】:2018-11-21 17:05:59
【问题描述】:
我需要帮助!我正在尝试修改游戏 BombSquad 并尝试为我的服务器构建一个禁止系统。
好的,所以有一个拒绝人们进入的功能
def onPlayerRequest(self, player):
"""
Called when a new bs.Player wants to join;
should return True or False to accept/reject.
"""
# limit player counts based on pro purchase/etc *unless* we're in a stress test
if bsUtils._gStressTestResetTimer is None:
if len(self.players) >= self._maxPlayers:
# print a rejection message *only* to the client trying to joinz
# (prevents spamming everyone else in the game)
bs.playSound(bs.getSound('error'))
bs.screenMessage(bs.Lstr(resource='playerLimitReachedText', subs=[('${COUNT}', bsInternal._getAccountDisplayString())]),
color=(0.8, 0.0, 0.0),
clients=[player.getInputDevice().getClientID()],
transient=True)
return False
bs.playSound(bs.getSound('dripity'))
return True
我需要另一个文件中的播放器名称,我将它放在 if 语句中以检查它是否与禁用列表匹配并完成! 带出播放器名称的文件是
class DamnPartyWindow(PartyWindow):
def _onPartyMemberPress(self, clientID, isHost, widget):
# if we're the host, pop up 'kick' options for all non-host members
if bsInternal._getForegroundHostSession() is not None:
kickStr = bs.Lstr(resource='kickText')
else:
# kick-votes appeared in build 14248
if bsInternal._getConnectionToHostInfo().get('buildNumber', 0) < 14248:
return
kickStr = bs.Lstr(resource='kickVoteText')
for rst in self._roster:
cid = rst['clientID']
if cid == clientID:
bs.screenMessage(rst['displayString'])
break
p = PopupMenuWindow(position=widget.getScreenSpaceCenter(),
scale=2.3 if gSmallUI else 1.65 if gMedUI else 1.23,
choices=['kick'],
choicesDisplay=[kickStr],
currentChoice='kick',
delegate=self).getRootWidget()
self._popupPartyMemberClientID = clientID
self._popupPartyMemberIsHost = isHost
(这是另一个人的模组)我需要 rst['displayString'] 的值并在第一个示例中检查它...帮助!
我尝试将 xyz = rst['displayString'] 然后放入 file1 使用
从文件 2 导入 xyz
文件 1:
class DamnPartyWindow(PartyWindow):
def _onPartyMemberPress(self, clientID, isHost, widget):
# if we're the host, pop up 'kick' options for all non-host members
if bsInternal._getForegroundHostSession() is not None:
kickStr = bs.Lstr(resource='kickText')
else:
# kick-votes appeared in build 14248
if bsInternal._getConnectionToHostInfo().get('buildNumber', 0) < 14248:
return
kickStr = bs.Lstr(resource='kickVoteText')
for rst in self._roster:
cid = rst['clientID']
xyz = rst['displayString']
if cid == clientID:
bs.screenMessage(rst['displayString'])
break
p = PopupMenuWindow(position=widget.getScreenSpaceCenter(),
scale=2.3 if gSmallUI else 1.65 if gMedUI else 1.23,
choices=['kick'],
choicesDisplay=[kickStr],
currentChoice='kick',
delegate=self).getRootWidget()
self._popupPartyMemberClientID = clientID
self._popupPartyMemberIsHost = isHost
文件 2:
def onPlayerRequest(self, player):
"""
Called when a new bs.Player wants to join;
should return True or False to accept/reject.
"""
# importing xyz i.e the value of client
from file2 import xyz
if bsUtils._gStressTestResetTimer is None:
if len(self.players) >= self._maxPlayers or xyz=="PC14567":
# print a rejection message *only* to the client trying to joinz
# (prevents spamming everyone else in the game)
bs.playSound(bs.getSound('error'))
bs.screenMessage(bs.Lstr(resource='playerLimitReachedText', subs=[('${COUNT}', bsInternal._getAccountDisplayString())]),
color=(0.8, 0.0, 0.0),
clients=[player.getInputDevice().getClientID()],
transient=True)
return False
bs.playSound(bs.getSound('dripity'))
return True
但是说不能导入 xyz 是行不通的。 请帮忙!我可以提供你们需要的任何信息,请帮助我!
【问题讨论】:
-
您能否添加触发错误的确切行和实际错误消息,而不仅仅是
xyz或blah?我以这种方式更容易理解和帮助。意思是,您将xyz = ....放在哪里以及尝试导入到哪里?在你的代码示例中展示它 -
@Andrew_Lvov 哦,是的,我真的很抱歉!我会做的
标签: python function class variables