Page 2 of 2

Re: [HL2:DM] 3 Teams

Posted: Tue Jun 19, 2018 4:48 pm
by Kami
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

Re: [HL2:DM] 3 Teams

Posted: Tue Jun 19, 2018 5:37 pm
by Painkiller
Work Good

Big Thanks Kami and thanks Satoon.

Re: [HL2:DM] 3 Teams

Posted: Mon Oct 12, 2020 1:32 pm
by PEACE
Hi there and where is my friend Kami ?

Ok so I just tried this plugin and when I join it kills me and then crashes the server right off ... did this plugin ever work if so what changed to kill it and can it be fixed ? I like the method it uses and want it on my server please :)
I have the batch auto restart on my server and it puts the server in a loop scrolling the console fast and doesn't restart it .

Thank you my friends

Re: [HL2:DM] 3 Teams

Posted: Mon Oct 12, 2020 10:24 pm
by Painkiller
I have not used it for a long time.
It had worked before.

Re: [HL2:DM] 3 Teams

Posted: Mon Oct 12, 2020 11:18 pm
by PEACE
thanks pain killer but its not now and i like that wish some one could fix it for me

Re: [HL2:DM] 3 Teams

Posted: Tue Oct 13, 2020 7:28 am
by Painkiller
I have not tested it yet but this is what I used a long time ago.


Syntax: Select all

from players.entity import Player
from events import Event
from filters.players import PlayerIter
from filters.entities import EntityIter
from entities.entity import Entity
import operator
from cvars import ConVar
from commands.client import ClientCommand
from commands import CommandReturn
from messages import SayText2, HintText
from commands.say import SayCommand
from menus import SimpleMenu, SimpleOption
from listeners import OnClientActive,OnEntityCreated,OnLevelInit
import random
from listeners.tick import Delay

count = {}
player_team = {}

new_team_names = {
1: 'Squad Spectator',
2: 'Squad Combine',
3: 'Squad Rebels',
}

teamplay = ConVar('mp_teamplay').get_int()


@OnClientActive
def on_client_active(index):
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)

@OnLevelInit
def on_level_init(map_name=None):
if teamplay == 1:
Delay(0.1,change_team_name)

def change_team_name():
for entity in EntityIter():
if entity.classname == "team_manager":
if entity.team != 0:
team_name = new_team_names.get(entity.team)
entity.set_property_string("m_szTeamname",team_name)

@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):
for team in new_team_names:
option = SimpleOption(team, new_team_names[team]+' Team')
menu.append(option)

choose_team_menu = SimpleMenu(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)
team_message = new_team_names[team_to_join]
SayText2("\x04%s \x03changed to Team \x04%s" % (player.name,team_message)).send()
return CommandReturn.BLOCK

Re: [HL2:DM] 3 Teams

Posted: Tue Oct 13, 2020 3:31 pm
by PEACE
Hey Rocks I have tried this and it will not compile , thanks for trying

Re: [HL2:DM] 3 Teams

Posted: Tue Oct 13, 2020 3:44 pm
by satoon101
What do you mean by "it will not compile"?

Re: [HL2:DM] 3 Teams

Posted: Tue Oct 13, 2020 3:57 pm
by PEACE
hello satoon long time no speak my friend ...

it doesnt create the fold
pycache folder
doesnt load

ok I cahanged the name to just Teams and it loaded but this one crashes the server before i even get in :(
also the server console just keeps scrolling garbage over and over and will not restart untill i kill it

Im using a few other plugins like silent hill , alpha_props , npc_score and they all work fine

by the way this is a win7 server if that means anything and i run sourcemod and ES


ok so it my hurricane bots , they are joining at the same time as me , its work if i turn them off


ok Update , maybe this code needs to ignore bots to work , if someone can do this for me that might fix the issue

Re: [HL2:DM] 3 Teams

Posted: Tue Oct 13, 2020 8:30 pm
by PEACE
So Hello out there Pythoners , can any of you awesome coders make this humans only so it ignores the Bots , I remember this in many of my sourcemod plugins its a simple one or 2 lines of code added . thanks a bunch would really appreciate it being a new guy on here :)

Re: [HL2:DM] 3 Teams

Posted: Wed Oct 14, 2020 7:51 pm
by PEACE
Ok kinda disappointing no one has an answer for this but I have noticed not many come here much it seems anymore ...

Re: [HL2:DM] 3 Teams

