Exemplo n.º 1
0
    def _set_team(self, value):
        # Does the player still exist?
        if not _es.exists('userid', self.userid):
            raise ValueError("userid (%s) doesn't exist." % self.userid)

        # Check for valid team values
        try:
            value = int(value)
            if value not in xrange(1, 4):
                raise ValueError
        except (TypeError, ValueError):
            raise ValueError('"%s" is an invalid team' % value)

        # Make sure we are not moving the player to the same team
        if self.team == value:
            return

        # Change the team
        _spe.switchTeam(self.userid, value)

        # No model change needed if going to spectator
        if value == 1:
            return

        # Retrieve a playerlib instance
        pPlayer = _getPlayer(self.userid)

        # Change to Terrorist Models
        if value == 2:
            pPlayer.model = 'player/%s' % choice(('t_arctic', 't_guerilla',
                                                  't_leet', 't_phoenix'))
        # Change to Counter-Terrorist Models
        else:
            pPlayer.model = 'player/%s' % choice(('ct_gign', 'ct_gsg9',
                                                  'ct_sas', 'ct_urban'))
Exemplo n.º 2
0
    def _set_team(self, value):
        # Does the player still exist?
        if not _es.exists('userid', self.userid):
            raise ValueError("userid (%s) doesn't exist." % self.userid)

        # Check for valid team values
        try:
            value = int(value)
            if value not in xrange(1, 4):
                raise ValueError
        except (TypeError, ValueError):
            raise ValueError('"%s" is an invalid team' % value)

        # Make sure we are not moving the player to the same team
        if self.team == value:
            return

        # Change the team
        _spe.switchTeam(self.userid, value)

        # No model change needed if going to spectator
        if value == 1:
            return

        # Retrieve a playerlib instance
        pPlayer = _getPlayer(self.userid)

        # Change to Terrorist Models
        if value == 2:
            pPlayer.model = 'player/%s' % choice(
                ('t_arctic', 't_guerilla', 't_leet', 't_phoenix'))
        # Change to Counter-Terrorist Models
        else:
            pPlayer.model = 'player/%s' % choice(
                ('ct_gign', 'ct_gsg9', 'ct_sas', 'ct_urban'))
Exemplo n.º 3
0
    def respawn(self, force=False):
        """Respawns the player."""
        # Player on server ?
        if not _es.exists('userid', self.userid):
            return

        # Player in spec or unassigned ?
        if self.team < 2:
            return

        # Player alive? (require force)
        if not _getPlayer(self.userid).isdead and not force:
            return

        _spe.respawn(self.userid)
Exemplo n.º 4
0
    def respawn(self, force=False):
        """Respawns the player."""
        # Player on server ?
        if not _es.exists('userid', self.userid):
            return

        # Player in spec or unassigned ?
        if self.team < 2:
            return

        # Player alive? (require force)
        if not _getPlayer(self.userid).isdead and not force:
            return

        _spe.respawn(self.userid)
Exemplo n.º 5
0
    def _find_by_uniqueid(self, userid):
        """Search for the player's uniqueid to see if they played previously
        in this round. If a match is found, the Player instance is returned. If
        no match is found, None is returned.

        """
        # Retrieve the UniqueID
        steamid = _getPlayer(userid).uniqueid(True)

        # Perform the search
        search = [self[x] for x in self.copy() if self[x].steamid == steamid]

        # Return the Player() instance or None
        if search:
            return search.pop()
        return None
Exemplo n.º 6
0
    def _find_by_uniqueid(self, userid):
        """Search for the player's uniqueid to see if they played previously
        in this round. If a match is found, the Player instance is returned. If
        no match is found, None is returned.

        """
        # Retrieve the UniqueID
        steamid = _getPlayer(userid).uniqueid(True)

        # Perform the search
        search = [self[x] for x in self.copy() if self[x].steamid == steamid]

        # Return the Player() instance or None
        if search:
            return search.pop()
        return None
