[HL2:DM] Mini Scoreboard Always display

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] Mini Scoreboard Always display

Postby Painkiller » Mon May 01, 2017 3:17 pm

Would it be possible to write a plugin for hl2dm,
What exactly does that indicate?
It is displayed up in the middle with a timeleft.
First place, last place with name and kills.
Thanks in Advance

1 place | Calle | 12 Kills
5 last place | RocKsPainkiller | 9 Kills




Image
Last edited by Painkiller on Tue Jun 06, 2017 2:29 pm, edited 1 time in total.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] mini scoreboard

Postby Painkiller » Mon May 08, 2017 2:08 pm

Hi mates,

can anybody help me for this ?

(You could display game_text in HL2:DM)
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] mini scoreboard

Postby Painkiller » Tue May 16, 2017 1:36 pm

No one idea please?
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Tue Jun 06, 2017 2:30 pm

Please help me with this idea
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Wed Jun 14, 2017 9:57 am

Nobody can help for it?
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2:DM] Mini Scoreboard Always display

Postby VinciT » Thu Jun 15, 2017 11:19 pm

Give this a try:

Syntax: Select all

#mini_scoreboard.py
from colors import Color
from events import Event

from players.entity import Player
from players.helpers import index_from_userid
from filters.players import PlayerIter

from messages import HudMsg
from listeners import OnLevelEnd
from listeners.tick import Repeat


# how often should the mini scoreboard refresh? (default: 0.49 seconds)
UPDATE_RATE = 0.49

# text colors
FIRST_PLACE_COLOR = Color(255, 187, 43)
LAST_PLACE_COLOR = Color(200, 200, 200)


FIRST_PLACE = None
LAST_PLACE = None

# =============================================================================
# >> PLAYER INSTANCE
# =============================================================================
player_instance = {}

def get_player_instance(userid):
if userid not in player_instance:
player_instance[userid] = Player(index_from_userid(userid))

return player_instance[userid]

def get_all_players():
return list(player_instance.values())


# =============================================================================
# >> EVENTS
# =============================================================================
def load():
for player in PlayerIter():
if player.userid not in player_instance:
player_instance[player.userid] = player

get_new_first_place()
get_new_last_place()


@Event('player_activate')
def player_joined(event):
userid = event.get_int('userid')
player = get_player_instance(userid)

global FIRST_PLACE
if not FIRST_PLACE:
FIRST_PLACE = player
return

if FIRST_PLACE.kills < 0:
FIRST_PLACE = player
get_new_last_place()

global LAST_PLACE
if not LAST_PLACE or LAST_PLACE.kills > 0:
LAST_PLACE = player


@Event('player_disconnect')
def player_left(event):
userid = event.get_int('userid')

if userid in player_instance:
del player_instance[userid]

if FIRST_PLACE and userid == FIRST_PLACE.userid:
get_new_first_place()

if LAST_PLACE and userid == LAST_PLACE.userid:
get_new_last_place()


@OnLevelEnd
def map_changing():
player_instance.clear()

global FIRST_PLACE
FIRST_PLACE = None

global LAST_PLACE
LAST_PLACE = None


@Event('player_death')
def player_died(event):
userid_a = event.get_int('attacker')

# killed by world
if userid_a == 0:
return

attacker = get_player_instance(userid_a)

global FIRST_PLACE
if attacker.kills > FIRST_PLACE.kills:
FIRST_PLACE = attacker

get_new_last_place()


# =============================================================================
# >> MINI SCOREBOARD RENDER / PRINT
# =============================================================================
def render_mini_scoreboard():
if FIRST_PLACE:
HudMsg(message='1 | {player_name} | {player_kills} kills'.format(
player_name=FIRST_PLACE.name,
player_kills=FIRST_PLACE.kills),
x=-1, y=0,
color1=FIRST_PLACE_COLOR,
fade_in=0.05, fade_out=0.05,
hold_time=UPDATE_RATE * 2, fx_time=0, channel=1).send()

if LAST_PLACE:
place = len(player_instance)
HudMsg(message='{player_place} | {player_name} | {player_kills} kills'.format(
player_place=place,
player_name=LAST_PLACE.name,
player_kills=LAST_PLACE.kills),
x=-1, y=0.03,
color1=LAST_PLACE_COLOR,
fade_in=0.05, fade_out=0.05,
hold_time=UPDATE_RATE * 2, fx_time=0, channel=2).send()


