[HL2:DM] 3 Teams

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

Please request only one plugin per thread.
User avatar
Kami
Global Moderator
Posts: 142
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [HL2:DM] 3 Teams

Postby Kami » Tue Jun 19, 2018 4:48 pm

Thank you satoon for pointing that out to me!

This version will remember which team you are on after mapchange (also it does not kill you on team change anymore, just respawns you)

Syntax: Select all

from players.entity import Player
from events import Event
from filters.players import PlayerIter
import operator
from cvars import ConVar
from commands.client import ClientCommand
from commands import CommandReturn
from messages import SayText2
from commands.say import SayCommand
from menus.esc import SimpleESCMenu,SimpleESCOption
from listeners import OnClientActive
import random

count = {}
player_team = {}

@OnClientActive
def on_client_active(index):
teamplay = ConVar('mp_teamplay').get_int()
if teamplay == 1:
player = Player(index)
if player.userid in player_team:
player.client_command("jointeam %s" % player_team[player.userid])
else:
team = get_team()
player.team_index = team
choose_team_menu.send(player.index)


@SayCommand("!team")
def team_command(command, index, team=None):
choose_team_menu.send(index)

def get_team():
count[1] = 0
count[2] = 0
count[3] = 0
for player in PlayerIter():
if player.team_index != 0:
count[player.team_index] += 1
return min(count.items(), key=operator.itemgetter(1))[0]


def choose_team_select(menu,index,choice):
Player(index).client_command("jointeam %s" % choice.choice_index)

def choose_team_build(menu,index):
option = SimpleESCOption(1,'Spectator Team')
menu.append(option)
option = SimpleESCOption(2,'Combine Team')
menu.append(option)
option = SimpleESCOption(3,'Rebel Team')
menu.append(option)

choose_team_menu = SimpleESCMenu(select_callback=choose_team_select, build_callback=choose_team_build, title="Choose your team")

@ClientCommand('jointeam')
def join_test(command,index):
team_to_join = int(command[1])
if team_to_join > 3 or team_to_join < 1:
team_to_join = random.randint(1, 3)
player = Player(index)
player.team_index = team_to_join
player_team[player.userid] = team_to_join
player.team_index = team_to_join
player.spawn(True)
if team_to_join == 1:
team_message = "Specator"
if team_to_join == 2:
team_message = "Combine"
if team_to_join == 3:
team_message = "Rebel"
SayText2("\x04%s \x03changed to Team \x04%s" % (player.name,team_message)).send()
return CommandReturn.BLOCK
User avatar
Painkiller
Senior Member
Posts: 376
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] 3 Teams

Postby Painkiller » Tue Jun 19, 2018 5:37 pm

Work Good

Big Thanks Kami and thanks Satoon.

Return to “Plugin Requests”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest