AlliedModders Donor
Join Date: Dec 2011
Location: Israel
|
12-15-2017
, 04:17
Re: Random Code Archive
|
#19
|
I'll post some too because it might end up being useful, but I don't want to create threads and provide support if needed.
Admins List
!admins - open the admins list.
(admin command) !admins <0/1> - make yourself invisible or visible in the list. Admins can see other invisible admins.
Admins with an immunity level of 100 or above are completely invisible and don't show up to other admins either.
The plugin also has my SteamID hardcoded so it doesn't display me whatsoever, even to other admins. Comment the #define HIDESHAVIT line if you want to disable the functionality.
Code:
#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1.0"
// comment if you care about micro-optimizations
#define HIDESHAVIT
bool gB_Visible[MAXPLAYERS+1] = {true, ...};
public Plugin myinfo =
{
name = "Admins List",
author = "shavit",
description = "swag",
version = PLUGIN_VERSION,
url = "http://forums.alliedmods.net/member.php?u=163134"
}
public void OnClientAuthorized(int client, const char[] auth)
{
gB_Visible[client] = true;
}
public void OnPluginStart()
{
RegConsoleCmd("sm_admins", Command_Admins, "Show a list of online admins.");
}
public Action Command_Admins(int client, int args)
{
if(client == 0 || !IsClientInGame(client))
{
return Plugin_Handled;
}
bool bAdmin = CheckAdmin(client);
if(bAdmin && args > 0)
{
char sArg[8];
GetCmdArg(1, sArg, 8);
gB_Visible[client] = view_as<bool>(StringToInt(sArg));
ReplyToCommand(client, " \x03[admins]\x01 whoosh~! %s\x01.", gB_Visible[client]? "\x04VISIBLE":"\x02INVISIBLE");
return Plugin_Handled;
}
Menu menu = new Menu(MenuHandler_Admins);
menu.SetTitle("Admins list:");
char[] sDisplay = new char[MAX_NAME_LENGTH*2];
for(int i = 1; i <= MaxClients; i++)
{
if(CheckAdmin(i))
{
#if defined HIDESHAVIT
char sAuth[32];
GetClientAuthId(i, AuthId_Steam3, sAuth, 32);
// shavit
if(StrEqual(sAuth, "[U:1:204506329]"))
{
continue;
}
#endif
GetClientName(i, sDisplay, MAX_NAME_LENGTH*2);
if(!gB_Visible[i])
{
Format(sDisplay, MAX_NAME_LENGTH*2, "[INVISIBLE] %s", sDisplay);
}
if((gB_Visible[i] || bAdmin) && GetAdminImmunityLevel(GetUserAdmin(i)) < 100)
{
menu.AddItem(":)", sDisplay);
}
}
}
if(GetMenuItemCount(menu) == 0)
{
menu.AddItem(":(", "There are no admins online right now.\nBut hey - there might be a stealth one, so don't cause any issues, they may be watching you!");
}
menu.Display(client, 20);
return Plugin_Handled;
}
public int MenuHandler_Admins(Menu menu, MenuAction action, int param1, int param2)
{
if(action == MenuAction_End)
{
delete menu;
}
}
bool CheckAdmin(int client)
{
return CheckCommandAccess(client, "sm_admin", ADMFLAG_GENERIC);
}
CS:S/CS:GO Auto Restart
I don't know why, but someone asked me to write this before.
All it does is restart the round 10 seconds after the very first player connects, when a map changes.
Code:
#include <sourcemod>
#include <cstrike>
#pragma newdecls required
#pragma semicolon 1
int gI_Players = 0;
public void OnMapStart()
{
gI_Players = 0;
}
public void OnClientPutInServer(int client)
{
if(++gI_Players == 1)
{
CS_TerminateRound(10.0, CSRoundEnd_Draw);
}
}
Connection message (SB)
Displays a player join/leave message message, but makes sure that the player isn't banned right now.
This was written because players could reconnect to a server endlessly before getting kicked via the SourceBans plugin and they would spam the server's chat.
Code:
#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required
bool gB_MessagePrinted[MAXPLAYERS+1];
char gS_NameColor[16];
Database gH_DB = null;
public Plugin myinfo =
{
name = "[SB] Connect Message",
author = "shavit",
description = "Prints a dis/connection message for every player individually. Respects SourceBans(++) 1.5.x.",
version = "1.0",
url = "http://forums.alliedmods.net/member.php?u=163134"
}
public void OnPluginStart()
{
strcopy(gS_NameColor, 16, GetEngineVersion() == Engine_CSGO? " \x03":"\x0773F1FA");
HookEvent("player_connect", Player_ConnectMessageHook, EventHookMode_Pre);
HookEvent("player_disconnect", Player_ConnectMessageHook, EventHookMode_Pre);
Database.Connect(OnDatabaseConnected, "sourcebans");
}
public Action Player_ConnectMessageHook(Event event, const char[] sName, bool dB)
{
dB = true;
return Plugin_Changed;
}
public void OnDatabaseConnected(Database db, const char[] error, any data)
{
if(db == null)
{
SetFailState("Failed to connect to SourceBans DB. Error: %s", error);
}
gH_DB = db;
}
public void OnClientPutInServer(int client)
{
if(IsFakeClient(client))
{
return;
}
gB_MessagePrinted[client] = false;
CreateTimer(1.0, PrintMessage, GetClientSerial(client));
}
public Action PrintMessage(Handle Timer, any data)
{
int client = GetClientFromSerial(client);
char[] auth = new char[32];
if(client == 0 || !GetClientAuthId(client, AuthId_Engine, auth, 32))
{
return Plugin_Stop;
}
auth[6] = '0';
char[] auth2 = new char[32];
strcopy(auth2, 32, auth);
auth2[6] = '1';
// auth2 is being used for bans that are placed using the STEAM_0 format
// that's good for communities that run both CS:GO and other source engine game servers
char[] sQuery = new char[256];
FormatEx(sQuery, 256, "SELECT * FROM `sb_bans` WHERE (authid = '%s' OR authid = '%s') AND RemoveType IS NULL", auth, auth2);
gH_DB.Query(SelectCallback, sQuery, GetClientSerial(client), DBPrio_Low);
return Plugin_Stop;
}
public void SelectCallback(Database db, DBResultSet results, const char[] error, any data)
{
int client = GetClientFromSerial(data);
if(results == null || client == 0 || results.RowCount > 0)
{
return;
}
gB_MessagePrinted[client] = true;
char[] auth = new char[32];
GetClientAuthId(client, AuthId_Engine, auth, 32);
if(StrContains(auth, "[") != -1)
{
ReplaceString(auth, 32, "[", "");
ReplaceString(auth, 32, "]", "");
}
PrintToChatAll("%s%N\x01 [\x04%s\x01] has \x05connected\x01.", gS_NameColor, client, auth);
}
public void OnClientDisconnect(int client)
{
if(!IsFakeClient(client) && gB_MessagePrinted[client] && IsClientInGame(client) && GetClientTeam(client) >= 1)
{
char[] sAuth = new char[32];
GetClientAuthId(client, AuthId_Engine, sAuth, 32);
if(StrContains(sAuth, "[") != -1)
{
ReplaceString(sAuth, 32, "[", "");
ReplaceString(sAuth, 32, "]", "");
}
PrintToChatAll("%s%N\x01 [\x04%s\x01] has \x02disconnected\x01.", gS_NameColor, client, sAuth);
}
}
CS:GO prestrafe
Enables prestrafing in CS:GO - extracted from KZTimer so it's very dated. I don't recommend running this if your server allows players to obtain weapons other than a pistol.
Use sv_friction 4 and sv_accelerate 5 with CS:GO Movement Unlocker instead if you're fine with the ground-sliding it adds, instead of this mess.
Code:
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
#pragma semicolon 1
#define PLUGIN_VERSION "1.0b"
int gI_PrestrafeFrameCounter[MAXPLAYERS+1];
bool gB_OnGround[MAXPLAYERS+1];
float gF_LastAngles[MAXPLAYERS+1][3];
float gF_VelocityModifierLastChange[MAXPLAYERS+1];
float gF_PrestrafeVelocity[MAXPLAYERS+1] = {1.0};
public Plugin myinfo =
{
name = "CS:GO Prestrafe",
author = "abckrieger/1NutWunDeR",
description = "Enables prestrafing in CS:GO. Extracted from KZTimer and massively optimized afterwards.",
version = PLUGIN_VERSION,
url = "https://bitbucket.org/kztimerglobalteam/kztimerglobal"
}
public void OnClientPutInServer(int client)
{
gF_PrestrafeVelocity[client] = 1.0;
gI_PrestrafeFrameCounter[client] = 0;
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3])
{
if(!IsPlayerAlive(client))
{
return Plugin_Continue;
}
gB_OnGround[client] = (GetEntityFlags(client) & FL_ONGROUND > 0);
float ang[3];
GetClientEyeAngles(client, ang);
if(gB_OnGround[client])
{
Prestrafe(client, ang, buttons, vel);
}
gF_LastAngles[client] = ang;
return Plugin_Continue;
}
void Prestrafe(int client, float angles[3], int &buttons, float vel[3])
{
bool bTurningRight = false;
bool bTurningLeft = false;
if(angles[1] < gF_LastAngles[client][1])
{
bTurningRight = true;
}
else if(angles[1] > gF_LastAngles[client][1])
{
bTurningLeft = true;
}
char[] sClassname = new char[16];
GetClientWeapon(client, sClassname, 16);
bool bHKP2000 = StrEqual(sClassname, "weapon_hkp2000");
int MaxFrameCount = 0;
float fIncSpeed = 0.0;
float fDecSpeed = 0.0;
float fVelocity[3];
GetEntPropVector(client, Prop_Data, "m_vecVelocity", fVelocity);
float speed = SquareRoot(Pow(fVelocity[0], 2.0) + Pow(fVelocity[1], 2.0));
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fVelocity);
if(angles[0] > 70.0)
{
angles[0] = 70.0;
}
if(angles[0] < -70.0)
{
angles[0] = -70.0;
}
float fViewDirection[3];
GetAngleVectors(angles, fViewDirection, NULL_VECTOR, NULL_VECTOR);
NormalizeVector(fVelocity, fVelocity);
NormalizeVector(fViewDirection, fViewDirection);
bool bForward = (GetVectorDotProduct(fVelocity, fViewDirection) > 0.0);
if(!bTurningRight && !bTurningLeft)
{
float fEngineTime = GetEngineTime();
float diff = fEngineTime - gF_VelocityModifierLastChange[client];
if(diff > 0.2)
{
gF_PrestrafeVelocity[client] = (bHKP2000)? 1.042:1.0;
gF_VelocityModifierLastChange[client] = fEngineTime;
SetEntPropFloat(client, Prop_Send, "m_flVelocityModifier", gF_PrestrafeVelocity[client]);
}
return;
}
bool bLeft = ((buttons & IN_MOVELEFT) > 0 || vel[1] < 0.0);
bool bRight = ((buttons & IN_MOVERIGHT) > 0 || vel[1] > 0.0);
if((bRight || bLeft) && speed > 249.0)
{
MaxFrameCount = 75;
fIncSpeed = 0.0009;
if((gF_PrestrafeVelocity[client] > 1.08 && bHKP2000) || (gF_PrestrafeVelocity[client] > 1.04 && !bHKP2000))
{
fIncSpeed = 0.001;
}
fDecSpeed = 0.005;
if((bRight && bTurningRight || bTurningLeft && !bForward) || (bLeft && bTurningLeft || bTurningRight && !bForward))
{
gI_PrestrafeFrameCounter[client]++;
if(gI_PrestrafeFrameCounter[client] < MaxFrameCount)
{
gF_PrestrafeVelocity[client] += fIncSpeed;
if(bHKP2000 && gF_PrestrafeVelocity[client] > 1.15)
{
gF_PrestrafeVelocity[client] -= 0.007;
}
else if(gF_PrestrafeVelocity[client] > 1.104)
{
gF_PrestrafeVelocity[client] -= 0.007;
}
gF_PrestrafeVelocity[client] += fIncSpeed;
}
else
{
gF_PrestrafeVelocity[client] -= fDecSpeed;
if(bHKP2000 && gF_PrestrafeVelocity[client] < 1.042)
{
gI_PrestrafeFrameCounter[client] = 0;
gF_PrestrafeVelocity[client] = 1.042;
}
else if(gF_PrestrafeVelocity[client] < 1.0)
{
gI_PrestrafeFrameCounter[client] = 0;
gF_PrestrafeVelocity[client] = 1.0;
}
gI_PrestrafeFrameCounter[client] = gI_PrestrafeFrameCounter[client] - 2;
}
}
else
{
gF_PrestrafeVelocity[client] -= 0.04;
if(bHKP2000 && gF_PrestrafeVelocity[client] < 1.042)
{
gF_PrestrafeVelocity[client]= 1.042;
}
else if(gF_PrestrafeVelocity[client]< 1.0)
{
gF_PrestrafeVelocity[client]= 1.0;
}
}
}
else
{
gF_PrestrafeVelocity[client] = (bHKP2000)? 1.042:1.0;
gI_PrestrafeFrameCounter[client] = 0;
}
SetEntPropFloat(client, Prop_Send, "m_flVelocityModifier", gF_PrestrafeVelocity[client]);
gF_VelocityModifierLastChange[client] = GetEngineTime();
}
CS:GO G-Strafe
Code written by ofir753. I've seen people ask for it before but forgot I even have it.
It enables ground-strafing. I don't know if this code even works, but I remember ofir letting me test a working version in his server once; so it can possibly work.
Code:
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
{
name = "Enable Gstrafe at Cs GO",
author = "Ofir",
description = "",
version = "1.0",
url = ""
};
#define DUCKHEIGHT 54.0
new bool:gb_isDucking[MAXPLAYERS+1];
new bool:gb_waitForGround[MAXPLAYERS+1];
new Float:gf_Velocity[MAXPLAYERS+1][3];
public OnClientPutInServer(client)
{
gb_isDucking[client] = false;
gb_waitForGround[client] = false;
}
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seed, mouse[2])
{
SetEntProp(client, Prop_Data, "m_nDuckTimeMsecs", 0);
if(GetEntityFlags(client) & FL_ONGROUND)
{
if(gb_waitForGround[client])
{
SetEntPropFloat(client, Prop_Send, "m_flStamina", 0.0);
gb_waitForGround[client] = false;
}
if(buttons & IN_DUCK)
{
gb_isDucking[client] = true;
GetEntPropVector(client, Prop_Data, "m_vecVelocity", gf_Velocity[client]);
}
}
if (!(buttons & IN_DUCK) && gb_isDucking[client])
{
gb_isDucking[client] = false;
if(!(GetEntityFlags(client) & FL_DUCKING) && CheckCeiling(client))
{
new Float:org[3];
GetClientAbsOrigin(client, org);
org[2] += DUCKHEIGHT;
TeleportEntity(client, org, NULL_VECTOR, gf_Velocity[client]);
SetEntPropFloat(client, Prop_Send, "m_flStamina", 0.0);
gb_waitForGround[client] = true;
}
}
}
bool:CheckCeiling(client)
{
new Float:vecOrigin[3], Float:vecPos[3];
new Float:vecEnd[3];
new bool:isHit = false;
for (new i = 0; i < 4; i++)
{
GetClientAbsOrigin(client, vecOrigin);
vecOrigin[2] += 70;
switch(i)
{
case 0:
{
vecOrigin[0] += 32;
}
case 1:
{
vecOrigin[1] += 32;
}
case 2:
{
vecOrigin[0] -= 32;
}
case 3:
{
vecOrigin[1] -= 32;
}
}
vecEnd = vecOrigin;
vecEnd[2] += 500.0
new Handle:trace = TR_TraceRayFilterEx(vecOrigin, vecEnd, MASK_PLAYERSOLID, RayType_EndPoint, WorldFilter);
if(TR_DidHit(trace))
{
TR_GetEndPosition(vecPos, trace);
if(vecPos[2] - vecOrigin[2] <= DUCKHEIGHT)
{
isHit = true;
}
}
CloseHandle(trace);
}
return !isHit;
}
public bool:WorldFilter(entity, mask)
{
// world has entity id 0: if nonzero, tis thing
if(entity)
return false;
return true;
}
I really don't think I have anything else to post, have fun.
__________________
retired
|
|