def _get_valid_attacker(game_event):
    """Return the attacker's userid if not a self or team inflicted event."""
    # Get the attacker's userid
    attacker = game_event.get_int('attacker')

    # Get the victim's userid
    victim = game_event.get_int('userid')

    # Was this self inflicted?
    if attacker in (victim, 0):

        # If self, inflicted, do not count
        return None

    # Get the victim's PlayerInfo instance
    vplayer = playerinfo_from_userid(victim)

    # Get the attacker's PlayerInfo instance
    aplayer = playerinfo_from_userid(attacker)

    # Are the player's on the same team?
    if vplayer.get_team_index() == aplayer.get_team_index():

        # Do not count
        return index_from_playerinfo(aplayer)

    # If all checks pass, count the attack/kill
    return player_dictionary[attacker]
def player_death(game_event):
    """ this includes bots apparently """
    print("Player Death")
    # Get the userid from the event
    victim = game_event.get_int('userid')
    attacker = game_event.get_int('attacker')
    print("victim: %s" % victim)
    print("attacker: %s" % attacker)
    
    #victim_edict = edict_from_userid(victim)
    #attacker_edict = edict_from_userid(attacker)
    #print("victim_edict: %s" % victim_edict)
    #print("attacker_edict: %s" % attacker_edict)
    
    # Get the CPlayerInfo instance from the userid
    victimplayerinfo = playerinfo_from_userid(victim)
    attackerplayerinfo = playerinfo_from_userid(attacker)
    print("victimplayerinfo: %s" % victimplayerinfo)
    print("attackerplayerinfo: %s" % attackerplayerinfo)
    # And finally get the player's name 
    #victimname = victimplayerinfo.get_name()
    #attackername = attackerplayerinfo.get_name()
    #print("victimname: %s" % victimname)
    #print("attackername: %s" % attackername)
    
    # Get the index of the player
    victimindex = index_from_userid(victim)
    attackerindex = index_from_userid(attacker)
    print("victimindex: %s" % victimindex)
    print("attackerindex: %s" % attackerindex)
    
    print("victim_is_fake_client: %s" % victimplayerinfo.is_fake_client())
    print("attacker_is_fake_client: %s" % attackerplayerinfo.is_fake_client())
    
    victim_steamid = victimplayerinfo.get_networkid_string()
    attacker_steamid = attackerplayerinfo.get_networkid_string()
    
    if not victimplayerinfo.is_fake_client() and not attackerplayerinfo.is_fake_client():
        count = alive_count()
        global round_count
        global round_won
        if count == 1 and round_count != 1: 
            userid = winning_player()
            amount = amount_to_pay()
            name = playerinfo_from_userid(userid).get_name()
            award = leetcoin_client.requestAward(amount, "Hunger Games Winner", userid)
            tell_winner(winning_playerinfo())
            for player in PlayerIter(['human'], return_types='playerinfo'):
                mes = name + " survived and won " + leetcoin_client.getConvertedAmountValue(convertSteamIDToCommunityID(player.get_networkid_string()), amount)
                SayText2(message="" + mes + "").send(index_from_playerinfo(player))
            print("Winner selected, userid: " + str(userid))
            round_won = True
            #leetcoin_client.submit_match_results_blank()
        else:
            print("Alive count at: " + str(count))


    return
def winning_player():
    rPlayer = 0
    if alive_count() == 1: 
        for player in PlayerIter(['human', 'alive'], return_types='userid'):
            rPlayer = player
        if playerinfo_from_userid(rPlayer) in paid_list:
            print("Player paid into the round")
        else: 
            steam64 = convertSteamIDToCommunityID(playerinfo_from_userid(rPlayer).get_networkid_string())
            #leetcoin_client.recordKill(steam64, steam64)
            #leetcoin_client.repeatingServerUpdate()
    return rPlayer
def my_repeat_callback():
    print(">>>>>>>>>>>>>>>>>>>>>  Repeat")
    
    pop_list = []
    
    for index, pending_activation_player_userid in enumerate(pending_activation_player_list):
        playerinfo = playerinfo_from_userid(pending_activation_player_userid)
        print("my_repeat_callback playerinfo: %s" % playerinfo)
    
        if not playerinfo.get_edict().is_valid():
            print("my_repeat_callback playerinfo edict invalid")
        else:
            steamid = playerinfo.get_networkid_string()
            print("my_repeat_callback player steamid: %s" % steamid)
            
            if not steamid == "BOT":
                print("REAL PLAYER FOUND!")
                steam64 = convertSteamIDToCommunityID(steamid)
                print("steam64: %s" % steam64)
                authorized_active_player = leetcoin_client.authorizeActivatePlayer(steam64, pending_activation_player_userid)
                
            pop_list.append(index)
        
    pop_list.reverse()
    for index_to_remove in pop_list:
        pending_activation_player_list.pop(index_to_remove)
    pass
