[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: 263
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: 725
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.
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Mon Oct 12, 2020 1:32 pm

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
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] 3 Teams

Postby Painkiller » Mon Oct 12, 2020 10:24 pm

I have not used it for a long time.
It had worked before.
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Mon Oct 12, 2020 11:18 pm

thanks pain killer but its not now and i like that wish some one could fix it for me
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] 3 Teams

Postby Painkiller » Tue Oct 13, 2020 7:28 am

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
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Tue Oct 13, 2020 3:31 pm

Hey Rocks I have tried this and it will not compile , thanks for trying
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [HL2:DM] 3 Teams

Postby satoon101 » Tue Oct 13, 2020 3:44 pm

What do you mean by "it will not compile"?
Image
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Tue Oct 13, 2020 3:57 pm

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
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Tue Oct 13, 2020 8:30 pm

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 :)
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Wed Oct 14, 2020 7:51 pm

Ok kinda disappointing no one has an answer for this but I have noticed not many come here much it seems anymore ...
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] 3 Teams

Postby Painkiller » Wed Oct 14, 2020 8:29 pm

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
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Thu Oct 15, 2020 1:13 pm

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 :)
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2:DM] 3 Teams

Postby VinciT » Thu Oct 15, 2020 5:57 pm

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.
ImageImageImageImageImage
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Thu Oct 15, 2020 7:04 pm

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 :)
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2:DM] 3 Teams

Postby VinciT » Thu Oct 15, 2020 8:20 pm

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
ImageImageImageImageImage
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: [HL2:DM] 3 Teams

Postby PEACE » Thu Oct 15, 2020 8:26 pm

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

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 18 guests