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) 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)) if(IsClientInGame(i))
ClientCommand(i, "playgamesound \"radio/bombpl.wav\""); 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) 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)) if(IsClientInGame(i))
ClientCommand(i, "playgamesound \"radio/bombdef.wav\""); ClientCommand(i, "playgamesound \"radio/bombdef.wav\"");

View File

@ -13,15 +13,49 @@ public Plugin myinfo =
url = "" 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, ...}; int g_Client_Alpha[MAXPLAYERS + 1] = {255, ...};
public void OnPluginStart() 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++) for(int client = 1; client <= MaxClients; client++)
{ {
if(IsClientInGame(client)) if(IsClientInGame(client))
OnClientPutInServer(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() public void OnPluginEnd()
@ -40,11 +74,13 @@ public void OnPluginEnd()
public void OnClientPutInServer(int client) public void OnClientPutInServer(int client)
{ {
g_Client_Alpha[client] = 255;
SDKHook(client, SDKHook_PostThink, OnPostThink); SDKHook(client, SDKHook_PostThink, OnPostThink);
} }
public void OnClientDisconnect(int client) public void OnClientDisconnect(int client)
{ {
g_Client_Alpha[client] = 255;
SDKUnhook(client, SDKHook_PostThink, OnPostThink); SDKUnhook(client, SDKHook_PostThink, OnPostThink);
} }
@ -84,21 +120,19 @@ public void OnPostThink(client)
GetClientAbsOrigin(client, fVec1); GetClientAbsOrigin(client, fVec1);
GetClientAbsOrigin(i, fVec2); GetClientAbsOrigin(i, fVec2);
float fMaxDistance = 150.0;
float fDistance = GetVectorDistance(fVec1, fVec2, false); float fDistance = GetVectorDistance(fVec1, fVec2, false);
if(fDistance <= g_fMaxDistance)
if(fDistance <= fMaxDistance)
{ {
float fFactor = fDistance / fMaxDistance; float fFactor = fDistance / g_fMaxDistance;
if(fFactor < 0.75) if(fFactor < g_fMinFactor)
fFactor = 0.75; fFactor = g_fMinFactor;
fAlpha *= fFactor; fAlpha *= fFactor;
} }
} }
if(fAlpha < 100.0) if(fAlpha < g_fMinAlpha)
fAlpha = 100.0; fAlpha = g_fMinAlpha;
int Alpha = RoundToNearest(fAlpha); int Alpha = RoundToNearest(fAlpha);
int LastAlpha = g_Client_Alpha[client]; 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); BfReadString(bf, g_MsgRadioSound, sizeof(g_MsgRadioSound), false);
if(StrEqual(g_MsgRadioSound, "radio.locknload"))
return Plugin_Continue;
DataPack pack = new DataPack(); DataPack pack = new DataPack();
pack.WriteCell(g_MsgDest); pack.WriteCell(g_MsgDest);
pack.WriteCell(g_MsgClient); 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.WriteString(g_MsgRadioSound);
pack.WriteCell(g_MsgPlayersNum); pack.WriteCell(g_MsgPlayersNum);
ArrayList aPlayers = new ArrayList(g_MsgPlayersNum, 1); for(int i = 0; i < g_MsgPlayersNum; i++)
aPlayers.SetArray(0, g_MsgPlayers, g_MsgPlayersNum); pack.WriteCell(g_MsgPlayers[i]);
pack.WriteCell(aPlayers);
RequestFrame(OnPlayerRadio, pack); RequestFrame(OnPlayerRadio, pack);
@ -891,13 +893,17 @@ public void OnPlayerRadio(DataPack pack)
pack.ReadString(g_MsgParam4, sizeof(g_MsgParam4)); pack.ReadString(g_MsgParam4, sizeof(g_MsgParam4));
pack.ReadString(g_MsgRadioSound, sizeof(g_MsgRadioSound)); pack.ReadString(g_MsgRadioSound, sizeof(g_MsgRadioSound));
g_MsgPlayersNum = pack.ReadCell(); 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); CloseHandle(pack);
aPlayers.GetArray(0, g_MsgPlayers, g_MsgPlayersNum); Handle RadioText = StartMessage("RadioText", g_MsgPlayers, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
delete aPlayers;
Handle RadioText = StartMessage("RadioText", g_MsgPlayers, g_MsgPlayersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
BfWriteByte(RadioText, g_MsgDest); BfWriteByte(RadioText, g_MsgDest);
BfWriteByte(RadioText, g_MsgClient); BfWriteByte(RadioText, g_MsgClient);
BfWriteString(RadioText, g_MsgName); BfWriteString(RadioText, g_MsgName);
@ -907,7 +913,7 @@ public void OnPlayerRadio(DataPack pack)
BfWriteString(RadioText, g_MsgParam4); BfWriteString(RadioText, g_MsgParam4);
EndMessage(); 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); BfWriteString(SendAudio, g_MsgRadioSound);
EndMessage(); EndMessage();
} }

View File

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

View File

@ -9,13 +9,30 @@ public Plugin myinfo =
{ {
name = "sv_gravity fix", name = "sv_gravity fix",
author = "BotoX", author = "BotoX",
description = "Resets sv_gravity at game_end", description = "Resets sv_gravity at game_end and prevents stupid admins from crashing your server.",
version = "1.0", version = "1.1",
url = "" url = ""
}; };
ConVar g_ConVar_SvGravity;
public void OnPluginStart()
{
g_ConVar_SvGravity = FindConVar("sv_gravity");
g_ConVar_SvGravity.AddChangeHook(OnConVarChanged);
}
public void OnMapEnd() public void OnMapEnd()
{ {
ConVar SvGravity = FindConVar("sv_gravity"); g_ConVar_SvGravity.IntValue = 800;
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" "AutoReplace"
{ {
"teh" "the"
":lenny:" "( ͡° ͜ʖ ͡°)" ":lenny:" "( ͡° ͜ʖ ͡°)"
":feel:" " ´_ゝ`" ":feel:" " ´_ゝ`"
":chill:" "( ≖‿≖)" ":chill:" "( ≖‿≖)"