Raised This Month: $ Target: $400
 0% 

Move player to team after connection


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gorgitko
Member
Join Date: Feb 2015
Old 05-20-2015 , 08:49   Move player to team after connection
Reply With Quote #1

Hi, I need to move player to team after his connection. I have tried this:

Code:
public OnClientPutInServer(client)
{
    PrintToConsole(client, "Player connected...");
    CreateTimer(5.0, MovePlayer, client);
}

public Action:MovePlayer(Handle:timer, any:client)
{
    PrintToConsole(client, "Preparing to move...");
    new Handle:pack = CreateDataPack();
    WritePackCell(pack, client);
    WritePackCell(pack, CS_TEAM_T);
    WritePackCell(pack, 0);
    PrintToConsole(client, "You have been moved.");
}
but it only show the message "Player connected..." in console. What am I doing wrong? Thanks.

EDIT: I forgot the client argument in CreateTimer(5.0, MovePlayer, client);. So now is MovePlayer() executed, messages are shown in console, but player is not moved.

Last edited by gorgitko; 05-20-2015 at 08:58. Reason: edited the code
gorgitko is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 05-20-2015 , 08:55   Re: Move player to team after connection
Reply With Quote #2

you're not transmitting the client to the timer function, you need to change it to CreateTimer(5.0, MovePlayer, client) or w/e it is
Miu is offline
gorgitko
Member
Join Date: Feb 2015
Old 05-20-2015 , 09:00   Re: Move player to team after connection
Reply With Quote #3

Quote:
Originally Posted by Miu View Post
you're not transmitting the client to the timer function, you need to change it to CreateTimer(5.0, MovePlayer, client) or w/e it is
Yes I had done it before I saw your post. See "EDIT" on the end of my post.
gorgitko is offline
gorgitko
Member
Join Date: Feb 2015
Old 05-20-2015 , 09:04   Re: Move player to team after connection
Reply With Quote #4

Well sometimes there are simple solutions such as function ChangeClientTeam(client, team). Problem solved
gorgitko is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 05-20-2015 , 09:05   Re: Move player to team after connection
Reply With Quote #5

Why are you creating a datapack?
You might be looking for an actual function that moves a client to another team...
https://sm.alliedmods.net/new-api/cl...angeClientTeam
https://sm.alliedmods.net/new-api/cstrike/CS_SwitchTeam
Mitchell is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-20-2015 , 10:12   Re: Move player to team after connection
Reply With Quote #6

Also, passing client indexes to a timer are a no-no. Always send a userid or serial.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 05-21-2015 , 03:36   Re: Move player to team after connection
Reply With Quote #7

ADVISE_QUERY(Powerlord, "GetClientUserId(int client) && GetClientOfUserId(int userid)");
__________________
Neuro Toxin is offline
gorgitko
Member
Join Date: Feb 2015
Old 05-21-2015 , 15:27   Re: Move player to team after connection
Reply With Quote #8

Quote:
Originally Posted by Powerlord View Post
Also, passing client indexes to a timer are a no-no. Always send a userid or serial.
Can you give me little advice please? All functions aimed on players are taking client ID as an argument. How can I deal with player's Steam ID?
________________________

I have another question: which forward is called when player is connected to the server, MOTD is showed him and he has no team? Is it OnClientConnected(), OnClientPutInServer() or something else?

I am setting up IDLE server and I need to put players to some team after some time.
So player is idling, game ends, map restarts, player stays on MOTD for some time (motdgd ads) and then I need to put him to some team.

Last edited by gorgitko; 05-21-2015 at 15:29.
gorgitko is offline
cam0
Senior Member
Join Date: Feb 2015
Old 05-22-2015 , 14:16   Re: Move player to team after connection
Reply With Quote #9

You can hook player_connect_full and set their team there.

https://forums.alliedmods.net/showpo...6&postcount=10
cam0 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 16:50.


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