This commit is contained in:
zaCade 2019-03-02 15:18:51 +01:00
parent d1fa3d4eb7
commit 466f7253b1
15 changed files with 11501 additions and 0 deletions

View File

@ -0,0 +1,258 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.01"
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <smlib>
#include <zr/infect.zr>
#include <cstrike>
//global
float g_IAdminspin;
float g_iBotairjump;
int g_iDelay;
bool g_bRoundStart;
public Plugin myinfo =
{
name = "autism bot",
author = PLUGIN_AUTHOR,
description = "spawns the bot on a team",
version = PLUGIN_VERSION,
url = "www.unloze.com"
};
public void OnMapStart()
{
g_IAdminspin = 0.0;
g_iBotairjump = 1.0;
g_iDelay = 0;
}
public void OnPluginStart()
{
RegAdminCmd("sm_botspin", Cmd_botSpin, ADMFLAG_GENERIC);
RegAdminCmd("sm_botjump", Cmd_botJump, ADMFLAG_GENERIC);
//hook
HookEvent("player_death", PlayerDeath);
HookEvent("round_start", Event_roundStart, EventHookMode_Post);
}
public void OnClientPostAdminCheck(int client)
{
if (IsFakeClient(client))
{
SDKHook(client, SDKHook_OnTakeDamagePost, OnTakeDamagePost);
ChangeClientTeam(client, CS_TEAM_CT);
}
}
public void Event_roundStart(Handle event, const char[] name, bool dontBroadcast)
{
g_bRoundStart = true;
for (int i = 1; i < MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && IsClientSourceTV(i) && IsPlayerAlive(i))
{
ForcePlayerSuicide(i);
CreateTimer(0.5, safeSpec, i);
break;
}
}
}
public Action PlayerDeath(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsClientSourceTV(client) && !g_bRoundStart)
{
CreateTimer(0.5, safeSpec, client);
CreateTimer(9.0, respawn_func, client);
}
}
public Action safeSpec(Handle timer, int client)
{
ChangeClientTeam(client, CS_TEAM_SPECTATOR);
}
public Action respawn_func(Handle timer, int client)
{
if (!g_bRoundStart)
{
ChangeClientTeam(client, CS_TEAM_CT);
ServerCommand("sm_fakecommand %N say /zspawn", client);
//ZR_InfectClient(client);
}
}
public Action Cmd_botSpin(int client, int args)
{
char inputArgs[250];
float input;
GetCmdArgString(inputArgs, sizeof(inputArgs));
input = StringToFloat(inputArgs);
PrintToChat(client, "spin value: %f", input);
if (input == 0.0)
{
PrintToChat(client, "input failed");
return Plugin_Handled;
}
else if (input >= 360.0 || input <= -360.0)
{
PrintToChat(client, "Input Range: -360 to 360");
return Plugin_Handled;
}
g_IAdminspin = input;
return Plugin_Handled;
}
public Action Cmd_botJump(int client, int args)
{
char inputArgs[250];
float input;
GetCmdArgString(inputArgs, sizeof(inputArgs));
input = StringToFloat(inputArgs);
PrintToChat(client, "jump value: %f", input);
if (input == 0.0)
{
PrintToChat(client, "input failed");
return Plugin_Handled;
}
else if (input >= 10.0 || input <= -10.0)
{
PrintToChat(client, "Input Range: -10 to 10");
return Plugin_Handled;
}
g_iBotairjump = input;
return Plugin_Handled;
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float move[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if (IsFakeClient(client))
{
if (g_IAdminspin == 0.0)
{
angles[1] += 30.0;
if (angles[1] >= 360.0)
{
angles[1] = 0.0;
}
TeleportEntity(client, NULL_VECTOR, angles, NULL_VECTOR);
++g_iDelay;
if (g_iDelay >= 10)
{
buttons |= IN_ATTACK;
g_iDelay = 0;
buttons |= IN_DUCK;
Client_Push(client);
}
return Plugin_Changed;
}
else
{
angles[1] += g_IAdminspin;
if (angles[1] >= 360.0)
{
angles[1] = 0.0;
}
TeleportEntity(client, NULL_VECTOR, angles, NULL_VECTOR);
++g_iDelay;
if (g_iDelay >= 10)
{
buttons |= IN_ATTACK;
buttons |= IN_DUCK;
g_iDelay = 0;
Client_Push(client);
}
return Plugin_Changed;
}
}
return Plugin_Continue;
}
public void Client_Push (int client)
{
float newVel[3];
int GroundEnt = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
if (GroundEnt == -1)
{
//PrintToChatAll("Bot %N is not on ground", client);
}
else
{
int i_nr = GetRandomInt(1, 4);
if (i_nr == 1)
{
newVel[1] += GetRandomInt(50, 350);
}
else if (i_nr == 2)
{
newVel[0] += GetRandomInt(50, 350);
}
else if (i_nr == 3)
{
newVel[0] -= GetRandomInt(50, 350);
}
else if (i_nr == 4)
{
newVel[1] -= GetRandomInt(50, 350);
}
newVel[2] += GetRandomInt(50, 350) * g_iBotairjump;
//newVel[1] += GetRandomFloat(0.10, 270.10);
Entity_SetAbsVelocity(client, newVel);
//PrintToChatAll("Bot %N is on ground", client);
}
}
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
if (!motherInfect)
return;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && IsClientSourceTV(i))
{
g_bRoundStart = false;
CreateTimer(1.0, respawn_func, i);
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: damageHook
//----------------------------------------------------------------------------------------------------
public Action OnTakeDamagePost(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
// Don't pass alive players
if (IsPlayerAlive(victim))
{
return Plugin_Handled;
}
if (attacker == 0)
{
// World
ServerCommand("sm_fakecommand #%i say \"fuck u world!\"", GetClientUserId(victim), attacker);
}
else if (victim == attacker)
{
// Suicide
ServerCommand("sm_fakecommand #%i say \"fuck ur admin abuse!\"", GetClientUserId(victim), attacker);
}
else if (1 <= attacker <= MaxClients)
{
ServerCommand("sm_fakecommand #%i say \"%N fuck u m8!\"", GetClientUserId(victim), attacker);
}
return Plugin_Handled;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,446 @@
#include <zombiereloaded>
#include <sourcemod>
#include <sdktools>
#include <colorvariables>
#include <chat-processor>
//#include <morecolors.inc>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo =
{
name = "Meteors",
author = "Neon",
description = "",
version = "Meteors",
url = "https://steamcommunity.com/id/n3ontm"
}
//ambient/explosions/explode_9.wav
//models/effects/vol_light128x512.mdl
bool g_bEnabled = false;
public void OnPluginStart()
{
HookEvent("round_end", OnRoundEnding);
RegAdminCmd("sm_meteors", Command_Meteors, ADMFLAG_GENERIC);
}
public void OnMapStart()
{
g_bEnabled = false;
PrecacheModel("models/props/cs_office/vending_machine.mdl");
CreateTimer(5.0, MeteorMain, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
g_bEnabled = false;
}
public Action Command_Meteors(int client, int args)
{
if (g_bEnabled)
{
g_bEnabled = false;
CPrintToChatAll("{orchid}[Meteors] {Green}%N has disabled Meteors!", client);
}
else if (!(g_bEnabled))
{
g_bEnabled = true;
CPrintToChatAll("{orchid}[Meteors] {Green}%N has enabled Meteors!", client);
}
}
public Action MeteorMain(Handle timer)
{
if (!(g_bEnabled))
{
return;
}
int victimClient = GetTargetClient();
if (victimClient == -1)
{
return;
}
int indicator = SpawnIndicator(victimClient);
int model = SpawnMeteor2(victimClient);
int hurt = SpawnTriggerHurt(victimClient);
int move = SpawnMoveLinear(victimClient);
int explosion = SpawnExplosion(victimClient);
int sound = SpawnAmbientGeneric(victimClient);
int particle = SpawnParticle(victimClient);
int particle2 = SpawnParticle(victimClient);
SetVariantString("!activator");
AcceptEntityInput(model, "SetParent", move);
SetVariantString("!activator");
AcceptEntityInput(hurt, "SetParent", move);
SetVariantString("!activator");
AcceptEntityInput(particle, "SetParent", move);
SetVariantString("!activator");
AcceptEntityInput(particle2, "SetParent", move);
AcceptEntityInput(move, "Open");
}
public Action SpawnParticle(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("info_particle_system")) == INVALID_ENT_REFERENCE)
return -1;
// Generate unique id for the entity
char StrEntityName[64];
Format(StrEntityName, sizeof(StrEntityName), "info_particle_system_%i", Entity);
// Setup entity
DispatchKeyValue(Entity, "targetname", "meteor_particle");
DispatchKeyValue(Entity, "effect_name", "fire_large_01");
//DispatchKeyValue(Entity, "effect_name", "burning_fx");
DispatchSpawn(Entity);
ActivateEntity(Entity);
AcceptEntityInput(Entity, "start");
float fVector[3];
float fAngles[3];
GetClientAbsOrigin(client, fVector);
GetClientAbsAngles(client, fAngles);
fVector[2] += 7000.0;
TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR);
return Entity;
}
public Action SpawnAmbientGeneric(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("ambient_generic")) == INVALID_ENT_REFERENCE)
return -1;
// Generate unique id for the entity
char StrEntityName[64];
Format(StrEntityName, sizeof(StrEntityName), "ambient_generic_%i", Entity);
// Setup entity
DispatchKeyValue(Entity, "targetname", "meteor_sound");
DispatchKeyValue(Entity, "spawnflags", "48");
DispatchKeyValue(Entity, "SourceEntityName", "meteor_model2");
DispatchKeyValue(Entity, "radius", "3050");
DispatchKeyValue(Entity, "message", "ambient/explosions/explode_9.wav");
DispatchKeyValue(Entity, "volume", "10");
DispatchKeyValue(Entity, "health", "10");
DispatchKeyValue(Entity, "preset", "0");
DispatchKeyValue(Entity, "pitch", "100");
DispatchKeyValue(Entity, "pitchstart", "100");
DispatchSpawn(Entity);
ActivateEntity(Entity);
return Entity;
}
public Action SpawnTriggerHurt(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("trigger_hurt")) == INVALID_ENT_REFERENCE)
return -1;
// Generate unique id for the entity
char StrEntityName[64];
Format(StrEntityName, sizeof(StrEntityName), "trigger_hurt_%i", Entity);
float fVector[3];
float fAngles[3];
GetClientAbsOrigin(client, fVector);
GetClientAbsAngles(client, fAngles);
fVector[2] += 7000.0;
// Setup entity
DispatchKeyValue(Entity, "targetname", "meteor_hurt");
DispatchKeyValue(Entity, "spawnflags", "1");
DispatchKeyValue(Entity, "StartDisabled", "0");
DispatchKeyValueVector(Entity, "origin", fVector);
DispatchKeyValue(Entity, "nodmgforce", "0");
DispatchKeyValue(Entity, "damage", "80");
//DispatchKeyValue(Entity, "damage", "320");
DispatchKeyValue(Entity, "damagetype", "128");
DispatchKeyValue(Entity, "damagemodel", "0");
DispatchSpawn(Entity);
ActivateEntity(Entity);
SetEntityModel(Entity, "models/props/cs_office/vending_machine.mdl");
float minbounds[3] = {-50.0, -50.0, -100.0};
float maxbounds[3] = {50.0, 50.0, 100.0};
SetEntPropVector(Entity, Prop_Send, "m_vecMins", minbounds);
SetEntPropVector(Entity, Prop_Send, "m_vecMaxs", maxbounds);
SetEntProp(Entity, Prop_Send, "m_nSolidType", 2);
int enteffects = GetEntProp(Entity, Prop_Send, "m_fEffects");
enteffects |= 32;
SetEntProp(Entity, Prop_Send, "m_fEffects", enteffects);
return Entity;
}
public Action SpawnMeteor2(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("prop_physics_multiplayer")) == INVALID_ENT_REFERENCE)
{
return -1;
}
// Generate unique id for the entity
char StrEntityName[512];
Format(StrEntityName, sizeof(StrEntityName), "prop_physics_multiplayer_%i", Entity);
// Setup entity
DispatchKeyValue(Entity, "targetname", "meteor_model2");
DispatchKeyValue(Entity, "model", "models/props/cs_militia/militiarock05.mdl");
DispatchKeyValue(Entity, "spawnflags", "8");
DispatchKeyValue(Entity, "pressuredelay", "0");
DispatchKeyValue(Entity, "physicsmode", "2");
DispatchKeyValue(Entity, "physdamagescale", "0.1");
DispatchKeyValue(Entity, "modelscale", "2.0");
DispatchSpawn(Entity);
float fVector[3];
float fAngles[3];
GetClientAbsOrigin(client, fVector);
GetClientAbsAngles(client, fAngles);
fVector[2] += 7000.0;
//fVector[1] += 1000.0;
TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR);
return Entity;
}
public Action SpawnExplosion(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("env_explosion")) == INVALID_ENT_REFERENCE)
return -1;
// Generate unique id for the entity
char StrEntityName[64];
Format(StrEntityName, sizeof(StrEntityName), "env_explosion_%i", Entity);
// Setup entity
DispatchKeyValue(Entity, "targetname", "meteor_explosion");
DispatchKeyValue(Entity, "fireballsprite", "sprites/zerogxplode.spr");
DispatchKeyValue(Entity, "rendermode", "5");
DispatchKeyValue(Entity, "iMagnitude", "300");
DispatchKeyValue(Entity, "iRadiusOverride", "70");
DispatchKeyValue(Entity, "spawnflags", "81");
DispatchSpawn(Entity);
float fVector[3];
float fAngles[3];
GetClientAbsOrigin(client, fVector);
GetClientAbsAngles(client, fAngles);
TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR);
return Entity;
}
public Action SpawnMeteor(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("prop_dynamic")) == INVALID_ENT_REFERENCE)
return -1;
// Generate unique id for the entity
char StrEntityName[64]; Format(StrEntityName, sizeof(StrEntityName), "prop_dynamic_%i", Entity);
// Setup entity
DispatchKeyValue(Entity, "targetname", "meteor_model");
DispatchKeyValue(Entity, "model", "models/props/cs_militia/militiarock05.mdl");
DispatchKeyValue(Entity, "solid", "0");
DispatchKeyValue(Entity, "modelscale", "1.0");
DispatchKeyValue(Entity, "renderamt", "255");
DispatchKeyValue(Entity, "rendercolor", "0 181 240");
DispatchKeyValue(Entity, "renderfx", "0");
DispatchKeyValue(Entity, "rendermode", "0");
DispatchSpawn(Entity);
float fVector[3];
float fAngles[3];
GetClientAbsOrigin(client, fVector);
GetClientAbsAngles(client, fAngles);
fVector[2] += 7000.0;
//fVector[1] += 1000.0;
TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR);
return Entity;
}
public Action SpawnMoveLinear(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("func_movelinear")) == INVALID_ENT_REFERENCE)
return -1;
// Generate unique id for the entity
char StrEntityName[64]; Format(StrEntityName, sizeof(StrEntityName), "func_movelinear_%i", Entity);
float fVectorClient[3];
float fVectorStart[3];
float fAngles[3];
float fVectorCalculated[3];
float fAnglesCalculated[3];
GetClientAbsOrigin(client, fVectorClient);
GetClientAbsAngles(client, fAngles);
fVectorStart = fVectorClient;
fVectorStart[2] += 7000.0;
SubtractVectors(fVectorClient, fVectorStart, fVectorCalculated);
float distanceF = GetVectorLength(fVectorCalculated, false);
distanceF -= 128.0;
NormalizeVector(fVectorCalculated, fVectorCalculated);
GetVectorAngles(fVectorCalculated, fAnglesCalculated);
// Setup entity
DispatchKeyValue(Entity, "targetname", "meteor_linear");
DispatchKeyValueVector(Entity, "movedir", fAnglesCalculated);
DispatchKeyValueVector(Entity, "origin", fVectorStart);
DispatchKeyValue(Entity, "speed", "3000");
DispatchKeyValueFloat(Entity, "movedistance", distanceF);
DispatchKeyValue(Entity, "spawnflags", "8");
DispatchKeyValue(Entity, "rendermode", "3");
DispatchKeyValue(Entity, "rendercolor", "136 0 0");
DispatchKeyValue(Entity, "OnFullyOpen", "!self,KillHierarchy,,0.01,1");
DispatchKeyValue(Entity, "OnFullyOpen", "meteor_indicator,Kill,,0,1");
DispatchKeyValue(Entity, "OnFullyOpen", "meteor_explosion,Explode,,0,1");
DispatchKeyValue(Entity, "OnFullyOpen", "meteor_explosion,Kill,,0.01,1");
DispatchKeyValue(Entity, "OnFullyOpen", "meteor_sound,PlaySound,,0,1");
DispatchKeyValue(Entity, "OnFullyOpen", "meteor_sound,Kill,,0.01,1");
DispatchSpawn(Entity);
return Entity;
}
public Action SpawnIndicator(int client)
{
int Entity;
// Spawn dynamic prop entity
if ((Entity = CreateEntityByName("prop_dynamic")) == INVALID_ENT_REFERENCE)
return -1;
// Generate unique id for the entity
char StrEntityName[64];
Format(StrEntityName, sizeof(StrEntityName), "prop_dynamic_%i", Entity);
// Setup entity
//this is problematic one
DispatchKeyValue(Entity, "targetname", "meteor_indicator");
DispatchKeyValue(Entity, "model", "models/editor/spot_cone.mdl");
DispatchKeyValue(Entity, "solid", "0");
DispatchKeyValue(Entity, "modelscale", "5.5");
DispatchKeyValue(Entity, "angles", "0 0 90");
DispatchKeyValue(Entity, "renderamt", "255");
DispatchKeyValue(Entity, "rendercolor", "255 0 0");
DispatchKeyValue(Entity, "renderfx", "0");
DispatchKeyValue(Entity, "rendermode", "0");
DispatchSpawn(Entity);
float fVector[3];
float fAngles[3];
GetClientAbsOrigin(client, fVector);
GetClientAbsAngles(client, fAngles);
fVector[2] += 35.0;
TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR);
return Entity;
}
public int GetTargetClient()
{
int outsideClientCount = 0;
int[] outsideClients = new int[MaxClients];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && IsPlayerAlive(i) && (ZR_IsClientHuman(i)) && (GetClientDistanceToCeiling(i) > 200.0))
{
outsideClients[outsideClientCount] = i;
outsideClientCount += 1;
}
}
if (outsideClientCount == 0)
return -1;
int randomIndex = GetRandomInt(0, outsideClientCount - 1);
return outsideClients[randomIndex];
}
public float GetClientDistanceToCeiling(int client)
{
float distanceF = 0.0;
float fOrigin[3];
float fCeiling[3];
GetClientAbsOrigin(client, fOrigin);
fOrigin[2] += 10.0;
TR_TraceRayFilter(fOrigin, {-90.0,0.0,0.0}, MASK_PLAYERSOLID, RayType_Infinite, TraceRayNoPlayers, client);
if (TR_DidHit())
{
TR_GetEndPosition(fCeiling);
fOrigin[2] -= 10.0;
distanceF = GetVectorDistance(fOrigin, fCeiling);
}
//PrintToChatAll("Client: %d - %f", client,distanceF);
return distanceF;
}
public bool TraceRayNoPlayers(int entity, int mask, any data)
{
if(entity == data || (entity >= 1 && entity <= MaxClients))
{
return false;
}
return true;
}

View File

@ -0,0 +1,854 @@
/************************************************************************
*************************************************************************
Simple Chat Processor
Description:
Process chat and allows other plugins to manipulate chat.
*************************************************************************
*************************************************************************
This file is part of Simple Plugins project.
This plugin is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License, or
later version.
This plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this plugin. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************
*************************************************************************
File Information
$Id$
$Author$
$Revision$
$Date$
$LastChangedBy$
$LastChangedDate$
$URL$
$Copyright: (c) Simple Plugins 2008-2009$
*************************************************************************
*************************************************************************
*/
#include <sourcemod>
#undef REQUIRE_PLUGIN
#include <updater>
#define PLUGIN_VERSION "2.0.3"
#define SENDER_WORLD 0
#define MAXLENGTH_INPUT 128 // Inclues \0 and is the size of the chat input box.
#define MAXLENGTH_NAME 64 // This is backwords math to get compability. Sourcemod has it set at 32, but there is room for more.
#define MAXLENGTH_MESSAGE 256 // This is based upon the SDK and the length of the entire message, including tags, name, : etc.
#define CHATFLAGS_INVALID 0
#define CHATFLAGS_ALL (1 << 0)
#define CHATFLAGS_TEAM (1 << 1)
#define CHATFLAGS_SPEC (1 << 2)
#define CHATFLAGS_DEAD (1 << 3)
#define ADDSTRING(%1) SetTrieValue(g_hChatFormats, %1, 1)
#define UPDATE_URL "http://dl.dropboxusercontent.com/u/83581539/ChatProcessor/updater.txt"
enum eMods
{
GameType_Unknown,
GameType_AOC,
GameType_CSGO,
GameType_CSS,
GameType_DOD,
GameType_FF,
GameType_HIDDEN,
GameType_HL2DM,
GameType_INS,
GameType_L4D,
GameType_L4D2,
GameType_NEO,
GameType_SGTLS,
GameType_TF,
GameType_DM,
GameType_ZPS,
};
//new Handle:g_hDPArray = INVALID_HANDLE;
new eMods:g_CurrentMod;
new String:g_sGameName[eMods][32] =
{
"Unknown",
"Age of Chivalry",
"Counter-Strike: GO",
"Counter Strike",
"Day Of Defeat",
"Fortress Forever",
"Hidden: Source",
"Half Life 2: Deathmatch",
"Insurgency",
"Left 4 Dead",
"Left 4 Dead 2",
"Neotokyo",
"Stargate TLS",
"Team Fortress 2",
"Dark Messiah",
"Zombie Panic: Source"
};
new Handle:g_hChatFormats = INVALID_HANDLE;
new Handle:g_fwdOnChatMessage;
new bool:g_bSayText2;
new bool:g_bAutoUpdate;
new g_CurrentChatType = CHATFLAGS_INVALID;
public Plugin:myinfo =
{
name = "Simple Chat Processor (Redux)",
author = "Simple Plugins, Mini",
description = "Process chat and allows other plugins to manipulate chat.",
version = PLUGIN_VERSION,
url = "http://forums.alliedmods.net"
};
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
MarkNativeAsOptional("GetUserMessageType");
CreateNative("GetMessageFlags", Native_GetMessageFlags);
RegPluginLibrary("scp");
return APLRes_Success;
}
public OnPluginStart()
{
new Handle:conVar = CreateConVar("sm_scp_autoupdate", "1", "Is auto-update enabled?");
g_bAutoUpdate = GetConVarBool(conVar);
HookConVarChange(conVar, OnAutoUpdateChange);
g_CurrentMod = GetCurrentMod();
g_hChatFormats = CreateTrie();
LogMessage("[SCP] Recognized mod [%s].", g_sGameName[g_CurrentMod]);
/**
Hook the usermessage or error out if the mod doesn't support saytext2
*/
new UserMsg:umSayText2 = GetUserMessageId("SayText2");
if (umSayText2 != INVALID_MESSAGE_ID)
{
g_bSayText2 = true;
HookUserMessage(umSayText2, OnSayText2, true);
}
else
{
new UserMsg:umSayText = GetUserMessageId("SayText");
if (umSayText != INVALID_MESSAGE_ID)
{
if (g_CurrentMod != GameType_DOD)
{
SetFailState("Unsupported game");
}
g_bSayText2 = false;
HookUserMessage(umSayText, OnSayText, true);
}
else
{
LogError("[SCP] This mod appears not to support SayText2 or SayText. Plugin disabled.");
SetFailState("Error hooking usermessage saytext2 and saytext");
}
}
/**
Get mod type and load the correct translation file
*/
if (g_bSayText2)
{
decl String:sGameDir[32];
decl String:sTranslationFile[PLATFORM_MAX_PATH];
decl String:sTranslationLocation[PLATFORM_MAX_PATH];
GetGameFolderName(sGameDir, sizeof(sGameDir));
Format(sTranslationFile, sizeof(sTranslationFile), "scp.%s.phrases", sGameDir);
BuildPath(Path_SM, sTranslationLocation, sizeof(sTranslationLocation), "translations/%s.txt", sTranslationFile);
if (FileExists(sTranslationLocation))
{
LogMessage("[SCP] Loading translation file [%s].", sTranslationFile);
LoadTranslations(sTranslationFile);
if (!GetChatFormats(sTranslationLocation))
{
LogError("[SCP] Could not parse the translation file");
SetFailState("Could not parse the translation file");
}
}
else
{
LogError("[SCP] Translation file is not present");
SetFailState("Translation file is not present");
}
}
/**
Create the global forward for other plugins
*/
g_fwdOnChatMessage = CreateGlobalForward("OnChatMessage", ET_Hook, Param_CellByRef, Param_Cell, Param_String, Param_String);
//g_hDPArray = CreateArray();
}
public OnAutoUpdateChange(Handle:conVar, const String:oldVal[], const String:newVal[])
{
g_bAutoUpdate = bool:StringToInt(newVal);
}
/**
*
* Updater Stuff
* By Dr. McKay
* Edited by Mini
*
*/
public OnAllPluginsLoaded()
{
new Handle:convar;
if (LibraryExists("updater"))
{
Updater_AddPlugin(UPDATE_URL);
decl String:newVersion[10];
FormatEx(newVersion, sizeof(newVersion), "%sA", PLUGIN_VERSION);
convar = CreateConVar("scp_version", newVersion, "Plugin Version", FCVAR_DONTRECORD | FCVAR_NOTIFY | FCVAR_CHEAT);
}
else
{
convar = CreateConVar("scp_version", PLUGIN_VERSION, "Plugin Version", FCVAR_DONTRECORD | FCVAR_NOTIFY | FCVAR_CHEAT);
}
HookConVarChange(convar, Callback_VersionConVarChanged);
}
public Callback_VersionConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
ResetConVar(convar);
}
public OnLibraryAdded(const String:name[])
{
if (!strcmp(name, "updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
public Action:Updater_OnPluginDownloading()
{
if (!g_bAutoUpdate)
{
return Plugin_Handled;
}
return Plugin_Continue;
}
public Updater_OnPluginUpdated()
{
ReloadPlugin();
}
public Action:OnSayText2(UserMsg:msg_id, Handle:bf, const clients[], numClients, bool:reliable, bool:init)
{
/**
Get the sender of the usermessage and bug out if it is not a player
*/
new bool:bProtobuf = (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf);
new cpSender;
if (bProtobuf)
{
cpSender = PbReadInt(bf, "ent_idx");
}
else
{
cpSender = BfReadByte(bf);
}
if (cpSender == SENDER_WORLD)
{
return Plugin_Continue;
}
/**
Get the chat bool. This determines if sent to console as well as chat
*/
new bool:bChat;
if (bProtobuf)
{
bChat = PbReadBool(bf, "chat");
}
else
{
bChat = (BfReadByte(bf) ? true : false);
}
/**
Make sure we have a default translation string for the message
This also determines the message type...
*/
decl String:cpTranslationName[32];
new buffer;
if (bProtobuf)
{
PbReadString(bf, "msg_name", cpTranslationName, sizeof(cpTranslationName));
}
else
{
BfReadString(bf, cpTranslationName, sizeof(cpTranslationName));
}
if (!GetTrieValue(g_hChatFormats, cpTranslationName, buffer))
{
return Plugin_Continue;
}
else
{
if (StrContains(cpTranslationName, "all", false) != -1)
{
g_CurrentChatType = g_CurrentChatType | CHATFLAGS_ALL;
}
if (StrContains(cpTranslationName, "team", false) != -1
|| StrContains(cpTranslationName, "survivor", false) != -1
|| StrContains(cpTranslationName, "infected", false) != -1
|| StrContains(cpTranslationName, "Cstrike_Chat_CT", false) != -1
|| StrContains(cpTranslationName, "Cstrike_Chat_T", false) != -1)
{
g_CurrentChatType = g_CurrentChatType | CHATFLAGS_TEAM;
}
if (StrContains(cpTranslationName, "spec", false) != -1)
{
g_CurrentChatType = g_CurrentChatType | CHATFLAGS_SPEC;
}
if (StrContains(cpTranslationName, "dead", false) != -1)
{
g_CurrentChatType = g_CurrentChatType | CHATFLAGS_DEAD;
}
}
/**
Get the senders name
*/
decl String:cpSender_Name[MAXLENGTH_NAME];
if (bProtobuf)
{
PbReadString(bf, "params", cpSender_Name, sizeof(cpSender_Name), 0);
}
else if (BfGetNumBytesLeft(bf))
{
BfReadString(bf, cpSender_Name, sizeof(cpSender_Name));
}
/**
Get the message
*/
decl String:cpMessage[MAXLENGTH_INPUT];
if (bProtobuf)
{
PbReadString(bf, "params", cpMessage, sizeof(cpMessage), 1);
}
else if (BfGetNumBytesLeft(bf))
{
BfReadString(bf, cpMessage, sizeof(cpMessage));
}
/**
Store the clients in an array so the call can manipulate it.
*/
new Handle:cpRecipients = CreateArray();
for (new i = 0; i < numClients; i++)
{
PushArrayCell(cpRecipients, clients[i]);
}
/**
Because the message could be changed but not the name
we need to compare the original name to the returned name.
We do this because we may have to add the team color code to the name,
where as the message doesn't get a color code by default.
*/
decl String:sOriginalName[MAXLENGTH_NAME];
strcopy(sOriginalName, sizeof(sOriginalName), cpSender_Name);
/**
Start the forward for other plugins
*/
new Action:fResult;
Call_StartForward(g_fwdOnChatMessage);
Call_PushCellRef(cpSender);
Call_PushCell(cpRecipients);
Call_PushStringEx(cpSender_Name, sizeof(cpSender_Name), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushStringEx(cpMessage, sizeof(cpMessage), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
new fError = Call_Finish(fResult);
g_CurrentChatType = CHATFLAGS_INVALID;
if (fError != SP_ERROR_NONE)
{
ThrowNativeError(fError, "Forward failed");
CloseHandle(cpRecipients);
return Plugin_Continue;
}
else if (fResult == Plugin_Continue)
{
CloseHandle(cpRecipients);
return Plugin_Continue;
}
else if (fResult == Plugin_Stop)
{
CloseHandle(cpRecipients);
return Plugin_Handled;
}
/**
This is the check for a name change. If it has not changed we add the team color code
*/
if (StrEqual(sOriginalName, cpSender_Name))
{
Format(cpSender_Name, sizeof(cpSender_Name), "\x03%s", cpSender_Name);
}
/**
Create a timer to print the message on the next gameframe
*/
new Handle:cpPack;
CreateDataTimer(0.0, RebuildMessage, cpPack);
new numRecipients = GetArraySize(cpRecipients);
WritePackCell(cpPack, cpSender);
for (new i = 0; i < numRecipients; i++)
{
new x = GetArrayCell(cpRecipients, i);
if (!IsValidClient(x))
{
numRecipients--;
RemoveFromArray(cpRecipients, i);
}
}
WritePackCell(cpPack, numRecipients);
for (new i = 0; i < numRecipients; i++)
{
new x = GetArrayCell(cpRecipients, i);
WritePackCell(cpPack, x);
}
WritePackCell(cpPack, bChat);
WritePackString(cpPack, cpTranslationName);
WritePackString(cpPack, cpSender_Name);
WritePackString(cpPack, cpMessage);
//PushArrayCell(g_hDPArray, cpPack);
WritePackCell(cpPack, bProtobuf);
CloseHandle(cpRecipients);
/**
Stop the original message
*/
return Plugin_Handled;
}
public Action:OnSayText(UserMsg:msg_id, Handle:bf, const clients[], numClients, bool:reliable, bool:init)
{
/**
Get the sender of the usermessage and bug out if it is not a player
*/
new bool:bProtobuf = (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf);
new cpSender;
if (bProtobuf)
{
cpSender = PbReadInt(bf, "ent_idx");
}
else
{
cpSender = BfReadByte(bf);
}
if (cpSender == SENDER_WORLD)
{
return Plugin_Continue;
}
/**
Get the chat message
*/
decl String:message[MAXLENGTH_INPUT];
if (bProtobuf)
{
PbReadString(bf, "text", message, sizeof(message));
}
else
{
BfReadString(bf, message, sizeof(message));
}
/**
Get the chat bool. This determines if sent to console as well as chat
*/
if (!bProtobuf)
{
BfReadBool(bf);
}
/**
Store the clients in an array so the call can manipulate it.
*/
new Handle:cpRecipients = CreateArray();
for (new i = 0; i < numClients; i++)
{
PushArrayCell(cpRecipients, clients[i]);
}
decl String:prefix[64], String:senderName[MAX_NAME_LENGTH], String:textMessage[MAXLENGTH_MESSAGE], String:buffer[MAXLENGTH_INPUT];
GetClientName(cpSender, senderName, sizeof(senderName));
Format(buffer, sizeof(buffer), "%s:", senderName);
new pos = StrContains(message, buffer);
if (pos == 0)
{
prefix[0] = '\0';
}
else
{
Format(prefix, pos + 1, "%s ", message);
}
g_CurrentChatType = CHATFLAGS_INVALID;
if (StrContains(prefix, "(Team)") != -1)
{
g_CurrentChatType |= CHATFLAGS_TEAM;
}
if (GetClientTeam(cpSender) <= 1)
{
g_CurrentChatType |= CHATFLAGS_SPEC;
}
if (StrContains(prefix, "(Dead)") != -1)
{
g_CurrentChatType |= CHATFLAGS_DEAD;
}
if (g_CurrentChatType == CHATFLAGS_INVALID)
{
g_CurrentChatType = CHATFLAGS_ALL;
}
ReplaceString(message, sizeof(message), "\n", "");
strcopy(textMessage, sizeof(textMessage), message[pos + strlen(senderName) + 2]);
/**
Start the forward for other plugins
*/
new Action:fResult;
Call_StartForward(g_fwdOnChatMessage);
Call_PushCellRef(cpSender);
Call_PushCell(cpRecipients);
Call_PushStringEx(senderName, sizeof(senderName), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushStringEx(textMessage, sizeof(textMessage), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
new fError = Call_Finish(fResult);
g_CurrentChatType = CHATFLAGS_INVALID;
if (fError != SP_ERROR_NONE)
{
ThrowNativeError(fError, "Forward failed");
CloseHandle(cpRecipients);
return Plugin_Continue;
}
else if (fResult == Plugin_Continue)
{
CloseHandle(cpRecipients);
return Plugin_Continue;
}
else if (fResult >= Plugin_Handled)
{
CloseHandle(cpRecipients);
return Plugin_Handled;
}
GetClientName(cpSender, buffer, sizeof(buffer));
if (StrEqual(senderName, buffer))
{
Format(senderName, sizeof(senderName), "\x03%s", senderName);
}
/**
Create a timer to print the message on the next gameframe
*/
new Handle:cpPack;
CreateDataTimer(0.0, RebuildMessage, cpPack);
new numRecipients = GetArraySize(cpRecipients);
WritePackCell(cpPack, cpSender);
for (new i = 0; i < numRecipients; i++)
{
new x = GetArrayCell(cpRecipients, i);
if (!IsValidClient(x))
{
numRecipients--;
RemoveFromArray(cpRecipients, i);
}
}
WritePackCell(cpPack, numRecipients);
for (new i = 0; i < numRecipients; i++)
{
new x = GetArrayCell(cpRecipients, i);
WritePackCell(cpPack, x);
}
WritePackString(cpPack, prefix);
WritePackString(cpPack, senderName);
WritePackString(cpPack, textMessage);
//PushArrayCell(g_hDPArray, cpPack);
WritePackCell(cpPack, bProtobuf);
CloseHandle(cpRecipients);
/**
Stop the original message
*/
return Plugin_Handled;
}
public Action:RebuildMessage(Handle:timer, Handle:pack)
{
ResetPack(pack);
if (g_bSayText2)
{
new client = ReadPackCell(pack);
new numClientsStart = ReadPackCell(pack);
new numClientsFinish;
new clients[numClientsStart];
for (new x = 0; x < numClientsStart; x++)
{
new buffer = ReadPackCell(pack);
if (IsValidClient(buffer))
{
clients[numClientsFinish++] = buffer;
}
}
new bool:bChat = bool:ReadPackCell(pack);
decl String:sChatType[32];
decl String:sSenderName[MAXLENGTH_NAME];
decl String:sMessage[MAXLENGTH_INPUT];
ReadPackString(pack, sChatType, sizeof(sChatType));
ReadPackString(pack, sSenderName, sizeof(sSenderName));
ReadPackString(pack, sMessage, sizeof(sMessage));
decl String:sTranslation[MAXLENGTH_MESSAGE];
Format(sTranslation, sizeof(sTranslation), " %t", sChatType, sSenderName, sMessage);
new Handle:bf = StartMessage("SayText2", clients, numClientsFinish, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
if (ReadPackCell(pack))
{
PbSetInt(bf, "ent_idx", client);
PbSetBool(bf, "chat", bChat);
PbSetString(bf, "msg_name", sTranslation);
PbAddString(bf, "params", "");
PbAddString(bf, "params", "");
PbAddString(bf, "params", "");
PbAddString(bf, "params", "");
}
else
{
BfWriteByte(bf, client);
BfWriteByte(bf, bChat);
BfWriteString(bf, sTranslation);
}
EndMessage();
}
else
{
new client = ReadPackCell(pack);
new numClientsStart = ReadPackCell(pack);
new numClientsFinish;
new clients[numClientsStart];
for (new x = 0; x < numClientsStart; x++)
{
new buffer = ReadPackCell(pack);
if (IsValidClient(buffer))
{
clients[numClientsFinish++] = buffer;
}
}
decl String:sPrefix[MAXLENGTH_NAME];
decl String:sSenderName[MAXLENGTH_NAME];
decl String:sMessage[MAXLENGTH_INPUT];
ReadPackString(pack, sPrefix, sizeof(sPrefix));
ReadPackString(pack, sSenderName, sizeof(sSenderName));
ReadPackString(pack, sMessage, sizeof(sMessage));
decl String:message[MAXLENGTH_MESSAGE];
new teamColor;
switch (GetClientTeam(client))
{
case 0, 1:teamColor = 0xCCCCCC;
case 2:teamColor = 0x4D7942;
case 3:teamColor = 0xFF4040;
}
decl String:buffer[32];
Format(buffer, sizeof(buffer), "\x07%06X", teamColor);
ReplaceString(sSenderName, sizeof(sSenderName), "\x03", buffer);
ReplaceString(sMessage, sizeof(sMessage), "\x03", buffer);
Format(message, sizeof(message), "\x01%s%s\x01: %s", sPrefix, sSenderName, sMessage);
PrintToServer(message);
for (new j = 0; j < numClientsFinish; j++)
{
PrintToChat(clients[j], "%s", message);
}
}
//CloseHandle(pack);
//RemoveFromArray(g_hDPArray, i);
}
public Native_GetMessageFlags(Handle:plugin, numParams)
{
return g_CurrentChatType;
}
stock bool:IsValidClient(client, bool:nobots = true)
{
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
{
return false;
}
return IsClientInGame(client);
}
stock bool:GetChatFormats(const String:file[])
{
new Handle:hParser = SMC_CreateParser();
new String:error[128];
new line = 0;
new col = 0;
SMC_SetReaders(hParser, Config_NewSection, Config_KeyValue, Config_EndSection);
SMC_SetParseEnd(hParser, Config_End);
new SMCError:result = SMC_ParseFile(hParser, file, line, col);
CloseHandle(hParser);
if (result != SMCError_Okay)
{
SMC_GetErrorString(result, error, sizeof(error));
LogError("%s on line %d, col %d of %s", error, line, col, file);
}
return (result == SMCError_Okay);
}
public SMCResult:Config_NewSection(Handle:parser, const String:section[], bool:quotes)
{
if (StrEqual(section, "Phrases"))
{
return SMCParse_Continue;
}
ADDSTRING(section);
return SMCParse_Continue;
}
public SMCResult:Config_KeyValue(Handle:parser, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
{
return SMCParse_Continue;
}
public SMCResult:Config_EndSection(Handle:parser)
{
return SMCParse_Continue;
}
public Config_End(Handle:parser, bool:halted, bool:failed)
{
//nothing
}
stock eMods:GetCurrentMod()
{
decl String:sGameType[64];
GetGameFolderName(sGameType, sizeof(sGameType));
if (StrEqual(sGameType, "aoc", false))
{
return GameType_AOC;
}
if (StrEqual(sGameType, "csgo", false))
{
return GameType_CSGO;
}
if (StrEqual(sGameType, "cstrike", false))
{
return GameType_CSS;
}
if (StrEqual(sGameType, "dod", false))
{
return GameType_DOD;
}
if (StrEqual(sGameType, "ff", false))
{
return GameType_FF;
}
if (StrEqual(sGameType, "hidden", false))
{
return GameType_HIDDEN;
}
if (StrEqual(sGameType, "hl2mp", false))
{
return GameType_HL2DM;
}
if (StrEqual(sGameType, "insurgency", false) || StrEqual(sGameType, "ins", false))
{
return GameType_INS;
}
if (StrEqual(sGameType, "left4dead", false) || StrEqual(sGameType, "l4d", false))
{
return GameType_L4D;
}
if (StrEqual(sGameType, "left4dead2", false) || StrEqual(sGameType, "l4d2", false))
{
return GameType_L4D2;
}
if (StrEqual(sGameType, "nts", false))
{
return GameType_NEO;
}
if (StrEqual(sGameType, "sgtls", false))
{
return GameType_SGTLS;
}
if (StrEqual(sGameType, "tf", false))
{
return GameType_TF;
}
if (StrEqual(sGameType, "zps", false))
{
return GameType_ZPS;
}
if (StrEqual(sGameType, "mmdarkmessiah", false))
{
return GameType_DM;
}
LogMessage("Unknown Game Folder: %s", sGameType);
return GameType_Unknown;
}

View File

@ -0,0 +1,384 @@
#include <sourcemod>
#include <scp>
public Plugin myinfo =
{
name = "Tags",
author = "Pan32",
description = "Saves text & color",
version = "3.1.0",
url = ""
}
#define MAXTAGSIZE 20
#define VIPFLAG ADMFLAG_RESERVATION
Handle g_hDatabase = INVALID_HANDLE;
int g_iChatColor[MAXPLAYERS+1];
int g_iNameColor[MAXPLAYERS+1];
char g_colortags[][] = {"{white}", "{darkred}", "{teamcolor}", "{green}", "{lightgreen}", "{lime}", "{red}", "{gray}", "{yellow}", "{clearblue}", "{lightblue}", "{blue}", "{cleargray}", "{purple}", "{darkorange}", "{orange}"};
char g_colors[][] = {"\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F", "\x10"};
char g_colornames[][] = { "White/None", "Dark Red", "Teamcolor", "Green", "Light Green", "Lime", "Red", "Gray", "Yellow", "Clear Blue", "Light Blue", "Blue", "Clear Gray", "Purple", "Dark Orange", "Orange" };
char g_tags[MAXPLAYERS+1][MAXTAGSIZE];
public void OnPluginStart()
{
LoadTranslations("common.phrases");
SQL_TConnect(OnSQLConnect, "tags");
RegAdminCmd("sm_chatcolor", Command_ColorsMenu, VIPFLAG, "Brings up the colors menu");
RegAdminCmd("sm_chatcolors", Command_ColorsMenu, VIPFLAG, "Brings up the colors menu");
RegAdminCmd("sm_colors", Command_ColorsMenu, VIPFLAG, "Brings up the colors menu");
RegAdminCmd("sm_namecolors", Command_NameColorsMenu, VIPFLAG, "Set name color");
RegAdminCmd("sm_namecolor", Command_NameColorsMenu, VIPFLAG, "Set name color");
RegAdminCmd("sm_settag", Command_SetTag, VIPFLAG, "Set tag");
RegAdminCmd("sm_colortags", Command_ColorTags, VIPFLAG, "Displays all available color tags");
for (new i = 1; i < MAXPLAYERS+1; i++)
{
g_iChatColor[i] = 0;
g_iNameColor[i] = 2;
}
}
public void OnClientPostAdminCheck(int client)
{
if (!IsFakeClient(client))
{
char query[512];
char steamid[32];
GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
Format(query, sizeof(query), "SELECT * FROM csgo_tagsncolors WHERE steamid='%s';", steamid);
Handle result = SQL_Query(g_hDatabase, query);
if (result == INVALID_HANDLE)
{
SetFailState("[Tags] Lost connection to database. Reconnecting on map change.");
}
else
{
if (SQL_MoreRows(result))
{
if (SQL_FetchRow(result))
{
g_iChatColor[client] = SQL_FetchInt(result, 1);
SQL_FetchString(result, 2, g_tags[client], MAXTAGSIZE);
g_iNameColor[client] = SQL_FetchInt(result, 3);
}
}
else
{
g_tags[client][0] = '\0';
g_iChatColor[client] = 0;
g_iNameColor[client] = 2;
}
CloseHandle(result);
}
}
}
public Action Command_SetTag(int client, int args)
{
if (client == 0)
return Plugin_Handled;
if (!args)
{
ReplyToCommand(client, " \x06[Unloze] \x01Check console for output");
PrintSetTagInfo(client);
return Plugin_Handled;
}
char argument[128];
bool isEmpty = false;
GetCmdArgString(argument, sizeof(argument));
if (StrContains(argument, "%s", false) > -1)
ReplaceString(argument, sizeof(argument), "%s", "", false);
if (StrEqual(argument, "none", false))
{
Format(argument, sizeof(argument), "");
isEmpty = true
}
else
CFormat(argument, sizeof(argument));
Format(g_tags[client], MAXTAGSIZE, "%s", argument);
char safetag[2 * MAXTAGSIZE + 1];
char query[1024];
char steamid[64];
SQL_EscapeString(g_hDatabase, g_tags[client], safetag, 2 * strlen(g_tags[client]) + 1);
GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
Format(query, sizeof(query), "INSERT INTO csgo_tagsncolors (steamid, tag) VALUES('%s', '%s') ON DUPLICATE KEY UPDATE tag='%s';", steamid, safetag, safetag);
SQL_Query(g_hDatabase, query);
if (isEmpty)
PrintToChat(client, " \x06[Unloze] \x01You removed your tag.");
else
PrintToChat(client, " \x06[Unloze] \x01Your tag was set to \"%s\x01\".", g_tags[client]);
return Plugin_Handled;
}
public void CFormat(char[] tag, int maxlength)
{
for (new i = 0; i < sizeof(g_colortags); i++)
{
/* If tag not found - skip */
if (StrContains(tag, g_colortags[i], false) == -1)
continue;
else
ReplaceString(tag, maxlength, g_colortags[i], g_colors[i], false);
}
}
public void InvCFormat(char[] tag, int maxlength)
{
for (new i = 0; i < sizeof(g_colors); i++)
{
/* If tag not found - skip */
if (StrContains(tag, g_colors[i], false) == -1)
continue;
else
ReplaceString(tag, maxlength, g_colors[i], g_colortags[i], false);
}
}
void PrintSetTagInfo(int client)
{
char currenttag[128];
char colorbuffer[256];
strcopy(currenttag, sizeof(currenttag), g_tags[client]);
InvCFormat(currenttag, sizeof(currenttag));
for (new i = 0; i < sizeof(g_colortags); i++)
{
Format(colorbuffer, sizeof(colorbuffer), "%s%s ", colorbuffer, g_colortags[i]);
}
PrintToConsole(client, "//////////////////////////////////////////////////////////////////////////");
PrintToConsole(client, "Usage: sm_settag [arg]");
PrintToConsole(client, "To disable the tag, type \"sm_settag none\"");
PrintToConsole(client, " ");
PrintToConsole(client, "Available colors: %s", colorbuffer);
PrintToConsole(client, "Type sm_colortags to see these tags on chat");
PrintToConsole(client, " ");
PrintToConsole(client, "Your current tag is \"%s\"", currenttag);
PrintToConsole(client, "//////////////////////////////////////////////////////////////////////////");
}
public Action Command_ColorTags(int client, int args)
{
char buffer[256];
for (new i = 0; i < sizeof(g_colors); i++)
{
Format(buffer, sizeof(buffer), "%s%s%s ", buffer, g_colors[i], g_colortags[i]);
}
PrintToChat(client, " %s", buffer);
}
public Action Command_ColorsMenu(int client, int args)
{
if (client == 0)
return Plugin_Handled;
SubColorsMenu(client);
return Plugin_Handled;
}
public Action Command_NameColorsMenu(int client, int args)
{
if (client == 0)
return Plugin_Handled;
Menu menu = new Menu(NameColorsHandler);
menu.SetTitle("Select a color:\n");
for (new i = 0; i < sizeof(g_colornames); i++)
{
if (i == g_iNameColor[client])
{
char buffer[32];
Format(buffer, sizeof(buffer), "%s (Current)", g_colornames[i]);
menu.AddItem("", buffer, ITEMDRAW_DISABLED);
}
else
menu.AddItem("", g_colornames[i]);
}
menu.ExitButton = true;
menu.Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public int NameColorsHandler(Handle menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[32];
bool found = GetMenuItem(menu, param2, info, sizeof(info));
if (found == true)
{
g_iNameColor[param1] = param2;
char query[512];
char steamid[32];
GetClientAuthId(param1, AuthId_Steam2, steamid, sizeof(steamid));
Format(query, sizeof(query), "SELECT * FROM csgo_tagsncolors WHERE steamid='%s';", steamid);
Handle result = SQL_Query(g_hDatabase, query);
if (result == INVALID_HANDLE)
{
SetFailState("[Tags] Lost connection to database. Reconnecting on map change.");
}
else
{
if (SQL_MoreRows(result)) // if it fetches the row, they are a supporter, grab their data and load it
{
Format(query, sizeof(query), "UPDATE csgo_tagsncolors SET namecolor=%d WHERE steamid='%s';", g_iNameColor[param1], steamid);
SQL_Query(g_hDatabase, query);
}
else // if not, add them
{
Format(query, sizeof(query), "INSERT INTO csgo_tagsncolors (steamid, namecolor) VALUES('%s', %d);", steamid, g_iNameColor[param1]);
SQL_Query(g_hDatabase, query);
}
CloseHandle(result);
}
PrintToChat(param1, " \x06[Unloze] \x01Your name color was set to %s%s\x01.", g_colors[g_iNameColor[param1]], g_colornames[g_iNameColor[param1]]);
}
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public void SubColorsMenu(int client)
{
Menu menu = new Menu(SubColorsHandler);
menu.SetTitle("Select a color:\n");
for (new i = 0; i < sizeof(g_colornames); i++)
{
if (i == g_iChatColor[client])
{
char buffer[32];
Format(buffer, sizeof(buffer), "%s (Current)", g_colornames[i]);
menu.AddItem("", buffer, ITEMDRAW_DISABLED);
}
else
menu.AddItem("", g_colornames[i]);
}
menu.ExitButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int SubColorsHandler(Handle menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[32];
bool found = GetMenuItem(menu, param2, info, sizeof(info));
if (found == true)
{
g_iChatColor[param1] = param2;
char query[512];
char steamid[32];
GetClientAuthId(param1, AuthId_Steam2, steamid, sizeof(steamid));
Format(query, sizeof(query), "SELECT * FROM csgo_tagsncolors WHERE steamid='%s';", steamid);
Handle result = SQL_Query(g_hDatabase, query);
if (result == INVALID_HANDLE)
{
SetFailState("[Tags] Lost connection to database. Reconnecting on map change.");
}
else
{
if (SQL_MoreRows(result)) // if it fetches the row, they are a supporter, grab their data and load it
{
Format(query, sizeof(query), "UPDATE csgo_tagsncolors SET color=%d WHERE steamid='%s';", g_iChatColor[param1], steamid);
SQL_Query(g_hDatabase, query);
}
else // if not, add them
{
Format(query, sizeof(query), "INSERT INTO csgo_tagsncolors (steamid, color) VALUES('%s', %d);", steamid, g_iChatColor[param1]);
SQL_Query(g_hDatabase, query);
}
CloseHandle(result);
}
PrintToChat(param1, " \x06[Unloze] \x01Your chat color was set to %s%s\x01.", g_colors[g_iChatColor[param1]], g_colornames[g_iChatColor[param1]]);
}
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public Action OnChatMessage(int &client, Handle recipients, char[] name, char[] message)
{
if (!CheckCommandAccess(client, "sm_colors", VIPFLAG))
return Plugin_Continue;
char namecopy[MAX_NAME_LENGTH];
Format(namecopy, MAX_NAME_LENGTH, "%s%s", g_colors[g_iNameColor[client]], name);
if (strlen(g_tags[client]))
{
Format(namecopy, MAX_NAME_LENGTH, "%s%s", g_tags[client], namecopy);
}
strcopy(name, MAX_NAME_LENGTH, namecopy);
if (g_iChatColor[client] >= 0)
{
char copy[MAXLENGTH_INPUT];
copy = g_colors[g_iChatColor[client]];
StrCat(copy, MAXLENGTH_INPUT, message);
strcopy(message, MAXLENGTH_INPUT, copy);
}
return Plugin_Changed;
}
public void OnSQLConnect(Handle owner, Handle hndl, const char[] error, any:data)
{
if(hndl == INVALID_HANDLE || strlen(error) > 0)
{
SetFailState("[Tags] Lost connection to database. Reconnecting on map change. Error: %s", error);
}
g_hDatabase = hndl;
SQL_TQuery(g_hDatabase, SQL_DoNothing, "CREATE TABLE IF NOT EXISTS csgo_tagsncolors (steamid VARCHAR(32) PRIMARY KEY, color INTEGER DEFAULT '0', tag VARCHAR(32) DEFAULT '', namecolor INTEGER DEFAULT '2');");
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && IsClientAuthorized(i))
{
OnClientPostAdminCheck(i);
}
}
}
public void SQL_DoNothing(Handle owner, Handle hndl, const char[] error, any:data)
{
if (hndl == INVALID_HANDLE || strlen(error) > 0)
{
SetFailState("[Tags] Lost connection to database. Reconnecting on map change. Error: %s", error);
}
}

View File

@ -0,0 +1,53 @@
"Phrases"
{
"Cstrike_Chat_CT_Loc"
{
"#format" "{1:s},{2:s}"
"en" "(Counter-Terrorist) {1}: {2}"
}
"Cstrike_Chat_CT"
{
"#format" "{1:s},{2:s}"
"en" "(Counter-Terrorist) {1}: {2}"
}
"Cstrike_Chat_T_Loc"
{
"#format" "{1:s},{2:s}"
"en" "(Terrorist) {1}: {2}"
}
"Cstrike_Chat_T"
{
"#format" "{1:s},{2:s}"
"en" "(Terrorist) {1}: {2}"
}
"Cstrike_Chat_CT_Dead"
{
"#format" "{1:s},{2:s}"
"en" "*DEAD*(Counter-Terrorist) {1}: {2}"
}
"Cstrike_Chat_T_Dead"
{
"#format" "{1:s},{2:s}"
"en" "*DEAD*(Terrorist) {1}: {2}"
}
"Cstrike_Chat_Spec"
{
"#format" "{1:s},{2:s}"
"en" "(Spectator) {1}: {2}"
}
"Cstrike_Chat_All"
{
"#format" "{1:s},{2:s}"
"en" "{1}: {2}"
}
"Cstrike_Chat_AllDead"
{
"#format" "{1:s},{2:s}"
"en" "*DEAD* {1}: {2}"
}
"Cstrike_Chat_AllSpec"
{
"#format" "{1:s},{2:s}"
"en" "*SPEC* {1}: {2}"
}
}

View File

@ -0,0 +1,829 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
//material
int g_iBeam = -1;
//zonepoints
char c_storestats[MAXPLAYERS+1][1024];
//drawing
int b_beamcolor[MAXPLAYERS];
float aimpos[MAXPLAYERS][3];
float beamangle[MAXPLAYERS];
float g_fClientDurationPref[MAXPLAYERS];
int colorrainbow[MAXPLAYERS][4];
int clientcolors[MAXPLAYERS][4];
int g_iClients[MAXPLAYERS];
int client_count;
bool b_beamhiding[MAXPLAYERS];
public Plugin myinfo =
{
name = "unloze shop beams",
author = PLUGIN_AUTHOR,
description = "beams purchaseable in the shop",
version = PLUGIN_VERSION,
url = "www.unloze.com"
};
public void OnPluginStart()
{
AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vmt");
AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vtf");
RegConsoleCmd("sm_beamers", cmd_beamPoint, "Enables beams through shop");
RegConsoleCmd("sm_beams", cmd_beamPoint, "Enables beams through shop");
RegConsoleCmd("sm_beam", cmd_beamPoint, "Enables beams through shop");
RegConsoleCmd("sm_hidebeam", cmd_beamPointHide, "Hides beams for the client");
RegConsoleCmd("sm_beamsize", cmd_beamPointangle, "Changes the BeamSize");
RegConsoleCmd("sm_beamtime", cmd_beamPointDuration, "Changes the BeamSize");
RegAdminCmd("sm_beammysql", cmd_beammysqltest, ADMFLAG_ROOT);
SQL_StartConnection();
//0.1 is not good enough
//CreateTimer(0.1, beamTesendDelay, INVALID_HANDLE, TIMER_REPEAT);
}
public Action cmd_beammysqltest(int client, int args)
{
CheckbeamprefHideMYSQL(client);
}
public Action cmd_beamPointDuration(int client, int args)
{
char number[5];
float check;
GetCmdArg(args, number, sizeof(number));
check = StringToFloat(number);
if (check > 5.0 || check < 0.1)
{
PrintToChat(client, "Input Range 0.1 - 5.0");
return Plugin_Handled;
}
g_fClientDurationPref[client] = check;
PrintToChat(client, "beamDuration value: %f", g_fClientDurationPref[client]);
MySQLStoreBeamDurationPref(client, check);
return Plugin_Handled;
}
public Action cmd_beamPointangle(int client, int args)
{
char number[5];
float check;
GetCmdArg(args, number, sizeof(number));
check = StringToFloat(number);
if (check > 20.0 || check < 0.1)
{
PrintToChat(client, "Input Range 0.1 - 20.0");
return Plugin_Handled;
}
beamangle[client] = check;
PrintToChat(client, "beamangle value: %f", beamangle[client]);
MySQLStoreBeamSizePref(client, check);
return Plugin_Handled;
}
public Action cmd_beamPointHide( int client, int args )
{
if (!b_beamhiding[client])
{
mysqlentryhidebeam(client, 1);
PrintToChat(client, "[UNLOZE] Disabled beams!");
b_beamhiding[client] = true;
}
else
{
mysqlentryhidebeam(client, 0);
PrintToChat(client, "[UNLOZE] Enabled beams!");
b_beamhiding[client] = false;
}
ClientCount();
return Plugin_Handled;
}
public Action cmd_beamPoint( int client, int args )
{
Menu menu = new Menu(MenuHandler1);
menu.SetTitle("UNLOZE Beams are unlocked through !shop");
menu.AddItem("Disable", "Disable");
if (StrContains(c_storestats[client], "w") >= 0)
{
menu.AddItem("Rainbow Beam", "Rainbow Beam");
}
if (StrContains(c_storestats[client], "v") >= 0)
{
menu.AddItem("Blue Beam", "Blue Beam");
}
if (StrContains(c_storestats[client], "x") >= 0)
{
menu.AddItem("Green Beam", "Green Beam");
}
if (StrContains(c_storestats[client], "y") >= 0)
{
menu.AddItem("Red Beam", "Red Beam");
}
if (StrContains(c_storestats[client], "z") >= 0)
{
menu.AddItem("Gold Beam", "Gold Beam");
}
if (StrContains(c_storestats[client], "3") >= 0)
{
menu.AddItem("Black Beam", "Black Beam");
}
if (StrContains(c_storestats[client], "4") >= 0)
{
menu.AddItem("Cyan Beam", "Cyan Beam");
}
if (StrContains(c_storestats[client], "5") >= 0)
{
menu.AddItem("Turquoise Beam", "Turquoise Beam");
}
if (StrContains(c_storestats[client], "6") >= 0)
{
menu.AddItem("Yellow Beam", "Yellow Beam");
}
if (StrContains(c_storestats[client], "7") >= 0)
{
menu.AddItem("Pink Beam", "Pink Beam");
}
if (StrContains(c_storestats[client], "8") >= 0)
{
menu.AddItem("Purple Beam", "Purple Beam");
}
if (StrContains(c_storestats[client], "9") >= 0)
{
menu.AddItem("gray Beam", "gray Beam");
}
menu.ExitButton = true;
menu.Display(client, 0);
return Plugin_Handled;
}
public int MenuHandler1(Menu menu, MenuAction action, int param1, int choice)
{
/* If the menu was cancelled, print a message to the server about it. */
if (action == MenuAction_Cancel)
{
PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, choice);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_Select)
{
char info[32];
menu.GetItem(choice, info, sizeof(info));
if (StrEqual(info, "Blue Beam", true))
{
PrintToChat(param1, "Selected Blue Beam!");
b_beamcolor[param1] = 1;
}
else if (StrEqual(info, "Red Beam", true))
{
PrintToChat(param1, "Selected Red Beam!");
b_beamcolor[param1] = 2;
}
else if (StrEqual(info, "Green Beam", true))
{
PrintToChat(param1, "Selected Green Beam!");
b_beamcolor[param1] = 3;
}
else if (StrEqual(info, "Gold Beam", true))
{
PrintToChat(param1, "Selected Gold Beam!");
b_beamcolor[param1] = 4;
}
else if (StrEqual(info, "Black Beam", true))
{
PrintToChat(param1, "Selected Black Beam!");
b_beamcolor[param1] = 5;
}
else if (StrEqual(info, "Cyan Beam", true))
{
PrintToChat(param1, "Selected Cyan Beam!");
b_beamcolor[param1] = 6;
}
else if (StrEqual(info, "Turquoise Beam", true))
{
PrintToChat(param1, "Selected Turquoise Beam!");
b_beamcolor[param1] = 7;
}
else if (StrEqual(info, "Yellow Beam", true))
{
PrintToChat(param1, "Selected Yellow Beam!");
b_beamcolor[param1] = 8;
}
else if (StrEqual(info, "Pink Beam", true))
{
PrintToChat(param1, "Selected Pink Beam!");
b_beamcolor[param1] = 9;
}
else if (StrEqual(info, "Purple Beam", true))
{
PrintToChat(param1, "Selected Purple Beam!");
b_beamcolor[param1] = 10;
}
else if (StrEqual(info, "gray Beam", true))
{
PrintToChat(param1, "Selected gray Beam!");
b_beamcolor[param1] = 11;
}
else if (StrEqual(info, "Rainbow Beam", true))
{
PrintToChat(param1, "Selected Rainbow Beam!");
b_beamcolor[param1] = 12;
}
else if (StrEqual(info, "Disable", true))
{
PrintToChat(param1, "Disabled Beam!");
b_beamcolor[param1] = 0;
}
InsertbeamprefMYSQL(param1, b_beamcolor[param1]);
}
}
public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2])
{
if (!IsValidClient(client) || !IsPlayerAlive(client) || client_count < 1)
{
return Plugin_Continue;
}
if (b_beamcolor[client] == 0)
{
return Plugin_Continue;
}
//blue
if (b_beamcolor[client] == 1)
{
clientcolors[client][0] = 0;
clientcolors[client][1] = 0;
clientcolors[client][2] = 255;
}
//red
else if (b_beamcolor[client] == 2)
{
clientcolors[client][0] = 255;
clientcolors[client][1] = 0;
clientcolors[client][2] = 0;
}
//green
else if (b_beamcolor[client] == 3)
{
clientcolors[client][0] = 0;
clientcolors[client][1] = 255;
clientcolors[client][2] = 0;
}
//gold
else if (b_beamcolor[client] == 4)
{
clientcolors[client][0] = 255;
clientcolors[client][1] = 215;
clientcolors[client][2] = 0;
}
//black
else if (b_beamcolor[client] == 5)
{
clientcolors[client][0] = 0;
clientcolors[client][1] = 0;
clientcolors[client][2] = 0;
}
//cyan
else if (b_beamcolor[client] == 6)
{
clientcolors[client][0] = 0;
clientcolors[client][1] = 255;
clientcolors[client][2] = 255;
}
//turqouise
else if (b_beamcolor[client] == 7)
{
clientcolors[client][0] = 64;
clientcolors[client][1] = 224;
clientcolors[client][2] = 208;
}
//yellow
else if (b_beamcolor[client] == 8)
{
clientcolors[client][0] = 255;
clientcolors[client][1] = 255;
clientcolors[client][2] = 0;
}
//pink
else if (b_beamcolor[client] == 9)
{
clientcolors[client][0] = 255;
clientcolors[client][1] = 105;
clientcolors[client][2] = 180;
}
//purple
else if (b_beamcolor[client] == 10)
{
clientcolors[client][0] = 128;
clientcolors[client][1] = 0;
clientcolors[client][2] = 128;
}
//gray
else if (b_beamcolor[client] == 11)
{
clientcolors[client][0] = 128;
clientcolors[client][1] = 128;
clientcolors[client][2] = 128;
}
//rainbow
else if (b_beamcolor[client] == 12)
{
int ran;
ran = GetRandomInt(0, 2);
colorrainbow[client][ran] -= 1;
if (colorrainbow[client][0] < 1)
{
colorrainbow[client][0] = 255;
}
if (colorrainbow[client][1] < 1)
{
colorrainbow[client][1] = 255;
}
if (colorrainbow[client][2] < 1)
{
colorrainbow[client][2] = 255;
}
}
float otherhalf;
otherhalf -= beamangle[client];
GetClientAbsOrigin(client, aimpos[client]);
if (b_beamcolor[client] == 12)
{
Circle(aimpos[client], beamangle[client], g_iBeam, client, colorrainbow[client]);
Circle(aimpos[client], otherhalf, g_iBeam, client, colorrainbow[client]);
}
else
{
Circle(aimpos[client], beamangle[client], g_iBeam, client, clientcolors[client]);
Circle(aimpos[client], otherhalf, g_iBeam, client, clientcolors[client]);
}
return Plugin_Continue;
}
//----------------------------------------------------------------------------------------------------
// Purpose: Mapstart
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{
g_iBeam = PrecacheModel("materials/unloze_tracers/xbeam.vmt");
}
public void OnClientDisconnect_Post(int client)
{
ClientCount();
}
//actually used on each mapchange according to mitchell
public void OnClientDisconnect (int client)
{
Format(c_storestats[client], sizeof(c_storestats), "");
beamangle[client] = 0.0;
b_beamcolor[client] = 0;
aimpos[client][0] = 0.0;
aimpos[client][1] = 0.0;
aimpos[client][2] = 0.0;
colorrainbow[client][0] = 255;
colorrainbow[client][1] = 255;
colorrainbow[client][2] = 255;
colorrainbow[client][3] = 255;
clientcolors[client][0] = 255;
clientcolors[client][1] = 255;
clientcolors[client][2] = 255;
clientcolors[client][3] = 255;
b_beamhiding[client] = false;
g_fClientDurationPref[client] = 1.0;
//IsClientConnected(client) && IsClientInGame(client) would be true here
}
public void OnClientPostAdminCheck(int client)
{
beamangle[client] = 5.0;
b_beamhiding[client] = false;
aimpos[client][0] = 0.0;
aimpos[client][1] = 0.0;
aimpos[client][2] = 0.0;
b_beamcolor[client] = 0;
colorrainbow[client][0] = 255;
colorrainbow[client][1] = 255;
colorrainbow[client][2] = 255;
colorrainbow[client][3] = 255;
clientcolors[client][0] = 255;
clientcolors[client][1] = 255;
clientcolors[client][2] = 255;
clientcolors[client][3] = 255;
g_fClientDurationPref[client] = 1.0;
CheckbeamSizeMYSQL(client);
CheckBeamDurationMYSQL(client);
CheckFlagsMYSQL(client);
CheckbeamprefMYSQL(client);
CheckbeamprefHideMYSQL(client);
}
stock void ClientCount()
{
client_count = 0;
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i) && !b_beamhiding[i])
{
g_iClients[client_count++] = i;
}
}
}
public void MySQLStoreBeamDurationPref(int client, float check)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beampref2` (`steam_id`, `Duration`) VALUES ('%s','%f') ON DUPLICATE KEY UPDATE `Duration` = '%f'", sSID, check, check);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void MySQLStoreBeamSizePref(int client, float check)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beampref2` (`steam_id`, `size`) VALUES ('%s','%f') ON DUPLICATE KEY UPDATE `size` = '%f'", sSID, check, check);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void CheckBeamDurationMYSQL(int client)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT Duration FROM `unloze_beampref2` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (rs.RowCount > 0 && rs.FetchRow())
{
char l_cSize[4];
SQL_FetchString(rs, 0, l_cSize, sizeof(l_cSize));
g_fClientDurationPref[client] = StringToFloat(l_cSize);
if (g_fClientDurationPref[client] == 0.0)
{
g_fClientDurationPref[client] = 1.0;
}
}
delete rs;
delete db;
}
public void CheckbeamSizeMYSQL(int client)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT size FROM `unloze_beampref2` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (rs.RowCount > 0 && rs.FetchRow())
{
char l_cSize[4];
SQL_FetchString(rs, 0, l_cSize, sizeof(l_cSize));
beamangle[client] = StringToFloat(l_cSize);
}
delete rs;
delete db;
}
public void CheckFlagsMYSQL(int client)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT storestats FROM `unloze_zonepoints` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (rs.RowCount > 0 && rs.FetchRow())
{
SQL_FetchString(rs, 0, c_storestats[client], sizeof(c_storestats));
}
delete rs;
delete db;
}
public void CheckbeamprefHideMYSQL(int client)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB CheckbeamprefHideMYSQL!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT hide FROM `unloze_beamprefhide` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs1;
if ((rs1 = SQL_Query(db, sQuery)) == null)
{
//PrintToChatAll("Failed, null result");
delete db;
delete rs1;
return;
}
if (rs1.RowCount > 0 && rs1.FetchRow())
{
//PrintToChatAll("Has Entry");
int translate;
translate = SQL_FetchInt(rs1, 0);
if (translate == 1)
{
b_beamhiding[client] = true;
delete db;
delete rs1;
return;
}
}
ClientCount();
delete rs1;
delete db;
}
public void CheckbeamprefMYSQL(int client)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT beam FROM `unloze_beampref` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (rs.RowCount > 0 && rs.FetchRow())
{
char translate[124];
SQL_FetchString(rs, 0, translate[client], MAX_NAME_LENGTH);
b_beamcolor[client] = StringToInt(translate[client]);
}
delete rs;
delete db;
}
public void InsertbeamprefMYSQL(int client, int colornumber)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beampref` (`steam_id`, `beam`) VALUES ('%s','%i') ON DUPLICATE KEY UPDATE `beam` = '%i'", sSID, colornumber, colornumber);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void mysqlentryhidebeam(int client, int hide)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beamprefhide` (`steam_id`, `hide`) VALUES ('%s','%i') ON DUPLICATE KEY UPDATE `hide` = '%i'", sSID, hide, hide);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void SQL_StartConnection()
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
//create tables
char sQuery[255];
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_beampref` (`steam_id` VARCHAR(254) NOT NULL, `beam` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_beamprefhide` (`steam_id` VARCHAR(254) NOT NULL, `hide` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_beampref2` (`steam_id` VARCHAR(254) NOT NULL, `size` VARCHAR(254) NOT NULL, `Duration` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
//old mitch coderino https://forums.alliedmods.net/showthread.php?t=141518&page=2
public void Circle(float vecLocation[3], float radius, int material, int client, const int colors[4])
{
float pos2[4][3];
//Create the start position for the first part of the beam
pos2[0][0] = vecLocation[0];
pos2[1][0] = vecLocation[0] + radius;
pos2[2][0] = vecLocation[0] + (radius*DegToRad(90.0));
pos2[3][0] = vecLocation[0] + (radius*DegToRad(45.0));
pos2[0][1] = vecLocation[1] + radius;
pos2[1][1] = vecLocation[1];
pos2[2][1] = vecLocation[1] + (radius*DegToRad(90.0));
pos2[3][1] = vecLocation[1] - (radius*DegToRad(45.0));
pos2[0][2] = vecLocation[2];
pos2[1][2] = vecLocation[2];
pos2[2][2] = vecLocation[2];
pos2[3][2] = vecLocation[2];
TE_SetupBeamPoints(pos2[0], vecLocation, material, 0, 0, 0, g_fClientDurationPref[client], 5.0, 5.0, 5, 0.0, colors, 3);
TE_Send(g_iClients, client_count);
}
//----------------------------------------------------------------------------------------------------
// Purpose: stocks
//----------------------------------------------------------------------------------------------------
stock bool IsValidClient(int client, bool alive = true, bool bots = false)
{
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
{
return true;
}
return false;
}
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
{
if (hOwner == null || hChild == null)
{
LogError("Query error. (%s)", err);
}
}

View File

@ -0,0 +1,361 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <sdktools>
#include <system2>
#pragma newdecls required
static char g_sEventURL[PLATFORM_MAX_PATH];
char c_EventContent[526][526];
bool b_eventLink[MAXPLAYERS];
public Plugin myinfo =
{
name = "unloze_EventScheduler",
author = PLUGIN_AUTHOR,
description = "Ingame Event Notifier",
version = PLUGIN_VERSION,
url = "www.unloze.com"
};
//----------------------------------------------------------------------------------------------------
// Purpose: pluginstart/ mapstart
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
//commands
RegConsoleCmd("say", Cmd_Say);
RegAdminCmd("sm_event", Cmd_EventNotifier, ADMFLAG_GENERIC);
RegAdminCmd("sm_mapstartevent", Cmd_CheckEventInfo, ADMFLAG_ROOT);
//FilePath
BuildPath(Path_SM, g_sEventURL, sizeof(g_sEventURL), "configs/EventURL.txt");
}
public void OnMapStart()
{
EventInfo();
}
//----------------------------------------------------------------------------------------------------
// Purpose: timer notifications
//----------------------------------------------------------------------------------------------------
public Action EventCountDown(Handle timer)
{
//PrintToChatAll("c_EventContent[1]: %s", c_EventContent[1]);
//PrintToChatAll("c_EventContent[2]: %s", c_EventContent[2]);
CalculateTimeToNextEvent(c_EventContent[1], c_EventContent[2]);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose: CalculateTimeToNextEvent
//----------------------------------------------------------------------------------------------------
public void CalculateTimeToNextEvent(char[] content, char[] content1)
{
char sPart[2][526];
char sMonth[24];
char sDay[24];
char sHour[24];
char sMinute[24];
int i_Month;
int i_Day;
int i_Hour;
int i_Minute;
int months;
int days;
int hours;
int minutes;
FormatTime(sMonth, sizeof(sMonth), "%m");
FormatTime(sDay, sizeof(sDay), "%d");
FormatTime(sHour, sizeof(sHour), "%H");
FormatTime(sMinute, sizeof(sMinute), "%M");
TrimString(content);
TrimString(content1);
ExplodeString(content, "/", sPart, 2, 526);
//update we apperently need to know month
i_Day = StringToInt(sDay);
days = StringToInt(sPart[0]);
i_Month = StringToInt(sMonth);
ExplodeString(sPart[1], "/", sPart, 2, 526);
months = StringToInt(sPart[0]);
i_Hour = StringToInt(sHour);
hours = StringToInt(content1);
//PrintToChatAll("hours: %i", hours);
i_Minute = StringToInt(sMinute);
if (days >= i_Day || months > i_Month)
{
///SHIIIET
if (days >= i_Day)
{
days -= i_Day;
}
else if (i_Month == 1 || i_Month == 3 || i_Month == 5 || i_Month == 7 || i_Month == 8 || i_Month == 10 || i_Month == 12)
{
days += (31 - i_Day);
}
else if (i_Month == 2)
{
days += (28 - i_Day);
}
else
{
days += (30 - i_Day);
}
//from 12 to 24 or from 7 to 19 etc etc
hours += 12;
if (i_Hour > hours)
{
days -= 1;
hours = 24 - (i_Hour - hours);
//PrintToChatAll("if statement hours: %i", hours);
}
else
{
hours -= i_Hour;
//PrintToChatAll("else statement: hours: %i", hours);
}
//should solve one hour delay
if (hours != 0)
{
hours -= 1;
}
minutes = 60 - i_Minute;
PrintToChatAll("\x06[UNLOZE]\x03 Next Event is: Event# %s", c_EventContent[0]);
PrintToChatAll("\x06[UNLOZE]\x03 Taking Place in: %i Days, %i Hours, %i Minutes", days, hours, minutes);
PrintToChatAll("\x06[UNLOZE]\x03 Rewards: %s VIP", c_EventContent[3]);
}
else
{
//PrintToChatAll("days: %i \ni_Day: %i", days, i_Day);
//PrintToChatAll("months: %i \ni_Month: %i", months, i_Month);
PrintToChatAll("[UNLOZE] Waiting for next Event to be Scheduled...");
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: EventInfo
//----------------------------------------------------------------------------------------------------
public void EventInfo()
{
//manual check if map event is read correctly on mapstart
Handle zonefile = INVALID_HANDLE;
char line[526];
//PrintToChatAll("g_sEventURL: %s", g_sEventURL);
zonefile = OpenFile(g_sEventURL, "r");
if (zonefile == INVALID_HANDLE)
{
//PrintToChatAll("Invalid handle");
return;
}
ReadFileLine(zonefile, line, sizeof(line));
//reading the link on every mapstart
ReplaceString(line, sizeof(line), "\"", "", false);
//PrintToChatAll("line: %s", line);
System2HTTPRequest httpRequest = new System2HTTPRequest(HttpResponseCallback, line);
httpRequest.GET();
delete httpRequest;
delete zonefile;
//5 minutes just
CreateTimer(300.0, EventCountDown, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
//----------------------------------------------------------------------------------------------------
// Purpose: cmds & menus
//----------------------------------------------------------------------------------------------------
public Action Cmd_CheckEventInfo(int client, any args)
{
EventInfo();
return Plugin_Handled;
}
public Action Cmd_EventNotifier(int client, any args)
{
EventNotifierMenu(client);
return Plugin_Handled;
}
static void EventNotifierMenu(int client)
{
char c_local[526];
Format(c_local, sizeof(c_local), "Next Event: %s", c_EventContent[0]);
Menu EventMenu = CreateMenu(Event_Menu);
EventMenu.SetTitle("UNLOZE Event Scheduler");
EventMenu.AddItem("nothing here", c_local, ITEMDRAW_DISABLED);
EventMenu.AddItem("nothing here", "Link an Event");
EventMenu.ExitButton = true;
EventMenu.ExitBackButton = true;
EventMenu.Display(client, 30);
}
public int Event_Menu(Menu menu, MenuAction action, int client, int choice)
{
if (action == MenuAction_Select)
{
if (choice == 1)
{
PrintToChat(client, "Copy the Event link Into the chat!");
b_eventLink[client] = true;
}
else if (action == MenuAction_End)
{
delete(menu);
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: simple say hook
//----------------------------------------------------------------------------------------------------
public Action Cmd_Say(int client, int args)
{
if (b_eventLink[client])
{
char arg[526];
GetCmdArgString(arg, sizeof(arg));
PrintToChat(client, "arg: %s", arg);
ReplaceString(arg, sizeof(arg), "\"", "", false);
System2HTTPRequest httpRequest = new System2HTTPRequest(HttpResponseCallback, arg);
httpRequest.GET();
delete httpRequest;
b_eventLink[client] = false;
Handle zonefile = INVALID_HANDLE;
zonefile = OpenFile(g_sEventURL, "w");
//one would think storing c_EventContent[0] could be better ohwell
WriteFileLine(zonefile, arg);
delete zonefile;
return Plugin_Handled;
}
return Plugin_Continue;
}
//----------------------------------------------------------------------------------------------------
// Purpose: http callbacks
//----------------------------------------------------------------------------------------------------
public void HttpResponseCallback(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method)
{
if (success)
{
//PrintToChatAll("Success");
char content[526];
char content1[1080];
//for some horrifying reason this is inconsistent
for (int found = 0; found < response.ContentLength;)
{
found += response.GetContent(content, sizeof(content), found);
FindRelevantData(content);
}
for (int found = 0; found < response.ContentLength;)
{
found += response.GetContent(content1, sizeof(content1), found);
FindRelevantDataRewards(content1);
}
ReplaceString(c_EventContent[0], sizeof(c_EventContent), "<title>", "", false);
ReplaceString(c_EventContent[0], sizeof(c_EventContent), "| UNLOZE", "", false);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: Finds relevant data like event title, hours & days left, event rewards
//----------------------------------------------------------------------------------------------------
public void FindRelevantDataRewards(char[] content)
{
if (StrContains(content, "Prize :", false) > -1)
{
//this is fragile as fuck
char sPart[2][526];
//PrintToChatAll("Prize content: %s", content);
ExplodeString(content, "Prize :", sPart, 2, 526);
//PrintToChatAll("sPart[1]: %s", sPart[1]);
//PrintToChatAll("sPart[0]: %s", sPart[0]);
c_EventContent[3] = sPart[1];
ExplodeString(c_EventContent[3], "VIP", sPart, 2, 526);
c_EventContent[3] = sPart[0];
ReplaceString(c_EventContent[3], sizeof(c_EventContent), "</span></b>", "");
PrintToChatAll("c_EventContent[3]: %s", c_EventContent[3]);
}
}
public void FindRelevantData(char[] content)
{
if (StrContains(content, "content=\"Event#", true) > -1)
{
char sPart[2][526];
//PrintToChatAll("content: %s", content);
//if event managers change formatting heads will roll
ExplodeString(content, "content=\"Event#", sPart, 2, 526);
//PrintToChatAll("sPart[0]: %s", sPart[0]);
//PrintToChatAll("sPart[1]: %s", sPart[1]);
c_EventContent[0] = sPart[1];
ExplodeString(c_EventContent[0], "\"/>", sPart, 2, 526);
//PrintToChatAll("POST sPart[0]: %s", sPart[0]);
c_EventContent[0] = sPart[0];
ReplaceString(c_EventContent[0], sizeof(c_EventContent), "amp;", "", false);
}
if (StrContains(content, "Date :", true) > -1)
{
//PrintToChatAll("StrContains Date :%s", content);
char sPart[2][526];
char c_localfix[526];
//PrintToChatAll("c_EventContent[1] Pre: %s", c_EventContent[1]);
//THIS IS FIIIINE
ExplodeString(content, "Date :", sPart, 2, 526);
c_localfix = sPart[1];
//PrintToChatAll("Date c_localfix: %s", c_localfix);
ExplodeString(c_localfix, "</span><br/>", sPart, 2, 526);
c_localfix = sPart[0];
TrimString(c_localfix);
if (StrContains(c_localfix, "'\">") > -1)
{
ExplodeString(c_localfix, "'\">", sPart, 2, 526);
}
else if (StrContains(c_localfix, "</b></span>") > -1)
{
ExplodeString(c_localfix, "</b></span>", sPart, 2, 526);
}
//PrintToChatAll("</span><br/> c_localfix: %s", c_localfix);
//PrintToChatAll("POST Day sPart[0]: %s", sPart[0]);
c_EventContent[1] = sPart[1];
ReplaceString(c_EventContent[1], sizeof(c_EventContent), "</span></span>", "");
PrintToChatAll("c_EventContent[1]: %s", c_EventContent[1]);
}
if (StrContains(content, "Time :", true) > -1)
{
char sPart[2][526];
//if event managers change formatting heads will roll
SplitString(content, " pm GMT+2", c_EventContent[2], sizeof(c_EventContent));
//THIS IS FIIIINE
ExplodeString(c_EventContent[2], "pm GMT+1", sPart, 2, 526);
//PrintToChatAll("hour sPart[0]: %s", sPart[0]);
c_EventContent[2] = sPart[1];
ReplaceString(c_EventContent[2], sizeof(c_EventContent), "/", "", false);
TrimString(c_EventContent[2]);
PrintToChatAll("c_EventContent[2]: %s", c_EventContent[2]);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: OnClientPostAdminCheck && disconnect
//----------------------------------------------------------------------------------------------------
public void OnClientPostAdminCheck(int client)
{
b_eventLink[client] = false;
}
public void OnClientDisconnect(int client)
{
b_eventLink[client] = false;
}

View File

@ -0,0 +1,833 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "2.00"
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
char g_cPollText[256][512];
char g_cPollVotes[256][512];
char g_cPollIRunOutOfNames[256][512];
char g_cPollTextClient[256];
char g_cPollVotesCvar[256];
char g_cPollCommands[512];
int g_iPollVoteWithHigestResult;
int g_iPollVotesCvar;
int g_iPollIndex;
int g_iAdminSay[MAXPLAYERS];
int g_iAdminVoteOptions[MAXPLAYERS];
Handle g_hTimer;
public Plugin myinfo =
{
name = "Unloze ingame polls",
author = PLUGIN_AUTHOR,
description = "ingame polls",
version = PLUGIN_VERSION,
url = "www.unloze.com"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
//Reg Cmds
RegConsoleCmd("sm_poll", Cmd_Polls, "Vote on ongoing polls");
RegConsoleCmd("sm_polls", Cmd_Polls, "Vote on ongoing polls");
RegConsoleCmd("say", Cmd_Say);
//mysql
SQL_StartConnection();
//admin cmds
RegAdminCmd("sm_pollmenu", Cmd_pollAdminMenu, ADMFLAG_GENERIC);
}
public void OnMapStart()
{
MySQLSelectPollTitles();
CreateTimer(1.0, evaluatedelayAll, INVALID_HANDLE);
g_hTimer = CreateTimer(260.0, pollNotifier, INVALID_HANDLE, TIMER_REPEAT);
//change to 260.0 again for main server
}
public void OnMapEnd()
{
if (g_hTimer != INVALID_HANDLE)
{
KillTimer(g_hTimer);
g_hTimer = INVALID_HANDLE;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void InitializeQueries(char[] PollText)
{
int l_iPollVoteOptions;
int l_iMax;
int i_lCounter;
//for loop here to count votes for each option of the specified poll
//needs state 0 to only count active votes
l_iPollVoteOptions = MySQLSelectPollVotes(PollText, 0);
for (int j = 0; j <= l_iPollVoteOptions; j++)
{
l_iMax = MySQLQueryVotes(PollText, j);
if (l_iMax > i_lCounter)
{
//index 4 is wrong should be 3
g_iPollVoteWithHigestResult = j;
i_lCounter = l_iMax;
}
}
}
public Action ExecuteVoteCommand(char[] command, bool mapstart)
{
if (StrContains(command, "mp_", true) == -1 && StrContains(command, "sv_", true) == -1 && StrContains(command, "plugins", true) == -1)
{
ServerCommand(command);
}
else if (mapstart)
{
ServerCommand(command);
}
//PrintToChatAll("command: %s", command);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action evaluatedelay(Handle timer)
{
char command[512];
InitializeQueries(g_cPollTextClient);
MySQLSelectHighestVoteForPoll(g_cPollText[g_iPollVotesCvar][256], g_iPollVoteWithHigestResult);
Format(command, sizeof(command), g_cPollCommands);
ExecuteVoteCommand(command, false);
}
//experimental to launch all on mapstart
public Action evaluatedelayAll(Handle timer)
{
int l_iIndex;
char command[512];
//should correctly itterate through all
//[numberOfStrings][lengthOfLongestString]
while (g_cPollText[l_iIndex][256] != '\0')
{
InitializeQueries(g_cPollText[l_iIndex][256]);
MySQLSelectHighestVoteForPoll(g_cPollText[l_iIndex][256], g_iPollVoteWithHigestResult);
Format(command, sizeof(command), g_cPollCommands);
ExecuteVoteCommand(command, true);
l_iIndex++;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action pollNotifier(Handle timer)
{
int l_iIndex;
//edited
while (g_cPollText[l_iIndex][256] != '\0')
{
PrintToChatAll("\x06[UNLOZE]\x07 Current Polls: %s", g_cPollText[l_iIndex][256]);
l_iIndex++;
}
PrintToChatAll("\x06[UNLOZE]\x07 Type !poll to vote");
}
public Action Cmd_pollAdminMenu(int client, int args)
{
EditPollAdminMenu(client);
}
public Action EditPollAdminMenu(int client)
{
Menu menu1 = new Menu(Menu_PollAdminMenu);
menu1.SetTitle("[UNLOZE] Admin menu to edit polls");
menu1.AddItem("nuffin here", "Create new Poll");
menu1.AddItem("nuffin here", "Edit poll");
menu1.Display(client, MENU_TIME_FOREVER);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Cmd_Say(int client, int args)
{
int l_iIndex;
if (g_iAdminSay[client] == 1)
{
//edited to dimensional array
while (g_cPollText[l_iIndex][256] != '\0')
{
l_iIndex++;
}
GetCmdArgString(g_cPollText[l_iIndex][256], sizeof(g_cPollText));
ReplaceString(g_cPollText[l_iIndex][256], sizeof(g_cPollText), "\"", "");
PrintToChat(client, "Creating new PollTitle: %s", g_cPollText[l_iIndex][256]);
//sends a new poll title to DB as a COLUMN
sendMYSQLPollTextCOLUMN(g_cPollText[l_iIndex][256]);
}
else if (g_iAdminSay[client] == 2)
{
//edited to dimensional array
char l_cArgStringUpdate[256];
GetCmdArgString(l_cArgStringUpdate, sizeof(l_cArgStringUpdate));
ReplaceString(l_cArgStringUpdate, sizeof(l_cArgStringUpdate), "\"", "");
PrintToChat(client, "Updating PollTitle to: %s", l_cArgStringUpdate);
//update the coloumn title if somebody wants to rename poll
//g_iPollIndex stores what POll an admin choose to edit
MySQLUpdateTextCOLUMN(g_cPollText[g_iPollIndex][256], l_cArgStringUpdate);
}
if (g_iAdminVoteOptions[client] == 1)
{
char l_cDummy[1];
GetCmdArgString(g_cPollVotes[client][256], sizeof(g_cPollVotes));
ReplaceString(g_cPollVotes[client][256], sizeof(g_cPollVotes), "\"", "");
PrintToChat(client, "Made %s an Vote Option", g_cPollVotes[client][256]);
PrintToChat(client, "Give the Vote Option a COMMAND BEFORE MAKING NEXT VOTE OPTION");
//After each vote option its cvar has to be set before next vote option can be made
mysqlStoreVoteOption(0, l_cDummy[0], client);
}
else if (g_iAdminVoteOptions[client] == 2)
{
char l_cPollcommands[256][512];
GetCmdArgString(l_cPollcommands[0][256], sizeof(l_cPollcommands));
ReplaceString(l_cPollcommands[0][256], sizeof(l_cPollcommands), "\"", "");
PrintToChat(client, "\x06Added %s as a cvar/command to vote option: %s", l_cPollcommands[0][256], g_cPollVotesCvar);
PrintToChat(client, "You can now add another vote option to the poll");
//After each vote option its cvar has to be set before next vote option can be made
mysqlStoreVoteOption(1, l_cPollcommands[0][256], client);
}
//Updating all polltitles
MySQLSelectPollTitles();
g_iAdminSay[client] = 0;
g_iAdminVoteOptions[client] = 0;
return Plugin_Continue;
}
public Action Cmd_Polls(int client, int args)
{
//select what poll to vote on
pollMenu(client, 0);
return Plugin_Handled;
}
public void pollMenu(int client, int state)
{
char c_activePoll1[512][512];
Menu menu1;
if (state == 0)
{
menu1 = new Menu(Menu_onGoingPolls);
}
else
{
menu1 = new Menu(Menu_EditonGoingPolls);
menu1.AddItem("Go Back", "Go Back");
}
int i;
menu1.SetTitle("Active Polls:");
while (g_cPollText[i][256] != '\0')
{
Format(c_activePoll1[i][256], sizeof(c_activePoll1), g_cPollText[i][256]);
menu1.AddItem("nuffin here", c_activePoll1[i][256]);
i++;
}
if (i < 1)
{
PrintToChat(client, "There are currently no Active polls to vote on");
return;
}
//display votes count for each vote here
menu1.Display(client, MENU_TIME_FOREVER);
}
public void pollSubSection(int client, int selection)
{
char l_cActivePoll[512];
char l_cPollIRunOutOfNames[256][512];
int l_iPollVoteOptions;
int l_iMax;
//selection here is the poll index that is voted on
g_iPollVotesCvar = selection;
Format(l_cActivePoll, sizeof(l_cActivePoll), g_cPollText[selection][256]);
Format(g_cPollTextClient, sizeof(g_cPollTextClient), l_cActivePoll);
Menu menu = new Menu(Menu_IndividualPoll);
//needs state 1 to select all vote options, aka not voted for yet
l_iPollVoteOptions = MySQLSelectPollVotes(l_cActivePoll, 1);
menu.SetTitle("Poll to vote on: %s", l_cActivePoll);
menu.AddItem("Go Back", "Go Back");
//for loop here to take care of all vote options for each pollText
for (int j = 0; j < l_iPollVoteOptions; j++)
{
menu.AddItem(g_cPollIRunOutOfNames[j][256], g_cPollIRunOutOfNames[j][256]);
}
for (int i = 0; i < l_iPollVoteOptions; i++)
{
//should be correct with searching for polltext
l_iMax = MySQLQueryVotes(g_cPollText[selection][256], i);
Format(l_cPollIRunOutOfNames[i][256], sizeof(l_cPollIRunOutOfNames), "%s = VOTES %i", g_cPollIRunOutOfNames[i][256], l_iMax);
menu.AddItem("", l_cPollIRunOutOfNames[i][256], ITEMDRAW_DISABLED);
}
menu.Display(client, MENU_TIME_FOREVER);
}
public int Menu_EditonGoingPolls(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
if (StrContains(info, "Go Back", true) > -1)
{
EditPollAdminMenu(client);
}
else
{
//storing selection
char l_cAtivePoll[512];
Format(l_cAtivePoll, sizeof(l_cAtivePoll), g_cPollText[selection][256]);
//get selected poll to edit down here so the cmd_say knows which index to update
g_cPollVotes[client][256] = selection;
g_iPollIndex = selection;
Menu menu1 = new Menu(Menu_EditSelectedPoll);
menu1.SetTitle("Selected Poll to Edit: %s", l_cAtivePoll);
menu1.AddItem("", "Rename Poll Title");
menu1.AddItem("", "add vote options");
menu1.AddItem("", "Add cvar or command to execute for each vote option");
menu1.AddItem("", "Delete poll");
menu1.Display(client, MENU_TIME_FOREVER);
}
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public int Menu_EditSelectedPoll(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
if (selection == 0)
{
g_iAdminSay[client] = 2;
PrintToChat(client, "Enter the poll Title into the chat to update it!");
}
else if (selection == 1)
{
//display menu here to list the polls current vote options
//and ability to add new one
int l_iPollVoteOptions;
char c_activePoll[512];
Format(c_activePoll, sizeof(c_activePoll), g_cPollText[g_iPollIndex][256]);
//needs state 1 to select all possible vote options
l_iPollVoteOptions = MySQLSelectPollVotes(c_activePoll, 1);
//gets c_activePoll correctly now ingame
Menu menu1 = new Menu(Menu_pollSpecificVoteOptions);
menu1.SetTitle("Selected Poll %s has Vote Options:", c_activePoll);
//gets these correctly now
for (int j = 0; j < l_iPollVoteOptions; j++)
{
menu1.AddItem(g_cPollIRunOutOfNames[j][256], g_cPollIRunOutOfNames[j][256], ITEMDRAW_DISABLED);
}
menu1.AddItem("AddVote Option", "AddVote Option");
menu1.Display(client, MENU_TIME_FOREVER);
}
else if (selection == 2)
{
//menu displaying vote options here
int l_iPollVoteOptions;
char c_activePoll[512];
Format(c_activePoll, sizeof(c_activePoll), g_cPollText[g_iPollIndex][256]);
//needs state 1 to select all possible vote options
l_iPollVoteOptions = MySQLSelectPollVotes(c_activePoll, 1);
Menu menu1 = new Menu(Menu_PollAdminCvartoVote);
menu1.SetTitle("[UNLOZE] Select what vote Option to Give a cvar/command");
for (int j = 0; j < l_iPollVoteOptions; j++)
{
menu1.AddItem(g_cPollIRunOutOfNames[j][256], g_cPollIRunOutOfNames[j][256]);
}
if (l_iPollVoteOptions > 0)
{
menu1.Display(client, MENU_TIME_FOREVER);
}
else
{
PrintToChat(client, "There currently aren´t any Vote options, add one to give it a cvar");
}
}
else if (selection == 3)
{
//add option to delete poll here
char c_activePoll[512];
Format(c_activePoll, sizeof(c_activePoll), g_cPollText[g_iPollIndex][256]);
MySQLDeletePoll(c_activePoll);
//Updating all polltitles
MySQLSelectPollTitles();
}
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public int Menu_pollSpecificVoteOptions(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
if (StrContains(info, "AddVote Option", true) > -1)
{
//Does insert part correctly with mysql query on mywebsql
g_iAdminVoteOptions[client] = 1;
PrintToChat(client, "Enter the vote option into the chat!");
}
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public int Menu_PollAdminCvartoVote(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
//storing which vote option to edit
char info[256];
menu.GetItem(selection, info, sizeof(info));
g_cPollVotesCvar = info;
//PrintToChatAll("g_cPollVotesCvar: %s", g_cPollVotesCvar);
g_iAdminVoteOptions[client] = 2;
PrintToChat(client, "Enter the cvar/command related to the vote into the chat");
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public int Menu_onGoingPolls(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
//VoteOption from the Poll to vote on
pollSubSection(client, selection);
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public int Menu_IndividualPoll(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
if (StrContains(info, "Go Back", true) > -1)
{
pollMenu(client, 0);
}
else
{
char VOTE[256];
menu.GetItem(selection, VOTE, sizeof(VOTE));
PrintToChat(client, "You voted %s", VOTE);
MYSQLInsertVotes(client, g_cPollTextClient, VOTE);
CreateTimer(1.0, evaluatedelay, INVALID_HANDLE);
}
}
else if (action == MenuAction_End)
{
delete menu;
}
}
public int Menu_PollAdminMenu(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
if (selection == 0)
{
g_iAdminSay[client] = 1;
PrintToChat(client, "Enter the poll text into the chat!");
}
else if (selection == 1)
{
//select what poll to edit
pollMenu(client, 1);
}
}
else if (action == MenuAction_End)
{
delete menu;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDisconnect (int client)
{
g_iAdminSay[client] = 0;
g_iAdminVoteOptions[client] = 0;
}
public void OnClientPostAdminCheck(int client)
{
g_iAdminSay[client] = 0;
g_iAdminVoteOptions[client] = 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose: MYSQL queries
//----------------------------------------------------------------------------------------------------
public void SQL_StartConnection()
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
//create tables
char sQuery[255];
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_pollvotes` (`steam_id` VARCHAR(64) NOT NULL, PRIMARY KEY (`steam_id`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_pollVoteCvars` (`command` VARCHAR(256) NOT NULL, PRIMARY KEY (`command`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void MySQLUpdateTextCOLUMN(char[] CurrentPollText, char[] NewPollText)
{
char error[255];
char sQuery[512];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollvotes` CHANGE `%s` `%s` VARCHAR(256) NOT NULL;", CurrentPollText, NewPollText);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollVoteCvars` CHANGE `%s` `%s` VARCHAR(256) NOT NULL;", CurrentPollText, NewPollText);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void sendMYSQLPollTextCOLUMN(char[] pollText)
{
char error[255];
char sQuery[512];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollvotes` ADD COLUMN `%s` VARCHAR(256) NOT NULL;", pollText);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollVoteCvars` ADD COLUMN `%s` VARCHAR(256) NOT NULL;", pollText);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void MYSQLInsertVotes(int client, char[] pollText, char[] VOTE)
{
char error[255];
char sQuery[512];
char sSID[64];
Database db;
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_pollvotes` (`steam_id`,`%s`) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE `%s` = '%s'", pollText, sSID, VOTE, pollText, VOTE);
//PrintToChatAll("MYSQLInsertVotes sQuery: %s", sQuery);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void mysqlStoreVoteOption(int state, char[] Command, int client)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
delete db;
return;
}
char sQuery[512];
if (state == 1)
{
Format(sQuery, sizeof(sQuery), "UPDATE `unloze_pollVoteCvars` SET `command`= '%s' WHERE `%s`= '%s'", Command, g_cPollText[g_iPollIndex][256], g_cPollVotesCvar);
//PrintToChatAll("VoteOption Squery: %s", sQuery);
}
else
{
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_pollVoteCvars` (`%s`) VALUES ('%s') ON DUPLICATE KEY UPDATE `%s` = '%s'", g_cPollText[g_iPollIndex][256], g_cPollVotes[client][256], g_cPollText[g_iPollIndex][256], g_cPollVotes[client][256]);
//PrintToChatAll("VoteOption Squery: %s", sQuery);
}
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void MySQLDeletePoll(char[] PollText)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
delete db;
return;
}
char sQuery[512];
Format(sQuery, sizeof(sQuery), "ALTER TABLE unloze_pollvotes DROP COLUMN `%s`", PollText);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "ALTER TABLE unloze_pollVoteCvars DROP COLUMN `%s`", PollText);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public int MySQLQueryVotes(char[] PollText, int indexJ)
{
char sQuery[512];
char error[255];
int l_iCounter;
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
delete db;
return 0;
}
DBResultSet rs;
Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM unloze_pollvotes WHERE `%s` = '%s'", PollText, g_cPollIRunOutOfNames[indexJ][256]);
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return 0;
}
//PrintToChatAll("success: %s", sQuery);
if (rs.RowCount > 0 && rs.FetchRow())
{
char l_cPollVoteCounter[512];
SQL_FetchString(rs, 0, l_cPollVoteCounter, sizeof(l_cPollVoteCounter));
//PrintToChatAll("l_cPollVoteCounter: %s", l_cPollVoteCounter);
//counting votes
l_iCounter = StringToInt(l_cPollVoteCounter);
}
delete rs;
delete db;
return l_iCounter;
}
public void MySQLSelectPollTitles()
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
delete db;
return;
}
char sQuery[512];
//Collects the column_names requires
Format(sQuery, sizeof(sQuery), "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = 'unloze_pollvotes'");
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
Format(g_cPollText[0][256], sizeof(g_cPollText), "No Active polls");
return;
}
int index;
if (rs.RowCount > 0)
{
//should skip steam_id
rs.FetchRow();
while (rs.FetchRow())
{
//should be 0
SQL_FetchString(rs, 0, g_cPollText[index][256], sizeof(g_cPollText));
index++;
}
}
delete rs;
delete db;
}
public int MySQLSelectPollVotes(char[] PollText, int state)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
delete db;
return 0;
}
char sQuery[512];
if (state == 1)
{
Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM unloze_pollVoteCvars", PollText);
}
else
{
Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM unloze_pollvotes", PollText);
}
//PrintToChatAll("Query i want: %s", sQuery);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
Format(g_cPollIRunOutOfNames[0][256], sizeof(g_cPollIRunOutOfNames), "No Active Votes available for the poll");
return 0;
}
int index;
char l_cLocalFix[256][512];
//regardless of state 1/0 it should need this to allocate it slightly more effectively
if (rs.RowCount > 0)
{
while (rs.FetchRow())
{
//preventing empty fields
SQL_FetchString(rs, 0, l_cLocalFix[index][256], sizeof(l_cLocalFix));
if (l_cLocalFix[index][256] != '\0')
{
Format(g_cPollIRunOutOfNames[index][256], sizeof(g_cPollIRunOutOfNames), l_cLocalFix[index][256]);
//PrintToChatAll("SUCCESS g_cPollIRunOutOfNames[index][256]: %s", g_cPollIRunOutOfNames[index][256]);
index++;
}
}
}
delete rs;
delete db;
return index;
}
public void MySQLSelectHighestVoteForPoll(char[] PollText, int index)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
delete db;
return;
}
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT command FROM unloze_pollVoteCvars WHERE `%s` = '%s'", PollText, g_cPollIRunOutOfNames[index][256]);
//PrintToChatAll("MySQLSelectHighestVoteForPoll: %s",sQuery);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (rs.RowCount > 0 && rs.FetchRow())
{
SQL_FetchString(rs, 0, g_cPollCommands, sizeof(g_cPollCommands));
}
delete rs;
delete db;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client))
{
return true;
}
return false;
}
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
{
if (hOwner == null || hChild == null)
{
LogError("Query error. (%s)", err);
}
}