def my_repeat_callback():
    print(">>>>>>>>>>>>>>>>>>>>>  Repeat")
    
    pop_list = []
    
    for index, pending_activation_player_userid in enumerate(pending_activation_player_list):
        playerinfo = playerinfo_from_userid(pending_activation_player_userid)
        print("my_repeat_callback playerinfo: %s" % playerinfo)
    
        if not playerinfo.get_edict().is_valid():
            print("my_repeat_callback playerinfo edict invalid")
        else:
            steamid = playerinfo.get_networkid_string()
            print("my_repeat_callback player steamid: %s" % steamid)
            
            if not steamid == "BOT":
                print("REAL PLAYER FOUND!")
                steam64 = convertSteamIDToCommunityID(steamid)
                print("steam64: %s" % steam64)
                authorized_active_player = leetcoin_client.authorizeActivatePlayer(steam64, pending_activation_player_userid)
                
            pop_list.append(index)
        
    pop_list.reverse()
    for index_to_remove in pop_list:
        pending_activation_player_list.pop(index_to_remove)
    pass
def player_activate(game_event):
    """ this includes bots apparently """
    print("Player Connect")
    userid = game_event.get_int('userid')
    print("userid: %s" % userid)
    
    playerinfo = playerinfo_from_userid(userid)
    print("playerinfo: %s" % playerinfo)
    print("playerinfo userid: %s" % playerinfo.get_userid())
    steam64 = convertSteamIDToCommunityID(playerinfo.get_networkid_string())
    print("playerinfo steamid: %s" % steam64)    
    if steam64:
        leetcoin_client.authorizeActivatePlayer(steam64, userid)
def player_activate(game_event):
    """ this includes bots apparently """
    print("Player Connect")
    userid = game_event.get_int('userid')
    print("userid: %s" % userid)
    
    playerinfo = playerinfo_from_userid(userid)
    print("playerinfo: %s" % playerinfo)
    print("playerinfo userid: %s" % playerinfo.get_userid())
    steam64 = convertSteamIDToCommunityID(playerinfo.get_networkid_string())
    print("playerinfo steamid: %s" % steam64)    
    if steam64:
        leetcoin_client.authorizeActivatePlayer(steam64, userid)
Exemple #8
0
def parse_event_args(event, args):
    parsed_args = {}
    for arg, argtype in args.items():
        if argtype == "name":
            parsed_args[arg] = playerinfo_from_userid(event.get_int(arg)).get_name()
        elif argtype == "string":
            parsed_args[arg] = event.get_string(arg)
        elif argtype == "int":
            parsed_args[arg] = event.get_int(arg)
        elif argtype == "bool":
            parsed_args[arg] = event.get_bool(arg)
        elif argtype == "float":
            parsed_args[arg] = event.get_float(arg)
    return parsed_args
def check_for_winner():
    count = alive_count()
    global round_count
    global round_won
    if count == 1 and round_count != 1 and not round_won: 
        userid = winning_player()
        amount = amount_to_pay()
        name = playerinfo_from_userid(userid).get_name()
        award = leetcoin_client.requestAward(amount, "Hunger Games Winner", userid)
        tell_winner(winning_playerinfo())
        for player in PlayerIter(['human'], return_types='playerinfo'):
            mes = name + " survived and won " + leetcoin_client.getConvertedAmountValue(convertSteamIDToCommunityID(player.get_networkid_string()), amount)
            SayText2(message="" + mes + "").send(index_from_playerinfo(player))
        print("Winner selected, userid: " + str(userid))
    else:
        print("Alive count at: " + str(count))
def player_disconnect(game_event):
    """ this includes bots apparently """
    print("Player Disconnect")
    userid = game_event.get_int('userid')
    print("userid: %s" % userid)
    playerinfo = playerinfo_from_userid(userid)
    print("playerinfo: %s" % playerinfo)
    steamid = playerinfo.get_networkid_string()
    print("player steamid: %s" % steamid)
    
    if not steamid == "BOT":
        print("REAL PLAYER FOUND!")
        steam64 = convertSteamIDToCommunityID(steamid)
        print("steam64: %s" % steam64)
        
        deactivated_result = leetcoin_client.deactivatePlayer(steam64)