Posted: Wed Oct 14, 2020 8:29 pm
by Painkiller
Maybe you should wait a little bit many have besides this project also others or real live.

Sometimes it is not possible to push a button.

Greeting Pain

Re: [HL2:DM] 3 Teams

Posted: Thu Oct 15, 2020 1:13 pm
by PEACE
Painkiller ,
I only ask for one thing , one plugin to work and its not a big request my friend only a simple fix but like I said I dont see much activity here compared to years ago . I see you have asked for many but thats fine ill wait :)

Re: [HL2:DM] 3 Teams

Posted: Thu Oct 15, 2020 5:57 pm
by VinciT
Going off of the plugin Painkiller posted - replace the on_client_active() function (lines 29 - 38) with this:

Syntax: Select all

@OnClientActive
def on_client_active(index):
if teamplay == 1:
player = Player(index)

if player.is_bot():
return

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)
And the join_test() function (lines 76 - 88) with this:

Syntax: Select all

@ClientCommand('jointeam')
def join_test(command, index):
player = Player(index)

if player.is_bot():
return

team_to_join = int(command[1])
if team_to_join > 3 or team_to_join < 1:
team_to_join = random.randint(1, 3)

player.team_index = team_to_join
player_team[player.userid] = team_to_join
player.team_index = team_to_join
player.spawn(True)
team_message = new_team_names[team_to_join]
SayText2("\x04%s \x03changed to Team \x04%s" % (player.name,team_message)).send()
return CommandReturn.BLOCK

Bots should no longer be affected by the plugin.

Re: [HL2:DM] 3 Teams

Posted: Thu Oct 15, 2020 7:04 pm
by PEACE
Hey VinciT , thank you , well I just tested this and was I supossed to remove the lines 76 - 88 or just add the code the prechach isnt created and if i add your 76-88 and leave the rest when i join i die but no menu pops up to select what team and i just respawn . maybe you can put your mods in for me and let me just copy all completed ? and thank you again for helping :)

Re: [HL2:DM] 3 Teams

Posted: Thu Oct 15, 2020 8:20 pm
by VinciT
This would be the complete code:

Syntax: Select all

from players.entity import Player
from events import Event
from filters.players import PlayerIter
from filters.entities import EntityIter
from entities.entity import Entity
import operator
from cvars import ConVar
from commands.client import ClientCommand
from commands import CommandReturn
from messages import SayText2, HintText
from commands.say import SayCommand
from menus import SimpleMenu, SimpleOption
from listeners import OnClientActive,OnEntityCreated,OnLevelInit
import random
from listeners.tick import Delay

count = {}
player_team = {}

new_team_names = {
1: 'Squad Spectator',
2: 'Squad Combine',
3: 'Squad Rebels',
}

teamplay = ConVar('mp_teamplay').get_int()


@OnClientActive
def on_client_active(index):
if teamplay == 1:
player = Player(index)

if player.is_bot():
return

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)

@OnLevelInit
def on_level_init(map_name=None):
if teamplay == 1:
Delay(0.1,change_team_name)

def change_team_name():
for entity in EntityIter():
if entity.classname == "team_manager":
if entity.team != 0:
team_name = new_team_names.get(entity.team)
entity.set_property_string("m_szTeamname",team_name)

@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):
for team in new_team_names:
option = SimpleOption(team, new_team_names[team]+' Team')
menu.append(option)

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

@ClientCommand('jointeam')
def join_test(command,index):
player = Player(index)

if player.is_bot():
return

team_to_join = int(command[1])
if team_to_join > 3 or team_to_join < 1:
team_to_join = random.randint(1, 3)

player.team_index = team_to_join
player_team[player.userid] = team_to_join
player.team_index = team_to_join
player.spawn(True)
team_message = new_team_names[team_to_join]
SayText2("\x04%s \x03changed to Team \x04%s" % (player.name,team_message)).send()
return CommandReturn.BLOCK
If the menu isn't popping up for you, run this command in your game console:

Code: Select all

cl_showpluginmessages 1

Re: [HL2:DM] 3 Teams

Posted: Thu Oct 15, 2020 8:26 pm
by PEACE
Ok I think i got it to work , it was where to place the line 76 and i placed it after this line
"choose_team_menu = SimpleMenu(select_callback=choose_team_select, build_callback=choose_team_build, title="Choose your team")" and again thank you my good man much appreciated :)

thank you :cool:

This now works perfect tested it for hours ^5