View File

@ -0,0 +1,809 @@
#pragma semicolon 1
#pragma newdecls required
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "6.20"
#define ZONE_PREFIX_RACE "ZONE_PREFIX_RACE"
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <unloze_zones>
#include <colorvariables>
#include <regex>
#include <zombiereloaded>
bool g_bMessage[MAXPLAYERS];
bool g_bStopTimer[MAXPLAYERS];
bool g_bRoundend;
bool g_bSmap;
bool g_bRmap;
char g_cMapname[512];
float g_fEngineRoundtimeSurf[MAXPLAYERS];
float g_fEngineSecondsSurf[MAXPLAYERS];
float g_fPlayertimes[MAXPLAYERS];
float g_fEngineRoundtime;
float g_fEngineSeconds;
int g_iEngine_minutesSurf[MAXPLAYERS];
int g_iCurrentS[MAXPLAYERS];
int g_iSurf[MAXPLAYERS];
int g_iEngine_minutes;
Handle g_hSurfTimer[MAXPLAYERS];
public Plugin myinfo =
{
name = "Unloze Map Timer",
author = PLUGIN_AUTHOR,
description = "Timers for Race Maps",
version = PLUGIN_VERSION,
url = ""
};
//----------------------------------------------------------------------------------------------------
// Purpose: Pluginstart/mapstart
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
SQL_StartConnection();
RegConsoleCmd("sm_toptime", cmd_timerCheck, "checking");
RegConsoleCmd("sm_s1", cmd_timerCheckS1, "checking");
RegConsoleCmd("sm_s2", cmd_timerCheckS2, "checking 2");
RegConsoleCmd("sm_s3", cmd_timerCheckS3, "checking 3");
RegConsoleCmd("sm_s4", cmd_timerCheckS4, "checking 4");
RegConsoleCmd("sm_s5", cmd_timerCheckS5, "checking 5");
RegConsoleCmd("sm_s6", cmd_timerCheckS6, "checking 6");
RegConsoleCmd("sm_s7", cmd_timerCheckS7, "checking 7");
RegConsoleCmd("sm_s8", cmd_timerCheckS8, "checking 8");
RegConsoleCmd("sm_s9", cmd_timerCheckS9, "checking 9");
RegConsoleCmd("sm_s10", cmd_timerCheckS010, "checking 10");
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("round_end", Event_RoundEnd);
}
public void OnMapStart()
{
GetCurrentMap(g_cMapname, sizeof(g_cMapname));
g_bSmap = false;
g_bRmap = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose: mysql queries/callbacks
//----------------------------------------------------------------------------------------------------
public void SQL_SelectTop_Callback(Database db, DBResultSet results, const char[] error, any data)
{
if (results == null)
{
//LogError("[SS] Selecting players error. Reason: %s", error);
return;
}
int client = GetClientFromSerial(data);
if (client == 0)
{
LogError("[SS] Client is not valid. Reason: %s", error);
return;
}
Menu menu = new Menu(MenuHandler1);
if (g_iSurf[client] != 0)
{
menu.SetTitle("Maptimer: %s_S%i", g_cMapname, g_iSurf[client]);
}
else
{
menu.SetTitle("Maptimer: %s", g_cMapname);
}
int iS_Count = 0;
char gS_MenuContent[524];
while (results.FetchRow())
{
float oldTime = 0.0;
int engine_cMin = 0;
float engine_cSec = 0.0;
iS_Count++;
//Player Name
char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
results.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
oldTime = results.FetchFloat(1);
engine_cMin = RoundToFloor(oldTime / 60);
engine_cSec = oldTime - (engine_cMin * 60);
Format(gS_MenuContent, sizeof(gS_MenuContent), "Position: %i Time: %i:%f - %s", iS_Count, engine_cMin, engine_cSec, gS_PlayerName);
menu.AddItem("-1", gS_MenuContent, ITEMDRAW_DISABLED);
}
if (!iS_Count)
{
menu.AddItem("-1", "No results.", ITEMDRAW_DISABLED);
}
//menu.AddItem("no", "No", ITEMDRAW_DISABLED);
menu.ExitButton = true;
menu.Display(client, 20);
//////message//////
char sQuery[564];
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
if (g_iSurf[client] != 0)
{
Format(sQuery, sizeof(sQuery), "SELECT name, `%sS%i` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", g_cMapname, g_iSurf[client], sSID);
}
else
{
Format(sQuery, sizeof(sQuery), "SELECT name, `%s` FROM `zetimer_table` WHERE steam_auth = '%s'", g_cMapname, sSID);
}
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
char gS_MessageContent[524];
if (rs.FetchRow())
{
float oldTime = 0.0;
int engine_cMin = 0;
float engine_cSec = 0.0;
//Player Name
char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
oldTime = rs.FetchFloat(1);
engine_cMin = RoundToFloor(oldTime / 60);
engine_cSec = oldTime - (engine_cMin * 60);
Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
if (g_iSurf[client] != 0)
{
CPrintToChat(client, "Your best time Stage %i: %s", g_iSurf[client], gS_MessageContent);
}
else
{
CPrintToChat(client, "Your best time: %s", gS_MessageContent);
}
}
delete db;
delete rs;
}
public float receiveMYSQL(int client, float f_playerTime)
{
//variables
float iCollected;
char sQuery[255];
char sSID[64];
char error[255];
DBResultSet rs;
Database db;
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
delete db;
}
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM `zetimer_table` WHERE steam_auth = '%s'", g_cMapname, sSID);
//PrintToChatAll("receiveMYSQL sQuery: %s", sQuery);
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return 0.0;
}
if(SQL_FetchRow(rs))
{
iCollected = SQL_FetchFloat(rs, 0);
}
delete rs;
delete db;
return iCollected;
}
public void sendMYSQLSurf(int client, float f_playerTime, int Entry)
{
char error[255];
Database db;
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[255];
//Format(sQuery, sizeof(sQuery), "SELECT `%sS1` FROM `zetimer_tableSurf` LIMIT 10", g_cMapname);
Format(sQuery, sizeof(sQuery), "SELECT `%sS%i` FROM `zetimer_tableSurf` LIMIT 10", g_cMapname, Entry);
//PrintToChatAll("sendMYSQLSurf sQuery: %s", sQuery);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_tableSurf` ADD COLUMN `%sS%i` DECIMAL(13,3) NOT NULL", g_cMapname, Entry);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
PrintToChat(client, "Sorry but the time was not counted since the Table had to be created first EKSDEE- jenz");
}
else
{
char l_cName[256];
SQL_FetchClientName(client, db, l_cName, sizeof(l_cName));
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_tableSurf` (`steam_auth`, `name`, `%sS%i`) VALUES ('%s', '%s', '%f') ON DUPLICATE KEY UPDATE `name` = '%s', `%sS%i` = '%f'", g_cMapname, Entry, sSID, l_cName, f_playerTime, l_cName, g_cMapname, Entry, f_playerTime);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
}
delete db;
delete rs;
//CPrintToChatAll("reaching end, query is: %s", sQuery);
}
public void sendMYSQL(int client, float f_playerTime)
{
char error[255];
Database db;
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
delete db;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[255];
Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM `zetimer_table` LIMIT 10", g_cMapname);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%s` DECIMAL(13,3) NOT NULL", g_cMapname);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
PrintToChat(client, "Sorry but the time was not counted since the Table had to be created first EKSDEE- jenz");
}
else
{
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%s`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%s` = '%f'", g_cMapname, sSID, client, f_playerTime, client, g_cMapname, f_playerTime);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
}
delete db;
delete rs;
//CPrintToChatAll("reaching end, query is: %s", sQuery);
}
public void SQL_StartConnection()
{
char error[255];
Database db;
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
}
//create tables
char sQuery[255];
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_table` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_tableSurf` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public float receiveMYSQLSurf(int client, float f_playerTime, int i_zoneEndIndex)
{
//variables
float iCollected;
char sQuery[255];
char sSID[64];
char error[255];
DBResultSet rs;
Database db;
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
delete db;
}
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(sQuery, sizeof(sQuery), "SELECT `%sS%i` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", g_cMapname, i_zoneEndIndex, sSID);
//PrintToChatAll("receiveMYSQLSurf sQuery: %s", sQuery);
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return 0.0;
}
if (SQL_FetchRow(rs))
{
iCollected = SQL_FetchFloat(rs, 0);
}
delete rs;
delete db;
return iCollected;
}
public void mysqlLoadNames(int client)
{
char error[255];
char sQuery[255];
char sSID[64];
Database db;
DBResultSet rs;
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
}
char cClient[250];
Format(cClient, sizeof(cClient), "%N", client);
if (StrContains(cClient, "'") >= 0)
{
ReplaceString(cClient, sizeof(cClient), "'", "", false);
}
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_table` SET `name`= '%s' WHERE `steam_auth` = '%s'", cClient, sSID);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_tableSurf` SET `name`= '%s' WHERE `steam_auth` = '%s'", cClient, sSID);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete rs;
delete db;
}
public Action MysqlCheckSurfStage(int client, int count)
{
if (g_bSmap == false)
{
CPrintToChat(client, "[UNLOZE] Does not support Surf zones");
return Plugin_Handled;
}
Database db;
char sQuery[512];
char error[255];
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
delete db;
}
Format(sQuery, sizeof(sQuery), "SELECT name, %sS%i FROM `zetimer_tableSurf` WHERE %sS%i > 0.000 ORDER BY %sS%i ASC LIMIT 10", g_cMapname, count, g_cMapname, count, g_cMapname, count);
db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
//CPrintToChat(client, " ");
delete db;
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose: Chat Command for Race timer
//----------------------------------------------------------------------------------------------------
public Action cmd_timerCheck(int client, int args)
{
if (g_bRmap == false)
{
CPrintToChat(client, "[UNLOZE] Does not support race zones");
return Plugin_Handled;
}
Database db;
char sQuery[512];
char error[555];
if (SQL_CheckConfig("zetimer"))
{
db = SQL_Connect("zetimer", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
delete db;
}
g_iSurf[client] = 0;
Format(sQuery, sizeof(sQuery), "SELECT name, %s FROM `zetimer_table` WHERE %s > 0.000 ORDER BY %s ASC LIMIT 10", g_cMapname, g_cMapname, g_cMapname);
db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
delete db;
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose: Chat Command for Surf timer
//----------------------------------------------------------------------------------------------------
public Action cmd_timerCheckS1(int client, int args)
{
g_iSurf[client] = 1;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS2(int client, int args)
{
g_iSurf[client] = 2;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS3(int client, int args)
{
g_iSurf[client] = 3;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS4(int client, int args)
{
g_iSurf[client] = 4;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS5(int client, int args)
{
g_iSurf[client] = 5;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS6(int client, int args)
{
g_iSurf[client] = 6;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS7(int client, int args)
{
g_iSurf[client] = 7;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS8(int client, int args)
{
g_iSurf[client] = 8;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS9(int client, int args)
{
g_iSurf[client] = 9;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
public Action cmd_timerCheckS010(int client, int args)
{
g_iSurf[client] = 10;
MysqlCheckSurfStage(client, g_iSurf[client]);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose: Menus
//----------------------------------------------------------------------------------------------------
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
/* If the menu was cancelled, print a message to the server about it. */
if (action == MenuAction_Cancel)
{
PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, param2);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: Roundstart/roundend, Postadmincheck, disconnect
//----------------------------------------------------------------------------------------------------
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i < MaxClients; i++)
{
if (IsValidClient(i))
{
g_fPlayertimes[i] = 0.0;
g_bMessage[i] = false;
g_fEngineRoundtimeSurf[i] = 0.0;
g_fEngineSecondsSurf[i] = 0.0;
g_iEngine_minutesSurf[i] = 0;
g_iCurrentS[i] = -1;
g_iSurf[i] = 0;
}
}
g_fEngineRoundtime = 0.0;
g_iEngine_minutes = 0;
g_fEngineSeconds = 0.0;
CreateTimer(0.1, Timer_CountdownRace, _, TIMER_REPEAT);
g_bRoundend = false;
}
public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
{
g_bRoundend = true;
}
public void OnClientDisconnect(int client)
{
//disconnect is triggered on each map switch
g_bMessage[client] = false;
g_fPlayertimes[client] = 0.0;
g_fEngineRoundtimeSurf[client] = 0.0;
g_fEngineSecondsSurf[client] = 0.0;
g_iEngine_minutesSurf[client] = 0;
g_iCurrentS[client] = 0;
g_iSurf[client] = 0;
g_bStopTimer[client] = false;
}
public void OnClientPostAdminCheck(int client)
{
g_bMessage[client] = false;
g_fPlayertimes[client] = 0.0;
g_fEngineRoundtimeSurf[client] = 0.0;
g_fEngineSecondsSurf[client] = 0.0;
g_iEngine_minutesSurf[client] = 0;
g_iCurrentS[client] = 0;
g_iSurf[client] = 0;
g_bStopTimer[client] = true;
}
//----------------------------------------------------------------------------------------------------
// Purpose: Counting maptime functions
//----------------------------------------------------------------------------------------------------
//Callback for timer
public Action Timer_CountdownRace(Handle timer, any data)
{
if (g_bRoundend)
{
return Plugin_Stop;
}
g_fEngineRoundtime += 0.1;
g_fEngineSeconds += 0.1;
if (g_fEngineSeconds >= 60.0)
{
g_iEngine_minutes += 1;
g_fEngineSeconds = 0.0;
}
return Plugin_Changed;
}
public Action Timer_CountdownSurf(Handle timer, int client)
{
if (g_iCurrentS[client] == -1 || !g_bStopTimer[client])
{
if (g_hSurfTimer[client] != INVALID_HANDLE)
{
delete g_hSurfTimer[client];
}
return Plugin_Stop;
}
//PrintToChatAll("g_fEngineRoundtimeSurf: %f", g_fEngineRoundtimeSurf[client]);
//PrintToChatAll("g_fEngineSecondsSurf: %f", g_fEngineSecondsSurf[client]);
g_fEngineRoundtimeSurf[client] += 0.1;
g_fEngineSecondsSurf[client] += 0.1;
if (g_fEngineSecondsSurf[client] >= 60.0)
{
g_iEngine_minutesSurf[client] += 1;
g_fEngineSecondsSurf[client] = 0.0;
}
return Plugin_Changed;
}
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
g_iCurrentS[client] = -1;
}
//----------------------------------------------------------------------------------------------------
// Purpose: zone forwards
//----------------------------------------------------------------------------------------------------
public void unloze_zoneLeave(int client, char [] zone)
{
if (IsValidClient(client) && GetClientTeam(client) == 3 && StrContains(zone, "ZONE_PREFIX_SURF_S", false) >= 0)
{
//PrintToChatAll("unloze_zoneLeave succesfull: %s", zone);
g_fEngineRoundtimeSurf[client] = 0.0;
g_fEngineSecondsSurf[client] = 0.0;
g_iEngine_minutesSurf[client] = 0;
g_iCurrentS[client] = -1;
//createtime only one per player
g_hSurfTimer[client] = CreateTimer(0.1, Timer_CountdownSurf, client, TIMER_REPEAT);
g_iCurrentS[client] = 0;
}
}
public void unloze_zoneEntry(int client, char[] zone)
{
float oldTime[MAXPLAYERS];
//ZONE_PREFIX_RACE
if (IsValidClient(client) && GetClientTeam(client) == 3 && StrContains(zone, ZONE_PREFIX_RACE, false) >= 0)
{
g_bRmap = true;
g_fPlayertimes[client] = g_fEngineRoundtime;
if (g_bMessage[client] == true)
{
return;
}
CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, g_iEngine_minutes, g_fEngineSeconds);
oldTime[client] = receiveMYSQL(client, g_fPlayertimes[client]);
int engine_cMin = 0;
float engine_cSec = 0.0;
engine_cMin = RoundToFloor(oldTime[client] / 60);
engine_cSec = oldTime[client] - (engine_cMin * 60);
CPrintToChat(client, "Your record: 0%i:%f \n Command: !toptime", engine_cMin, engine_cSec);
if (g_fPlayertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000)
{
sendMYSQL(client, g_fPlayertimes[client]);
CPrintToChat(client, "Updated timer");
}
g_bMessage[client] = true;
return;
}
//everything below here is only for ZONE_PREFIX_SURF
if (StrContains(zone, "ZONE_PREFIX_SURF_S", false) >= 0)
{
//When the first client enters the surf gets unlocked
//else do nothing with surf start zoneEntry
g_bSmap = true;
return;
}
if (StrContains(zone, "ZONE_PREFIX_SURF_E", false) < 0)
{
//if client entered non surf end zone stop
return;
}
char out[64];
//stops timer unsafe?
g_iCurrentS[client] = -1;
if (StrContains(zone, "10", false) < 0)
{
Regexmatcher(zone, out, sizeof(out));
}
else
{
Format(out, sizeof(out), "10");
}
if (GetClientTeam(client) != 3)
{
return;
}
int i_zoneEndIndex;
int engine_cMinS1 = 0;
float engine_cSecS1 = 0.0;
//PrintToChatAll("zone: %s", zone);
//PrintToChatAll("out: %s", out);
i_zoneEndIndex = StringToInt(out);
g_fPlayertimes[client] = g_fEngineRoundtimeSurf[client];
oldTime[client] = receiveMYSQLSurf(client, g_fPlayertimes[client], i_zoneEndIndex);
//CPrintToChat(client, "oldTime[%N] ZONE_PREFIX_SURF: %f", client, oldTime[client]);
CPrintToChat(client, "{green}[UNLOZE] Client: %N \nTime: %i:%f", client, g_iEngine_minutesSurf[client], g_fEngineSecondsSurf[client]);
engine_cMinS1 = RoundToFloor(oldTime[client] / 60);
engine_cSecS1 = oldTime[client] - (engine_cMinS1 * 60);
CPrintToChat(client, "Your record Stage %i: 0%i:%f \n Command: !s%i", i_zoneEndIndex, engine_cMinS1, engine_cSecS1, i_zoneEndIndex);
if (g_fPlayertimes[client] < oldTime[client] || oldTime[client] <= 0.000000)
{
sendMYSQLSurf(client, g_fPlayertimes[client], i_zoneEndIndex);
CPrintToChat(client, "Updated surftimer");
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: stocks
//----------------------------------------------------------------------------------------------------
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(client))
{
return true;
}
return false;
}
stock void Regexmatcher(const char[] message, char[] out, int maxlen)
{
Regex regex = CompileRegex("[0-9]");
//the match is needed for getsubstring apperently
regex.Match(message);
regex.GetSubString(0, out, maxlen);
}
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
{
if (hOwner == null || hChild == null)
{
LogError("Query error. (%s)", err);
}
}
stock void SQL_FetchClientName(int client, Database database, char[] buffer, int size)
{
char sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName));
int size2 = 2 * strlen(sName) + 1;
char[] sEscapedName = new char[size2 + 1];
SQL_EscapeString(database, sName, sEscapedName, size2 + 1);
strcopy(buffer, size, sEscapedName);
}

View File

@ -0,0 +1,974 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "2.00"
#define MAX_DEFINED_COLORS 128
#define MAX_DEFINED_MATERIALS 128
//taser
#define TASER "weapon_tracers_taser"
#define GLOW "weapon_taser_glow_impact"
#define SOUND_IMPACT "weapons/taser/taser_hit.wav"
#define SOUND_SHOOT "weapons/taser/taser_shoot.wav"
#include <sourcemod>
#include <sdktools>
#include <csgocolors>
#include <sdkhooks>
#include <clientprefs>
#include <emitsoundany>
#undef REQUIRE_EXTENSIONS
#tryinclude <dhooks>
#define REQUIRE_EXTENSIONS
#pragma newdecls required
//potentially 1024 bits
char g_cStorestats[MAXPLAYERS][526];
bool g_bZeusOwner[MAXPLAYERS];
float g_fLastAngles[MAXPLAYERS + 1][3];
int g_iTracerpref[MAXPLAYERS];
int g_iPlayerRank[MAXPLAYERS + 1];
int g_iPlayerPoints[MAXPLAYERS + 1];
int g_iTEsends[MAXPLAYERS];
int g_iBeam = -1;
int g_iPlayerCount;
int g_iPlayerCountTop10;
int g_iPlayerArrayTop10[MAXPLAYERS];
int g_iPlayerArray[MAXPLAYERS];
int g_iStoreColors[MAXPLAYERS][3];
bool g_bStoreColorbool[MAXPLAYERS];
public Plugin myinfo =
{
name = "Unloze Tracers based on zeustracers",
author = PLUGIN_AUTHOR,
description = "Grants sprayTracers based on clients ranking",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?p=2501632"
};
//Startup
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
return APLRes_Success;
}
public void OnPluginStart()
{
//Reg Cmds
RegConsoleCmd("sm_tracers", Cmd_Tracer, "enable/ disable tracers");
//mysql
SQL_StartConnection();
AddTempEntHook("Shotgun Shot", Hook_BulletShot);
HookEvent("bullet_impact", Event_OnBulletImpact);
HookEvent("round_start", Event_RoundStart);
}
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
for (int i = 0; i < MaxClients; i++)
{
if (IsValidClient(i) && IsPlayerAlive(i))
{
g_iTEsends[i] = 0;
}
}
}
public void OnMapStart()
{
g_iBeam = PrecacheModel("materials/unloze_tracers/xbeam.vmt");
AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vmt");
AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vtf");
PrecacheEffect("ParticleEffect");
PrecacheParticleEffect(TASER);
PrecacheParticleEffect(GLOW);
PrecacheSound(SOUND_IMPACT);
PrecacheSound(SOUND_SHOOT);
}
void PrecacheEffect(const char[] sEffectName)
{
static int table = INVALID_STRING_TABLE;
if (table == INVALID_STRING_TABLE)
table = FindStringTable("EffectDispatch");
bool save = LockStringTables(false);
AddToStringTable(table, sEffectName);
LockStringTables(save);
}
void PrecacheParticleEffect(const char[] sEffectName)
{
static int table = INVALID_STRING_TABLE;
if (table == INVALID_STRING_TABLE)
table = FindStringTable("ParticleEffectNames");
bool save = LockStringTables(false);
AddToStringTable(table, sEffectName);
LockStringTables(save);
}
public Action Cmd_Tracer(int client, int args)
{
Menu menu = new Menu(MenuHandler1);
menu.SetTitle("UNLOZE tracers are unlocked through !shop");
menu.AddItem("", "Toggle Tracer Visibility");
if (StrContains(g_cStorestats[client], "k") >= 0)
{
menu.AddItem("", "Zeus tracers");
}
if (StrContains(g_cStorestats[client], "§") >= 0)
{
menu.AddItem("255 255 0", "Yellow Tracers");
}
if (StrContains(g_cStorestats[client], "@") >= 0)
{
menu.AddItem("0 0 255", "Blue Tracers");
}
if (StrContains(g_cStorestats[client], "£") >= 0)
{
menu.AddItem("0 255 0", "Green Tracers");
}
if (StrContains(g_cStorestats[client], "$") >= 0)
{
menu.AddItem("255 0 0", "Red Tracers");
}
if (StrContains(g_cStorestats[client], "") >= 0)
{
menu.AddItem("255 215 0", "Gold Tracers");
}
if (StrContains(g_cStorestats[client], "(") >= 0)
{
menu.AddItem("0 255 255", "cyan Tracers");
}
menu.ExitButton = true;
menu.Display(client, 0);
return Plugin_Handled;
}
public int MenuHandler1(Menu menu, MenuAction action, int param1, int choice)
{
char info[256];
menu.GetItem(choice, info, sizeof(info));
if (action == MenuAction_Cancel)
{
//PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, choice);
}
else if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_Select)
{
if (choice == 0)
{
g_bZeusOwner[param1] = false;
g_bStoreColorbool[param1] = false;
static char SID[32];
GetClientAuthId(param1, AuthId_Steam2, SID, sizeof(SID));
if (g_iTracerpref[param1] == 0)
{
g_iTracerpref[param1] = 1;
PrintToChat(param1, "Disabled tracers");
}
else
{
g_iTracerpref[param1] = 0;
PrintToChat(param1, "Enabled tracers");
}
ClientCount();
tracerprefMYSQL(param1);
return 0;
}
else if (choice == 1)
{
g_bZeusOwner[param1] = true;
g_bStoreColorbool[param1] = false;
}
else if (choice > 1)
{
char l_cColorPref[256];
g_bStoreColorbool[param1] = true;
g_bZeusOwner[param1] = false;
Format(l_cColorPref, sizeof(l_cColorPref), info);
char sPart[3][526];
ExplodeString(l_cColorPref, " ", sPart, 3, 526);
g_iStoreColors[param1][0] = StringToInt(sPart[0]);
g_iStoreColors[param1][1] = StringToInt(sPart[1]);
g_iStoreColors[param1][2] = StringToInt(sPart[2]);
InsertTracerPrefMYSQL(param1, l_cColorPref);
}
}
ClientCount();
return 0;
}
public Action Event_OnBulletImpact(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
//unnecesary checks but eh
if (!IsClientInGame(client) || IsFakeClient(client) || g_iPlayerArray[0] == '\0' || g_iPlayerCount < 1)
{
return Plugin_Handled;
}
if (g_iTracerpref[client] == 1)
{
return Plugin_Handled;
}
//bought tracers for 25000 tokens in the shop if true
if (!g_bZeusOwner[client] && !g_bStoreColorbool[client])
{
//making sure if not bought from shop that atleast rank 32 and 5000 points
if (g_iPlayerRank[client] > 32 || g_iPlayerPoints[client] < 5000)
{
//PrintToChatAll("g_cStorestats client %N: %s", client, g_cStorestats[client]);
return Plugin_Handled;
}
}
++g_iTEsends[client];
if (g_iTEsends[client] < 2)
{
return Plugin_Handled;
}
g_iTEsends[client] = 0;
float impact_pos[3];
float fPosition[3], fImpact[3], fDifference[3];
float muzzle_pos[3], camera_pos[3];
float pov_pos[3];
int l_iStoreColors[3];
GetClientEyePosition(client, fPosition);
impact_pos[0] = event.GetFloat("x");
impact_pos[1] = event.GetFloat("y");
impact_pos[2] = event.GetFloat("z");
fImpact[0] = GetEventFloat (event, "x");
fImpact[1] = GetEventFloat (event, "y");
fImpact[2] = GetEventFloat (event, "z");
GetWeaponAttachmentPosition(client, "muzzle_flash", muzzle_pos);
GetWeaponAttachmentPosition(client, "camera_buymenu", camera_pos);
//Create an offset for first person
pov_pos[0] = muzzle_pos[0] - camera_pos[0];
pov_pos[1] = muzzle_pos[1] - camera_pos[1];
pov_pos[2] = muzzle_pos[2] - camera_pos[2] + 0.1;
ScaleVector(pov_pos, 0.4);
SubtractVectors(muzzle_pos, pov_pos, pov_pos);
//Move the beam a bit forward so it isn't too close for first person
float distance = GetVectorDistance(pov_pos, impact_pos);
float percentage = 0.2 / (distance / 100);
pov_pos[0] = pov_pos[0] + ((impact_pos[0] - pov_pos[0]) * percentage);
pov_pos[1] = pov_pos[1] + ((impact_pos[1] - pov_pos[1]) * percentage);
pov_pos[2] = pov_pos[2] + ((impact_pos[2] - pov_pos[2]) * percentage);
float fDistance = GetVectorDistance(fPosition, fImpact);
float fPercent = (0.4 / (fDistance / 100.0));
fDifference[0] = fPosition[0] + ((fImpact[0] - fPosition[0]) * fPercent);
fDifference[1] = fPosition[1] + ((fImpact[1] - fPosition[1]) * fPercent) - 0.08;
fDifference[2] = fPosition[2] + ((fImpact[2] - fPosition[2]) * fPercent);
//MASK_SOLID_BRUSHONLY
Handle trace = TR_TraceRayFilterEx(fDifference, fImpact, MASK_SHOT, RayType_EndPoint, Bool_TraceFilterPlayers);
TR_GetEndPosition(fImpact, trace);
CloseHandle(trace);
if (g_bZeusOwner[client])
{
if (g_iPlayerArrayTop10[0] == '\0' || g_iPlayerCountTop10 < 1)
{
return Plugin_Handled;
}
TE_DispatchEffect(TASER, impact_pos, pov_pos, g_fLastAngles[client]);
TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10);
//Display the particle to everyone else under the normal position
TE_DispatchEffect(TASER, impact_pos, muzzle_pos, g_fLastAngles[client]);
TE_Send(g_iPlayerArray, g_iPlayerCount);
//Move the impact glow a bit out so it doesn't clip the wall
impact_pos[0] = impact_pos[0] + ((pov_pos[0] - impact_pos[0]) * percentage);
impact_pos[1] = impact_pos[1] + ((pov_pos[1] - impact_pos[1]) * percentage);
impact_pos[2] = impact_pos[2] + ((pov_pos[2] - impact_pos[2]) * percentage);
TE_DispatchEffect(GLOW, impact_pos, impact_pos);
TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10);
TE_DispatchEffect(GLOW, impact_pos, impact_pos);
TE_Send(g_iPlayerArray, g_iPlayerCount);
//play taser sounds to clients
EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
EmitSoundToClient(client, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
EmitSoundToClient(client, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
return Plugin_Handled;
}
else if (g_bStoreColorbool[client])
{
l_iStoreColors[0] = g_iStoreColors[client][0];
l_iStoreColors[1] = g_iStoreColors[client][1];
l_iStoreColors[2] = g_iStoreColors[client][2];
}
if (g_iPlayerRank[client] > 32)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {192, 192, 192, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
//red
else if (g_iPlayerRank[client] > 29 || colorIndex(l_iStoreColors, 255, 0, 0))
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 0, 0, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 27)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 77, 0, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
//yellow
else if (g_iPlayerRank[client] > 25 || colorIndex(l_iStoreColors, 255, 255, 0))
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 255, 0, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
//blue
else if (colorIndex(l_iStoreColors, 0, 0, 255))
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 0, 255, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
//gold
else if (colorIndex(l_iStoreColors, 255, 215, 0))
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 215, 0, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
//cyan 0 255 255
else if (colorIndex(l_iStoreColors, 0, 255, 255))
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 255, 255, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 23)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {35, 142, 35, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 21)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {128, 128, 0, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 18)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {64, 224, 208, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 15)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 128, 128, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 13)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {240, 248, 255, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 12)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {128, 0, 128, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 9)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {148, 0, 211, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
//green
else if (g_iPlayerRank[client] > 6 || colorIndex(l_iStoreColors, 255, 255, 0))
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 255, 0, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] > 3)
{
TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {218, 112, 214, 105}, 1);
TE_Send(g_iPlayerArray, g_iPlayerCount);
return Plugin_Handled;
}
else if (g_iPlayerRank[client] >= 0)
{
//Display the particle to first person
TE_DispatchEffect(TASER, impact_pos, pov_pos, g_fLastAngles[client]);
TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10);
//Display the particle to everyone else under the normal position
TE_DispatchEffect(TASER, impact_pos, muzzle_pos, g_fLastAngles[client]);
TE_Send(g_iPlayerArray, g_iPlayerCount);
//Move the impact glow a bit out so it doesn't clip the wall
impact_pos[0] = impact_pos[0] + ((pov_pos[0] - impact_pos[0]) * percentage);
impact_pos[1] = impact_pos[1] + ((pov_pos[1] - impact_pos[1]) * percentage);
impact_pos[2] = impact_pos[2] + ((pov_pos[2] - impact_pos[2]) * percentage);
TE_DispatchEffect(GLOW, impact_pos, impact_pos);
TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10);
TE_DispatchEffect(GLOW, impact_pos, impact_pos);
TE_Send(g_iPlayerArray, g_iPlayerCount);
//play taser sounds to clients SNDCHAN_STATIC
EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
EmitSoundToClient(client, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
EmitSoundToClient(client, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL);
return Plugin_Handled;
}
return Plugin_Handled;
}
public Action Hook_BulletShot(const char[] te_name, const int[] Players, int numClients, float delay)
{
int client = TE_ReadNum("m_iPlayer") + 1;
float origin[3];
TE_ReadVector("m_vecOrigin", origin);
g_fLastAngles[client][0] = TE_ReadFloat("m_vecAngles[0]");
g_fLastAngles[client][1] = TE_ReadFloat("m_vecAngles[1]");
g_fLastAngles[client][2] = 0.0;
float impact_pos[3];
Handle trace = TR_TraceRayFilterEx(origin, g_fLastAngles[client], MASK_SHOT, RayType_Infinite, TR_DontHitSelf, client);
if (TR_DidHit(trace))
{
TR_GetEndPosition(impact_pos, trace);
}
delete trace;
return Plugin_Continue;
}
public bool TR_DontHitSelf(int entity, int mask, any data)
{
if (entity == data)
return false;
return true;
}
void GetWeaponAttachmentPosition(int client, const char[] attachment, float pos[3])
{
if (!attachment[0])
return;
int entity = CreateEntityByName("info_target");
DispatchSpawn(entity);
int weapon;
if ((weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon")) == -1)
return;
if ((weapon = GetEntPropEnt(weapon, Prop_Send, "m_hWeaponWorldModel")) == -1)
return;
SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", weapon, entity, 0);
SetVariantString(attachment);
AcceptEntityInput(entity, "SetParentAttachment", weapon, entity, 0);
TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR);
GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", pos);
AcceptEntityInput(entity, "kill");
}
void TE_DispatchEffect(const char[] particle, const float pos[3], const float endpos[3], const float angles[3] = NULL_VECTOR)
{
TE_Start("EffectDispatch");
TE_WriteFloatArray("m_vStart.x", pos, 3);
TE_WriteFloatArray("m_vOrigin.x", endpos, 3);
TE_WriteVector("m_vAngles", angles);
TE_WriteNum("m_nHitBox", GetParticleEffectIndex(particle));
TE_WriteNum("m_iEffectName", GetEffectIndex("ParticleEffect"));
}
int GetParticleEffectIndex(const char[] sEffectName)
{
static int table = INVALID_STRING_TABLE;
if (table == INVALID_STRING_TABLE)
table = FindStringTable("ParticleEffectNames");
int iIndex = FindStringIndex(table, sEffectName);
if (iIndex != INVALID_STRING_INDEX)
return iIndex;
return 0;
}
int GetEffectIndex(const char[] sEffectName)
{
static int table = INVALID_STRING_TABLE;
if (table == INVALID_STRING_TABLE)
table = FindStringTable("EffectDispatch");
int iIndex = FindStringIndex(table, sEffectName);
if (iIndex != INVALID_STRING_INDEX)
return iIndex;
return 0;
}
public void OnClientPostAdminCheck(int client)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client))
{
g_bStoreColorbool[client] = false;
CheckFlagsMYSQL(client);
tracerprefMYSQLpostadmin(client);
CheckMYSQLTracerColorPref(client);
g_iPlayerRank[client] = CheckMYSQL(client);
g_iPlayerPoints[client] = CheckMYSQLPoints(client);
g_iTEsends[client] = 0;
g_bZeusOwner[client] = false;
if (StrContains(g_cStorestats[client], "k") >= 0 && !g_bStoreColorbool[client])
{
g_bZeusOwner[client] = true;
}
ClientCount();
}
}
public void OnClientDisconnect_Post(int client)
{
ClientCount();
}
public void OnClientDisconnect (int client)
{
Format(g_cStorestats[client], sizeof(g_cStorestats), "");
g_iPlayerRank[client] = 0;
g_iPlayerPoints[client] = 0;
g_iTEsends[client] = 0;
g_bZeusOwner[client] = false;
g_bStoreColorbool[client] = false;
g_iTracerpref[client] = 0;
g_iStoreColors[client][0] = 0;
g_iStoreColors[client][1] = 0;
g_iStoreColors[client][2] = 0;
}
public bool Bool_TraceFilterPlayers(int entity, int contentsMask, any client)
{
return !entity || entity > MaxClients;
}
public int CheckMYSQL(int client)
{
if (client < 1 || client > MaxClients)
{
return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client);
}
if (!IsClientConnected(client))
{
return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client);
}
char error[255];
Database db;
if (SQL_CheckConfig("stats"))
{
db = SQL_Connect("stats", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return -1;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
strcopy(sSID, sizeof(sSID), sSID[8]); //matching up with hlstats_PlayerUniqueIds
Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = 'csgo-ze' AND hideranking = 0 AND skill > (SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = 'csgo-ze')", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return -1;
}
int iCollected;
if (!(rs.RowCount > 0))
{
iCollected = 0;
}
else
{
int iField;
rs.FetchRow();
rs.FieldNameToNum("collected", iField);
iCollected = rs.FetchInt(iField);
}
delete rs;
delete db;
return iCollected;
}
public void InsertTracerPrefMYSQL(int client, char[] colornumber)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_tracerprefColor` (`steam_id`, `Color`) VALUES ('%s','%s') ON DUPLICATE KEY UPDATE `Color` = '%s'", sSID, colornumber, colornumber);
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
/*neon idea */
public int CheckMYSQLPoints (int client)
{
if (client < 1 || client > MaxClients)
{
return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client);
}
if (!IsClientConnected(client))
{
return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client);
}
char error[255];
Database db;
if (SQL_CheckConfig("levels"))
{
db = SQL_Connect("levels", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return -1;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
strcopy(sSID, sizeof(sSID), sSID[8]); //matching up with hlstats_PlayerUniqueIds
char sQuery[255];
Format(sQuery, sizeof(sQuery), "SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = 'csgo-ze'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
//PrintToConsole(client, "[Unloze] Failed sQuery: %s", sQuery);
delete db;
delete rs;
return -1;
}
//PrintToConsole(client, "[Unloze] Success sQuery: %s", sQuery);
int iCollected;
if (!(rs.RowCount > 0))
{
iCollected = 0;
}
else
{
int iField;
rs.FetchRow();
rs.FieldNameToNum("collected", iField);
iCollected = rs.FetchInt(iField);
}
delete rs;
delete db;
return iCollected;
}
public void SQL_StartConnection()
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
//create tables
char sQuery[255];
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_tracerpref` (`steam_id` VARCHAR(254) NOT NULL, `disabled` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_tracerprefColor` (`steam_id` VARCHAR(254) NOT NULL, `Color` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))");
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void tracerprefMYSQL(int client)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
//create tables
char sQuery[255];
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
if (g_iTracerpref[client] == 1)
{
Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_tracerpref` (`steam_id`, `disabled`) VALUES ('%s','1') ON DUPLICATE KEY UPDATE `disabled` = '1'", sSID);
}
else if (g_iTracerpref[client] == 0)
{
Format(sQuery, sizeof(sQuery), "DELETE FROM unloze_tracerpref WHERE `steam_id` = '%s'", sSID);
}
SQL_TQuery(db, DummyCallbackSimple, sQuery);
delete db;
}
public void CheckMYSQLTracerColorPref(int client)
{
char error[255];
Database db;
//the points not related to hlstats are stored together with tracer prefferences but have
//their own table
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT Color FROM `unloze_tracerprefColor` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (rs.RowCount > 0 && rs.FetchRow())
{
char translate[124];
char sPart[3][526];
SQL_FetchString(rs, 0, translate, MAX_NAME_LENGTH);
ExplodeString(translate, " ", sPart, 3, 526);
g_iStoreColors[client][0] = StringToInt(sPart[0]);
g_iStoreColors[client][1] = StringToInt(sPart[1]);
g_iStoreColors[client][2] = StringToInt(sPart[2]);
g_bStoreColorbool[client] = true;
delete rs;
delete db;
return;
}
g_iStoreColors[client][0] = 0;
g_iStoreColors[client][1] = 0;
g_iStoreColors[client][2] = 0;
delete rs;
delete db;
}
public void tracerprefMYSQLpostadmin(int client)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
//create tables
char sQuery[255];
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(sQuery, sizeof(sQuery), "SELECT disabled FROM `unloze_tracerpref` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (!(rs.RowCount > 0))
{
g_iTracerpref[client] = 0;
}
else
{
g_iTracerpref[client] = 1;
}
delete rs;
delete db;
}
public void CheckFlagsMYSQL(int client)
{
char error[255];
Database db;
if (SQL_CheckConfig("unloze_tracerpref"))
{
db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error));
}
if (db == null)
{
PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
delete db;
return;
}
char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT storestats FROM `unloze_zonepoints` WHERE `steam_id` = '%s'", sSID);
DBResultSet rs;
if ((rs = SQL_Query(db, sQuery)) == null)
{
delete db;
delete rs;
return;
}
if (rs.FetchRow())
{
SQL_FetchString(rs, 0, g_cStorestats[client], sizeof(g_cStorestats));
}
delete rs;
delete db;
}
//----------------------------------------------------------------------------------------------------
// Purpose: stocks
//----------------------------------------------------------------------------------------------------
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
{
if (hOwner == null || hChild == null)
{
LogError("Query error. (%s)", err);
}
}
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
{
return true;
}
return false;
}
stock void ClientCount()
{
g_iPlayerCount = 0;
g_iPlayerCountTop10 = 0;
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i) && g_iTracerpref[i] == 0)
{
if (g_iPlayerRank[i] < 4 || g_bZeusOwner[i])
{
g_iPlayerArrayTop10[g_iPlayerCountTop10++] = i;
}
g_iPlayerArray[g_iPlayerCount++] = i;
}
}
}
stock bool colorIndex(int colors[3], int a, int g, int b)
{
if (colors[0] == a && colors[1] == g && colors[2] == b)
{
return true;
}
return false;
}

View File

@ -0,0 +1,34 @@
/** Double-include prevention */
#if defined _unloze_zones_included_
#endinput
#endif
#define _unloze_zones_included_
/**
* Called when client Enters a zone
*
* @int Client entering zone.
* @char name of the zone.
*/
forward void unloze_zoneEntry(int client, char[] zone);
/**
* Called when client Leaves a zone
*
* @int Client leaving zone.
* @char name of the zone.
*/
forward void unloze_zoneLeave(int client, char[] zone);
/**
* @int zone index
* @char modifies the zone indexes name
*/
native void ZoneNameBasedOnIndex(int index, char[] callbackresult);
/**
* @returns total count of zones
*/
native int unloze_zoneCount();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff