Page 1 of 1

Error with bots and PlayerDictionary

Posted: Tue Aug 30, 2022 8:33 am
by ghetto_life
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.

Re: Error with bots and PlayerDictionary

Posted: Tue Aug 30, 2022 10:55 am
by cssbestrpg
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?

Re: Error with bots and PlayerDictionary

Posted: Tue Aug 30, 2022 11:55 am
by ghetto_life
Hi. I want to use PlayerDictionary to store player data (for the game mod).

Re: Error with bots and PlayerDictionary

Posted: Tue Aug 30, 2022 12:23 pm
by cssbestrpg
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

Re: Error with bots and PlayerDictionary

Posted: Tue Aug 30, 2022 12:47 pm
by ghetto_life

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)

Re: Error with bots and PlayerDictionary

Posted: Wed Aug 31, 2022 3:03 am
by L'In20Cible

Re: Error with bots and PlayerDictionary

Posted: Wed Aug 31, 2022 7:49 am
by ghetto_life
Thank you!

Re: Error with bots and PlayerDictionary

Posted: Wed Aug 31, 2022 12:03 pm
by cssbestrpg
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.

Re: Error with bots and PlayerDictionary

Posted: Wed Aug 31, 2022 3:12 pm
by ghetto_life
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: