Debriefing > Impressions & Feedback
New Python API Callback: OnCommandUsed(player,command,parameters)
(1/1)
Joe:
Hi,
This new callback function would be useful for DAD mode because it needs to respond to players killing themselves with the kill command but there's currently no way to know when a player has been killed by using this command.
killermonkey:
Disagree. You can figure out suicide in OnPlayerKilled if the attacker is the same as the victim. Why would knowing if they issued the kill command be helpful?
Joe:
--- Quote ---You can figure out suicide in OnPlayerKilled if the attacker is the same as the victim. Why would knowing if they issued the kill command be helpful?
--- End quote ---
DAD mode's OnPlayerKilled() callback can't simply eliminate all players who commit suicide because players are forced to commit suicide when they change their team. These forced deaths are the only deaths in DAD mode which shouldn't eliminate players.
I made the "if(not type(weapon) == GEPlayer.CGEMPPlayer):" condition in the code below before I knew about the kill command, so I thought that Player.CommitSuicide() is only called when players are forced to commit suicide when they change their team but I now know that the "kill" console command also calls this function:
--- Code: ---
def OnPlayerKilled( self, victim, killer, weapon ):
self.pltracker.SetValue(victim,self.trSpawned,False)
super( DieAnotherDay, self ).OnPlayerKilled( victim, killer, weapon )
#Don't allow team mate elimination greifing:
if(victim.GetTeamNumber() != killer.GetTeamNumber() or victim == killer):
#If the player wasn't forced to commit suicide by changing their team:
if(not type(weapon) == GEPlayer.CGEMPPlayer):
self.OnPlayerEliminated(victim,killer,weapon)
'''
This function is responsible for eliminating players and for responding to this event.
'''
def OnPlayerEliminated(self,victim,killer=None,weapon=None):
team = victim.GetTeamNumber()
#1.Eliminate the player:
self.pltracker.SetValue(victim,self.trEliminated,True)
self.eliminatedPlayerCount += 1
#2. Cancel their resurrections:
self.resurrections.playerHasBeenKilled(victim)
#3. Announce the elimination:
if killer != None:
GEUtil.EmitGameplayEvent("DieAnotherDay_elimination",
"%s" % victim.GetPlayerName(),
"%i" % victim.GetTeamNumber(),
"%s" % killer.GetPlayerName())
if team == GEGlobal.TEAM_MI6:
GEUtil.ClientPrint(None,GEGlobal.HUD_PRINTTALK, "#GES_GP_DAD_MI6_PLAYER_ELIMINATED", victim.GetPlayerName())
else:
GEUtil.ClientPrint(None,GEGlobal.HUD_PRINTTALK, "#GES_GP_DAD_JANUS_PLAYER_ELIMINATED", victim.GetPlayerName())
#4. Change their scoreboard colour:
victim.SetScoreBoardColor(GEGlobal.SB_COLOR_ELIMINATED)
#If the round won't end because of this elimination:
if GEMPGameRules.GetNumInRoundTeamPlayers(team) - 1 > 0:
self.OnTeamHasNewEliminatedMember(victim,killer,weapon)
def OnTeamHasNewEliminatedMember(self,player,killer,weapon):
moveTo = self.decideWhereREWillBeLocated(player,killer,weapon)
currentTeam = player.GetTeamNumber()
self.REs.spawnNewResurrectionEntity(player,currentTeam,moveTo)
self.addPlayerToResurrectionQueue(player,currentTeam)
self.drawEliminatedPlayerResQueueMessage(player)
--- End code ---
If there was an OnCommandUsed(player,command) callback function, my code could simply be changed to this:
--- Code: ---
def OnCommandUsed(player,command)
if(command == "kill"):
self.pltracker.SetValue(player,"death_cause","kill_command")
def OnPlayerKilled( self, victim, killer, weapon ):
self.pltracker.SetValue(victim,self.trSpawned,False)
super( DieAnotherDay, self ).OnPlayerKilled( victim, killer, weapon )
#Don't allow team mate elimination greifing:
if(victim.GetTeamNumber() != killer.GetTeamNumber() or victim == killer):
#If the player wasn't forced to commit suicide by changing their team:
deathCause = self.pltracker.GetValue(player,"death_cause","null")
self.pltracker.SetValue(player,"death_cause","null")
if(not type(weapon) == GEPlayer.CGEMPPlayer or deathCause == "kill_command"):
self.OnPlayerEliminated(victim,killer,weapon)
--- End code ---
Maybe an OnCommandUsed() callback wouldn't be worth adding to the API because the kill command is one of the few console commands which a mode scripter might want their mode to react to.
The problem I have in my DAD mode script could be more simply solved by giving the OnPlayerKilled() callback a cause parameter or a boolean teamChangeSuicide? parameter.
Navigation
[0] Message Index
Go to full version