configobj.ConfigObjError

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

configobj.ConfigObjError

Postby Painkiller » Fri Jan 21, 2022 11:29 am

I get an error with a plugin.

Could someone tell me how to fix this?

Thanks in advance

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/plugins/command.py", line 164, in load_plugin
    plugin = self.manager.load(plugin_name)
  File "../addons/source-python/packages/source-python/plugins/manager.py", line 207, in load
    plugin._load()
  File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
    self.module = import_module(self.import_name)
  File "../addons/source-python/plugins/lms/lms.py", line 28, in <module>
    database = ConfigObj(db_path)
  File "../addons/source-python/packages/site-packages/configobj.py", line 1229, in __init__
    self._load(infile, configspec)
  File "../addons/source-python/packages/site-packages/configobj.py", line 1318, in _load
    raise error
  File "<string>", line None

configobj.ConfigObjError: Parsing failed with several errors.
First error at line 9.


2022-01-19 12:55:03 - sp   -   MESSAGE   [SP] Plugin 'lms' was unable to be loaded.
User avatar
Articha
Member
Posts: 32
Joined: Tue Sep 21, 2021 12:13 pm
Location: Russia

ConfigObj file

Postby Articha » Sat Jan 22, 2022 5:54 am

ConfigObj works with config file somewhere. This file contains error. At line 9, to be exactly
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: ConfigObj file

Postby Painkiller » Sat Jan 22, 2022 1:11 pm

Articha wrote:ConfigObj works with config file somewhere. This file contains error. At line 9, to be exactly


I think I've found the line.

Syntax: Select all

