[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: 290
Joined: Sun Mar 01, 2015 8:09 am
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
Image
User avatar
satoon101
Project Leader
Posts: 2387
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: 290
Joined: Sun Mar 01, 2015 8:09 am
Contact:

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

Delete
Image
User avatar
satoon101
Project Leader
Posts: 2387
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: 290
Joined: Sun Mar 01, 2015 8:09 am
Contact:

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

Aie it lacked a line apologize.

It works flawlessly
Image
User avatar
Painkiller
Senior Member
Posts: 290
Joined: Sun Mar 01, 2015 8:09 am
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.

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 2 guests