Exemplo n.º 7
0
    def give_weapon(self):
        '''
        Gives a player their current levels weapon.
        '''
        error = None
        # Make sure player is on a team
        if self.team < 2:
            error = ('Unable to give player weapon (%s): ' % self.userid +
                     'is not on a team.')

        # Make sure player is alive
        elif _getPlayer(self.userid).isdead:
            error = ('Unable to give player weapon (%s): ' % self.userid +
                     'is not alive.')

        # Error ?
        if error:
            raise GunGameError(error)

        # Knife ?
        if self.weapon == 'knife':
            # Make them use their knife
            _es.server.queuecmd('es_xsexec %s "use weapon_knife"' %
                                (self.userid))

            # If there is a level below the user's current level
            if self.level > 1:
                # Strip previous weapons
                self.strip_weapons(_level_weapon(self.level - 1))
            else:
                self.strip()

        # Nade ?
        elif self.weapon == 'hegrenade':
            # Give them a grenade.
            given_weapon = _spe.giveNamedItem(self.userid, "weapon_hegrenade")

            # Make them use the grenade
            _es.server.queuecmd('es_xsexec %s "use weapon_hegrenade"' %
                                (self.userid))

            # If there is a level below the user's current level
            if self.level > 1:
                # Strip previous weapons
                self.strip_weapons(_level_weapon(self.level - 1))
            else:
                self.strip()

        else:
            # Player owns this weapon.
            if _spe.ownsWeapon(self.userid, "weapon_%s" % self.weapon):
                # Make them use it. If we don't do this, a very
                # strange bug comes up which prevents the player
                # from getting their current level's weapon after
                # being stripped,
                _es.server.queuecmd('es_xsexec %s "use weapon_%s"' %
                                    (self.userid, self.weapon))

                return

            # Player DOES NOT own this weapon.
            else:
                # Retrieve a list of all weapon names in the player's
                # possession
                playerWeapons = _spe.getWeaponDict(self.userid)

                if playerWeapons:
                    # See if there is a primary weapon in the list of weapons
                    pWeapon = set(
                        playerWeapons.keys()).intersection(list_pWeapons)

                    # See if there is a primary weapon in the list of weapons
                    sWeapon = set(
                        playerWeapons.keys()).intersection(list_sWeapons)

                    # Set up the weapon to strip
                    weapToStrip = None

                    # Strip secondary weapon ?
                    if 'weapon_' + self.weapon in list_sWeapons and sWeapon:
                        weapToStrip = sWeapon.pop()

                    # Strip primary weapon ?
                    elif 'weapon_' + self.weapon in list_pWeapons and pWeapon:
                        weapToStrip = pWeapon.pop()

                    if weapToStrip:
                        # Make them drop the weapon
                        _spe.dropWeapon(self.userid, weapToStrip)

                        # Now remove it
                        _spe.removeEntityByInstance(
                            playerWeapons[weapToStrip]["instance"])

                # Now give them the weapon and save the weapon instance
                given_weapon = _spe.giveNamedItem(self.userid,
                                                  "weapon_%s" % self.weapon)

                # Retrieve the weapon instance of the weapon they "should" own
                weapon_check = _spe.ownsWeapon(self.userid,
                                               "weapon_%s" % self.weapon)

                # Make sure that the player owns the weapon we gave them
                if weapon_check != given_weapon:
                    # Remove the given weapon since the player does not own it
                    _spe.removeEntityByInstance(given_weapon)

                    # If they don't have the right weapon, fire give_weapon()
                    if not weapon_check:
                        self.give_weapon()
                        return

                _es.server.queuecmd('es_xsexec %s "use weapon_%s"' %
                                    (self.userid, self.weapon))
Exemplo n.º 8
0
    def give(self, weapon, useWeapon=False, strip=False):
        '''
        Gives a player the specified weapon.
        Weapons given by this method will not be stripped by gg_dead_strip.

        Setting strip to True will make it strip the weapon currently
        held in the slot you are trying to give to.
        '''
        # Format weapon
        weapon = 'weapon_%s' % str(weapon).replace('weapon_', '')

        # Check if weapon is valid
        if weapon not in list_pWeapons + list_sWeapons + [
                'weapon_hegrenade', 'weapon_flashbang', 'weapon_smokegrenade'
        ]:
            raise ValueError('Unable to give "%s": ' % weapon[7:] +
                             'is not a valid weapon')

        # Add weapon to strip exceptions so gg_dead_strip will not
        #   strip the weapon
        if int(_es.ServerVar('gg_dead_strip')):
            self.stripexceptions.append(weapon[7:])

            # Delay removing the weapon long enough for gg_dead_strip to fire
            _gamethread.delayed(0.10, self.stripexceptions.remove,
                                (weapon[7:]))

        # If the player owns the weapon and the player is not being given a
        # second flashbang, stop here
        if (_spe.ownsWeapon(self.userid, weapon)
                and not (weapon == "weapon_flashbang"
                         and _getPlayer(self.userid).getFB() < 2)):
            return

        # Strip the weapon ?
        if strip:
            # Retrieve a list of all weapon names in the player's possession
            playerWeapons = _spe.getWeaponDict(self.userid)

            if playerWeapons:
                # See if there is a primary weapon in the list of weapons
                pWeapon = set(playerWeapons.keys()).intersection(list_pWeapons)

                # See if there is a primary weapon in the list of weapons
                sWeapon = set(playerWeapons.keys()).intersection(list_sWeapons)

                stripWeapon = None

                # Holding a primary weapon ?
                if weapon in list_pWeapons and pWeapon:
                    stripWeapon = pWeapon.pop()

                # Holding a secondary weapon ?
                elif weapon in list_sWeapons and sWeapon:
                    stripWeapon = sWeapon.pop()

                # Strip the weapon
                if stripWeapon:
                    # Make them drop the weapon
                    _spe.dropWeapon(self.userid, stripWeapon)

                    # Remove the weapon
                    _spe.removeEntityByInstance(
                        playerWeapons[stripWeapon]["instance"])

        # Give the player the weapon
        _spe.giveNamedItem(self.userid, weapon)

        if useWeapon:
            _es.server.queuecmd('es_xsexec %s "use %s"' %
                                (self.userid, weapon))
Exemplo n.º 9
0
 def __new__(cls, userid):
     self = object.__new__(cls, userid)
     self._userid = int(userid)
     self._steamid = _getPlayer(self.userid).uniqueid(True)
     self._index = _getPlayer(self.userid).index
     return self
Exemplo n.º 10
0
    def give_weapon(self):
        '''
        Gives a player their current levels weapon.
        '''
        error = None
        # Make sure player is on a team
        if self.team < 2:
            error = ('Unable to give player weapon (%s): ' % self.userid +
                     'is not on a team.')

        # Make sure player is alive
        elif _getPlayer(self.userid).isdead:
            error = ('Unable to give player weapon (%s): ' % self.userid +
                     'is not alive.')

        # Error ?
        if error:
            raise GunGameError(error)

        # Knife ?
        if self.weapon == 'knife':
            # Make them use their knife
            _es.server.queuecmd('es_xsexec %s "use weapon_knife"' % (
                                                                self.userid))

            # If there is a level below the user's current level
            if self.level > 1:
                # Strip previous weapons
                self.strip_weapons(_level_weapon(self.level - 1))
            else:
                self.strip()

        # Nade ?
        elif self.weapon == 'hegrenade':
            # Give them a grenade.
            given_weapon = _spe.giveNamedItem(self.userid, "weapon_hegrenade")

            # Make them use the grenade
            _es.server.queuecmd('es_xsexec %s "use weapon_hegrenade"' % (
                                                                self.userid))

            # If there is a level below the user's current level
            if self.level > 1:
                # Strip previous weapons
                self.strip_weapons(_level_weapon(self.level - 1))
            else:
                self.strip()

        else:
            # Player owns this weapon.
            if _spe.ownsWeapon(self.userid, "weapon_%s" % self.weapon):
                # Make them use it. If we don't do this, a very
                # strange bug comes up which prevents the player
                # from getting their current level's weapon after
                # being stripped,
                _es.server.queuecmd('es_xsexec %s "use weapon_%s"'
                    % (self.userid, self.weapon))

                return

            # Player DOES NOT own this weapon.
            else:
                # Retrieve a list of all weapon names in the player's
                # possession
                playerWeapons = _spe.getWeaponDict(self.userid)

                if playerWeapons:
                    # See if there is a primary weapon in the list of weapons
                    pWeapon = set(playerWeapons.keys()).intersection(
                                                                list_pWeapons)

                    # See if there is a primary weapon in the list of weapons
                    sWeapon = set(playerWeapons.keys()).intersection(
                                                                list_sWeapons)

                    # Set up the weapon to strip
                    weapToStrip = None

                    # Strip secondary weapon ?
                    if 'weapon_' + self.weapon in list_sWeapons and sWeapon:
                        weapToStrip = sWeapon.pop()

                    # Strip primary weapon ?
                    elif 'weapon_' + self.weapon in list_pWeapons and pWeapon:
                        weapToStrip = pWeapon.pop()

                    if weapToStrip:
                        # Make them drop the weapon
                        _spe.dropWeapon(self.userid, weapToStrip)

                        # Now remove it
                        _spe.removeEntityByInstance(playerWeapons
                                                    [weapToStrip]["instance"])

                # Now give them the weapon and save the weapon instance
                given_weapon = _spe.giveNamedItem(self.userid,
                    "weapon_%s" % self.weapon)

                # Retrieve the weapon instance of the weapon they "should" own
                weapon_check = _spe.ownsWeapon(self.userid, "weapon_%s"
                    % self.weapon)

                # Make sure that the player owns the weapon we gave them
                if weapon_check != given_weapon:
                    # Remove the given weapon since the player does not own it
                    _spe.removeEntityByInstance(given_weapon)

                    # If they don't have the right weapon, fire give_weapon()
                    if not weapon_check:
                        self.give_weapon()
                        return

                _es.server.queuecmd('es_xsexec %s "use weapon_%s"'
                    % (self.userid, self.weapon))
