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), RespawnPlayer, client_id);
}
public Action RespawnPlayer(Handle timer, any client)
{
if(!IsPlayerAlive(client)) { DispatchSpawn(client); }
}
public Action:OnPlayerRunCmd(client, &Buttons, &impulse, Float: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, &impulse, Float: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