Example #1
0
def wcs_randplayer_command(command_info, var:ConVar, players:convert_identifier_to_players):
    players = list(players)

    if players:
        var.set_int(choice(players).userid)
    else:
        var.set_int(0)
Example #2
0
def checkBuy(userid, item):
    userid = int(userid)
    iteminfo = wcs.wcs.ini.getItems[wcs.wcs.itemdb.getSectionFromItem(
        item)][item]
    player_entity = Player(index_from_userid(userid))
    if player_entity.dead:
        is_dead = 0
    else:
        is_dead = 1
    if is_dead == int(iteminfo['dab']) or int(iteminfo['dab']) == 2:
        ConVar('wcs_userid').set_int(userid)
        ConVar('wcs_dice').set_int(random.randint(0, 100))
        if iteminfo['cfg'] == 'player_buy' and iteminfo['cmdactivate']:
            settings = iteminfo['cmdactivate']
            if ';' in settings:
                sub_settings = settings.split(';')
                for com in sub_settings:
                    execute_server_command('es', com)
            else:
                execute_server_command('es', settings)
        elif iteminfo['cmdbuy']:
            settings = iteminfo['cmdbuy']
            if ';' in settings:
                sub_settings = settings.split(';')
                for com in sub_settings:
                    execute_server_command('es', com)
            else:
                execute_server_command('es', settings)