def player_disconnect(game_event):
    """ this includes bots apparently """
    print("Player Disconnect")
    userid = game_event.get_int('userid')
    print("userid: %s" % userid)
    playerinfo = playerinfo_from_userid(userid)
    print("playerinfo: %s" % playerinfo)
    steamid = playerinfo.get_networkid_string()
    print("player steamid: %s" % steamid)
    
    if not steamid == "BOT":
        print("REAL PLAYER FOUND!")
        steam64 = convertSteamIDToCommunityID(steamid)
        print("steam64: %s" % steam64)
        
        deactivated_result = leetcoin_client.deactivatePlayer(steam64)
def player_death(game_event):
    """ this includes bots apparently """
    print("Player Death")
    # Get the userid from the event
    victim = game_event.get_int('userid')
    attacker = game_event.get_int('attacker')
    print("victim: %s" % victim)
    print("attacker: %s" % attacker)
    
    #victim_edict = edict_from_userid(victim)
    #attacker_edict = edict_from_userid(attacker)
    #print("victim_edict: %s" % victim_edict)
    #print("attacker_edict: %s" % attacker_edict)
    
    # Get the CPlayerInfo instance from the userid
    victimplayerinfo = playerinfo_from_userid(victim)
    attackerplayerinfo = playerinfo_from_userid(attacker)
    print("victimplayerinfo: %s" % victimplayerinfo)
    print("attackerplayerinfo: %s" % attackerplayerinfo)
    # And finally get the player's name 
    victimname = victimplayerinfo.get_name()
    attackername = attackerplayerinfo.get_name()
    print("victimname: %s" % victimname)
    print("attackername: %s" % attackername)
    
    # Get the index of the player
    victimindex = index_from_userid(victim)
    attackerindex = index_from_userid(attacker)
    print("victimindex: %s" % victimindex)
    print("attackerindex: %s" % attackerindex)
    
    print("victim_is_fake_client: %s" % victimplayerinfo.is_fake_client())
    print("attacker_is_fake_client: %s" % attackerplayerinfo.is_fake_client())
    
    victim_steamid = victimplayerinfo.get_networkid_string()
    attacker_steamid = attackerplayerinfo.get_networkid_string()
    
    if not victimplayerinfo.is_fake_client() and not attackerplayerinfo.is_fake_client():
        
        print("victim_steamid: %s" % victim_steamid)
        print("attacker_steamid: %s" % attacker_steamid)
    
        victim_64 = convertSteamIDToCommunityID(victim_steamid)
        attacker_64 = convertSteamIDToCommunityID(attacker_steamid)
        
        kick_player, v_balance, a_balance = leetcoin_client.recordKill(victim_64, attacker_64)
        if v_balance == "noreg":
            SayText2(message="Unregistered kill/death. Win free bitcoin by registering at leetcoin.com! (if you haven't already)").send(victimindex)
            SayText2(message="Unregistered kill/death. Win free bitcoin by registering at leetcoin.com! (if you haven't already)").send(attackerindex)
        vbalance = leetcoin_client.getPlayerBalance(convertSteamIDToCommunityID(victimplayerinfo.get_networkid_string()))
        SayText2(message="Updated " + vbalance + "").send(victimindex)
        if victim_steamid != attacker_steamid:
            # award bounty
            if victimindex in bounties:
                leetcoin_client.requestAward(bounties[victimindex], "BOUNTY", attackerindex)
                SayText2(message="BOUNTY COLLECTED - " + str(bounties[victimindex]) + " SAT").send(attackerindex)
                del bounties[victimindex]
            abalance = leetcoin_client.getPlayerBalance(convertSteamIDToCommunityID(attackerplayerinfo.get_networkid_string()))
            SayText2(message="Updated " + abalance + "").send(attackerindex)    	

    return
