Could someone please make for SourcePython?
https://forums.alliedmods.net/showthread.php?p=660327
[HL2:DM] Save Scores
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Try this (untested):
Syntax: Select all
from events import Event
from listeners import OnClientDisconnect
from listeners import OnLevelShutdown
from players.entity import Player
from players.helpers import index_from_userid
scores = dict()
@OnLevelShutdown
def clear_scores():
scores.clear()
@OnClientDisconnect
def save_player_score(index):
player = Player(index)
scores[player.uniqueid] = {
'kills': player.kills,
'deaths': player.deaths,
}
@Event('player_activate')
def reset_player_score(game_event):
player = Player(index_from_userid(game_event['userid']))
if player.uniqueid not in scores:
return
player_scores = scores.pop(player.uniqueid)
player.kills = player_scores['kills']
player.deaths = player_scores['deaths']
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
It shouldn't matter if there are bots. Are you trying to store the scores for bots, too?
I just tested, and it works fine, at least for human players.
It should also work for bots, as 'uniqueid' uses the name for bots. I guess it might not work if bots don't call OnClientDisconnect or event player_activate.
I just tested, and it works fine, at least for human players.
It should also work for bots, as 'uniqueid' uses the name for bots. I guess it might not work if bots don't call OnClientDisconnect or event player_activate.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: [HL2:DM] Save Scores
Code: Select all
2017-02-20 19:31:45 - sp - EXCEPTION
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/plugins/savescore/savescore.py", line 15, in save_player_score
player = Player(index)
File "../addons/source-python/packages/source-python/players/_base.py", line 86, in __init__
super().__init__(index)
File "../addons/source-python/packages/source-python/entities/_base.py", line 94, in __init__
super().__init__(index)
ValueError: Conversion from "Index" (1) to "BaseEntity" failed.
Re: [HL2:DM] Save Scores
The error is not critical. It doesn't affect anything. It occurs only when a player disconnects before activating. But such player doesn't have any score to save anyways. You can safely ignore it.
But here's the fix:
But here's the fix:
Syntax: Select all
from events import Event
from listeners import OnClientDisconnect, OnLevelShutdown
from players.entity import Player
scores = dict()
@OnLevelShutdown
def clear_scores():
scores.clear()
@OnClientDisconnect
def save_player_score(index):
try:
player = Player(index)
except ValueError:
return
scores[player.uniqueid] = {
'kills': player.kills,
'deaths': player.deaths,
}
@Event('player_activate')
def reset_player_score(game_event):
player = Player.from_userid(game_event['userid'])
if player.uniqueid not in scores:
return
player_scores = scores.pop(player.uniqueid)
player.kills = player_scores['kills']
player.deaths = player_scores['deaths']

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: [HL2:DM] Save Scores
Thanks it worksfine for me.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: [HL2:DM] Save Scores
Hello,
i find a error in the logs.
Can anybody help for this problem ?
i find a error in the logs.
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/plugins/savescore/savescore.py", line 15, in save_player_score
player = Player(index)
File "../addons/source-python/packages/source-python/players/_base.py", line 88, in __init__
super().__init__(index)
File "../addons/source-python/packages/source-python/entities/_base.py", line 94, in __init__
super().__init__(index)
ValueError: Conversion from "Index" (2) to "BaseEntity" failed.
Dropped luisdaquixx from server (Disconnect by user.)
L 06/29/2019 - 20:41:03: "sasha.sh181e<6><[U:1:946818002]><>" disconnected (reason "Disconnect by user.")
Spawn/Chat Protection; ClientDisconnect
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/plugins/savescore/savescore.py", line 15, in save_player_score
player = Player(index)
File "../addons/source-python/packages/source-python/players/_base.py", line 88, in __init__
super().__init__(index)
File "../addons/source-python/packages/source-python/entities/_base.py", line 94, in __init__
super().__init__(index)
ValueError: Conversion from "Index" (3) to "BaseEntity" failed.
Can anybody help for this problem ?
Re: [HL2:DM] Save Scores
That's the same issue you already posted in 2017 and it has been solved by the version of iPlayer.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: [HL2:DM] Save Scores
I'm gonna retest that. Maybe I had an older version in use.
Edit: There doesn't seem to be any mistakes now.
Thank you very much for the reminder.
Edit: There doesn't seem to be any mistakes now.
Thank you very much for the reminder.
Who is online
Users browsing this forum: No registered users and 59 guests