render_loop = Repeat(render_mini_scoreboard)
render_loop.start(UPDATE_RATE)


# =============================================================================
# >> HELPER FUNCTIONS
# =============================================================================
def get_new_first_place():
players = get_all_players()
new_first_place = None

for player in players:
if LAST_PLACE and player.userid == LAST_PLACE.userid:
continue

if not new_first_place:
new_first_place = player
continue

if player.kills > new_first_place.kills:
new_first_place = player

global FIRST_PLACE
FIRST_PLACE = new_first_place


def get_new_last_place():
players = get_all_players()
new_last_place = None

for player in players:
if FIRST_PLACE and player.userid == FIRST_PLACE.userid:
continue

if not new_last_place:
new_last_place = player
continue

if player.kills < new_last_place.kills:
new_last_place = player

global LAST_PLACE
LAST_PLACE = new_last_place
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [HL2:DM] Mini Scoreboard Always display

Postby satoon101 » Thu Jun 15, 2017 11:58 pm

I think that might work, but I really don't think you need to keep track of all the players like that. Retrieving the kills on the fly should work just fine. Maybe something like (untested):

Syntax: Select all

from time import time

import colors
from cvars import ConVar
from filters.players import PlayerIter
from listeners import OnLevelInit
from listeners.tick import Repeat
from messages import HudMsg


# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Set to the number of seconds between refreshing the messages
UPDATE_RATE = 1.0

# Set to the color to use for the First Place player
# Choices can be found starting here:
# http://wiki.sourcepython.com/developing/modules/colors.html#colors.BLACK
FIRST_PLACE_COLOR = 'ORANGE'

# Set to the color to use for the Last Place player
# Choices can be found starting here:
# http://wiki.sourcepython.com/developing/modules/colors.html#colors.BLACK
LAST_PLACE_COLOR = 'LIGHT_BLUE'

# Set to the color to use for the Timeleft message
# Choices can be found starting here:
# http://wiki.sourcepython.com/developing/modules/colors.html#colors.BLACK
TIME_LEFT_COLOR = 'WHITE'


# =============================================================================
# >> END OF CONFIGURATION
# =============================================================================

_common_kwargs = {
'x': -0.7,
'fade_in': 0.0,
'fade_out': 0.0,
'hold_time': UPDATE_RATE + 0.04,
'fx_time': .07,
}

FIRST_PLACE_MESSAGE = HudMsg(
message='1 | {player.name} | {player.kills}',
y=0.0,
color1=getattr(colors, FIRST_PLACE_COLOR, colors.ORANGE),
channel=1,
**_common_kwargs
)

LAST_PLACE_MESSAGE = HudMsg(
message='{place} | {player.name} | {player.kills}',
y=0.03,
color1=getattr(colors, LAST_PLACE_COLOR, colors.LIGHT_BLUE),
channel=2,
**_common_kwargs
)

TIME_LEFT_MESSAGE = HudMsg(
message='{minutes}:{seconds}',
x=-1.0,
y=0.0,
fade_in=0.0,
fade_out=0.0,
hold_time=0.5,
fx_time=0,
color1=getattr(colors, TIME_LEFT_COLOR, colors.WHITE),
channel=3,
)

map_end_time = None
mp_timelimit = ConVar('mp_timelimit')


@OnLevelInit
def load(map_name=None):
global map_end_time
timelimit = mp_timelimit.get_int() * 60
map_end_time = time() + timelimit if timelimit else None


@Repeat
def _send_messages():
players = list(PlayerIter())
total_places = len(players)
if total_places < 2:
return

sorted_players = sorted(
players,
key=lambda player: (player.kills, -player.deaths),
reverse=True,
)

FIRST_PLACE_MESSAGE.send(
player=sorted_players[0],
)
LAST_PLACE_MESSAGE.send(
player=sorted_players[~0],
place=total_places,
)

_send_messages.start(UPDATE_RATE)


@Repeat
def _send_timeleft():
if map_end_time is None:
return

timeleft = map_end_time - time()
if timeleft < 0:
return

minutes, seconds = divmod(timeleft, 60)