Example #3
0
    def game_start(self, player_index: int, game_mode, api):
        if api.input_json['weapon_for_user']:
            self.player_weapon = api.input_json['weapon_for_user']
            sdm_logger.debug(f'Current player from backend {self.player_weapon}')
        else:
            sdm_logger.debug(f'No weapon for player from backend Leaving {self.player_weapon}')
        if api.input_json['weapon_for_bot'] and api.input_json['weapon_for_bot'] != "weapon_knife":
            self.bot_weapon = api.input_json['weapon_for_bot']
            sdm_logger.debug(f'Current bot from backend {self.bot_weapon}')
        else:
            sdm_logger.debug(f'No weapon for bot from backend Leaving {self.bot_weapon}')
        game_mode.single_start = True
        ConVar('mp_roundtime').set_int(api.input_json["game_time"] // 60)  # in minutes
        ConVar('mp_round_restart_delay').set_int(14)
        ConVar('mp_teammates_are_enemies').set_int(0)
        ConVar('bot_difficulty').set_int(api.input_json.get("difficulty", 1))
        sdm_logger.info(f"Bot difficulty is set to {ConVar('bot_difficulty').get_int()}")
        queue_server_command('bot_kick')
        queue_server_command('mp_warmup_end')
        if not self.state_warmup:
            self.spawn_enemies(player_index, api)

            #sdm_logger.debug(f'Restriction of {bot_team[player.team]} team from {self.player_weapon} is done')
        else:
            sdm_logger.error('Warmup was not finished. Skipping game start.')
Example #4
0
def get_wall_between_command(command_info, var:ConVar, x:float, y:float, z:float, x2:float, y2:float, z2:float):
    vector = Vector(x, y, z)
    vector2 = Vector(x, y, z)

    trace = GameTrace()
    ray = Ray(vector, vector2)

    engine_trace.trace_ray(ray, ContentMasks.ALL, None, trace)

    var.set_int(trace.did_hit_world())
Example #5
0
def get_colors(command):
    userid = int(command[1])
    r = command[2]
    g = command[3]
    b = command[4]
    a = command[5]
    if exists(userid):
        ConVar(r).set_int(Player.from_userid(userid).color[0])
        ConVar(g).set_int(Player.from_userid(userid).color[1])
        ConVar(b).set_int(Player.from_userid(userid).color[2])
        ConVar(a).set_int(Player.from_userid(userid).color[3])
Example #6
0
def wcs_get_cooldown_command(command_info,
                             wcsplayer: convert_userid_to_wcsplayer,
                             var: ConVar):
    active_race = wcsplayer.active_race

    for skill in active_race.skills.values():
        if 'player_ultimate' in skill.config['event']:
            var.set_float(max(skill.cooldown - time(), 0))
            break
    else:
        var.set_int(-1)
Example #7
0
def viewcoord(command):
    userid = int(command[1])
    xvar = str(command[2])
    yvar = str(command[3])
    zvar = str(command[4])
    if exists(userid):
        player = Player(index_from_userid(userid))
        view_vec = player.get_view_coordinates()
        ConVar(xvar).set_float(view_vec[0])
        ConVar(yvar).set_float(view_vec[1])
        ConVar(zvar).set_float(view_vec[2])
Example #8
0
def set_cvar_value(cvar):
    value = cvar_list[cvar]
    if value.isdigit():
        ConVar(cvar).set_int(int(value))

    if re.match("^\d+?\.\d+?$", value) is not None:
        ConVar(cvar).set_float(float(value))

    if re.match("[^a-zA-Z]", value) is None:
        ConVar(cvar).set_string(value)

    return False
Example #9
0
def get_cooldown(command):
    userid = int(command[1])
    var = str(command[2])
    if exists(userid):
        cooldown = wcs.wcs.get_cooldown(userid)
        timed = int(float(time.time()))
        cooldown = wcsgroup.getUser(userid, 'player_ultimate_cooldown')
        downtime = wcs.wcs.get_cooldown(userid)
        if cooldown == None:
            ConVar(var).set_int(downtime)
            return
        ConVar(var).set_int(downtime - (timed - cooldown))
Example #10
0
def wcsgroup_get_command(command_info, key:str, var:ConVar, userid:valid_userid_and_team):
    if userid is None:
        var.set_int(0)
        return

    if isinstance(userid, str):
        value = team_data[{'T':2, 'CT':3}[userid]].get(key, '0')
    else:
        wcsplayer = WCSPlayer.from_userid(userid)

        value = wcsplayer.data.get(key, '0')

    var.set_string(str(value))
Example #11
0
def wcs_getwallbetween_command(command_info, var:ConVar, player:convert_userid_to_player, target:convert_userid_to_player):
    if player is None or target is None:
        var.set_int(-1)
        return

    vector = player.origin
    vector2 = target.origin

    trace = GameTrace()
    ray = Ray(vector, vector2)

    engine_trace.trace_ray(ray, ContentMasks.ALL, None, trace)

    var.set_int(trace.did_hit_world())
Example #12
0
def getweapon(command):
    userid = int(command[1])
    var = str(command[2])
    slot = str(command[3])
    if slot == "1":
        slot = "primary"
    if slot == "2":
        slot = "secondary"
    if exists(userid):
        player = Player.from_userid(userid)
        weapon = player.get_weapon(is_filters=slot)
        if weapon != None:
            ConVar(var).set_string(weapon.classname)
        else:
            ConVar(var).set_int(-1)
Example #13
0
    class SurvivalFriendlyFireBase(*parent_classes):
        cvar_friendlyfire = ConVar('mp_friendlyfire')

        stage_groups = {
            'mapgame-start': [
                "mapgame-equip-weapons",
                "mapgame-register-push-handlers",
                "mapgame-apply-cvars",
                "mapgame-fire-mapdata-outputs",
                "survival-enable-ff",
                "mapgame-entry",
            ]
        }

        @stage('survival-enable-ff')
        def stage_survival_enable_ff(self):
            no_ff_spam_enable()

            self._cvars['friendlyfire'] = self.cvar_friendlyfire.get_bool()

            silent_set(self.cvar_friendlyfire, 'bool', True)

        @stage('undo-survival-enable-ff')
        def stage_undo_survival_enable_ff(self):
            no_ff_spam_disable()

            silent_set(self.cvar_friendlyfire, 'bool',
                       self._cvars['friendlyfire'])
Example #14
0
    def __init__(self, name, default, description, flags, min_value,
                 max_value):
        """Called on instantiation."""
        # Initialize the dictionary
        super().__init__()

        # Is the given description a TranslationStrings instance?
        if isinstance(description, TranslationStrings):

            # Store the description as the proper language string
            description = description.get_string()

        # Store the base attributes for the cvar
        self._name = name
        self._default = default
        self._description = description

        # Get the cvar instance
        self._cvar = ConVar(name, str(default), description, flags, min_value,
                            max_value)

        # Set the attribute to show the default value
        self.show_default = True

        # Store a list to iterate over description fields and text
        self._order = list()
Example #15
0
def getViewPlayer(command):
    if len(command) == 3:
        if exists(int(command[1])):
            ConVar(str(command[2])).set_string(
                str(
                    Player.from_userid(int(
                        command[1])).get_view_player().userid))
Example #16
0
def wcs_getinfo_command(command_info, wcsplayer: convert_userid_to_wcsplayer,
                        var: ConVar, attribute: str, key: str):
    if wcsplayer is None:
        var.set_int(0)
        return

    if key == 'race':
        if attribute == 'realname':
            var.set_string(wcsplayer.active_race.name)
        elif attribute == 'name':
            var.set_string(wcsplayer.active_race.settings.strings['name'])
    elif key == 'player':
        if attribute == 'realcurrace':
            var.set_string(wcsplayer.active_race.name)
        elif attribute == 'currace':
            var.set_string(wcsplayer.active_race.settings.strings['name'])
Example #17
0
def getViewEntity(command):
    if len(command) == 3:
        if exists(int(command[1])):
            ConVar(str(command[2])).set_string(
                str(
                    Player.from_userid(int(
                        command[1])).get_view_entity().index))
Example #18
0
def wcs_getcolors_command(command_info, player:convert_userid_to_player, red:ConVar, green:ConVar, blue:ConVar, alpha:ConVar):
    if player is None:
        return

    color = player.color

    red.set_int(color.r)
    green.set_int(color.g)
    blue.set_int(color.b)
    alpha.set_int(color.a)
Example #19
0
    def execute(self, name=None, event=None, define=False):
        if self.level:
            if name is None:
                name = self.name

            variables = {}

            for variable, values in self.config['variables'].items():
                variables[variable] = values[self.level - 1] if self.level <= len(values) else values[-1]

            if self._type is ModuleType.SP:
                callback = _race_callbacks.get(self._race_name, {}).get(name)

                if callback is not None:
                    if event is None:
                        callback(self.wcsplayer, variables)
                    else:
                        callback(event, self.wcsplayer, variables)
            elif self._type is ModuleType.ESP:
                callback = es.addons.Blocks.get(f'wcs/modules/items/{self._race_name}/{name}')

                if callback is not None:
                    if event is None:
                        callback(self.wcsplayer, variables)
                    else:
                        callback(es.event_var, self.wcsplayer, variables)
            else:
                addon = esc.addons.get(f'wcs/modules/races/{self._race_name}')

                if addon is not None:
                    executor = addon.blocks.get(name)

                    if executor is not None:
                        if define:
                            cvar_wcs_userid.set_int(self.wcsplayer.userid)

                        for cvar in cvar_wcs_dices:
                            cvar.set_int(randint(0, 100))

                        for variable, values in variables.items():
                            variable = f'wcs_{variable}'
                            cvar = cvars.get(variable)

                            if cvar is None:
                                cvar = cvars[variable] = ConVar(variable, '0')

                            if isinstance(values, list):
                                if isinstance(values[0], float) or isinstance(values[1], float):
                                    cvar.set_float(uniform(*values))
                                else:
                                    cvar.set_int(randint(*values))
                            else:
                                if isinstance(values, float):
                                    cvar.set_float(values)
                                else:
                                    cvar.set_int(values)

                        executor.run()
Example #20
0
 def game_prepare(self, authorized_client):
     sdm_api.request_get_game(hostname=ConVar('hostname').get_string())
     player_freeze()
     message_show("Начнется через", 5, x=-1, y=0.15) #without
     if self.players_to_start_sdm > 1:
         sdm_logger.warning('Multiplayer requested. Assigning single player mode.')
     Delay(6, self.game_start, (authorized_client, sdm_single, sdm_api))
     self.state_warmup = False
     sdm_logger.debug('==============sdm_warmup ended=============')
def _get_convar(name, create=False, description='Custom server variable.'):
    convar = cvar.find_var(name)
    if convar is None:
        if create or autocreate_cvar.get_bool():
            return ConVar(name, '', description)
        else:
            import es
            es.dbgmsg(0, 'ERROR: Variable does not exist.')

    return convar
Example #22
0
    def maxammo(self):
        """Return the maxammo amount for the weapon."""
        # Is the stored maxammo an integer?
        if isinstance(self._maxammo, int):

            # Return the value
            return self._maxammo

        # Get the cvar value of the maxammo
        return ConVar(self._maxammo).get_int()
Example #23
0
def get_wall_between(command):
    var = str(command[1])
    user_one = int(command[2])
    user_two = int(command[3])
    origin_vector = Player.from_userid(user_one).origin
    direction_vector = Player.from_userid(user_two).origin
    trace = GameTrace()
    engine_trace.trace_ray(Ray(origin_vector, direction_vector),
                           ContentMasks.ALL, None, trace)
    ConVar(var).set_int(trace.did_hit_world())
Example #24
0
def _getdistance(command):
    var = str(command[1])
    x1 = float(command[2])
    y1 = float(command[3])
    z1 = float(command[4])
    x2 = float(command[5])
    y2 = float(command[6])
    z2 = float(command[7])
    vec1 = Vector(x1, y1, z1)
    vec2 = Vector(x2, y2, z2)
    distance = vec1.get_distance(vec2)
    ConVar(var).set_float(distance)
Example #25
0
def log(text, level=0):
    if int(ConVar('wcs_logging').get_int()) >= level:
        path = join(get_addon_path(), 'logs')
        if not isdir(path):
            mkdir(path)

        path = join(path, strftime('%m%d.log'))

        file = open(path, 'a+')

        file.write(strftime('L %m/%d/%Y - %H:%M:%S: ') + str(text) + '\n')
        file.close()
Example #26
0
def wcsx_get_command(command_info, key:str, var:ConVar, userid:valid_userid):
    if userid is None:
        var.set_int(-1)
        return

    player = getPlayer(userid)

    if not hasattr(player, key):
        var.set_int(-1)
        return

    value = getattr(player, key)

    if callable(value):
        value = value()

    if hasattr(value, '__iter__'):
        if hasattr(value[0], '__iter__'):
            if len(value[0]) == 1:
                value = value[0][0]
            else:
                value = ','.join([str(x) for x in value[0]])
        else:
            value = value[0]

    var.set_string(str(value))
Example #27
0
    def execute(self):
        """Execute the config file."""
        # Does the file exist?
        if not self.fullpath.isfile():
            raise FileNotFoundError(
                'Cannot execute file "{0}", file not found'.format(
                    self.fullpath))

        # Open/close the file
        with self.fullpath.open() as open_file:

            # Loop through all lines in the file
            for line in open_file.readlines():

                # Strip the line
                line = line.strip()

                # Is the line a command or cvar?
                if line.startswith('//') or not line:
                    continue

                # Get the command's or cvar's name
                name = line.split(' ', 1)[0]

                # Is the command/cvar valid
                if name not in self._commands | self._cvars:
                    continue

                # Does the command/cvar have any value/arguments?
                if not line.count(' '):
                    continue

                # Is this a command?
                if name in self._commands:

                    # Execute the line
                    queue_command_string(line)

                # Is this a cvar
                else:

                    # Get the cvar's value
                    value = line.split(' ', 1)[1]

                    # Do quotes need removed?
                    if value.startswith('"') and line.count('"') >= 2:

                        # Remove the quotes
                        value = value.split('"')[1]

                    # Set the cvar's value
                    ConVar(name).set_string(value)
Example #28
0
def randplayer(command):
    var = str(command[1])
    ident = str(command[2])
    if "#" in ident:
        ident = ident.replace("#", "")
    if ";" in ident:
        ident = ident.split(";")
    elif "," in ident:
        ident = ident.split(",")
    playlist = []
    for play in PlayerIter(ident):
        playlist.append(play)
    ConVar(var).set_string(str(choice(playlist).userid))
Example #29
0
def checkEvent(userid, event):
    userid = int(userid)
    player = Player.from_userid(userid)
    if player.team > 1:
        if userid in items:
            if event in items[userid]:
                for item in items[userid][event]:
                    v = items[userid][event][item]
                    item, section = item, wcs.wcs.itemdb.getSectionFromItem(
                        item)
                    iteminfo = wcs.wcs.ini.getItems[section][item]

                    ConVar('wcs_userid').set_int(userid)
                    ConVar('wcs_dice').set_int(random.randint(0, 100))

                    while v > 0:
                        if (iteminfo['cfg'] == 'player_buy' or event
                                == 'player_buy') and iteminfo['cmdbuy']:
                            settings = str(iteminfo['cmdbuy'])
                            if ';' in settings:
                                sub_settings = settings.split(';')
                                for com in sub_settings:
                                    execute_server_command('es', com)
                            else:
                                execute_server_command('es', settings)

                        elif iteminfo['cmdactivate']:
                            settings = str(iteminfo['cmdactivate'])
                            if ';' in settings:
                                sub_settings = settings.split(';')
                                for com in sub_settings:
                                    execute_server_command('es', com)
                            else:
                                execute_server_command('es', settings)
                            wcs.wcs.tell(
                                userid, '\x04[WCS] %s \x05activated!' %
                                iteminfo['name'])

                        v -= 1
Example #30
0
def random_race(command):
    userid = int(command[1])
    var = str(command[2])
    if exists(userid):
        race_list = []
        races = wcs.wcs.racedb.getAll()
        allraces = races.keys()
        for number, race in enumerate(allraces):
            v = changerace.canUse(userid, race)
            if not v:
                race_list.append(race)
        if len(race_list):
            chosen = str(choice(race_list))
            ConVar(var).set_string(chosen)