AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Block player respawn in CS:S (https://forums.alliedmods.net/showthread.php?t=88690)

exvel 03-28-2009 05:03

Block player respawn in CS:S
 
Hello, sorry for my bad english :)
In a while ago I found a way of how to block player respawn. It can be done by using a CS_SwitchTeam function on a spectator. To give player ability to respawn back CS_RespawnPlayer is only needed. I wrote a little test code that will block respawn when client is just joined a team and will spawn him on next round:

PHP Code:

new player_team[MAXPLAYERS 1];
new 
bool:need_respawn[MAXPLAYERS 1];
new 
just_swaped[MAXPLAYERS 1];

public 
OnPluginStart()
{
    
HookEvent("player_team"Event_PlayerTeamEventHookMode_Post);
    
HookEvent("round_start"Event_NewRoundEventHookMode_Post);
}

public 
Action:Event_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
    
// player_team will fire three times in a row and we must ignor two of them    
    
if (just_swaped[client] < 2)
    {
        
just_swaped[client]++;
        return 
Plugin_Continue;
    }
    
    
    new 
team GetEventInt(event"team");
    
    if (
client == || team == || IsFakeClient(client) || !IsClientInGame(client))
    {
        return 
Plugin_Continue;
    }
    
    
PrintToChatAll("Step 1!");
    
    
player_team[client] = team;
     
// We dont wanna get a server crash so timer is needed before team change
    
CreateTimer(0.01EnforceTeamSpecany:client);    
    
    return 
Plugin_Continue;
}

public 
Action:EnforceTeamSpec(Handle:timerany:client)
{
    if (!
IsClientInGame(client))
    {
        return;
    }
    
    
PrintToChatAll("Step 2!");
    
    
just_swaped[client] = 0;
    
// Move player to spectators for a milisecond
    
ChangeClientTeam(client1);
    
CreateTimer(0.1EnforceTeamany:client);    
}

public 
Action:EnforceTeam(Handle:timerany:client)
{
    if (!
IsClientInGame(client))
    {
        return;
    }
    
    
PrintToChatAll("Step 3!");
    
    
// Now move player back to team where he tried to join, he will never respawn by himself now
    
CS_SwitchTeam(clientplayer_team[client]);
    
need_respawn[client] = true;
}

public 
Action:Event_NewRound(Handle:event, const String:name[], bool:dontBroadcast)
{
    
// Now lets spawn poor player :)
    
for (new client 1client <= MaxClientsclient++)
    {
        if (!
IsClientInGame(client))
        {
            continue;
        }

        if (
need_respawn[client] == true)
        {
            
CS_RespawnPlayer(client);
            
need_respawn[client] = false;
        }
    }
        
    return 
Plugin_Continue;
}

public 
OnClientPutInServer(client)
{
    
need_respawn[client] = false;
    
just_swaped[client] = 2;


I do not like this way because script will fire two fictive events and will print two chat messages about swapping client. I also could just use RegConsoleCmd("jointeam", CommandJoinTeam) but in that way I must check many of other situations based on does client have permission to join team or not. If anybody have a suggestions about how to modify this test script in a better way please post replies.

exvel 04-06-2009 16:00

Re: Block player respawn in CS:S
 
Yes, I found it! :)
The answer was so simple.
To block player respawn we can simply Hook "joinclass" command. Player will not spawn if he didn't select a class. :)
Added it to antirejoin plugin.

bl4nk 04-06-2009 16:07

Re: Block player respawn in CS:S
 
There's a "joinclass" command in CS:S?

Greyscale 04-06-2009 20:23

Re: Block player respawn in CS:S
 
Quote:

Originally Posted by bl4nk (Post 799117)
There's a "joinclass" command in CS:S?

I believe so. It's just like jointeam except it changes your player class, which is basically just your model.

exvel 04-07-2009 03:11

Re: Block player respawn in CS:S
 
Quote:

Originally Posted by bl4nk (Post 799117)
There's a "joinclass" command in CS:S?

Yeap, this is a player's skin. :)

p.s. If player already choosed the class we can set it back to 0 by changing m_iClass to 0 and he will not spawn next round.

bl4nk 04-07-2009 05:41

Re: Block player respawn in CS:S
 
Typing "joinclass" into my console says it's an Unknown Command.

exvel 04-07-2009 13:30

Re: Block player respawn in CS:S
 
Quote:

Originally Posted by bl4nk (Post 799625)
Typing "joinclass" into my console says it's an Unknown Command.

Because it is a server side command, client console doesn't know about it and it works only on the server.

bl4nk 04-07-2009 15:36

Re: Block player respawn in CS:S
 
http://joe.to/~bl4nk/imgs/joinclass.png

Are you sure you're testing it on CS:S?

exvel 04-07-2009 15:52

Re: Block player respawn in CS:S
 
Yes, I do. :) This is a command like "drop" or "jointeam" (or any radio command) that are actually a player's actions so only client can send them when he are playing on the server.
p.s. when I wrote about "server side command" I mean that client can send it only when he on the server

teame06 04-07-2009 16:25

Re: Block player respawn in CS:S
 
Quote:

Originally Posted by bl4nk (Post 800049)
http://joe.to/~bl4nk/imgs/joinclass.png

Are you sure you're testing it on CS:S?

joinclass is a client command.


All times are GMT -4. The time now is 20:02.

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