def player_death(game_event):
    """ this includes bots apparently """
    print("Player Death")
    # Get the userid from the event
    victim = game_event.get_int('userid')
    attacker = game_event.get_int('attacker')
    print("victim: %s" % victim)
    print("attacker: %s" % attacker)
    
    #victim_edict = edict_from_userid(victim)
    #attacker_edict = edict_from_userid(attacker)
    #print("victim_edict: %s" % victim_edict)
    #print("attacker_edict: %s" % attacker_edict)
    
    # Get the CPlayerInfo instance from the userid
    victimplayerinfo = playerinfo_from_userid(victim)
    attackerplayerinfo = playerinfo_from_userid(attacker)
    print("victimplayerinfo: %s" % victimplayerinfo)
    print("attackerplayerinfo: %s" % attackerplayerinfo)
    # And finally get the player's name 
    victimname = victimplayerinfo.get_name()
    attackername = attackerplayerinfo.get_name()
    print("victimname: %s" % victimname)
    print("attackername: %s" % attackername)
    
    # Get the index of the player
    victimindex = index_from_userid(victim)
    attackerindex = index_from_userid(attacker)
    print("victimindex: %s" % victimindex)
    print("attackerindex: %s" % attackerindex)
    
    print("victim_is_fake_client: %s" % victimplayerinfo.is_fake_client())
    print("attacker_is_fake_client: %s" % attackerplayerinfo.is_fake_client())
    
    victim_steamid = victimplayerinfo.get_networkid_string()
    attacker_steamid = attackerplayerinfo.get_networkid_string()
    
    if not victimplayerinfo.is_fake_client() and not attackerplayerinfo.is_fake_client():
        
        print("victim_steamid: %s" % victim_steamid)
        print("attacker_steamid: %s" % attacker_steamid)
    
        victim_64 = convertSteamIDToCommunityID(victim_steamid)
        attacker_64 = convertSteamIDToCommunityID(attacker_steamid)
        
        kick_player, v_balance, a_balance = leetcoin_client.recordKill(victim_64, attacker_64)
        if v_balance == "noreg":
            SayText2(message="Unregistered kill/death. Win free bitcoin by registering at leetcoin.com! (if you haven't already)").send(victimindex)
            SayText2(message="Unregistered kill/death. Win free bitcoin by registering at leetcoin.com! (if you haven't already)").send(attackerindex)
        vbalance = leetcoin_client.getPlayerBalance(convertSteamIDToCommunityID(victimplayerinfo.get_networkid_string()))
        SayText2(message="Updated " + vbalance + "").send(victimindex)
        if victim_steamid != attacker_steamid:
            # award bounty
            if victimindex in bounties:
                leetcoin_client.requestAward(bounties[victimindex], "BOUNTY", attackerindex)
                SayText2(message="BOUNTY COLLECTED - " + str(bounties[victimindex]) + " SAT").send(attackerindex)
                del bounties[victimindex]
            abalance = leetcoin_client.getPlayerBalance(convertSteamIDToCommunityID(attackerplayerinfo.get_networkid_string()))
            SayText2(message="Updated " + abalance + "").send(attackerindex)    	

    return
def round_end(game_event):
    print(">>>>>>>>>>>>>>>>>>>  Round End")
    # award winners
    global bets
    winner = game_event.get_int("winner")

    # Check both teams have bets
    if not bets['ct'] or not bets['t']:
        # Refund bets
        for userid, amount in bets['ct'].items():
            SayText2(message="REFUND - " + str(amount) + " SAT - NOT ENOUGH BETS").send(index_from_userid(userid))
            leetcoin_client.requestAward(amount, "REFUND - " + str(amount) + " SAT - NOT ENOUGH BETS", userid)
        for userid, amount in bets['t'].items():
            SayText2(message="REFUND - " + str(amount) + " SAT - NOT ENOUGH BETS").send(index_from_userid(userid))
            leetcoin_client.requestAward(amount, "REFUND - " + str(amount) + " SAT - NOT ENOUGH BETS", userid)
        pass
    else:
        # Calculate pool
        pool_ct = 0
        pool_t = 0
        for userid, amount in bets['ct'].items():
            pool_ct += amount
        for userid, amount in bets['t'].items():
            pool_t += amount
        pool = pool_ct + pool_t

        # 10% for players
        player_cut = pool * 0.1
        remaining = pool - player_cut

        if winner == 2:
            print("T Wins!")
            for userid, amount in bets['t'].items():
                award = remaining / (amount / pool_t)
                leetcoin_client.requestAward(award, "Won bet on T", userid)
                playerinfo = playerinfo_from_userid(userid)
                SayText2(message="You won " + str(award) + " Satoshi").send(index_from_playerinfo(playerinfo))

            if not bets['t']:
                pass
            else:
                # Pay players
                players = PlayerIter('t', 'bot', 'userid')
                for player in players:
                    kickback = player_cut / len(players)
                    leetcoin_client.requestAward(math.ceil(kickback), "Player on winning team", player)
        if winner == 3:
            print("CT Wins!")
            # Pay winners
            for userid, amount in bets['ct'].items():
                award = remaining / (amount / pool_ct)
                leetcoin_client.requestAward(award, "Won bet on CT", userid)
                playerinfo = playerinfo_from_userid(userid)
                SayText2(message="You won " + str(award) + "Satoshi").send(index_from_playerinfo(playerinfo))

            if not bets['ct']:
                pass
            else:
                # Pay players
                players = PlayerIter('ct', 'bot', 'userid')
                for player in players:
                    kickback = player_cut / len(players)
                    leetcoin_client.requestAward(math.ceil(kickback), "Player on winning team", player)
                
    leetcoin_client.repeatingServerUpdate()
    bets = {'ct': {}, 't': {}}
    pass