added convars to PlayerVisibility

fixed errors in SelfMute, StopSound and ExtraCommands
added server crash prevention to SvGravityFix
This commit is contained in:
BotoX 2016-05-08 23:03:46 +02:00
parent eaec96f084
commit 574eba7ee5
6 changed files with 93 additions and 33 deletions

View File

@ -93,7 +93,7 @@ public Action Listener_Pause(int client, const char[] command, int argc)
public Action:Event_BombPlanted(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i = 1; i <= MAXPLAYERS; i++)
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
ClientCommand(i, "playgamesound \"radio/bombpl.wav\"");
@ -103,7 +103,7 @@ public Action:Event_BombPlanted(Handle:event, const String:name[], bool:dontBroa
public Action:Event_BombDefused(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i = 1; i <= MAXPLAYERS; i++)
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
ClientCommand(i, "playgamesound \"radio/bombdef.wav\"");

View File

@ -13,15 +13,49 @@ public Plugin myinfo =
url = ""
};
ConVar g_CVar_MaxDistance;
ConVar g_CVar_MinFactor;
ConVar g_CVar_MinAlpha;
float g_fMaxDistance;
float g_fMinFactor;
float g_fMinAlpha;
int g_Client_Alpha[MAXPLAYERS + 1] = {255, ...};
public void OnPluginStart()
{
g_CVar_MaxDistance = CreateConVar("sm_pvis_maxdistance", "100.0", "Distance at which models stop fading.", 0, true, 0.0);
g_fMaxDistance = g_CVar_MaxDistance.FloatValue;
g_CVar_MaxDistance.AddChangeHook(OnConVarChanged);
g_CVar_MinFactor = CreateConVar("sm_pvis_minfactor", "0.75", "Smallest allowed alpha factor per client.", 0, true, 0.0, true, 1.0);
g_fMinFactor = g_CVar_MinFactor.FloatValue;
g_CVar_MinFactor.AddChangeHook(OnConVarChanged);
g_CVar_MinAlpha = CreateConVar("sm_pvis_minalpha", "75.0", "Minimum allowed alpha value.", 0, true, 0.0, true, 255.0);
g_fMinAlpha = g_CVar_MinAlpha.FloatValue;
g_CVar_MinAlpha.AddChangeHook(OnConVarChanged);
for(int client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
OnClientPutInServer(client);
}
AutoExecConfig(true, "plugin.PlayerVisibility");
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if(convar == g_CVar_MaxDistance)
g_fMaxDistance = g_CVar_MaxDistance.FloatValue;
else if(convar == g_CVar_MinFactor)
g_fMinFactor = g_CVar_MinFactor.FloatValue;
else if(convar == g_CVar_MinAlpha)
g_fMinAlpha = g_CVar_MinAlpha.FloatValue;
}
public void OnPluginEnd()
@ -40,11 +74,13 @@ public void OnPluginEnd()
public void OnClientPutInServer(int client)
{
g_Client_Alpha[client] = 255;
SDKHook(client, SDKHook_PostThink, OnPostThink);
}
public void OnClientDisconnect(int client)
{
g_Client_Alpha[client] = 255;
SDKUnhook(client, SDKHook_PostThink, OnPostThink);
}
@ -84,21 +120,19 @@ public void OnPostThink(client)
GetClientAbsOrigin(client, fVec1);
GetClientAbsOrigin(i, fVec2);
float fMaxDistance = 150.0;
float fDistance = GetVectorDistance(fVec1, fVec2, false);
if(fDistance <= fMaxDistance)
if(fDistance <= g_fMaxDistance)
{
float fFactor = fDistance / fMaxDistance;
if(fFactor < 0.75)
fFactor = 0.75;
float fFactor = fDistance / g_fMaxDistance;
if(fFactor < g_fMinFactor)
fFactor = g_fMinFactor;
fAlpha *= fFactor;
}
}
if(fAlpha < 100.0)
fAlpha = 100.0;
if(fAlpha < g_fMinAlpha)
fAlpha = g_fMinAlpha;
int Alpha = RoundToNearest(fAlpha);
int LastAlpha = g_Client_Alpha[client];

View File

