GoldenEye: Source Forums

  • November 21, 2024, 10:01:36 pm
  • Welcome, Guest
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: New Python API Callback: OnCommandUsed(player,command,parameters)  (Read 8640 times)

0 Members and 1 Guest are viewing this topic.

Joe

  • Secret Agent
  • **
  • Posts: 139
  • Reputation Power: 54
  • Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.
  • Offline Offline

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.
Logged
Free games:FPS + RTS: Renegade X & Battlezone 1.5,RTS: 7 Kingdoms & Open Red Alert, TBS:Hedgewars, playcatan.com & www.wesnoth.org

killermonkey

  • GES Programmer
  • Retired Lead Developer
  • GE:S Fanatic
  • *
  • Posts: 5,473
  • Reputation Power: 346
  • killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!
  • Offline Offline
    • DroidMonkey Apps
Re: New Python API Callback: OnCommandUsed(player,command,parameters)
« Reply #1 on: April 20, 2014, 10:39:40 pm »

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?
Logged

Joe

  • Secret Agent
  • **
  • Posts: 139
  • Reputation Power: 54
  • Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.Joe has an aura about them.
  • Offline Offline
Re: New Python API Callback: OnCommandUsed(player,command,parameters)
« Reply #2 on: April 22, 2014, 12:18:35 pm »

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?

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: [Select]
    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)

If there was an OnCommandUsed(player,command) callback function, my code could simply be changed to this:
Code: [Select]
    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)

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.
« Last Edit: April 22, 2014, 01:03:33 pm by Joe »
Logged
Free games:FPS + RTS: Renegade X & Battlezone 1.5,RTS: 7 Kingdoms & Open Red Alert, TBS:Hedgewars, playcatan.com & www.wesnoth.org
Pages: [1]   Go Up