Exemplo n.º 11
0
    def give(self, weapon, useWeapon=False, strip=False):
        '''
        Gives a player the specified weapon.
        Weapons given by this method will not be stripped by gg_dead_strip.

        Setting strip to True will make it strip the weapon currently
        held in the slot you are trying to give to.
        '''
        # Format weapon
        weapon = 'weapon_%s' % str(weapon).replace('weapon_', '')

        # Check if weapon is valid
        if weapon not in list_pWeapons + list_sWeapons + [
          'weapon_hegrenade', 'weapon_flashbang', 'weapon_smokegrenade']:
            raise ValueError('Unable to give "%s": ' % weapon[7:] +
                             'is not a valid weapon')

        # Add weapon to strip exceptions so gg_dead_strip will not
        #   strip the weapon
        if int(_es.ServerVar('gg_dead_strip')):
            self.stripexceptions.append(weapon[7:])

            # Delay removing the weapon long enough for gg_dead_strip to fire
            _gamethread.delayed(0.10, self.stripexceptions.remove,
                                (weapon[7:]))

        # If the player owns the weapon and the player is not being given a
        # second flashbang, stop here
        if (_spe.ownsWeapon(self.userid, weapon) and not
          (weapon == "weapon_flashbang" and
          _getPlayer(self.userid).getFB() < 2)):
            return

        # Strip the weapon ?
        if strip:
            # Retrieve a list of all weapon names in the player's possession
            playerWeapons = _spe.getWeaponDict(self.userid)

            if playerWeapons:
                # See if there is a primary weapon in the list of weapons
                pWeapon = set(playerWeapons.keys()).intersection(list_pWeapons)

                # See if there is a primary weapon in the list of weapons
                sWeapon = set(playerWeapons.keys()).intersection(list_sWeapons)

                stripWeapon = None

                # Holding a primary weapon ?
                if weapon in list_pWeapons and pWeapon:
                    stripWeapon = pWeapon.pop()

                # Holding a secondary weapon ?
                elif weapon in list_sWeapons and sWeapon:
                    stripWeapon = sWeapon.pop()

                # Strip the weapon
                if stripWeapon:
                    # Make them drop the weapon
                    _spe.dropWeapon(self.userid, stripWeapon)

                    # Remove the weapon
                    _spe.removeEntityByInstance(playerWeapons[stripWeapon][
                                                                "instance"])

        # Give the player the weapon
        _spe.giveNamedItem(self.userid, weapon)

        if useWeapon:
            _es.server.queuecmd('es_xsexec %s "use %s"' % (self.userid,
                                                           weapon))
Exemplo n.º 12
0
 def __new__(cls, userid):
     self = object.__new__(cls, userid)
     self._userid = int(userid)
     self._steamid = _getPlayer(self.userid).uniqueid(True)
     self._index = _getPlayer(self.userid).index
     return self