Error with bots and PlayerDictionary

Please post any questions about developing your plugin here. Please use the search function before posting!
ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Error with bots and PlayerDictionary

Postby ghetto_life » Tue Aug 30, 2022 8:33 am

Hello!
I have code:

Code: Select all

from players.dictionary import PlayerDictionary
from players.entity import Player


class CustomPlayer(Player):
    points = 0

    def has_c4(self):
        pass


def create_player(index: int) -> CustomPlayer:
    player = CustomPlayer(index)
    return player


players = PlayerDictionary(create_player)


Actions:
1) Join server
2) Add bot with tf_bot_add
3) Leave server (After leaving, the bot is kicked)

Errors in the console:

Code: Select all

Client "Player" connected (192.168.133.1:27006).
Server waking up from hibernation
tf_bot_add
NextBot tickrate changed from 0 (0.000ms) to 7 (0.105ms)
[Source.Python]
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 133, in __call__
    obj = super().__call__(index)
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 229, in __init__
    BaseEntity.__init__(self, index)

ValueError: Conversion from "Index" (1) to "BaseEntity" failed.


Dropped Player from server (Client Disconnect)
Server is hibernating
[Source.Python]
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 133, in __call__
    obj = super().__call__(index)
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 229, in __init__
    BaseEntity.__init__(self, index)

ValueError: Conversion from "Index" (2) to "BaseEntity" failed.


Dropped The G-Man from server (Punting bot, server is hibernating)


Manual bot kick also raise error.
cssbestrpg
Senior Member
Posts: 309
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Error with bots and PlayerDictionary

Postby cssbestrpg » Tue Aug 30, 2022 10:55 am

Hi, these coding questions should be asked in Plugin Developement Support.
Also when you paste a code please use [python] syntax tags when pasting a code to be more readable.

Anyway what are you trying to do in code?
ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Re: Error with bots and PlayerDictionary

Postby ghetto_life » Tue Aug 30, 2022 11:55 am

Hi. I want to use PlayerDictionary to store player data (for the game mod).
cssbestrpg
Senior Member
Posts: 309
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Error with bots and PlayerDictionary

Postby cssbestrpg » Tue Aug 30, 2022 12:23 pm

ghetto_life wrote:Hi. I want to use PlayerDictionary to store player data (for the game mod).

You try do something like this?

Syntax: Select all

from events import Event
from players.entity import Player
from players.helpers import index_from_userid
from players.dictionary import PlayerDictionary
from filters.players import PlayerIter

players = PlayerDictionary()

def load():
''' Called when plugin is loaded '''
# For late loading
for player in PlayerIter('all'):
players[player.index] = player

@Event('player_active')
def player_active(args):
''' Called when player fully connect during a map '''
index = index_from_userid(args['userid'])
players[index] = player

@Event('player_disconnect')
def player_disconnect(args):
''' Called when player disconnects '''
try:
del players[index_from_userid(game_event.get_int('userid'))]
except ValueError:
return
ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Re: Error with bots and PlayerDictionary

Postby ghetto_life » Tue Aug 30, 2022 12:47 pm

Syntax: Select all

from events import Event
from players.entity import Player
from players.helpers import index_from_userid
from players.dictionary import PlayerDictionary
from filters.players import PlayerIter

players = PlayerDictionary()


def load():
''' Called when plugin is loaded '''
# For late loading
for player in PlayerIter('all'):
players[player.index] = player


@Event('player_active')
def player_active(args):
''' Called when player fully connect during a map '''
index = index_from_userid(args['userid'])
players[index] = Player(index)


@Event('player_disconnect')
def player_disconnect(game_event):
''' Called when player disconnects '''
try:
del players[index_from_userid(game_event.get_int('userid'))]
except ValueError:
return


Code: Select all

Client "Player" connected (192.168.133.1:27006).
Server waking up from hibernation
tf_bot_add
NextBot tickrate changed from 0 (0.000ms) to 7 (0.105ms)
[Source.Python]
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 133, in __call__
    obj = super().__call__(index)
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 229, in __init__
    BaseEntity.__init__(self, index)

ValueError: Conversion from "Index" (1) to "BaseEntity" failed.


Dropped Player from server (Client Disconnect)
Server is hibernating
Dropped Maggot from server (Punting bot, server is hibernating)
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Error with bots and PlayerDictionary

Postby L'In20Cible » Wed Aug 31, 2022 3:03 am

ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Re: Error with bots and PlayerDictionary

Postby ghetto_life » Wed Aug 31, 2022 7:49 am

Thank you!
cssbestrpg
Senior Member
Posts: 309
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Error with bots and PlayerDictionary

Postby cssbestrpg » Wed Aug 31, 2022 12:03 pm

If you don't have the build that fixes the issue, here is the tf2 build for it and follow the update guide to update it properly.
ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Re: Error with bots and PlayerDictionary

Postby ghetto_life » Wed Aug 31, 2022 3:12 pm

cssbestrpg wrote:If you don't have the build that fixes the issue, here is the tf2 build for it and follow the update guide to update it properly.


Yes, the error is gone. Thank you! :smile:

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 11 guests