TIME_LEFT_MESSAGE.send(
minutes=int(minutes),
seconds=int(seconds),
)

_send_timeleft.start(0.3)


I don't believe that HL2:DM allows for spectators. But, if I am wrong, I can attempt to fix that later.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Fri Jun 16, 2017 8:09 am

Ok I tried both plugins VinciT and satoon101.

At VinciT everything worked as far as desired only the timeleft display the map round did not go.

At satoon101 The display blinked a bit and it only showed the player at the last place. Timeleft was not displayed.

Thank you first until then mates
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [HL2:DM] Mini Scoreboard Always display

Postby satoon101 » Fri Jun 16, 2017 2:58 pm

Painkiller wrote:At satoon101 The display blinked a bit and it only showed the player at the last place. Timeleft was not displayed.

I fixed those 2 issues in my plugin above. I honestly missed that the "timeleft" was a part of this request. I will look into that one after work tonight.
Image
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2:DM] Mini Scoreboard Always display

Postby VinciT » Fri Jun 16, 2017 3:08 pm

Wow, that's much cleaner than what I did.
I tried to cache stuff as much as I could, cause I thought PlayerIter created new player objects every time it ran.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [HL2:DM] Mini Scoreboard Always display

Postby satoon101 » Fri Jun 16, 2017 4:53 pm

VinciT wrote:I thought PlayerIter created new player objects every time it ran.

It does, but it's not like that takes a long time to do. I prefer to only create roundabout optimizations when it is absolutely necessary.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Fri Jun 16, 2017 9:53 pm

satoon101 wrote:
Painkiller wrote:At satoon101 The display blinked a bit and it only showed the player at the last place. Timeleft was not displayed.

I fixed those 2 issues in my plugin above. I honestly missed that the "timeleft" was a part of this request. I will look into that one after work tonight.



Yes now is ok.

thanks for soon timeleft
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Sat Jun 24, 2017 7:19 pm

satoon101 wrote:
Painkiller wrote:At satoon101 The display blinked a bit and it only showed the player at the last place. Timeleft was not displayed.

I fixed those 2 issues in my plugin above. I honestly missed that the "timeleft" was a part of this request. I will look into that one after work tonight.



Hi,

You could already make progress in order to timeleft?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [HL2:DM] Mini Scoreboard Always display

Postby satoon101 » Sun Jun 25, 2017 2:25 pm

Updated post above to include the timeleft.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Sun Jun 25, 2017 6:40 pm

As far as it works well but it still seems to admit to a regulating problem.

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

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Sat Jul 01, 2017 8:35 am

satoon101 wrote:Updated post above to include the timeleft.


Can you please set me this as on the first picture?

Timleft left and then right scoreboard.

I tried it but it disappears the scoreboard when I put the coordinates.

I tried to set an x coordinate.




Syntax: Select all

FIRST_PLACE_MESSAGE = HudMsg(
message='1 | {player.name} | {player.kills}',
y=0.0,
color1=getattr(colors, FIRST_PLACE_COLOR, colors.ORANGE),
channel=1,
**_common_kwargs
)

LAST_PLACE_MESSAGE = HudMsg(
message='{place} | {player.name} | {player.kills}',
y=0.03,
color1=getattr(colors, LAST_PLACE_COLOR, colors.LIGHT_BLUE),
channel=2,
**_common_kwargs
)

TIME_LEFT_MESSAGE = HudMsg(
message='{minutes}:{seconds}',
x=0.3,
y=0.0,
fade_in=0.0,
fade_out=0.0,
hold_time=0.5,
fx_time=0,
color1=getattr(colors, TIME_LEFT_COLOR, colors.WHITE),
channel=3,
)
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Sat Jul 08, 2017 10:25 am

Hi mates, could someone put it in the right position?
I do not get it.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Sun Sep 24, 2017 7:41 am

Hello, after the last SP update I have errors in the display

Could anyone fix this?

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

Re: [HL2:DM] Mini Scoreboard Always display

Postby Painkiller » Mon Oct 02, 2017 11:39 am

I installed the latest SP version

Now it looks like this and the timeleft display is missing completely.

Painkiller wrote:As far as it works well but it still seems to admit to a regulating problem.

Image


it should look like this(in the center top):

Image[/quote]

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 1 guest