#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#include <sdkhooks>
#include <colors>
#include "mg_shop/variables.inc"
#include "mg_shop/helper.inc"
#include "mg_shop/sql.inc"
#include "mg_shop/menu.inc"
public Plugin:myinfo =
{
name = "[CS:S] Shop plugin",
author = "[RUS] DiviX",
description = "[CS:S] Shop plugin for MG servers",
version = VERSION,
url = "N/A"
}
public OnPluginStart()
{
ConnectSQL();
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("round_start", Event_RoundStart);
RegConsoleCmd("say", Command_Say);
RegConsoleCmd("say_team", Command_Say);
RegConsoleCmd("sm_store", Command_Shop);
RegConsoleCmd("sm_shop", Command_Shop);
RegConsoleCmd("sm_getpos", Command_GetPos);
RegConsoleCmd("sm_scout", Command_Scout);
RegAdminCmd("sm_store_admin", Command_Admin, ADMFLAG_CUSTOM5);
CvarTransmitCost = CreateConVar("shop_transmit_cost", "5", "Commission to transfer a percentage.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0);
CvarTransmitMin = CreateConVar("shop_transmit_min", "100", "The minimum amount for the transfer.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0);
CvarLuckCost = CreateConVar("shop_luck_cost", "150", "Credits to Try your luck.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 1.0);
CvarLuckChance = CreateConVar("shop_luck_chance", "10", "A chance to win to Try your luck a percentage.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0, true, 99.0);
CvarSalePercent = CreateConVar("shop_sale_percent", "25", "How many will not return from the price of the trail a percentage.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0, true, 100.0);
CvarTestTime = CreateConVar("shop_test_time", "30.0", "How much time is given for a fitting.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.1);
CvarModelCost = CreateConVar("shop_model_cost", "500", "The cost of skins.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0);
CvarModelT = CreateConVar("shop_model_t", "models/player/ct_urban.mdl", "Skin for T.", FCVAR_PLUGIN|FCVAR_NOTIFY);
CvarModelCT = CreateConVar("shop_model_ct", "models/player/ct_urban.mdl", "Skin for CT.", FCVAR_PLUGIN|FCVAR_NOTIFY);
CvarAutoGive = CreateConVar("shop_cred_amount", "2", "How much credit is given in a minute.", FCVAR_PLUGIN|FCVAR_NOTIFY);
CvarGiveForKill = CreateConVar("shop_give_for_kill", "10", "Credits for killing.", FCVAR_PLUGIN|FCVAR_NOTIFY);
AutoExecConfig();
CreateTimer(60.0, Timer_AutoGiveCredits, _, TIMER_REPEAT);
LoadTranslations("plugin.mg_shop.phrases");
LoadTranslations("common.phrases");
}
public Action:Timer_AutoGiveCredits(Handle:timer)
{
for(new client = 1; client <= MaxClients; client++)
{
if(IsValidPlayer(client, true))
SQL_Credits[client] += GetConVarInt(CvarAutoGive);
}
}
public Action:Command_Scout(client, args)
{
if(IsValidPlayer(client))
{
if(!IsPlayerAlive(client))
{
CPrintToChat(client, Prefix, "You have to be alive!", client);
return Plugin_Handled;
}
new weapon = GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY);
if(weapon != -1)
{
CPrintToChat(client, Prefix, "Do you already have a gun!", client);
return Plugin_Handled;
}
if(SQL_Credits[client] >= 50)
{
new scout = GivePlayerItem(client, "weapon_scout");
if(scout != -1)
{
SetEntProp(scout, Prop_Send, "m_iClip1", 0);
new ammoOffset = FindSendPropInfo("CCSPlayer", "m_iAmmo");
SetEntData(client, ammoOffset+8, 0);
SQL_Credits[client] -= 50;
CPrintToChat(client, Prefix, "You bought a scout for 100 credits.", client);
}
}
else
CPrintToChat(client, Prefix, "It is not enough money.", client);
}
return Plugin_Handled;
}
public Action:Command_GetPos(client, args)
{
if(IsValidPlayer(client))
{
new Float:pos[3];
GetClientEyePosition(client, pos);
ReplyToCommand(client, "\x04[SM]\x01 Your position: %f %f %f", pos[0], pos[1], pos[2]);
}
return Plugin_Handled;
}
public Action:Command_Shop(client, args)
{
if(IsValidPlayer(client))
DisplayMenu(BuildMenuMain(client), client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public Action:Command_Admin(client, args)
{
if(IsValidPlayer(client))
DisplayMenu(BuildMenuAdmin(client), client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public OnPluginEnd()
{
for(new i = 1; i <= MaxClients; i++)
{
if(!IsValidPlayer(i, false))
continue;
if(SQL_IsClientLoaded)
{
decl String:auth[128];
GetClientAuthString(i, auth, sizeof(auth));
SQL_UpdatePlayer(i, auth);
}
}
}
public OnMapStart()
{
CreateShopTrails();
CreateShopHats();
ReadBall();
decl String:buffer[PLATFORM_MAX_PATH];
GetConVarString(CvarModelT, buffer, sizeof(buffer));
PrecacheModel(buffer, true);
GetConVarString(CvarModelCT, buffer, sizeof(buffer));
PrecacheModel(buffer, true);
PrecacheSound("weapons/hegrenade/explode3.wav", true);
ExplosionModel = PrecacheModel("materials/sprites/zerogxplode.vmt", false);
}
public OnMapEnd()
{
for(new i = 1; i <= MaxClients; i++)
{
hTimerResetPlayers = INVALID_HANDLE;
if(!IsValidPlayer(i, false))
continue;
if(SQL_IsClientLoaded)
{
decl String:auth[128];
GetClientAuthString(i, auth, sizeof(auth));
SQL_UpdatePlayer(i, auth);
}
}
}
public OnClientAuthorized(client, const String:auth[])
{
if(SQL_IsConnectedDB)
SQL_LoadPlayer(client, auth);
}
public OnClientDisconnect(client)
{
if(SQL_IsClientLoaded[client])
{
decl String:auth[128];
GetClientAuthString(client, auth, sizeof(auth));
SQL_UpdatePlayer(client, auth);
SQL_IsClientLoaded[client] = false;
}
RemoveShopItems(client);
}
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(IsValidPlayer(client))
if(GetClientTeam(client) == CS_TEAM_T || GetClientTeam(client) == CS_TEAM_CT)
CreateTimer(1.0, Timer_PostSpawn, client, TIMER_FLAG_NO_MAPCHANGE);
}
public Action:Timer_PostSpawn(Handle:timer, any:client)
{
if(IsValidPlayer(client, true))
{
IsPlayerTakeBall[client] = false;
decl String:model[PLATFORM_MAX_PATH];
if(SQL_DefItem[client][2] == 1)
{
if(GetClientTeam(client) == CS_TEAM_T)
GetConVarString(CvarModelT, model, sizeof(model));
else if(GetClientTeam(client) == CS_TEAM_CT)
GetConVarString(CvarModelCT, model, sizeof(model));
SetEntityModel(client, model);
}
else
{
GetClientModel(client, model, sizeof(model));
if(StrEqual(model, "models/player/ct_gsg9.mdl") || StrEqual(model, "models/player/ct_sas.mdl"))
SetEntityModel(client, "models/player/ct_urban.mdl");
}
new Float:pos[3];
GetClientAbsOrigin(client, pos);
new Handle:datapack = CreateDataPack();
WritePackCell(datapack, client);
WritePackFloat(datapack, pos[0]);
WritePackFloat(datapack, pos[1]);
WritePackFloat(datapack, pos[2]);
hTimerResetPlayers[client] = CreateTimer(0.5, Timer_ResetPlayers, datapack, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
RemoveShopItems(client);
CreateShopItems(client);
}
return Plugin_Stop;
}
public Action:Timer_ResetPlayers(Handle:timer, Handle:datapack)
{
ResetPack(datapack);
new client = ReadPackCell(datapack);
if(!IsValidPlayer(client, true))
{
hTimerResetPlayers[client] = INVALID_HANDLE;
return Plugin_Stop;
}
if(!IsPlayerTakeBall[client])
return Plugin_Continue;
new Float:pos[3], Float:pos2[3];
pos[0] = ReadPackFloat(datapack);
pos[1] = ReadPackFloat(datapack);
pos[2] = ReadPackFloat(datapack);
GetClientAbsOrigin(client, pos2);
if(GetVectorDistance(pos, pos2) > 200.0)
return Plugin_Continue;
IsPlayerTakeBall[client] = false;
CPrintToChat(client, Prefix, "Your pass maps of reset.", client);
return Plugin_Continue;
}
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
RemoveShopItems(victim);
if(AreValidPlayers(victim, attacker))
SQL_Credits[attacker] += GetConVarInt(CvarGiveForKill);
}
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new client = 1; client <= MaxClients; client++)
{
if(hTimerResetPlayers[client] != INVALID_HANDLE)
{
KillTimer(hTimerResetPlayers[client]);
hTimerResetPlayers[client] = INVALID_HANDLE;
}
}
if((fBallPos[0] != 0.0 && fBallPos[1] != 0.0 && fBallPos[2] != 0.0))
{
WinnerPosition = 0;
new ent = CreateEntityByName("prop_dynamic_override");
if(IsValidEntity(ent))
{
DispatchKeyValue(ent, "model", "models/items/cs_gift.mdl");
//DispatchKeyValue(ent, "spawnflags", "256");
DispatchKeyValue(ent, "solid", "0");
DispatchKeyValue(ent, "disablereceiveshadows", "1");
DispatchKeyValue(ent, "disableshadows", "1");
DispatchKeyValue(ent, "DefaultAnim", "spin");
DispatchSpawn(ent);
ActivateEntity(ent);
TeleportEntity(ent, fBallPos, NULL_VECTOR, NULL_VECTOR);
CreateTimer(0.1, Timer_CheckPlayers, ent, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}
}
}
public Action:Timer_CheckPlayers(Handle:timer, any:entity)
{
if(!IsValidEntity(entity))
return Plugin_Stop;
if(WinnerPosition > 3)
WinnerPosition = 3;
if(BallCredits[WinnerPosition] <= 0)
return Plugin_Stop;
decl Float:pos_ent[3], Float:pos[3];
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", pos_ent);
for(new client = 1; client <= MaxClients; client++)
{
if(IsValidPlayer(client, true))
{
if(IsPlayerTakeBall[client])
continue;
GetClientAbsOrigin(client, pos);
if(GetVectorDistance(pos_ent, pos) > 200.0)
continue;
decl String:name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
new amount = BallCredits[WinnerPosition];
if(HasAdminFlags(client, ADMFLAG_CUSTOM6))
amount *= 2;
CPrintToChatAll("\x04[SHOP] \x01%t", "Prize", name, amount);
EmitSoundToAll("weapons/hegrenade/explode3.wav");
pos_ent[0] += 150.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll();
pos_ent[0] -= 300.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll();
pos_ent[0] += 150.0;
pos_ent[1] += 150.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll(1.0);
pos_ent[1] -= 300.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll(1.0);
pos_ent[1] += 150.0;
pos_ent[0] += 150.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll(2.0);
pos_ent[0] -= 300.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll(2.0);
pos_ent[0] += 150.0;
pos_ent[1] += 150.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll(2.0);
pos_ent[1] -= 300.0;
TE_SetupExplosion(pos_ent, ExplosionModel, 10.0, 1, 0, 275, 160);
TE_SendToAll(2.0);
CreateTimer(1.0, Timer_SoundEffectPlayerPrize, 0, TIMER_FLAG_NO_MAPCHANGE);
SQL_Credits[client] += amount;
WinnerPosition++;
IsPlayerTakeBall[client] = true;
}
}
return Plugin_Continue;
}
public Action:Timer_SoundEffectPlayerPrize(Handle:timer, any:amount)
{
EmitSoundToAll("weapons/hegrenade/explode3.wav");
amount++;
if(amount < 2)
CreateTimer(1.0, Timer_SoundEffectPlayerPrize, amount, TIMER_FLAG_NO_MAPCHANGE);
}
public Action:Hook_TrailShouldHide(entity, client)
{
if(IsValidEntity(entity) && IsValidPlayer(client, false))
if(SQL_SetShowItems[client][0] == false)
return Plugin_Handled;
return Plugin_Continue;
}
public Action:Hook_HatShouldHide(entity, client)
{
if(IsValidPlayer(client, false))
{
if(entity == ItemEntity[client][1] || SQL_SetShowItems[client][1] == false)
return Plugin_Handled;
if(GetEntProp(client, Prop_Send, "m_iObserverMode") == 4 && GetEntPropEnt(client, Prop_Send, "m_hObserverTarget") >= 0)
{
new target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if(entity == ItemEntity[target][1])
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action:Command_Say(client, args)
{
if(IsValidPlayer(client))
{
decl String:text[192];
GetCmdArgString(text, sizeof(text));
StripQuotes(text);
if(!SQL_IsClientLoaded[client])
{
CPrintToChat(client, Prefix, "You were not loaded. Please, rejoin the game.", client);
return Plugin_Continue;
}
else if(StrEqual(text, "store", false) || StrEqual(text, "shop", false))
{
DisplayMenu(BuildMenuMain(client), client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
else if(bTransmitEnable[client])
{
bTransmitEnable[client] = false;
new amount = StringToInt(text);
if(!amount)
{
CPrintToChat(client, Prefix, "Wrong amount!", client);
return Plugin_Handled;
}
if(amount < GetConVarInt(CvarTransmitMin))
{
CPrintToChat(client, Prefix, "The minimum amount to transfer:", client, GetConVarInt(CvarTransmitMin));
return Plugin_Handled;
}
if(amount > SQL_Credits[client])
{
CPrintToChat(client, Prefix, "It is not enough money.", client);
return Plugin_Handled;
}
LastTransmitAmount[client] = amount;
DisplayMenu(BuildMenuTransmit(client), client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
else if(bAdminAddCredits[client])
{
bAdminAddCredits[client] = false;
new amount = StringToInt(text);
if(!amount)
{
CPrintToChat(client, Prefix, "Wrong amount!", client);
return Plugin_Handled;
}
SQL_Credits[LastAdminTarget[client]] += amount;
return Plugin_Handled;
}
else if(bAdminTakeCredits[client])
{
bAdminTakeCredits[client] = false;
new amount = StringToInt(text);
if(!amount)
{
CPrintToChat(client, Prefix, "Wrong amount!", client);
return Plugin_Handled;
}
SQL_Credits[LastAdminTarget[client]] -= amount;
return Plugin_Handled;
}
}
return Plugin_Continue;
}