configobj.ConfigObjError

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: configobj.ConfigObjError

Postby cssbestrpg » Sat Feb 05, 2022 8:49 am

Fixed the error in this one:

Syntax: Select all

import os
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

def fixed_uniqueid(uniqueid):
return uniqueid.replace('[', '').replace(']', '')

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():
already_played[player.uniqueid] = False
uniqueid = fixed_uniqueid(player.uniqueid)
database.setdefault(uniqueid, {'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:
for player in PlayerIter('alive'):
if living_players > 0:
HudMsg("Last Man Standing\n"+(player.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']))
already_played.setdefault(player.uniqueid, False)
if already_played[player.uniqueid]:
player.delay(0.1,_late_join,(player.index,))
uniqueid = fixed_uniqueid(player.uniqueid)
database.setdefault(uniqueid, {'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'])
if attacker.index == player.index:
attacker = None

except ValueError:
attacker = None

player_steamid = player.steamid
already_played[player.uniqueid] = True

player_steamid = fixed_uniqueid(player.uniqueid)

if attacker is not None:
give_points(fixed_uniqueid(attacker.uniqueid),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()

elif living_players == 1:
give_points(player_steamid, config.cfg['psp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04zweiten \x03Platz!").send()

for player in PlayerIter('alive'):
winner_steamid = player.uniqueid.replace('[', '').replace(']', '')
give_points(winner_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()
break

_restart_game()

elif living_players == 0:
_restart_game()

def _restart_game():
SayText2("\x04[LastManStanding] \x03Die neue Runde beginnt in\x04 5 Sekunden").send()
already_played.clear()
for player in PlayerIter():
player.team = 0
already_played[player.uniqueid] = False
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():
return len(PlayerIter('alive'))

def get_player_count():
return len(PlayerIter())

#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 » Sat Feb 05, 2022 9:01 am

Thanks

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 27 guests