cfg =  {'ppk': points_per_kill.get_int(),

Can you tell me where there is a problem?

and here the complete config.py:

Syntax: Select all

from config.manager import ConfigManager

core_config = ConfigManager('lms_config')

points_per_kill = core_config.cvar('points_per_kill', 5, "Wieviele Punkte kriegt ein Spieler pro Kill")
points_third_place = core_config.cvar('points_third_place', 20, "Wieviele Punkte der dritte Platz kriegt")
points_second_place = core_config.cvar('points_second_place',50, "Wieviele Punkte der zweite Platz kriegt")
points_first_place = core_config.cvar('points_first_place',100, "Wieviele Punkte der erste Platz kriegt")


cfg = {'ppk': points_per_kill.get_int(),
'ptp': points_third_place.get_int(),
'psp': points_second_place.get_int(),
'pfp': points_first_place.get_int()}

core_config.write()
core_config.execute()
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: configobj.ConfigObjError

Postby satoon101 » Sat Jan 22, 2022 1:23 pm

It wouldn't be line 9 of the config.py file. There is a .ini file somewhere that it's reading where line 9 isn't valid. In your lms.py file, what is db_path set to? That path is the location of the .ini file that is causing the error.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Sat Jan 22, 2022 2:35 pm

satoon101 wrote:It wouldn't be line 9 of the config.py file. There is a .ini file somewhere that it's reading where line 9 isn't valid. In your lms.py file, what is db_path set to? That path is the location of the .ini file that is causing the error.



There was no one anywhere :(

I set now in the info

Syntax: Select all

# ../addons/source-python/plugins/lms/info.ini


and in the py

Syntax: Select all

# ../addons/source-python/plugins/lms/lms.py


would that be so corect?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: configobj.ConfigObjError

Postby satoon101 » Mon Jan 24, 2022 6:47 pm

No, the issue has nothing to do with the info.ini file. In the lms.py file, there is likely a line that starts with db_path =

Could you post that line here so we can see which file is causing this error.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Mon Jan 24, 2022 10:13 pm

I find this.

Syntax: Select all

if not os.path.isdir(PLUGIN_DATA_PATH+"/lms"):
os.makedirs (PLUGIN_DATA_PATH+"/lms")
db_path = os.path.join(PLUGIN_DATA_PATH,'lms','database.ini')
database = ConfigObj(db_path)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: configobj.ConfigObjError

Postby satoon101 » Mon Jan 24, 2022 11:02 pm

Ok, so the issue is in the ../addons/source-python/data/plugins/lms/database.ini file on the server. Specifically on line #9 in that file.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Tue Jan 25, 2022 1:22 pm

I have this in line 9.

Code: Select all

[BOT_bad comrade [CC]]
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: configobj.ConfigObjError

Postby Ayuto » Tue Jan 25, 2022 4:30 pm

Try putting it in quotes:

Code: Select all

["BOT_bad comrade [CC]"]
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Tue Jan 25, 2022 5:08 pm

I think the error is still there.

Maybe the plugin can't handle the bot names.

Probably I should have entered this for each line.

But the bot names change constantly


Code: Select all

2022-01-25 18:03:59 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/plugins/command.py", line 164, in load_plugin
    plugin = self.manager.load(plugin_name)
  File "../addons/source-python/packages/source-python/plugins/manager.py", line 207, in load
    plugin._load()
  File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
    self.module = import_module(self.import_name)
  File "../addons/source-python/plugins/lms/lms.py", line 30, in <module>
    database = ConfigObj(db_path)
  File "../addons/source-python/packages/site-packages/configobj.py", line 1229, in __init__
    self._load(infile, configspec)
  File "../addons/source-python/packages/site-packages/configobj.py", line 1318, in _load
    raise error
  File "<string>", line None

configobj.ConfigObjError: Parsing failed with several errors.
First error at line 29.


2022-01-25 18:03:59 - sp   -   MESSAGE   [SP] Plugin 'lms' was unable to be loaded.


database.ini

Code: Select all

[U:1:43907303]
points = 725
[U:1:15288069]
points = 100
[BOT_[{CSF}]Terr0rCow]
points = 0
[BOT_[SXE] Squat]
points = 20
["BOT_bad comrade [CC]"]
points = 0
[BOT_{+STF+} MoonPie]
points = 20
[BOT_=STS= NiGHtSHad3]
points = 50
[BOT_TH3 FAT C0NTR0LL3R]
points = 70
[BOT_|gCf| Bearded Clam]
points = 20
[U:1:17377130]
points = 120
[BOT_{CFF} BOT0x_InJECtIOn]
points = 0
[BOT_=STS= NixieT00b]
points = 0
[BOT_g0nZ0 |eFa|]
points = 0
[BOT_Mr. BuBBle |eFa|]
points = 0
[BOT_MayHEm! [CC]]
points = 0
[BOT_{+STF+} KaUStic]
points = 0
[BOT_{DDE} Donkey Punch]
points = 0
[BOT_[SXE] HamBURgER HelPeR]
points = 0
[BOT_FunKyMucKer [dXb]]
points = 0
[BOT_split2nd |THL|]
points = 0
[BOT_[SXE] raBButpUNch]
points = 0
[BOT_{DDE}-=SPiTFiRe=-]
points = 0
[BOT_[{CSF}]Simplex]
points = 0
[BOT_|gCf| K1LLeRX]
points = 0
[BOT_BOTToMF33D3r |eFa|]
points = 0
[BOT_SlaPHaPPy [dXb]]
points = 0
[U:1:19510774]
points = 50
[U:1:941473720]
points = 105
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Wed Jan 26, 2022 7:17 am

I removed all bots from database.cfg
The plugin loaded normally again.
After the die came this error.

Code: Select all

2022-01-26 08:14:06 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/events/listener.py", line 92, in fire_game_event
    callback(game_event)
  File "../addons/source-python/plugins/lms/lms.py", line 85, in player_death
    attacker = Player.from_userid(int(ev['attacker']))
  File "../addons/source-python/packages/source-python/players/_base.py", line 109, in from_userid
    return cls(index_from_userid(userid), caching=caching)

ValueError: Conversion from "Userid" (0) to "Index" failed.


Edit: When I bleed out or suicide, I can't get out of the spectate to respawn. It only happens when I am alone on the server, apparently.
Edit2: It also happens with players straight tested.

Edit3: I refer then here times to the Haubt topic

https://forums.sourcepython.com/viewtopic.php?f=37&t=2004&p=12701&hilit=LMS#p12701
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: configobj.ConfigObjError

Postby cssbestrpg » Wed Jan 26, 2022 8:56 am

Paste the whole code that the plugin have, so i can fix suicide errors.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Wed Jan 26, 2022 9:14 am

Hello @cssbestrpg
The plugin is on the link.

but i like to send it here again too.

config.py

Syntax: Select all

from config.manager import ConfigManager

core_config = ConfigManager('lms_config')

points_per_kill = core_config.cvar('points_per_kill', 5, "Wieviele Punkte kriegt ein Spieler pro Kill")
points_third_place = core_config.cvar('points_third_place', 20, "Wieviele Punkte der dritte Platz kriegt")
points_second_place = core_config.cvar('points_second_place',50, "Wieviele Punkte der zweite Platz kriegt")
points_first_place = core_config.cvar('points_first_place',100, "Wieviele Punkte der erste Platz kriegt")


cfg = {'ppk': points_per_kill.get_int(),
'ptp': points_third_place.get_int(),
'psp': points_second_place.get_int(),
'pfp': points_first_place.get_int()}

core_config.write()
core_config.execute()



lms.py

Syntax: Select all

# ../lms/lms.py

from players.entity import Player
from events import Event
from events.hooks import PreEvent, EventAction
from filters.players import PlayerIter
from lms import config

from messages import SayText2, HudMsg
from listeners.tick import Delay,Repeat

from commands.server import ServerCommand
from commands.client import ClientCommand
from commands.say import SayCommand
from commands import CommandReturn

from engines.server import queue_command_string

from configobj import ConfigObj
from paths import PLUGIN_DATA_PATH
import os
import re


already_played = {}

if not os.path.isdir(PLUGIN_DATA_PATH+"/lms"):
os.makedirs (PLUGIN_DATA_PATH+"/lms")
db_path = os.path.join(PLUGIN_DATA_PATH,'lms','database.ini')
database = ConfigObj(db_path)

for player in PlayerIter():
steamid = player.steamid
already_played[steamid] = 0
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['points'] = 0


def display_players():
living_players = get_living_player_count()
all_players = get_player_count()
if living_players >= 2:
HudMsg("Last Man Standing\n"+str(living_players)+" von "+str(all_players)+" Spielern sind noch übrig",-1,0.02,channel=1).send()
else:
count = 0
for player in PlayerIter('alive'):
count += 1
name = player.name
if count > 0:
HudMsg("Last Man Standing\n"+str(name)+" hat diese Runde gewonnen",-1,0.02,channel=1).send()

display_players_repeat = Repeat(display_players)
display_players_repeat.start(0.5)

@PreEvent('player_activate')
def activate(ev):
player = Player.from_userid(int(ev['userid']))
steamid = player.steamid
if player.steamid not in already_played:
already_played[player.steamid] = 0
if already_played[player.steamid] == 1:
Delay(0.1,_late_join,(player.index,))
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['points'] = 0

def _late_join(index):
Player(index).team = 1
SayText2("\x04[LastManStanding] \x03Du musst warten bis die neue Runde beginnt").send(index)


@Event('player_death')
def player_death(ev):
player = Player.from_userid(int(ev['userid']))
player.team = 1
attacker = Player.from_userid(int(ev['attacker']))
player_steamid = player.steamid
already_played[player.steamid] = 1
if "BOT" in player_steamid:
player_steamid = "BOT_"+player.name
else:
player_steamid = player_steamid.replace("[","").replace("]","")
attacker_steamid = attacker.steamid
if "BOT" in attacker_steamid:
attacker_steamid = "BOT_"+attacker.name
else:
attacker_steamid = attacker_steamid.replace("[","").replace("]","")
if attacker != player:
give_points(attacker_steamid,config.cfg['ppk'])
living_players = get_living_player_count()
if living_players == 2:
give_points(player_steamid, config.cfg['ptp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04dritten \x03Platz!").send()
if living_players == 1:
give_points(player_steamid, config.cfg['psp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04zweiten \x03Platz!").send()
if attacker.name != player.name:
give_points(attacker_steamid, config.cfg['pfp'])
SayText2("\x04[LastManStanding] "+attacker.name+" \x03ist der \x04Last Man Standing!").send()
HudMsg(""+attacker.name+" ist der Last Man Standing",-1,0.4).send()
else:
for player in PlayerIter('alive'):
steamid = player.steamid
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
give_points(steamid, config.cfg['pfp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist der \x04Last Man Standing!").send()
HudMsg(""+player.name+" ist der Last Man Standing",-1,0.4).send()
_restart_game()


def _restart_game():
SayText2("\x04[LastManStanding] \x03Die neue Runde beginnt in\x04 5 Sekunden").send()
already_played = {}
for player in PlayerIter():
player.team = 0
already_played[player.steamid] = 0
queue_command_string("mp_restartgame 5")


def save_database():
database.write()

def give_points(steamid,amount):
points = int(database[steamid]['points'])
database[steamid]['points'] = (points+amount)
save_database()


#Get the amount of living players
def get_living_player_count():
count = 0
for player in PlayerIter('alive'):
count += 1
return count

def get_player_count():
count = 0
for player in PlayerIter():
count += 1
return count

#Block teamchange messages
@PreEvent('player_team')
def team(ev):
if int(ev['team']) in [0,1]:
return EventAction.BLOCK

#Block usage of jointeam
@ClientCommand('jointeam')
def join_test(command,index):
return CommandReturn.BLOCK

#Rank command and helper function
def get_rank(steamid):
steamid = steamid.replace("[","").replace("]","")
ranks = sorted(database, key=lambda x: int(database[x]['points']),reverse=True)
i = 0
for x in ranks:
i += 1
if x == steamid:
break
return(i,len(ranks))

@SayCommand('rank')
@ClientCommand('rank')
def rank(command,index,team=None):
player = Player(index)
rank,ofall = get_rank(player.steamid)
SayText2("\x04[LastManStanding] \x03Du bist auf Platz \x04"+str(rank)+"\x03 von \x04"+str(ofall)+".").send(player.index)
return CommandReturn.BLOCK

#ServerCommand that restarts the current round and respawns every player
@ServerCommand('lms_restart')
def _restart(command):
_restart_game()
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: configobj.ConfigObjError

Postby cssbestrpg » Wed Jan 26, 2022 1:11 pm

This should fix the suicide errors:

Syntax: Select all

# ../lms/lms.py

from players.entity import Player
from events import Event
from events.hooks import PreEvent, EventAction
from filters.players import PlayerIter
from lms import config

from messages import SayText2, HudMsg
from listeners.tick import Delay,Repeat

from commands.server import ServerCommand
from commands.client import ClientCommand
from commands.say import SayCommand
from commands import CommandReturn

from engines.server import queue_command_string

from configobj import ConfigObj
from paths import PLUGIN_DATA_PATH
import os
import re


already_played = {}

if not os.path.isdir(PLUGIN_DATA_PATH+"/lms"):
os.makedirs (PLUGIN_DATA_PATH+"/lms")
db_path = os.path.join(PLUGIN_DATA_PATH,'lms','database.ini')
database = ConfigObj(db_path)

for player in PlayerIter():
steamid = player.steamid
already_played[steamid] = 0
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['points'] = 0


def display_players():
living_players = get_living_player_count()
all_players = get_player_count()
if living_players >= 2:
HudMsg("Last Man Standing\n"+str(living_players)+" von "+str(all_players)+" Spielern sind noch übrig",-1,0.02,channel=1).send()
else:
count = 0
for player in PlayerIter('alive'):
count += 1
name = player.name
if count > 0:
HudMsg("Last Man Standing\n"+str(name)+" hat diese Runde gewonnen",-1,0.02,channel=1).send()

display_players_repeat = Repeat(display_players)
display_players_repeat.start(0.5)

@PreEvent('player_activate')
def activate(ev):
player = Player.from_userid(int(ev['userid']))
steamid = player.steamid
if player.steamid not in already_played:
already_played[player.steamid] = 0
if already_played[player.steamid] == 1:
Delay(0.1,_late_join,(player.index,))
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['points'] = 0

def _late_join(index):
Player(index).team = 1
SayText2("\x04[LastManStanding] \x03Du musst warten bis die neue Runde beginnt").send(index)


@Event('player_death')
def player_death(ev):
player = Player.from_userid(int(ev['userid']))
player.team = 1
try:
attacker = Player.from_userid(ev['attacker'])
except ValueError:
return
player_steamid = player.steamid
already_played[player.steamid] = 1
if "BOT" in player_steamid:
player_steamid = "BOT_"+player.name
else:
player_steamid = player_steamid.replace("[","").replace("]","")
attacker_steamid = attacker.steamid
if "BOT" in attacker_steamid:
attacker_steamid = "BOT_"+attacker.name
else:
attacker_steamid = attacker_steamid.replace("[","").replace("]","")
if attacker != player:
give_points(attacker_steamid,config.cfg['ppk'])
living_players = get_living_player_count()
if living_players == 2:
give_points(player_steamid, config.cfg['ptp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04dritten \x03Platz!").send()
if living_players == 1:
give_points(player_steamid, config.cfg['psp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04zweiten \x03Platz!").send()
if attacker.name != player.name:
give_points(attacker_steamid, config.cfg['pfp'])
SayText2("\x04[LastManStanding] "+attacker.name+" \x03ist der \x04Last Man Standing!").send()
HudMsg(""+attacker.name+" ist der Last Man Standing",-1,0.4).send()
else:
for player in PlayerIter('alive'):
steamid = player.steamid
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
give_points(steamid, config.cfg['pfp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist der \x04Last Man Standing!").send()
HudMsg(""+player.name+" ist der Last Man Standing",-1,0.4).send()
_restart_game()


def _restart_game():
SayText2("\x04[LastManStanding] \x03Die neue Runde beginnt in\x04 5 Sekunden").send()
already_played = {}
for player in PlayerIter():
player.team = 0
already_played[player.steamid] = 0
queue_command_string("mp_restartgame 5")


def save_database():
database.write()

def give_points(steamid,amount):
points = int(database[steamid]['points'])
database[steamid]['points'] = (points+amount)
save_database()


#Get the amount of living players
def get_living_player_count():
count = 0
for player in PlayerIter('alive'):
count += 1
return count

def get_player_count():
count = 0
for player in PlayerIter():
count += 1
return count

#Block teamchange messages
@PreEvent('player_team')
def team(ev):
if int(ev['team']) in [0,1]:
return EventAction.BLOCK

#Block usage of jointeam
@ClientCommand('jointeam')
def join_test(command,index):
return CommandReturn.BLOCK

#Rank command and helper function
def get_rank(steamid):
steamid = steamid.replace("[","").replace("]","")
ranks = sorted(database, key=lambda x: int(database[x]['points']),reverse=True)
i = 0
for x in ranks:
i += 1
if x == steamid:
break
return(i,len(ranks))

@SayCommand('rank')
@ClientCommand('rank')
def rank(command,index,team=None):
player = Player(index)
rank,ofall = get_rank(player.steamid)
SayText2("\x04[LastManStanding] \x03Du bist auf Platz \x04"+str(rank)+"\x03 von \x04"+str(ofall)+".").send(player.index)
return CommandReturn.BLOCK

#ServerCommand that restarts the current round and respawns every player
@ServerCommand('lms_restart')
def _restart(command):
_restart_game()
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Wed Jan 26, 2022 1:16 pm

Unfortunately the problem still exists

If I join the server alone and kill myself, I can't get out of the spectate.

178.63.54.240:28060 Irrenanstallt [Rocks] | Coop -> 18+ | FastDL
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: configobj.ConfigObjError

Postby cssbestrpg » Wed Jan 26, 2022 1:45 pm

I think i found the issue of the code, try this version:

Syntax: Select all

# ../lms/lms.py

from players.entity import Player
from events import Event
from events.hooks import PreEvent, EventAction
from filters.players import PlayerIter
from lms import config

from messages import SayText2, HudMsg
from listeners.tick import Delay,Repeat

from commands.server import ServerCommand
from commands.client import ClientCommand
from commands.say import SayCommand
from commands import CommandReturn

from engines.server import queue_command_string

from configobj import ConfigObj
from paths import PLUGIN_DATA_PATH
import os
import re


already_played = {}

if not os.path.isdir(PLUGIN_DATA_PATH+"/lms"):
os.makedirs (PLUGIN_DATA_PATH+"/lms")
db_path = os.path.join(PLUGIN_DATA_PATH,'lms','database.ini')
database = ConfigObj(db_path)

for player in PlayerIter():
steamid = player.steamid
already_played[steamid] = 0
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['points'] = 0


def display_players():
living_players = get_living_player_count()
all_players = get_player_count()
if living_players >= 2:
HudMsg("Last Man Standing\n"+str(living_players)+" von "+str(all_players)+" Spielern sind noch übrig",-1,0.02,channel=1).send()
else:
count = 0
for player in PlayerIter('alive'):
count += 1
name = player.name
if count > 0:
HudMsg("Last Man Standing\n"+str(name)+" hat diese Runde gewonnen",-1,0.02,channel=1).send()

display_players_repeat = Repeat(display_players)
display_players_repeat.start(0.5)

@PreEvent('player_activate')
def activate(ev):
player = Player.from_userid(int(ev['userid']))
steamid = player.steamid
if player.steamid not in already_played:
already_played[player.steamid] = 0
if already_played[player.steamid] == 1:
Delay(0.1,_late_join,(player.index,))
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['points'] = 0

def _late_join(index):
Player(index).team = 1
SayText2("\x04[LastManStanding] \x03Du musst warten bis die neue Runde beginnt").send(index)


@Event('player_death')
def player_death(ev):
player = Player.from_userid(int(ev['userid']))
player.team = 1
try:
attacker = Player.from_userid(ev['attacker'])
except ValueError:
return
player_steamid = player.steamid
already_played[player.steamid] = 1
if "BOT" in player_steamid:
player_steamid = "BOT_"+player.name
else:
player_steamid = player_steamid.replace("[","").replace("]","")
attacker_steamid = attacker.steamid
if "BOT" in attacker_steamid:
attacker_steamid = "BOT_"+attacker.name
else:
attacker_steamid = attacker_steamid.replace("[","").replace("]","")
if attacker != player:
give_points(attacker_steamid,config.cfg['ppk'])
living_players = get_living_player_count()
if living_players == 2:
give_points(player_steamid, config.cfg['ptp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04dritten \x03Platz!").send()
if living_players == 1:
give_points(player_steamid, config.cfg['psp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04zweiten \x03Platz!").send()
if attacker.name != player.name:
give_points(attacker_steamid, config.cfg['pfp'])
SayText2("\x04[LastManStanding] "+attacker.name+" \x03ist der \x04Last Man Standing!").send()
HudMsg(""+attacker.name+" ist der Last Man Standing",-1,0.4).send()
else:
for player in PlayerIter('alive'):
steamid = player.steamid
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
give_points(steamid, config.cfg['pfp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist der \x04Last Man Standing!").send()
HudMsg(""+player.name+" ist der Last Man Standing",-1,0.4).send()
_restart_game()


def _restart_game():
SayText2("\x04[LastManStanding] \x03Die neue Runde beginnt in\x04 5 Sekunden").send()
already_played = {}
for player in PlayerIter():
player.team = 0
already_played[player.steamid] = 0
queue_command_string("mp_restartgame 5")


def save_database():
database.write()

def give_points(steamid,amount):
points = int(database[steamid]['points'])
database[steamid]['points'] = (points+amount)
save_database()


#Get the amount of living players
def get_living_player_count():
count = 0
for player in PlayerIter('alive'):
count += 1
return count

def get_player_count():
count = 0
for player in PlayerIter():
count += 1
return count

#Block teamchange messages
@PreEvent('player_team')
def team(ev):
if int(ev['team']) in [0,1]:
return EventAction.BLOCK

#Rank command and helper function
def get_rank(steamid):
steamid = steamid.replace("[","").replace("]","")
ranks = sorted(database, key=lambda x: int(database[x]['points']),reverse=True)
i = 0
for x in ranks:
i += 1
if x == steamid:
break
return(i,len(ranks))

@SayCommand('rank')
@ClientCommand('rank')
def rank(command,index,team=None):
player = Player(index)
rank,ofall = get_rank(player.steamid)
SayText2("\x04[LastManStanding] \x03Du bist auf Platz \x04"+str(rank)+"\x03 von \x04"+str(ofall)+".").send(player.index)
return CommandReturn.BLOCK

#ServerCommand that restarts the current round and respawns every player
@ServerCommand('lms_restart')
def _restart(command):
_restart_game()
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Wed Jan 26, 2022 2:50 pm

The same problem
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Sat Jan 29, 2022 9:05 am

Good morning, unfortunately the problem still exists that you can not get out of the Spectate.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: configobj.ConfigObjError

Postby Painkiller » Sat Feb 05, 2022 8:32 am

Next Error, i updated SP.

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/plugins/command.py", line 164, in load_plugin
    plugin = self.manager.load(plugin_name)
  File "../addons/source-python/packages/source-python/plugins/manager.py", line 207, in load
    plugin._load()
  File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
    self.module = import_module(self.import_name)
  File "../addons/source-python/plugins/lms/lms.py", line 36, in <module>
    uniqueid = fixed_uniqueid(player.uniqueid)

NameError: name 'player' is not defined

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 21 guests