Raised This Month: $ Target: $400
 0% 

AutoRespawn Plugin Breaking Spectate


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xXNewGuyXx
Member
Join Date: Jun 2016
Old 01-26-2017 , 01:47   AutoRespawn Plugin Breaking Spectate
Reply With Quote #1

Hello,

I have created a plugin that both strips and gives player weapons at spawn. I have also created an AutoRespawn plugin that creates a custom spawn time. The AutoRespawn plugin is the focus of this post. More specifically, the code within this plugin which is breaking the spectate mode. Spectate is not broken without this code, but this code is vital for the plugins to work correctly (if a player is allowed to input buttons and commands during respawn, they can effectively initiate their own respawn timer and ruin various aspects of the plugin).

Entire plugin:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma semicolon 1;

new Handle:hEnableAutoRespawn;
new 
Handle:hAutoRespawnTime;
new 
Handle:hDisableManualRespawn;

public 
OnPluginStart()
{
    
hEnableAutoRespawn CreateConVar("auto_respawn_enable""1""Enable/Disable AutoRespawn");
    
hAutoRespawnTime CreateConVar("auto_respawn_time""3.0""Time In Seconds to Respawn (Must be a float value; ie. 0.5, 10.0)");
    
hDisableManualRespawn CreateConVar("auto_respawn_disable_manual""1""Disable Manual Respawning (Will force auto-respawn time value)");

    
HookEvent("player_death"Event_PlayerDeath);
}

public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
GetConVarInt(hEnableAutoRespawn)){ return; }
    
    new 
client_id GetClientOfUserId(GetEventInt(event"userid"));
    
CreateTimer(GetConVarFloat(hAutoRespawnTime), RespawnPlayerclient_id);
}

public 
Action RespawnPlayer(Handle timerany client)
{
    if(!
IsPlayerAlive(client)) { DispatchSpawn(client); }
}

public 
Action:OnPlayerRunCmd(client, &Buttons, &impulseFloat:vel[3], Float:angles[3], &weapon){
    if(!
GetConVarInt(hDisableManualRespawn)){ return Plugin_Continue; }
    if(!
IsPlayerAlive(client)){ return Plugin_Handled; }
    return 
Plugin_Continue;

Code from above plugin that is breaking spectate:
PHP Code:
public Action:OnPlayerRunCmd(client, &Buttons, &impulseFloat:vel[3], Float:angles[3], &weapon){
    if(!
GetConVarInt(hDisableManualRespawn)){ return Plugin_Continue; }
    if(!
IsPlayerAlive(client)){ return Plugin_Handled; }
    return 
Plugin_Continue;

What do I mean by breaking spectate?
When a player joins spectate, using the "free camera" mode in spectate does not allow the player to move throughout the map freely- it just vibrates a bit when trying to move. Furthermore, upon using the command jointeam 2 or jointeam 3 (to join team unassigned) the player joins the team but is unable to spawn. Lastly, if the player issues jointeam 2 or jointeam 3 without holding the duck command, sometimes the screen will begin to shake up and down and the in-game console will loop "Restoring player view height"- while still not allowing the player to actually spawn.

I believe this block of code is the culprit as- auto_respawn_disable_manual "0" allows the player to join and leave spectators as normal.

Thanks for your time, all help is greatly appreciated.
-newguy
xXNewGuyXx is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 01-26-2017 , 05:20   Re: AutoRespawn Plugin Breaking Spectate
Reply With Quote #2

Add a check to not block spectator's movement

PHP Code:
public Action:OnPlayerRunCmd(client, &Buttons, &impulseFloat:vel[3], Float:angles[3], &weapon){ 
    if(!
GetConVarInt(hDisableManualRespawn)){ return Plugin_Continue; } 
    if(!
IsPlayerAlive(client) && GetClientTeam(client) != 1){ return Plugin_Handled; } 
    return 
Plugin_Continue

EDIT: Since this is a scripting question, I moved this to the scripting section.

Last edited by headline; 01-26-2017 at 05:22.
headline is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 01-26-2017 , 07:00   Re: AutoRespawn Plugin Breaking Spectate
Reply With Quote #3

Quote:
Originally Posted by Headline View Post
Add a check to not block spectator's movement
Hey there Headline, thanks for your response.

Before checking back to the thread, I had the spectate camera movement fixed using !IsClientObserver. However, I am now using your method as it's team-value-based.

Update:
I was able to fix the player spawning issue when leaving spectate by adding a command listener:

PHP Code:
public OnPluginStart()
{
    
AddCommandListener(Cmd_Jointeam"jointeam");
}

public 
Action:Cmd_Jointeam(client_id, const String:command[], args)
{
    if(
GetClientTeam(client_id) == && !IsFakeClient(client_id))
    {
        
CreateTimer(GetConVarFloat(hAutoRespawnTime), RespawnPlayerclient_id);
    }

Lastly, although there is nothing technically broken at this state, there is still the persistent annoyance of my screen shaking and console being spammed with "Restoring player view height" for the duration of auto_respawn_time when joining a team from spectate.
xXNewGuyXx 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 02:58.


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