Last Man Standing
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Last Man Standing
Hello SourcePython Team and Community,
Is there any way someone can finish me a Last Man Standing Plugin?
- If someone dies, you will see how much remains
- Dead players can wait in the Spectate until the end of the round
- if possible a small rank system which is stored in a txt file 1 place 250 points, 2 place 100 points, 3 place 50 points
(a rank list that persists when players come back)
Thanks in Advance
Painkiller
Is there any way someone can finish me a Last Man Standing Plugin?
- If someone dies, you will see how much remains
- Dead players can wait in the Spectate until the end of the round
- if possible a small rank system which is stored in a txt file 1 place 250 points, 2 place 100 points, 3 place 50 points
(a rank list that persists when players come back)
Thanks in Advance
Painkiller
Re: Last Man Standing
Last Man Standing Plugin
The code is a bit messy, but it should get the job done.
Code: Select all
Config:
points_per_kill - How many points you get per kill / Wieviele Punkte man pro Kill bekommt.
points_third_place - How many points you get for third place / Wieviele Punkte der dritte Platz kriegt
points_second_place - How many points you get for second place / Wieviele Punkte der zweite Platz kriegt
points_first_place - How many points you get for first place / Wieviele Punkte der erste Platz kriegt
Code: Select all
Commands:
lms_restart - Restarts the round and respawns players / Startet die Runde neu und belebt alle Spieler wieder
rank - Display your rank / Zeigt deinen Rank im Chat an.
The code is a bit messy, but it should get the job done.
- Attachments
-
- lms.zip
- (2.1 KiB) Downloaded 1385 times
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
I can not test it right now
since my root is making a rebuild of a disk Raid1
Duration approx. 5h.
Nevertheless many thanks and I give as soon a feedback.
since my root is making a rebuild of a disk Raid1
Duration approx. 5h.
Nevertheless many thanks and I give as soon a feedback.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
Meal,
I tested it and I get this message.
I tested it and I get this message.
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/listeners/tick.py", line 80, in _tick
self.pop(0).execute()
File "../addons/source-python/packages/source-python/listeners/tick.py", line 161, in execute
return self.callback(*self.args, **self.kwargs)
File "../addons/source-python/packages/source-python/listeners/tick.py", line 606, in _execute
self.callback(*self.args, **self.kwargs)
File "../addons/source-python/plugins/lms/lms.py", line 50, in display_players
HudMsg("Last Man Standing\n"+str(name)+" hat diese Runde gewonnen",-1,0.02,channel=1).send()
UnboundLocalError: local variable 'name' referenced before assignment
Re: Last Man Standing
Syntax: Select all
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
import os
import re
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():
steamid = player.steamid
already_played[steamid] = 0
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['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:
count = 0
for player in PlayerIter('alive'):
count += 1
name = player.name
if count > 0:
HudMsg("Last Man Standing\n"+str(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']))
steamid = player.steamid
if player.steamid not in already_played:
already_played[player.steamid] = 0
if already_played[player.steamid] == 1:
Delay(0.1,_late_join,(player.index,))
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
if not steamid in database:
database[steamid] = {}
database[steamid]['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
attacker = Player.from_userid(int(ev['attacker']))
player_steamid = player.steamid
already_played[player.steamid] = 1
if "BOT" in player_steamid:
player_steamid = "BOT_"+player.name
else:
player_steamid = player_steamid.replace("[","").replace("]","")
attacker_steamid = attacker.steamid
if "BOT" in attacker_steamid:
attacker_steamid = "BOT_"+attacker.name
else:
attacker_steamid = attacker_steamid.replace("[","").replace("]","")
if attacker != player:
give_points(attacker_steamid,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()
if living_players == 1:
give_points(player_steamid, config.cfg['psp'])
SayText2("\x04[LastManStanding] "+player.name+" \x03ist auf dem \x04zweiten \x03Platz!").send()
if attacker.name != player.name:
give_points(attacker_steamid, config.cfg['pfp'])
SayText2("\x04[LastManStanding] "+attacker.name+" \x03ist der \x04Last Man Standing!").send()
HudMsg(""+attacker.name+" ist der Last Man Standing",-1,0.4).send()
else:
for player in PlayerIter('alive'):
steamid = player.steamid
if "BOT" in steamid:
steamid = "BOT_"+player.name
else:
steamid = steamid.replace("[","").replace("]","")
give_points(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()
_restart_game()
def _restart_game():
SayText2("\x04[LastManStanding] \x03Die neue Runde beginnt in\x04 5 Sekunden").send()
already_played = {}
for player in PlayerIter():
player.team = 0
already_played[player.steamid] = 0
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():
count = 0
for player in PlayerIter('alive'):
count += 1
return count
def get_player_count():
count = 0
for player in PlayerIter():
count += 1
return count
#Block teamchange messages
@PreEvent('player_team')
def team(ev):
if int(ev['team']) in [0,1]:
return EventAction.BLOCK
#Block usage of jointeam
@ClientCommand('jointeam')
def join_test(command,index):
return CommandReturn.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()
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
Code: Select all
20:29:33 [SP] Unloading plugin 'lms'...
[SP] Unable to unload plugin 'lms' as it is not currently loaded.
[SP] Loading plugin 'lms'...
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "../addons/source-python/packages/source-python/plugins/manager.py", line 194, in load
plugin._load()
File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "../addons/source-python/plugins/lms/lms.py", line 46
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xfc in position 20: invalid start byte
[SP] Plugin 'lms' was unable to be loaded.
Re: Last Man Standing
Loads fine for me, not sure what your problem is. Try to copy the code again.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
I Play HL2:DM .
Re: Last Man Standing
And this plugin was written and tested on a HL2:DM server and it still loads fine there. I guess you made a mistake when copying it over.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
I have copied it three times and more times reloaded with server restart always the same error
can you uploaded the file again ?
can you uploaded the file again ?
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
21:42:55 sp plugin reload lms
21:42:55 [SP] Unloading plugin 'lms'...
[SP] Unable to unload plugin 'lms' as it is not currently loaded.
[SP] Loading plugin 'lms'...
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "../addons/source-python/packages/source-python/plugins/manager.py", line 194, in load
plugin._load()
File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "../addons/source-python/plugins/lms/lms.py", line 46
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xfc in position 20: invalid start byte
[SP] Plugin 'lms' was unable to be loaded.
Please fix your syntaxerror please
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: Last Man Standing
Painkiller wrote:Please fix your syntaxerror please
This seems to be an issue with the encoding of your file you created.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
this iy the file its python file
- Attachments
-
- lms.rar
- (2.03 KiB) Downloaded 1381 times
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
It works now
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Last Man Standing
Gameserver IP: gs.rocks-clan.de:28090
Who is online
Users browsing this forum: No registered users and 59 guests