- - Random Code Archive
(https://forums.alliedmods.net/showthread.php?t=295055)
headline
03-14-2017 23:17
Random Code Archive
So I've been looking for a place to share code that I've found that's written by other people, but I feel may be useful to others. Nothing posted here has any guarantee to work, but it may prove to be useful to some people. I comb through and ensure nothing malicious has been posted on her.
All code I will/have posted are not indicated to be kept private and were posted publicly on the internet, just in hard places to find :D
I will continue editing this post to add new finds..
Seems to be some jailbreak plugin running with the warden plugin so wardens can draw markers.
new g_color_red[MAXPLAYERS+1];
new g_color_green[MAXPLAYERS+1];
new g_color_blue[MAXPLAYERS+1];
new g_color_yellow[MAXPLAYERS+1];
new const String:RELATIVE_SOUND_PATH[] = "*/buttons/bell1.wav";
//lasers!
new g_LightningSprite;
new g_beamSprite;
new g_haloSprite;
public Plugin:myinfo =
{
name = "Warden Pointers",
author = "Lt.DoomY",
description = "Warden's can place a pointer on the map.",
version = PLUGIN_VERSION,
url = "http://tangoworldwide.net"
};
public OnPluginStart()
{
RegConsoleCmd("buyammo1", Command_Pointer);
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
Clear_vars(client);
}
public Action:Command_Pointer(client, args)
{
if(IsClientInGame(client))
{
if(warden_iswarden(client))
{
PointerMenu(client);
return Plugin_Handled;
}
PrintToChat(client, "\x01 \x04[Pointers]\x02 You must be warden to use pointers.");
}
return Plugin_Continue;
}
//FOR ONE WAY COMMANDS ONLY!!!----
//----
public Checkstatus(client, number)
{
if(IsClientInGame(client))
{
if(warden_iswarden(client))
{
switch(number)
{
case 1: //red
{
if (g_color_red[client])
{
SpamMessage(client);
return;
}
}
case 2: //green
{
if (g_color_green[client])
{
SpamMessage(client);
return;
}
}
case 3: //blue
{
if (g_color_blue[client])
{
SpamMessage(client);
return;
}
}
case 4: //yellow
{
if (g_color_yellow[client])
{
SpamMessage(client);
return;
}
}
}
Pointers_function(client, number)
return;
}
PrintToChat(client, "\x01 \x04[Pointers]\x02 You must be warden to use pointers.");
}
}
public WPMenuHandler(Handle:wpmenu, MenuAction:action, client, number)
{
if (action == MenuAction_End)
{
CloseHandle(wpmenu);
}
if (action == MenuAction_Select)
{
if(warden_iswarden(client))
{
number = number + 1;
switch(number)
{
case 1: //red
{
if (g_color_red[client])
{
SpamMessage(client);
return;
}
}
case 2: //green
{
if (g_color_green[client])
{
SpamMessage(client);
return;
}
}
case 3: //blue
{
if (g_color_blue[client])
{
SpamMessage(client);
return;
}
}
case 4: //yellow
{
if (g_color_yellow[client])
{
SpamMessage(client);
return;
}
}
}
Pointers_function(client, number);
}
}
}
SpamMessage(client)
{
if(IsClientInGame(client))
{
if(warden_iswarden(client))
{
PointerMenu(client);
}
PrintToChat(client, "\x01 \x04[Pointers]\x02 You must wait 10 seconds before placing that color again.");
}
}
Pointers_function(client, colors)
{
//VARS
new Float:clientOrigin[3];
new Float:StartOrigin[3];
new Float:clientEyePos[3];
new Float:clientEyeAngle[3];
new Float:baseOrigin[3];
GetClientAbsOrigin(client, clientOrigin);
GetClientEyeAngles(client, clientEyeAngle);
GetClientEyePosition(client, clientEyePos);
new String:weapon13[MAXPLAYERS+1][PLATFORM_MAX_PATH];
new String:WeaponList[8][32];
new g_iSizeOfList;
new Handle:g_PEnabled = INVALID_HANDLE;
new Handle:g_SEnabled = INVALID_HANDLE;
new Handle:g_TEnabled = INVALID_HANDLE;
new Handle:g_PeeSound = INVALID_HANDLE;
new g_PRagdoll[MAXPLAYERS + 1] = { 0, ... }
new g_PKiller[MAXPLAYERS + 1] = { 0, ... }
new g_TRagdoll[MAXPLAYERS + 1] = { 0, ... }
new g_TKiller[MAXPLAYERS + 1] = { 0, ... }
new g_SRagdoll[MAXPLAYERS + 1] = { 0, ... }
new g_SKiller[MAXPLAYERS + 1] = { 0, ... }
new g_Attachments[MAXPLAYERS + 1] = { 0, ... }
new Handle:g_Timers[MAXPLAYERS + 1] = { INVALID_HANDLE, ... }
new bool:g_Teabagging[MAXPLAYERS + 1] = { false, ... };
new bool:g_bPiss[MAXPLAYERS + 1] = { false, ... }
new bool:g_bCanPiss[MAXPLAYERS + 1] = { true, ... }
new g_TickCounter = 0;
new BeamSprite;
new HaloSprite;
new String:fsound[256];
new String:psound[256];
new Handle:g_CVarAdmFlag;
new Handle:g_CVarAdmFlag2;
new Handle:g_veces;
new g_AdmFlag;
new g_AdmFlag2;
new veces[MAXPLAYERS+1];
public Plugin:myinfo =
{
name = "Piss+Shit+Teabag Mod",
author = "Franc1sco Franug",
description = "Privately coded plugin",
version = PLUGIN_VERSION,
url = ""
}
g_CVarAdmFlag = CreateConVar("sm_piss_adminflag", "0", "Admin flag required. 0 = No flag needed. Can use a b c ....");
g_CVarAdmFlag2 = CreateConVar("sm_piss_inmunity", "0", "Admin flag required for be inmunity. 0 = No flag needed. Can use a b c ....");
HookConVarChange(g_CVarAdmFlag, CVarChange);
HookConVarChange(g_CVarAdmFlag2, CVarChange2);
}
public CVarChange(Handle:convar, const String:oldValue[], const String:newValue[]) {
g_AdmFlag = ReadFlagString(newValue);
}
public CVarChange2(Handle:convar, const String:oldValue[], const String:newValue[]) {
g_AdmFlag2 = ReadFlagString(newValue);
}
public OnMapStart()
{
BeamSprite = PrecacheModel("materials/sprites/xbeam2.vmt");
HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");
public Action:Help(client, args)
{
new Handle:menu = CreateMenu(DIDMenuHandler);
SetMenuTitle(menu, "Help Menu");
AddMenuItem(menu, "", "To piss on your victim's dead body you have to bind a key to sm_piss\nOpen your console and type: bind key sm_piss\nExample: bind x sm_piss\nThen stand still above your victim's body and press your key and you'll piss on him!\nYou can control the direction of the pee with your mouse!\nYou are not able to move or to shoot for 8 seconds when you piss, so beware!");
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, 0);
return Plugin_Handled;
}
public DIDMenuHandler(Handle:menu, MenuAction:action, client, itemNum)
{
if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Action:Piss_In(client, args)
{
if(!GetConVarBool(g_PEnabled))
return Plugin_Continue;
if(!g_bCanPiss[client])
return Plugin_Continue;
if ((g_AdmFlag > 0) && !CheckCommandAccess(client, "sm_piss", g_AdmFlag, true))
{
PrintToChat(client, "\x04You do not have access");
return Plugin_Handled;
}
if(veces[client] > GetConVarInt(g_veces))
{
PrintToChat(client, "\x04Times for round excedded");
return Plugin_Handled;
}
for(new i=1;i<=MaxClients;++i)
{
if(g_PKiller[i] == client)
{
if(IsValidEdict(g_PRagdoll[i]))
{
if ((g_AdmFlag2 > 0) && !CheckCommandAccess(client, "sm_piss2", g_AdmFlag2, true))
{
PrintToChat(client, "\x04You do not have access");
return Plugin_Handled;
}
new Float:rposition[3];
new Float:cposition[3];
GetEntPropVector(g_PRagdoll[i], Prop_Send, "m_vecOrigin", rposition);
GetClientAbsOrigin(client, cposition);
decl Float:DistanceG;
DistanceG = GetVectorDistance(rposition,cposition);
if(DistanceG <= 300.0)
{
/* if(rposition[0] > cposition[0]-50 && rposition[0] < cposition[0]+50)
{
if(rposition[1] > cposition[1]-50 && rposition[1] < cposition[1]+50)
{
if(rposition[2] > cposition[2]-5 && rposition[2] < cposition[2]+5)
{ */
new String:clientname[32];
new String:victimname[32];
GetClientName(client, clientname, sizeof(clientname));
GetClientName(i, victimname, sizeof(victimname));
new Float:pos[3];
new Float:end[3];
new Float:ang[3];
GetClientEyePosition(client, pos);
GetClientEyeAngles(client, ang);
pos[2] -= 23.0;
ang[0] = 50.0;
TR_TraceRayFilter(pos, ang, MASK_PLAYERSOLID, RayType_Infinite, DontHitSelf, client);
TR_GetEndPosition(end);
A player tracker that tells you by peeking into the db information about a player's last connection, last server joined, etc. UNESCAPED PLAYER NAME ENTRY! DO NOT RUN UNLESS YOU KNOW WHAT TO EDIT
SQL_Query(DB, "CREATE TABLE IF NOT EXISTS `GlobalTracker` (`SteamID` varchar(64) NOT NULL, `LastName` varchar(128) NOT NULL, `TotalPlayed` int NOT NULL, `LastSeen` varchar(128) NOT NULL, `Server` varchar(128) NOT NULL, `FirstConnect` varchar(128) NOT NULL, PRIMARY KEY (`STEAMID`));");
}
public Action tAlert(Handle timer)
{
CPrintToChatAll("%s Server not specified! Contact Ownership/Oscar", PLUGIN_PREFIX);
}
public Action tAddtime(Handle timer)
{
if(tEnabled)
{
for (new i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && !IsFakeClient(i))
{
Handle sendQuery;
char queryH[1028], clientid[150];
GetClientAuthId(i, AuthId_Steam3, clientid, sizeof(clientid));
Format(queryH, sizeof(queryH), "UPDATE `GlobalTracker` SET `TotalPlayed`= `TotalPlayed` + 1 WHERE `SteamID` = '%s'", clientid);
sendQuery = SQL_Query(DB, queryH);
new limit_poziomu = 401;
new limit_inteligencji = 100;
new limit_zdrowia = 50;
new limit_obrazen = 50;
new limit_wytrzymalosci = 100;
new limit_kondycji = 100;
new co_ile_lv_punkt = 1;
new ile_rozdawac[] = {1, 10, -1};
new ilosc_dynamitow_gracza[MAX_PLAYERS+1]
new xp_kill = 10;
new xp_kill_hs = 5;
new xp_winround = 10;
new xp_objectives = 10;
new xp_kill_vip = 20;
new xp_kill_hs_vip = 10;
new xp_winround_vip = 20;
new xp_objectives_vip = 20;
new co_ile_zapisywac = 30; // co ile sekund nadpisywac dane graczowi (tylko gdy zdobyl/stracil poziom/doswiadczenie lub rozdal/zresetowal statystyki)
new Handle:sql,
Handle:sql_task[MAX_PLAYERS+1],
Handle:hud_task[MAX_PLAYERS+1],
sql_baza;
HookUserMessage(GetUserMessageId("TextMsg"), TextMessage, true);
LoadTranslations("common.phrases");
DataBaseConnect();
}
public OnMapStart()
{
for(new i = 1; i < sizeof dzwieki_serwera; i ++)
{
new String:sound_serwer[512];
Format(sound_serwer, sizeof(sound_serwer), "sound/%s", dzwieki_serwera[i]);
AddFileToDownloadsTable(sound_serwer);
}
for(new i = 1; i < sizeof modele_serwera; i ++)
PrecacheModel(modele_serwera[i]);
DisplayMenu(menu, client, 250);
}
else
PrintToChat(client, "[\x02COD MOD\x01]\x04 Musisz mieć wybraną klasę aby móc oddać item!");
}
public OddajItem_Handler(Handle:classhandle, MenuAction:action, client, Position)
{
if(action == MenuAction_Select)
{
new String:Item[64];
GetMenuItem(classhandle, Position, Item, sizeof(Item));
Position ++;
new userid = FindTarget(0, Item);
if(!IsValidClient(userid) || userid == -1)
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie odnaleziono wybranego gracza!");
else if(!klasa_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz musi mieć klasę by móc mu przekazać item!");
else if(informacje_itemu_gracza[userid][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz ma już item!");
else if(!informacje_itemu_gracza[client][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie masz żadnego itemu!");
else
{
new String:nazwa[512];
Format(nazwa, sizeof(nazwa), "Czy chcesz przyjac item od %s?", nazwa_gracza[client]);
new Handle:menu = CreateMenu(OddajItem_Handler2);
SetMenuTitle(menu, nazwa);
AddMenuItem(menu, "1", "Tak");
AddMenuItem(menu, "2", "Nie");
DisplayMenu(menu, userid, 250);
client_gracza[userid] = client;
}
}
else if(action == MenuAction_End)
CloseHandle(classhandle);
}
public OddajItem_Handler2(Handle:classhandle, MenuAction:action, client, Position)
{
if(action == MenuAction_Select)
{
new String:Item[32];
GetMenuItem(classhandle, Position, Item, sizeof(Item));
new userid = client_gracza[client];
if(StrEqual(Item, "1"))
{
if(!IsValidClient(userid))
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie odnaleziono wybranego gracza!");
else if(!klasa_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz musi mieć klasę by móc od niego odebrać item!");
else if(!informacje_itemu_gracza[userid][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz nie ma żadnego itemu!");
else if(informacje_itemu_gracza[client][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Masz już item!");
else
{
DajItem(client, informacje_itemu_gracza[userid][0]);
informacje_itemu_gracza[client][1] = informacje_itemu_gracza[userid][1];
UsunItem(userid);
PrintToChatAll("[\x02COD MOD\x01]\x04 Gracz %s przekazał item graczowi %s.", nazwa_gracza[userid], nazwa_gracza[client]);
}
}
else if(StrEqual(Item, "2"))
{
if(IsValidClient(userid))
PrintToChat(userid, "[\x02COD MOD\x01]\x04 Wybrany gracz nie zgodził się na przyjęcie itemu!");
}
}
else if(action == MenuAction_End)
CloseHandle(classhandle);
}
public Action:WymienItem(client)
{
if(klasa_gracza[client])
{
new Handle:menu = CreateMenu(WymienItem_Handler);
SetMenuTitle(menu, "Oddaj Item:");
for(new i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i) || i == client)
continue;
DisplayMenu(menu, client, 250);
}
else
PrintToChat(client, "[\x02COD MOD\x01]\x04 Musisz mieć wybraną klasę aby móc wymienić item!");
}
public WymienItem_Handler(Handle:classhandle, MenuAction:action, client, Position)
{
if(action == MenuAction_Select)
{
new String:Item[64];
GetMenuItem(classhandle, Position, Item, sizeof(Item));
Position ++;
new userid = FindTarget(0, Item);
if(!IsValidClient(userid) || userid == -1)
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie odnaleziono wybranego gracza!");
else if(!klasa_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz musi mieć klasę by móc mu przekazać item!");
else if(!informacje_itemu_gracza[userid][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz nie ma żadnego itemu!");
else if(!informacje_itemu_gracza[client][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie masz żadnego itemu!");
else if(informacje_itemu_gracza[client][0] == informacje_itemu_gracza[userid][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie możesz wymienić swojego itemu na ten sam!");
else if(wymiana_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz wymieniał już swój item!");
else if(wymiana_gracza[client])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Możesz wymienić item tylko raz na mapę!");
else if(blokada_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz zablokował wymianę itemu!");
else if(blokada_gracza[client])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Masz zablokowaną wymianę itemu!");
else
{
new String:nazwa[512];
Format(nazwa, sizeof(nazwa), "Czy chcesz wymienic swój item na %s z graczem %s?", nazwy_itemow[informacje_itemu_gracza[client][0]], nazwa_gracza[client]);
new Handle:menu = CreateMenu(WymienItem_Handler2);
SetMenuTitle(menu, nazwa);
AddMenuItem(menu, "1", "Tak");
AddMenuItem(menu, "2", "Nie");
DisplayMenu(menu, userid, 250);
client_gracza[userid] = client;
}
}
else if(action == MenuAction_End)
CloseHandle(classhandle);
}
public WymienItem_Handler2(Handle:classhandle, MenuAction:action, client, Position)
{
if(action == MenuAction_Select)
{
new String:Item[32];
GetMenuItem(classhandle, Position, Item, sizeof(Item));
new userid = client_gracza[client];
if(StrEqual(Item, "1"))
{
if(!IsValidClient(userid))
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie odnaleziono wybranego gracza!");
else if(!klasa_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz musi mieć klasę by móc od niego odebrać item!");
else if(!informacje_itemu_gracza[userid][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz nie ma żadnego itemu!");
else if(!informacje_itemu_gracza[client][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie masz żadnego itemu!");
else if(informacje_itemu_gracza[client][0] == informacje_itemu_gracza[userid][0])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Nie możesz wymienić swojego itemu na ten sam!");
else if(wymiana_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz wymieniał już swój item!");
else if(wymiana_gracza[client])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Mozesz wymienić item tylko raz na mapę!");
else if(blokada_gracza[userid])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Wybrany gracz zablokował wymianę itemu!");
else if(blokada_gracza[client])
PrintToChat(client, "[\x02COD MOD\x01]\x04 Masz zablokowaną wymianę itemu!");
else
{
new item_zmienny[4];
item_zmienny[0] = informacje_itemu_gracza[userid][0];
item_zmienny[1] = informacje_itemu_gracza[client][0];
item_zmienny[2] = informacje_itemu_gracza[userid][1];
item_zmienny[3] = informacje_itemu_gracza[client][1];
public void OnRoundStart(Handle E, const char[] N, bool NB)
{
CreateTimer(0.125, Timer_Decoys, _, TIMER_FLAG_NO_MAPCHANGE);
}
public Action Timer_Decoys(Handle pTimer, any Data)
{
for (int iId = 1; iId <= MaxClients; iId++)
{
if (IsClientInGame(iId) && IsPlayerAlive(iId) && g_bDecoy[iId])
{
g_bDecoy[iId] = false;
GivePlayerItem(iId, "weapon_decoy");
}
}
}
Feel free to post some of your own finds
Franc1sco
03-15-2017 09:35
Re: Random Code Archive
I posted Teabag here but I removed it because people said me that these type of plugin is not allowed here for be obscene. No idea if still I have all the files in my PC.
OSWO
03-16-2017 14:10
Re: Random Code Archive
I think you should step off your high horse.
headline
03-16-2017 14:22
Re: Random Code Archive
Quote:
Originally Posted by OSWO
(Post 2504175)
I think you should step off your high horse.
If this is about me please PM me. :D
balonfx
03-16-2017 16:26
Re: Random Code Archive
Normally I'd think you would post when you had multiple instances of code... not just two but :bee:
Thanks, we lost the source to this so re-wrote it entirely! Think this version used to crash our servers, or didn't work with our version of warden. Who knows.
headline
03-16-2017 21:24
Re: Random Code Archive
Quote:
Originally Posted by balonfx
(Post 2504223)
Normally I'd think you would post when you had multiple instances of code... not just two but :bee:
Thanks, we lost the source to this so re-wrote it entirely! Think this version used to crash our servers, or didn't work with our version of warden. Who knows.
Yeah, perhaps I should've waited to post until I had more, however I like the idea of everyone posting cool stuff on here so why not do it a little early :D
sdz
03-17-2017 14:31
Re: Random Code Archive
Quote:
Originally Posted by balonfx
(Post 2504223)
Normally I'd think you would post when you had multiple instances of code... not just two but :bee:
Thanks, we lost the source to this so re-wrote it entirely! Think this version used to crash our servers, or didn't work with our version of warden. Who knows.
SQL_Query
OSWO
03-17-2017 15:03
Re: Random Code Archive
:) Thanks for the free shoutout. :bee:
headline
05-18-2017 15:30
Re: Random Code Archive
Editing the main post was freezing due to the amount of text so I'll continue from here
Someone's donation system. Looks pretty good to me
//////////////////////////////////
// GLOBAL VARIABLES //
//////////////////////////////////
new GAME_CSS = false;
new GAME_CSGO = false;
new GAME_DOD = false;
new GAME_TF2 = false;
new GAME_L4D = false;
new GAME_L4D2 = false;
new String:g_szGameDir[64];
new Handle:g_hDatabase = INVALID_HANDLE;
new Handle:g_hAdminMenu = INVALID_HANDLE;
new Handle:g_hLogFile = INVALID_HANDLE;
new g_cvarDatabaseEntry = -1;
new g_cvarDatabaseRetries = -1;
new g_cvarDatabaseTimeout = -1;
new g_cvarItemSource = -1;
new g_cvarItemsTable = -1;
new g_cvarStartCredits = -1;
new g_cvarCreditTimer = -1;
new g_cvarCreditAmountActive = -1;
new g_cvarCreditAmountInactive = -1;
new g_cvarCreditAmountKill = -1;
new g_cvarRequiredFlag = -1;
new g_cvarVIPFlag = -1;
new g_cvarSellEnabled = -1;
new g_cvarGiftEnabled = -1;
new g_cvarCreditGiftEnabled = -1;
new g_cvarSellRatio = -1;
new g_cvarConfirmation = -1;
new g_cvarAdminFlag = -1;
new g_cvarSaveOnDeath = -1;
new g_cvarCreditMessages = -1;
new g_cvarShowVIP = -1;
new g_cvarLogging = -1;
new g_cvarSilent = -1;
new g_eItems[STORE_MAX_ITEMS][Store_Item];
new g_eClients[MAXPLAYERS+1][Client];
new g_eClientItems[MAXPLAYERS+1][STORE_MAX_ITEMS][Client_Item];
new g_eTypeHandlers[STORE_MAX_HANDLERS][Type_Handler];
new g_eMenuHandlers[STORE_MAX_HANDLERS][Menu_Handler];
new g_ePlans[STORE_MAX_ITEMS][STORE_MAX_PLANS][Item_Plan];
new g_iItems = 0;
new g_iTypeHandlers = 0;
new g_iMenuHandlers = 0;
new g_iMenuBack[MAXPLAYERS+1];
new g_iLastSelection[MAXPLAYERS+1];
new g_iSelectedItem[MAXPLAYERS+1];
new g_iSelectedPlan[MAXPLAYERS+1];
new g_iMenuClient[MAXPLAYERS+1];
new g_iMenuNum[MAXPLAYERS+1];
new g_iSpam[MAXPLAYERS+1];
new g_iPackageHandler = -1;
new g_iDatabaseRetries = 0;
new bool:g_bInvMode[MAXPLAYERS+1];
new bool:g_bMySQL = false;
// Register ConVars
g_cvarDatabaseEntry = RegisterConVar("sm_store_database", "storage-local", "Name of the default store database entry", TYPE_STRING);
g_cvarDatabaseRetries = RegisterConVar("sm_store_database_retries", "4", "Number of retries if the connection fails to estabilish with timeout", TYPE_INT);
g_cvarDatabaseTimeout = RegisterConVar("sm_store_database_timeout", "10", "Timeout in seconds to wait for database connection before retry", TYPE_FLOAT);
g_cvarItemSource = RegisterConVar("sm_store_item_source", "flatfile", "Source of the item list, can be set to flatfile and database, sm_store_items_table must be set if database is chosen (THIS IS HIGHLY EXPERIMENTAL AND MAY NOT WORK YET)", TYPE_STRING);
g_cvarItemsTable = RegisterConVar("sm_store_items_table", "store_menu", "Name of the items table", TYPE_STRING);
g_cvarStartCredits = RegisterConVar("sm_store_startcredits", "0", "Number of credits a client starts with", TYPE_INT);
g_cvarCreditTimer = RegisterConVar("sm_store_credit_interval", "60", "Interval in seconds to give out credits", TYPE_FLOAT, ConVar_CreditTimer);
g_cvarCreditAmountActive = RegisterConVar("sm_store_credit_amount_active", "1", "Number of credits to give out for active players", TYPE_INT, ConVar_CreditTimer);
g_cvarCreditAmountInactive = RegisterConVar("sm_store_credit_amount_inactive", "1", "Number of credits to give out for inactive players (spectators)", TYPE_INT, ConVar_CreditTimer);
g_cvarCreditAmountKill = RegisterConVar("sm_store_credit_amount_kill", "1", "Number of credits to give out for killing a player", TYPE_INT, ConVar_CreditTimer);
g_cvarRequiredFlag = RegisterConVar("sm_store_required_flag", "", "Flag to access the !store menu", TYPE_FLAG);
g_cvarVIPFlag = RegisterConVar("sm_store_vip_flag", "", "Flag for VIP access (all items unlocked). Leave blank to disable.", TYPE_FLAG);
g_cvarAdminFlag = RegisterConVar("sm_store_admin_flag", "z", "Flag for admin access. Leave blank to disable.", TYPE_FLAG);
g_cvarSellEnabled = RegisterConVar("sm_store_enable_selling", "1", "Enable/disable selling of already bought items.", TYPE_INT);
g_cvarGiftEnabled = RegisterConVar("sm_store_enable_gifting", "1", "Enable/disable gifting of already bought items. [1=everyone, 2=admins only]", TYPE_INT);
g_cvarCreditGiftEnabled = RegisterConVar("sm_store_enable_credit_gifting", "1", "Enable/disable gifting of credits.", TYPE_INT);
g_cvarSellRatio = RegisterConVar("sm_store_sell_ratio", "0.60", "Ratio of the original price to get for selling an item.", TYPE_FLOAT);
g_cvarConfirmation = RegisterConVar("sm_store_confirmation_windows", "1", "Enable/disable confirmation windows.", TYPE_INT);
g_cvarSaveOnDeath = RegisterConVar("sm_store_save_on_death", "0", "Enable/disable client data saving on client death.", TYPE_INT);
g_cvarCreditMessages = RegisterConVar("sm_store_credit_messages", "1", "Enable/disable messages when a player earns credits.", TYPE_INT);
g_cvarChatTag = RegisterConVar("sm_store_chat_tag", "[Store] ", "The chat tag to use for displaying messages.", TYPE_STRING);
g_cvarShowVIP = RegisterConVar("sm_store_show_vip_items", "0", "If you enable this VIP items will be shown in grey.", TYPE_INT);
g_cvarLogging = RegisterConVar("sm_store_logging", "0", "Set this to 1 for file logging and 2 to SQL logging (only MySQL). Leaving on 0 means disabled.", TYPE_INT);
g_cvarSilent = RegisterConVar("sm_store_silent_givecredits", "0", "Controls the give credits message visibility. 0 = public 1 = private 2 = no message", TYPE_INT);
public Native_IsItemInBoughtPackage(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new itemid = GetNativeCell(2);
new uid = GetNativeCell(3);
public Native_DisplayConfirmMenu(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
decl String:title[255];
GetNativeString(2, STRING(title));
new callback = GetNativeCell(3);
new data = GetNativeCell(4);
public Native_GiveItem(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new itemid = GetNativeCell(2);
new purchase = GetNativeCell(3);
new expiration = GetNativeCell(4);
new price = GetNativeCell(5);
new m_iDateOfPurchase = (purchase==0?GetTime():purchase);
new m_iDateOfExpiration = expiration;
public Native_GetClientTarget(Handle:plugin, numParams)
{
return g_iMenuClient[GetNativeCell(1)];
}
public Native_GiveClientItem(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new receiver = GetNativeCell(2);
new itemid = GetNativeCell(3);
new item = Store_GetClientItemId(client, itemid);
if(item == -1)
return 1;
new m_iId = g_eClientItems[client][item][iUniqueId];
new target = g_iMenuClient[client];
g_eClientItems[client][item][bDeleted] = true;
Store_UnequipItem(client, m_iId);
public Native_HasClientItem(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new itemid = GetNativeCell(2);
// Can he even have it?
if(!GetClientPrivilege(client, g_eItems[itemid][iFlagBits]))
return false;
// Is the item free (available for everyone)?
if(g_eItems[itemid][iPrice] <= 0 && g_eItems[itemid][iPlans]==0)
return true;
// Is the client a VIP therefore has access to all the items already?
if(Store_IsClientVIP(client) && !g_eItems[itemid][bIgnoreVIP])
return true;
// Can he even have it?
if(!GetClientPrivilege(client, g_eItems[itemid][iFlagBits]))
return false;
// Check if the client actually has the item
for(new i=0;i<g_eClients[client][iItems];++i)
{
if(g_eClientItems[client][i][iUniqueId] == itemid && !g_eClientItems[client][i][bDeleted])
if(g_eClientItems[client][i][iDateOfExpiration]==0 || (g_eClientItems[client][i][iDateOfExpiration] && GetTime()<g_eClientItems[client][i][iDateOfExpiration]))
return true;
else
return false;
}
// Check if the item is part of a group the client already has
if(Store_IsItemInBoughtPackage(client, itemid))
return true;
return false;
}
public Native_IterateEquippedItems(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new start = GetNativeCellRef(2);
new bool:attributes = GetNativeCell(3);
// The player is on the server
if(m_iReceiver != -1)
{
Store_LogMessage(client, -g_eClients[m_iReceiver][iCredits], "Player resetted");
g_eClients[m_iReceiver][iCredits] = 0;
for(new i=0;i<g_eClients[m_iReceiver][iItems];++i)
Store_RemoveItem(m_iReceiver, g_eClientItems[m_iReceiver][i][iUniqueId]);
ChatAll("%t", "Player Resetted", g_eClients[m_iReceiver][szName]);
}
public SQLCallback_Connect(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if(hndl==INVALID_HANDLE)
{
SetFailState("Failed to connect to SQL database. Error: %s", error);
}
else
{
// If it's already connected we are good to go
if(g_hDatabase != INVALID_HANDLE)
return;
g_hDatabase = hndl;
decl String:m_szDriver[2];
SQL_ReadDriver(g_hDatabase, STRING(m_szDriver));
if(m_szDriver[0] == 'm')
{
g_bMySQL = true;
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_players` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`authid` varchar(32) NOT NULL,\
`name` varchar(64) NOT NULL,\
`credits` int(11) NOT NULL,\
`date_of_join` int(11) NOT NULL,\
`date_of_last_join` int(11) NOT NULL,\
PRIMARY KEY (`id`),\
UNIQUE KEY `id` (`id`),\
UNIQUE KEY `authid` (`authid`)\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_items` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`date_of_purchase` int(11) NOT NULL,\
`date_of_expiration` int(11) NOT NULL,\
PRIMARY KEY (`id`)\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_equipment` (\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`slot` int(11) NOT NULL\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_logs` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`player_id` int(11) NOT NULL,\
`credits` int(11) NOT NULL,\
`reason` varchar(256) NOT NULL,\
`date` int(11) NOT NULL,\
PRIMARY KEY (`id`)\
)");
SQL_TQuery(g_hDatabase, SQLCallback_NoError, "ALTER TABLE store_items ADD COLUMN price_of_purchase int(11)");
decl String:m_szQuery[512];
Format(STRING(m_szQuery), "CREATE TABLE IF NOT EXISTS `%s` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`parent_id` int(11) NOT NULL DEFAULT '-1',\
`item_price` int(32) NOT NULL,\
`item_type` varchar(64) NOT NULL,\
`item_flag` varchar(64) NOT NULL,\
`item_name` varchar(64) NOT NULL,\
`additional_info` text NOT NULL,\
`item_status` tinyint(1) NOT NULL,\
`supported_game` varchar(64) NOT NULL,\
PRIMARY KEY (`id`)\
)", g_eCvars[g_cvarItemsTable][sCache]);
SQL_TVoid(g_hDatabase, m_szQuery);
}
else
{
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_players` (\
`id` INTEGER PRIMARY KEY AUTOINCREMENT,\
`authid` varchar(32) NOT NULL,\
`name` varchar(64) NOT NULL,\
`credits` int(11) NOT NULL,\
`date_of_join` int(11) NOT NULL,\
`date_of_last_join` int(11) NOT NULL\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_items` (\
`id` INTEGER PRIMARY KEY AUTOINCREMENT,\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`date_of_purchase` int(11) NOT NULL,\
`date_of_expiration` int(11) NOT NULL\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_equipment` (\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`slot` int(11) NOT NULL\
)");
SQL_TQuery(g_hDatabase, SQLCallback_NoError, "ALTER TABLE store_items ADD COLUMN price_of_purchase int(11)");
if(strcmp(g_eCvars[g_cvarItemSource][sCache], "database")==0)
{
SetFailState("Database item source can only be used with MySQL databases");
}
}
// Do some housekeeping
decl String:m_szQuery[256];
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE `date_of_expiration` <> 0 AND `date_of_expiration` < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);
}
}
public SQLCallback_ResetPlayer(Handle:owner, Handle:hndl, const String:error[], any:userid)
{
if(hndl==INVALID_HANDLE)
LogError("Error happened. Error: %s", error);
else
{
new client = GetClientOfUserId(userid);
if(SQL_GetRowCount(hndl))
{
SQL_FetchRow(hndl);
new id = SQL_FetchInt(hndl, 0);
decl String:m_szAuthId[32];
SQL_FetchString(hndl, 1, STRING(m_szAuthId));
decl String:m_szQuery[512];
Format(STRING(m_szQuery), "DELETE FROM store_players WHERE id=%d", id);
SQL_TVoid(g_hDatabase, m_szQuery);
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE player_id=%d", id);
SQL_TVoid(g_hDatabase, m_szQuery);
Format(STRING(m_szQuery), "DELETE FROM store_equipment WHERE player_id=%d", id);
SQL_TVoid(g_hDatabase, m_szQuery);
ChatAll("%t", "Player Resetted", m_szAuthId);
}
else
if(client)
Chat(client, "%t", "Credit No Match");
}
}
public Store_LoadClientInventory(client)
{
if(g_hDatabase == INVALID_HANDLE)
{
LogError("Database connection is lost or not yet initialized.");
return;
}
public Store_SaveClientInventory(client)
{
if(g_hDatabase == INVALID_HANDLE)
{
LogError("Database connection is lost or not yet initialized.");
return;
}
// Player disconnected before his inventory was even fetched
if(g_eClients[client][iCredits]==-1 && g_eClients[client][iItems]==-1)
return;
new String:m_szAttribute[64];
new String:m_szValue[64];
do
{
KvGetSectionName(kv, STRING(m_szAttribute));
KvGetString(kv, NULL_STRING, STRING(m_szValue));
SetTrieString(g_eItems[g_iItems][hAttributes], m_szAttribute, m_szValue);
} while (KvGotoNextKey(kv, false));
//////////////////////////////////
// GLOBAL VARIABLES //
//////////////////////////////////
new GAME_CSS = false;
new GAME_CSGO = false;
new GAME_DOD = false;
new GAME_TF2 = false;
new GAME_L4D = false;
new GAME_L4D2 = false;
new String:g_szGameDir[64];
new Handle:g_hDatabase = INVALID_HANDLE;
new Handle:g_hAdminMenu = INVALID_HANDLE;
new Handle:g_hLogFile = INVALID_HANDLE;
new g_cvarDatabaseEntry = -1;
new g_cvarDatabaseRetries = -1;
new g_cvarDatabaseTimeout = -1;
new g_cvarItemSource = -1;
new g_cvarItemsTable = -1;
new g_cvarStartCredits = -1;
new g_cvarCreditTimer = -1;
new g_cvarCreditAmountActive = -1;
new g_cvarCreditAmountInactive = -1;
new g_cvarCreditAmountKill = -1;
new g_cvarRequiredFlag = -1;
new g_cvarVIPFlag = -1;
new g_cvarSellEnabled = -1;
new g_cvarGiftEnabled = -1;
new g_cvarCreditGiftEnabled = -1;
new g_cvarSellRatio = -1;
new g_cvarConfirmation = -1;
new g_cvarAdminFlag = -1;
new g_cvarSaveOnDeath = -1;
new g_cvarCreditMessages = -1;
new g_cvarShowVIP = -1;
new g_cvarLogging = -1;
new g_cvarSilent = -1;
new g_eItems[STORE_MAX_ITEMS][Store_Item];
new g_eClients[MAXPLAYERS+1][Client];
new g_eClientItems[MAXPLAYERS+1][STORE_MAX_ITEMS][Client_Item];
new g_eTypeHandlers[STORE_MAX_HANDLERS][Type_Handler];
new g_eMenuHandlers[STORE_MAX_HANDLERS][Menu_Handler];
new g_ePlans[STORE_MAX_ITEMS][STORE_MAX_PLANS][Item_Plan];
new g_iItems = 0;
new g_iTypeHandlers = 0;
new g_iMenuHandlers = 0;
new g_iMenuBack[MAXPLAYERS+1];
new g_iLastSelection[MAXPLAYERS+1];
new g_iSelectedItem[MAXPLAYERS+1];
new g_iSelectedPlan[MAXPLAYERS+1];
new g_iMenuClient[MAXPLAYERS+1];
new g_iMenuNum[MAXPLAYERS+1];
new g_iSpam[MAXPLAYERS+1];
new g_iPackageHandler = -1;
new g_iDatabaseRetries = 0;
new bool:g_bInvMode[MAXPLAYERS+1];
new bool:g_bMySQL = false;
// Register ConVars
g_cvarDatabaseEntry = RegisterConVar("sm_store_database", "storage-local", "Name of the default store database entry", TYPE_STRING);
g_cvarDatabaseRetries = RegisterConVar("sm_store_database_retries", "4", "Number of retries if the connection fails to estabilish with timeout", TYPE_INT);
g_cvarDatabaseTimeout = RegisterConVar("sm_store_database_timeout", "10", "Timeout in seconds to wait for database connection before retry", TYPE_FLOAT);
g_cvarItemSource = RegisterConVar("sm_store_item_source", "flatfile", "Source of the item list, can be set to flatfile and database, sm_store_items_table must be set if database is chosen (THIS IS HIGHLY EXPERIMENTAL AND MAY NOT WORK YET)", TYPE_STRING);
g_cvarItemsTable = RegisterConVar("sm_store_items_table", "store_menu", "Name of the items table", TYPE_STRING);
g_cvarStartCredits = RegisterConVar("sm_store_startcredits", "0", "Number of credits a client starts with", TYPE_INT);
g_cvarCreditTimer = RegisterConVar("sm_store_credit_interval", "60", "Interval in seconds to give out credits", TYPE_FLOAT, ConVar_CreditTimer);
g_cvarCreditAmountActive = RegisterConVar("sm_store_credit_amount_active", "1", "Number of credits to give out for active players", TYPE_INT, ConVar_CreditTimer);
g_cvarCreditAmountInactive = RegisterConVar("sm_store_credit_amount_inactive", "1", "Number of credits to give out for inactive players (spectators)", TYPE_INT, ConVar_CreditTimer);
g_cvarCreditAmountKill = RegisterConVar("sm_store_credit_amount_kill", "1", "Number of credits to give out for killing a player", TYPE_INT, ConVar_CreditTimer);
g_cvarRequiredFlag = RegisterConVar("sm_store_required_flag", "", "Flag to access the !store menu", TYPE_FLAG);
g_cvarVIPFlag = RegisterConVar("sm_store_vip_flag", "", "Flag for VIP access (all items unlocked). Leave blank to disable.", TYPE_FLAG);
g_cvarAdminFlag = RegisterConVar("sm_store_admin_flag", "z", "Flag for admin access. Leave blank to disable.", TYPE_FLAG);
g_cvarSellEnabled = RegisterConVar("sm_store_enable_selling", "1", "Enable/disable selling of already bought items.", TYPE_INT);
g_cvarGiftEnabled = RegisterConVar("sm_store_enable_gifting", "1", "Enable/disable gifting of already bought items. [1=everyone, 2=admins only]", TYPE_INT);
g_cvarCreditGiftEnabled = RegisterConVar("sm_store_enable_credit_gifting", "1", "Enable/disable gifting of credits.", TYPE_INT);
g_cvarSellRatio = RegisterConVar("sm_store_sell_ratio", "0.60", "Ratio of the original price to get for selling an item.", TYPE_FLOAT);
g_cvarConfirmation = RegisterConVar("sm_store_confirmation_windows", "1", "Enable/disable confirmation windows.", TYPE_INT);
g_cvarSaveOnDeath = RegisterConVar("sm_store_save_on_death", "0", "Enable/disable client data saving on client death.", TYPE_INT);
g_cvarCreditMessages = RegisterConVar("sm_store_credit_messages", "1", "Enable/disable messages when a player earns credits.", TYPE_INT);
g_cvarChatTag = RegisterConVar("sm_store_chat_tag", "[Store] ", "The chat tag to use for displaying messages.", TYPE_STRING);
g_cvarShowVIP = RegisterConVar("sm_store_show_vip_items", "0", "If you enable this VIP items will be shown in grey.", TYPE_INT);
g_cvarLogging = RegisterConVar("sm_store_logging", "0", "Set this to 1 for file logging and 2 to SQL logging (only MySQL). Leaving on 0 means disabled.", TYPE_INT);
g_cvarSilent = RegisterConVar("sm_store_silent_givecredits", "0", "Controls the give credits message visibility. 0 = public 1 = private 2 = no message", TYPE_INT);
public Native_IsItemInBoughtPackage(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new itemid = GetNativeCell(2);
new uid = GetNativeCell(3);
public Native_DisplayConfirmMenu(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
decl String:title[255];
GetNativeString(2, STRING(title));
new callback = GetNativeCell(3);
new data = GetNativeCell(4);
public Native_GiveItem(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new itemid = GetNativeCell(2);
new purchase = GetNativeCell(3);
new expiration = GetNativeCell(4);
new price = GetNativeCell(5);
new m_iDateOfPurchase = (purchase==0?GetTime():purchase);
new m_iDateOfExpiration = expiration;
public Native_GetClientTarget(Handle:plugin, numParams)
{
return g_iMenuClient[GetNativeCell(1)];
}
public Native_GiveClientItem(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new receiver = GetNativeCell(2);
new itemid = GetNativeCell(3);
new item = Store_GetClientItemId(client, itemid);
if(item == -1)
return 1;
new m_iId = g_eClientItems[client][item][iUniqueId];
new target = g_iMenuClient[client];
g_eClientItems[client][item][bDeleted] = true;
Store_UnequipItem(client, m_iId);
public Native_HasClientItem(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new itemid = GetNativeCell(2);
// Can he even have it?
if(!GetClientPrivilege(client, g_eItems[itemid][iFlagBits]))
return false;
// Is the item free (available for everyone)?
if(g_eItems[itemid][iPrice] <= 0 && g_eItems[itemid][iPlans]==0)
return true;
// Is the client a VIP therefore has access to all the items already?
if(Store_IsClientVIP(client) && !g_eItems[itemid][bIgnoreVIP])
return true;
// Can he even have it?
if(!GetClientPrivilege(client, g_eItems[itemid][iFlagBits]))
return false;
// Check if the client actually has the item
for(new i=0;i<g_eClients[client][iItems];++i)
{
if(g_eClientItems[client][i][iUniqueId] == itemid && !g_eClientItems[client][i][bDeleted])
if(g_eClientItems[client][i][iDateOfExpiration]==0 || (g_eClientItems[client][i][iDateOfExpiration] && GetTime()<g_eClientItems[client][i][iDateOfExpiration]))
return true;
else
return false;
}
// Check if the item is part of a group the client already has
if(Store_IsItemInBoughtPackage(client, itemid))
return true;
return false;
}
public Native_IterateEquippedItems(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
new start = GetNativeCellRef(2);
new bool:attributes = GetNativeCell(3);
// The player is on the server
if(m_iReceiver != -1)
{
Store_LogMessage(client, -g_eClients[m_iReceiver][iCredits], "Player resetted");
g_eClients[m_iReceiver][iCredits] = 0;
for(new i=0;i<g_eClients[m_iReceiver][iItems];++i)
Store_RemoveItem(m_iReceiver, g_eClientItems[m_iReceiver][i][iUniqueId]);
ChatAll("%t", "Player Resetted", g_eClients[m_iReceiver][szName]);
}
public SQLCallback_Connect(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if(hndl==INVALID_HANDLE)
{
SetFailState("Failed to connect to SQL database. Error: %s", error);
}
else
{
// If it's already connected we are good to go
if(g_hDatabase != INVALID_HANDLE)
return;
g_hDatabase = hndl;
decl String:m_szDriver[2];
SQL_ReadDriver(g_hDatabase, STRING(m_szDriver));
if(m_szDriver[0] == 'm')
{
g_bMySQL = true;
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_players` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`authid` varchar(32) NOT NULL,\
`name` varchar(64) NOT NULL,\
`credits` int(11) NOT NULL,\
`date_of_join` int(11) NOT NULL,\
`date_of_last_join` int(11) NOT NULL,\
PRIMARY KEY (`id`),\
UNIQUE KEY `id` (`id`),\
UNIQUE KEY `authid` (`authid`)\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_items` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`date_of_purchase` int(11) NOT NULL,\
`date_of_expiration` int(11) NOT NULL,\
PRIMARY KEY (`id`)\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_equipment` (\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`slot` int(11) NOT NULL\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_logs` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`player_id` int(11) NOT NULL,\
`credits` int(11) NOT NULL,\
`reason` varchar(256) NOT NULL,\
`date` int(11) NOT NULL,\
PRIMARY KEY (`id`)\
)");
SQL_TQuery(g_hDatabase, SQLCallback_NoError, "ALTER TABLE store_items ADD COLUMN price_of_purchase int(11)");
decl String:m_szQuery[512];
Format(STRING(m_szQuery), "CREATE TABLE IF NOT EXISTS `%s` (\
`id` int(11) NOT NULL AUTO_INCREMENT,\
`parent_id` int(11) NOT NULL DEFAULT '-1',\
`item_price` int(32) NOT NULL,\
`item_type` varchar(64) NOT NULL,\
`item_flag` varchar(64) NOT NULL,\
`item_name` varchar(64) NOT NULL,\
`additional_info` text NOT NULL,\
`item_status` tinyint(1) NOT NULL,\
`supported_game` varchar(64) NOT NULL,\
PRIMARY KEY (`id`)\
)", g_eCvars[g_cvarItemsTable][sCache]);
SQL_TVoid(g_hDatabase, m_szQuery);
}
else
{
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_players` (\
`id` INTEGER PRIMARY KEY AUTOINCREMENT,\
`authid` varchar(32) NOT NULL,\
`name` varchar(64) NOT NULL,\
`credits` int(11) NOT NULL,\
`date_of_join` int(11) NOT NULL,\
`date_of_last_join` int(11) NOT NULL\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_items` (\
`id` INTEGER PRIMARY KEY AUTOINCREMENT,\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`date_of_purchase` int(11) NOT NULL,\
`date_of_expiration` int(11) NOT NULL\
)");
SQL_TVoid(g_hDatabase, "CREATE TABLE IF NOT EXISTS `store_equipment` (\
`player_id` int(11) NOT NULL,\
`type` varchar(16) NOT NULL,\
`unique_id` varchar(256) NOT NULL,\
`slot` int(11) NOT NULL\
)");
SQL_TQuery(g_hDatabase, SQLCallback_NoError, "ALTER TABLE store_items ADD COLUMN price_of_purchase int(11)");
if(strcmp(g_eCvars[g_cvarItemSource][sCache], "database")==0)
{
SetFailState("Database item source can only be used with MySQL databases");
}
}
// Do some housekeeping
decl String:m_szQuery[256];
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE `date_of_expiration` <> 0 AND `date_of_expiration` < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);
}
}
public SQLCallback_ResetPlayer(Handle:owner, Handle:hndl, const String:error[], any:userid)
{
if(hndl==INVALID_HANDLE)
LogError("Error happened. Error: %s", error);
else
{
new client = GetClientOfUserId(userid);
if(SQL_GetRowCount(hndl))
{
SQL_FetchRow(hndl);
new id = SQL_FetchInt(hndl, 0);
decl String:m_szAuthId[32];
SQL_FetchString(hndl, 1, STRING(m_szAuthId));
decl String:m_szQuery[512];
Format(STRING(m_szQuery), "DELETE FROM store_players WHERE id=%d", id);
SQL_TVoid(g_hDatabase, m_szQuery);
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE player_id=%d", id);
SQL_TVoid(g_hDatabase, m_szQuery);
Format(STRING(m_szQuery), "DELETE FROM store_equipment WHERE player_id=%d", id);
SQL_TVoid(g_hDatabase, m_szQuery);
ChatAll("%t", "Player Resetted", m_szAuthId);
}
else
if(client)
Chat(client, "%t", "Credit No Match");
}
}
public Store_LoadClientInventory(client)
{
if(g_hDatabase == INVALID_HANDLE)
{
LogError("Database connection is lost or not yet initialized.");
return;
}
public Store_SaveClientInventory(client)
{
if(g_hDatabase == INVALID_HANDLE)
{
LogError("Database connection is lost or not yet initialized.");
return;
}
// Player disconnected before his inventory was even fetched
if(g_eClients[client][iCredits]==-1 && g_eClients[client][iItems]==-1)
return;
new String:m_szAttribute[64];
new String:m_szValue[64];
do
{
KvGetSectionName(kv, STRING(m_szAttribute));
KvGetString(kv, NULL_STRING, STRING(m_szValue));
SetTrieString(g_eItems[g_iItems][hAttributes], m_szAttribute, m_szValue);
} while (KvGotoNextKey(kv, false));