@ -859,6 +859,9 @@ public Action Hook_UserMessageSendAudio(UserMsg msg_id, Handle bf, const int[] p
BfReadString(bf, g_MsgRadioSound, sizeof(g_MsgRadioSound), false);
if(StrEqual(g_MsgRadioSound, "radio.locknload"))
return Plugin_Continue;
DataPack pack = new DataPack();
pack.WriteCell(g_MsgDest);
pack.WriteCell(g_MsgClient);
@ -870,9 +873,8 @@ public Action Hook_UserMessageSendAudio(UserMsg msg_id, Handle bf, const int[] p
pack.WriteString(g_MsgRadioSound);
pack.WriteCell(g_MsgPlayersNum);
ArrayList aPlayers = new ArrayList(g_MsgPlayersNum, 1);
aPlayers.SetArray(0, g_MsgPlayers, g_MsgPlayersNum);
pack.WriteCell(aPlayers);
for(int i = 0; i < g_MsgPlayersNum; i++)
pack.WriteCell(g_MsgPlayers[i]);
RequestFrame(OnPlayerRadio, pack);
@ -891,13 +893,17 @@ public void OnPlayerRadio(DataPack pack)
pack.ReadString(g_MsgParam4, sizeof(g_MsgParam4));
pack.ReadString(g_MsgRadioSound, sizeof(g_MsgRadioSound));
g_MsgPlayersNum = pack.ReadCell();
ArrayList aPlayers = pack.ReadCell();
int playersNum = 0;
for(int i = 0; i < g_MsgPlayersNum; i++)
{
int client_ = pack.ReadCell();
if(IsClientInGame(client_))
g_MsgPlayers[playersNum++] = client_;
}
CloseHandle(pack);
aPlayers.GetArray(0, g_MsgPlayers, g_MsgPlayersNum);
delete aPlayers;
Handle RadioText = StartMessage("RadioText", g_MsgPlayers, g_MsgPlayersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
Handle RadioText = StartMessage("RadioText", g_MsgPlayers, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
BfWriteByte(RadioText, g_MsgDest);
BfWriteByte(RadioText, g_MsgClient);
BfWriteString(RadioText, g_MsgName);
@ -907,7 +913,7 @@ public void OnPlayerRadio(DataPack pack)
BfWriteString(RadioText, g_MsgParam4);
EndMessage();
Handle SendAudio = StartMessage("SendAudio", g_MsgPlayers, g_MsgPlayersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
Handle SendAudio = StartMessage("SendAudio", g_MsgPlayers, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
BfWriteString(SendAudio, g_MsgRadioSound);
EndMessage();
}

View File

@ -344,9 +344,8 @@ public Action Hook_ReloadEffect(UserMsg msg_id, BfRead msg, const int[] players,
pack.WriteCell(client);
pack.WriteCell(newTotal);
ArrayList aPlayers = new ArrayList(newTotal, 1);
aPlayers.SetArray(0, newClients, newTotal);
pack.WriteCell(aPlayers);
for(int i = 0; i < newTotal; i++)
pack.WriteCell(newClients[i]);
RequestFrame(OnReloadEffect, pack);
@ -357,13 +356,18 @@ public void OnReloadEffect(DataPack pack)
{
pack.Reset();
int client = pack.ReadCell();
int playersNum = pack.ReadCell();
ArrayList aPlayers = pack.ReadCell();
CloseHandle(pack);
int newTotal = pack.ReadCell();
int[] players = new int[playersNum];
aPlayers.GetArray(0, players, playersNum);
delete aPlayers;
int[] players = new int[newTotal];
int playersNum = 0;
for(int i = 0; i < newTotal; i++)
{
int client_ = pack.ReadCell();
if(IsClientInGame(client_))
players[playersNum++] = client_;
}
CloseHandle(pack);
Handle ReloadEffect = StartMessage("ReloadEffect", players, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
if(GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf)

View File

@ -9,13 +9,30 @@ public Plugin myinfo =
{
name = "sv_gravity fix",
author = "BotoX",
description = "Resets sv_gravity at game_end",
version = "1.0",
description = "Resets sv_gravity at game_end and prevents stupid admins from crashing your server.",
version = "1.1",
url = ""
};
ConVar g_ConVar_SvGravity;
public void OnPluginStart()
{
g_ConVar_SvGravity = FindConVar("sv_gravity");
g_ConVar_SvGravity.AddChangeHook(OnConVarChanged);
}
public void OnMapEnd()
{
ConVar SvGravity = FindConVar("sv_gravity");
SvGravity.IntValue = 800;
g_ConVar_SvGravity.IntValue = 800;
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if(convar.IntValue < 1)
{
convar.IntValue = 800;
for(int i = 0; i < 10; i++)
PrintToChatAll("Setting sv_gravity to values less than 1 will crash the server!!!");
}
}

View File

@ -1,6 +1,5 @@
"AutoReplace"
{
"teh" "the"
":lenny:" "( ͡° ͜ʖ ͡°)"
":feel:" " ´_ゝ`"
":chill:" "( ≖‿≖)"