Пример #1
0
def remove_weapon(userid, item):
    # Remove weapon
    weaponName = "weapon_%s" % item
    theWeapon = spe.ownsWeapon(userid, weaponName)
    if theWeapon:
        spe.dropWeapon(userid, weaponName)
        spe.removeEntityByInstance(theWeapon)
Пример #2
0
def remove_weapon(userid, item):
    # Remove weapon
    weaponName = "weapon_%s" % item
    theWeapon = spe.ownsWeapon(userid, weaponName)
    if theWeapon:
        spe.dropWeapon(userid, weaponName)
        spe.removeEntityByInstance(theWeapon)
Пример #3
0
def getWeaponIndex(userid, weapon_name):
    # Retrieve the weapon pointer
    weapon = spe.ownsWeapon(userid, weapon_name)

    # Make sure the weapon pointer is valid
    if not weapon:
        # Return None if the weapon pointer is not valid
        return None

    # Return the index of the weapon
    return spe.getEntityIndex(weapon)
Пример #4
0
def getWeaponIndex(userid, weapon_name):
    # Retrieve the weapon pointer
    weapon = spe.ownsWeapon(userid, weapon_name)

    # Make sure the weapon pointer is valid
    if not weapon:
        # Return None if the weapon pointer is not valid
        return None

    # Return the index of the weapon
    return spe.getEntityIndex(weapon)
Пример #5
0
def dropWeapon(userid, weapon_name, throwWeapon=True):
    # Get the player instance
    pPlayer = spe.getPlayer(int(userid))

    # Is the player instance valid?
    if not pPlayer:
        # Return False since the player instance was not valid
        return False

    # Get the weapon instance
    weapon_instance = spe.ownsWeapon(userid, weapon_name)

    # Is the weapon instance valid?
    if not weapon_instance:
        # Return False since the weapon instance was not valid
        return False

    # Throw the weapon?
    if throwWeapon:
        return spe.call('DropWeapon', pPlayer, weapon_instance, 0, 1)

    # Otherwise, don't.
    return spe.call('DropWeapon', pPlayer, weapon_instance, 0, 0)
Пример #6
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))
Пример #7
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))
Пример #8
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))
Пример #9
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))