[HL2:DM] Save Scores

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

[HL2:DM] Save Scores

Postby Painkiller » Mon Apr 11, 2016 1:29 pm

Could someone please make for SourcePython?

https://forums.alliedmods.net/showthread.php?p=660327
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Apr 11, 2016 2:48 pm

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']
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Postby Painkiller » Mon Apr 11, 2016 3:37 pm

Delete
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Apr 11, 2016 3:46 pm

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.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Postby Painkiller » Mon Apr 11, 2016 3:47 pm

Aie it lacked a line apologize.

It works flawlessly
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Save Scores

Postby Painkiller » Mon Feb 20, 2017 8:51 pm

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.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: [HL2:DM] Save Scores

Postby iPlayer » Mon Oct 02, 2017 7:04 pm

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:

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']
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Save Scores

Postby Painkiller » Tue Oct 03, 2017 2:21 pm

Thanks it worksfine for me.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Save Scores

Postby Painkiller » Tue Jul 09, 2019 4:59 pm

Hello,
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 ?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [HL2:DM] Save Scores

Postby Ayuto » Tue Jul 09, 2019 6:05 pm

That's the same issue you already posted in 2017 and it has been solved by the version of iPlayer.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Save Scores

Postby Painkiller » Tue Jul 09, 2019 6:21 pm

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.

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 4 guests