[HL2:DM] Team Names

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] Team Names

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

Hey,
this is a Sourcemod code would it be possible to write that for SP and to integrate the Spec-mode?




Code: Select all

#include <sourcemod>

new Handle:g_Terrorist = INVALID_HANDLE;
new Handle:g_CTerrorist = INVALID_HANDLE;
new Handle:g_hCvarTeamName1  = INVALID_HANDLE;
new Handle:g_hCvarTeamName2 = INVALID_HANDLE;

public Plugin:myinfo =
{
    name = "Team Names",
    author = "Internet Bully",
    description = "Allows you to set the name of teams",
   version     = "1.1",
    url = "http://www.sourcemod.net/"
}

public OnPluginStart()
{
   g_Terrorist    = CreateConVar("sm_teamname_t", "", "Set your Terrorist team name.", FCVAR_PLUGIN);
   g_CTerrorist    = CreateConVar("sm_teamname_ct", "", "Set your Counter-Terrorist team name.", FCVAR_PLUGIN);
   
   HookConVarChange(g_Terrorist, OnConVarChange);
   HookConVarChange(g_CTerrorist, OnConVarChange);
   
   g_hCvarTeamName1 = FindConVar("mp_teamname_1");
   g_hCvarTeamName2 = FindConVar("mp_teamname_2");
}

public OnMapStart()
{
   decl String:sBuffer[32];
   GetConVarString(g_Terrorist, sBuffer, sizeof(sBuffer));
   SetConVarString(g_hCvarTeamName2, sBuffer);
   GetConVarString(g_CTerrorist, sBuffer, sizeof(sBuffer));
   SetConVarString(g_hCvarTeamName1, sBuffer);
}

public OnConVarChange(Handle:hCvar, const String:oldValue[], const String:newValue[])
{
   decl String:sBuffer[32];
   GetConVarString(hCvar, sBuffer, sizeof(sBuffer));
   
   if(hCvar == g_Terrorist)
      SetConVarString(g_hCvarTeamName2, sBuffer);
   else if(hCvar == g_CTerrorist)
      SetConVarString(g_hCvarTeamName1, sBuffer);
}
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [HL2:DM] Team Names

Postby Kami » Tue Jun 19, 2018 5:57 pm

This is a mod for CS:GO.

Half Life 2 Deathmatch does not have the cvars mp_teamname_1 and mp_teamname_2.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Team Names

Postby Painkiller » Tue Jun 19, 2018 6:07 pm

It still worked at that time.

Could you do something for HL2DM?
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [HL2:DM] Team Names

Postby Kami » Tue Jun 19, 2018 6:21 pm

Syntax: Select all

from events import Event
import os
from filters.entities import EntityIter


for ent in EntityIter('team_manager'):
team_name = ent.get_property_string('m_szTeamname')
teams = "Test"
ent.set_property_string("m_szTeamname","Test")


This will set ALL teams to "Test". Not sure how to seperate them. By the way, I highly recommend you at least try to do some of those things yourself.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Team Names

Postby Painkiller » Tue Jun 19, 2018 6:25 pm

That does not get me any further if all tests are called.

And I'm not a coder so I put my requests here in the forum.

Many Thanks
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [HL2:DM] Team Names

Postby Kami » Tue Jun 19, 2018 7:07 pm

Well you could always try and learn something new. That would propably make it easier for you to get things done.

Here is what you wanted, I hope it's okay that way as I do not plan to add anything more to it if you are not at least willing to try to understand whats done here.

This combines the 3 teams plugin with the custom team names plugin.

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
from commands.say import SayCommand
from menus.esc import SimpleESCMenu,SimpleESCOption
from listeners import OnClientActive,OnEntityCreated
import random

count = {}
player_team = {}

combine_name = "Combine"
rebels_name = "Rebels"
spectator_name = "Spectator"


@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)

@OnEntityCreated
def OnEntityCreated(entity):
teamplay = ConVar('mp_teamplay').get_int()
if teamplay == 1:
if entity.classname == 'team_manager':
ent = Entity(entity.index)
ent.delay(0.1,change_team_name,(ent,))



def change_team_name(ent):
team_name = ent.get_property_string('m_szTeamname')
if team_name == "Combine":
ent.set_property_string("m_szTeamname",combine_name)
if team_name == "Rebels":
ent.set_property_string("m_szTeamname",rebels_name)
if team_name == "Spectator":
ent.set_property_string("m_szTeamname",spectator_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):
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 = spectator_name
if team_to_join == 2:
team_message = combine_name
if team_to_join == 3:
team_message = rebels_name
SayText2("\x04%s \x03changed to Team \x04%s" % (player.name,team_message)).send()
return CommandReturn.BLOCK


I hope you can figure out where your new team names go :)
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Team Names

Postby Painkiller » Tue Jun 19, 2018 7:27 pm

Thank you I will test it.

But I do not want to deal with coding, scripting.
I leave that to those who can.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [HL2:DM] Team Names

Postby satoon101 » Tue Jun 19, 2018 10:55 pm

A couple quick tips, Kami.

Syntax: Select all

combine_name = "Combine"
rebels_name = "Rebels"
spectator_name = "Spectator"

@OnEntityCreated
def OnEntityCreated(entity):
teamplay = ConVar('mp_teamplay').get_int()
if teamplay == 1:
if entity.classname == 'team_manager':
ent = Entity(entity.index)
ent.delay(0.1,change_team_name,(ent,))

def change_team_name(ent):
team_name = ent.get_property_string('m_szTeamname')
if team_name == "Combine":
ent.set_property_string("m_szTeamname",combine_name)
if team_name == "Rebels":
ent.set_property_string("m_szTeamname",rebels_name)
if team_name == "Spectator":
ent.set_property_string("m_szTeamname",spectator_name)

Could be (untested):

Syntax: Select all

from filters.entities import EntityIter
from listeners import OnLevelInit
from players.teams import team_managers

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

@OnLevelInit
def load(map_name=None):
for entity in EntityIter(team_managers):
team_name = new_team_names.get(entity.team)
if team_name is not None:
entity.team_name = team_name


Also, you can easily reuse ConVar('mp_teamplay'):

Syntax: Select all

team_play = ConVar('mp_teamplay')

def something():
if not int(team_play):
return


Lastly, I mentioned the ESCMenu thing, but you never made those changes:

Syntax: Select all

# this imports ESCMenus/Options in hl2mp and RadioMenus/Options in all other games
from menus import SimpleMenu, SimpleOption
Image
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [HL2:DM] Team Names

Postby Kami » Wed Jun 20, 2018 4:14 am

Thank you satoon, I will try those Things later. The OnLevelInit does Not Work though. I used that before, but team_managers property team_name seems to be Set a little bit later and is empty in that listener.

That is why I used that delay in the OnEntityCreated listener too.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [HL2:DM] Team Names

Postby satoon101 » Wed Jun 20, 2018 5:03 am

Yeah, you might use a 1 tick delay (0.0) in load/OnLevelInit to see if that works. Now that you mention it, I think that's what I have used in GunGame when interacting with entities in that listener. You might also check OnEntitySpawned to see if that one works without a delay, but I think load/OnLevelInit should suffice, instead of checking every single time an entity is spawned on the server.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Team Names

Postby Painkiller » Wed Jun 20, 2018 9:57 am

Hello,
Kami had been there for the team names I was able to chat in ESC and chat.

So that was already possible before.
Maybe I mispronounced myself, I meant those names in the scorboard.

Image
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [HL2:DM] Team Names

Postby Kami » Wed Jun 20, 2018 10:41 am

Painkiller you need to adjust the

Syntax: Select all

combine_name = "Combine"
rebels_name = "Rebels"
spectator_name = "Spectator"


Part and add the names you want there.
Like:

Syntax: Select all

combine_name = "Painkiller"
rebels_name = "No noobs"
spectator_name = "Noobs"
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Team Names

Postby Painkiller » Wed Jun 20, 2018 11:19 am

Yes i have but not work.

Works only for ESC Menü and Chat
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [HL2:DM] Team Names

Postby Kami » Wed Jun 20, 2018 4:29 pm

So I think this should work (and make use of Satoons tips):

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: 'Spectator',
2: 'Combine',
3: '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
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Team Names

Postby Painkiller » Wed Jun 20, 2018 5:02 pm

Kami wrote:So I think this should work (and make use of Satoons tips):

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: 'Spectator',
2: 'Combine',
3: '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


Thank you Kami for your effort.

But the tips were addressed to you because I do not know where I would tie that into the script.


Thank you also to Satoon.


Edit: So it's like the previous script from you Kami.It is not displayed in the scorebar.


Image
Image
Image

Edit1: here is my 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.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


Edit2: Is there still a solution?

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 13 guests