Page 1 of 1

[HL2:DM] Team Names

Posted: Tue Jun 19, 2018 5:43 pm
by Painkiller
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);
}

Re: [HL2:DM] Team Names

Posted: Tue Jun 19, 2018 5:57 pm
by Kami
This is a mod for CS:GO.

Half Life 2 Deathmatch does not have the cvars mp_teamname_1 and mp_teamname_2.

Re: [HL2:DM] Team Names

Posted: Tue Jun 19, 2018 6:07 pm
by Painkiller
It still worked at that time.

Could you do something for HL2DM?

Re: [HL2:DM] Team Names

Posted: Tue Jun 19, 2018 6:21 pm
by Kami

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.

Re: [HL2:DM] Team Names

Posted: Tue Jun 19, 2018 6:25 pm
by Painkiller
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

Re: [HL2:DM] Team Names

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

Re: [HL2:DM] Team Names

Posted: Tue Jun 19, 2018 7:27 pm
by Painkiller
Thank you I will test it.

But I do not want to deal with coding, scripting.
I leave that to those who can.

Re: [HL2:DM] Team Names

Posted: Tue Jun 19, 2018 10:55 pm
by satoon101
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

Re: [HL2:DM] Team Names

Posted: Wed Jun 20, 2018 4:14 am
by Kami
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.

Re: [HL2:DM] Team Names

Posted: Wed Jun 20, 2018 5:03 am
by satoon101
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.

Re: [HL2:DM] Team Names

Posted: Wed Jun 20, 2018 9:57 am
by Painkiller
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

Re: [HL2:DM] Team Names

Posted: Wed Jun 20, 2018 10:41 am
by Kami
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"

Re: [HL2:DM] Team Names

Posted: Wed Jun 20, 2018 11:19 am
by Painkiller
Yes i have but not work.

Works only for ESC MenĂ¼ and Chat

Re: [HL2:DM] Team Names

Posted: Wed Jun 20, 2018 4:29 pm
by Kami
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

Re: [HL2:DM] Team Names

Posted: Wed Jun 20, 2018 5:02 pm
by Painkiller
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?