Raised This Month: $32 Target: $400
 8% 

Assign to a team automatically on joining the server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
as_pingwin
Junior Member
Join Date: Feb 2016
Old 02-08-2016 , 04:43   Assign to a team automatically on joining the server
Reply With Quote #1

Hi,

I'm trying to write a plugin which is intent to place a player to a team based on the player's steamID.
There's a list for the steamIDs.
I was trying with this but no success :/

public OnClientPostAdminCheck(int client) {
ChangeClientTeam(client, 1);
}

Thanks for the help!
Akos
as_pingwin is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 02-08-2016 , 05:10   Re: Assign to a team automatically on joining the server
Reply With Quote #2

Did players join spec team on server join (exactly this must do your plugin)? What game (CS:GO have convar mp_force_assign_teams)?

Last edited by Kailo; 02-08-2016 at 05:11.
Kailo is offline
as_pingwin
Junior Member
Join Date: Feb 2016
Old 02-08-2016 , 05:43   Re: Assign to a team automatically on joining the server
Reply With Quote #3

Quote:
Originally Posted by Kailo View Post
Did players join spec team on server join (exactly this must do your plugin)? What game (CS:GO have convar mp_force_assign_teams)?
Yes it's CS:GO, sry!
mp_force_assign_teams is not good for me because I will have a list with steamIDs

for example:

ct_team[0] = STEAMID:1
ct_team[1] = STEAMID:2

t_team[0] = STEAMID
t_team[1] = STEAMID:4

And when the player with STEAMID:2 joins the game I have to force to assign the player to the ct team.
Index 1 means the spectator?


Thanks
as_pingwin is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 02-08-2016 , 06:14   Re: Assign to a team automatically on joining the server
Reply With Quote #4

Team indexes you can see here, also use this defines (but need #incude <cstrike>).
PHP Code:
bool IsIdInList(const char[] steamid, const char[][] array, int count)
{
    for (
int i 0counti++)
        if (
StrEqual(steamid, array[i]))
            return 
true;

    return 
false;
}

// somewhere
char steamid[32];
GetClientAuthId(clientAuthId_Steam2steamidsizeof(steamid));
if (
IsIdInList(steamidct_teamsizeof(ct_team)))
   
ChangeClientTeam(clientCS_TEAM_CT); 

Last edited by Kailo; 02-08-2016 at 06:20.
Kailo is offline
as_pingwin
Junior Member
Join Date: Feb 2016
Old 02-08-2016 , 13:56   Re: Assign to a team automatically on joining the server
Reply With Quote #5

Quote:
Originally Posted by Kailo View Post
Team indexes you can see here, also use this defines (but need #incude <cstrike>).
PHP Code:
bool IsIdInList(const char[] steamid, const char[][] array, int count)
{
    for (
int i 0counti++)
        if (
StrEqual(steamid, array[i]))
            return 
true;

    return 
false;
}

// somewhere
char steamid[32];
GetClientAuthId(clientAuthId_Steam2steamidsizeof(steamid));
if (
IsIdInList(steamidct_teamsizeof(ct_team)))
   
ChangeClientTeam(clientCS_TEAM_CT); 
Hi Kailo,

Thanks for the code, I think I got it
But there is something wrong.
I'm trying to Change the client team on the OnClientPostAdminCheck action.
In the server logs I can see that the client changes team from unassigned to CT,but then it changes back to unassigned from ct.
I took a screenshot where u can see the logs: http://prntscr.com/a0ofsy

On which action should I run the ChangeClientTeam function?

Thanks,
Akos
as_pingwin is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 02-08-2016 , 15:51   Re: Assign to a team automatically on joining the server
Reply With Quote #6

ok, i looked at your screen and see that best way to do it after "entered the game" action. I used google and search in source engien source files and found this in game/server/EventLog.cpp. This printed in "player_activate" event case. So i think need hook (post mode) this and change player team.

P.S. event info from "csgo/resource/serverevents.res"
Code:
"player_activate"
{
    "userid" "short" // user ID on server
}

Last edited by Kailo; 02-09-2016 at 08:15.
Kailo is offline
as_pingwin
Junior Member
Join Date: Feb 2016
Old 02-08-2016 , 17:06   Re: Assign to a team automatically on joining the server
Reply With Quote #7

Quote:
Originally Posted by Kailo View Post
ok, i looked at your screen and see that best way to do it after "entered the game" action. I used google and search in source engien source files and found this in game/shared/soundenvelope.cpp. This printed in "player_activate" event case. So i think need hook (post mode) this and change player team.

P.S. event info from "csgo/resource/serverevents.res"
Code:
"player_activate"
{
    "userid" "short" // user ID on server
}
Hi Kailo,

Thanks for the great help. It's working.. but

I couldn't make it to get the activated client's id so I had to make a workaround for this.
PHP Code:
int Connections[20];
int ConnectionCount 0;

public 
OnPluginStart()
{
    
HookEvent("player_activate"PlayerActivateEventHookMode_Post);
}

public 
OnClientPostAdminCheck(int client) {
    
Connections[ConnectionCount] = client;
    
ConnectionCount++;
    
}

public 
Action PlayerActivate(Handle event, const char[]useridbool dontBroadcast) {
    for(
int isizeof(Connections); i++) {
        if(
Connections[i]) {
            new 
String:auth[64];
            
GetClientAuthString(Connections[i], authsizeof(auth));
            
PrintToServer("PlayerActive EVENT: Auth: %s"auth);
            
ChangeClientTeam(Connections[i], CS_TEAM_CT);
            
Connections[i] = false;
        }
    }


What do you think about it?
One more problem with it is when I entered the game into the right team the BOT GOTV was standing beside me How can I prevent to put GOTV bot in the team.

Really appreciate your help

AKos
as_pingwin is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 02-08-2016 , 23:56   Re: Assign to a team automatically on joining the server
Reply With Quote #8

Use IsClientSourceTV

https://sm.alliedmods.net/new-api/cl...ClientSourceTV
Addicted. is offline
as_pingwin
Junior Member
Join Date: Feb 2016
Old 02-10-2016 , 01:37   Re: Assign to a team automatically on joining the server
Reply With Quote #9

Thank you guys. I successfully wrote my first plugin!
as_pingwin is offline
penalte
Member
Join Date: Jan 2016
Old 02-11-2016 , 23:47   Re: Assign to a team automatically on joining the server
Reply With Quote #10

share it plz
penalte is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode