You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

734 lines
17 KiB

/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
#include <mapchooser>
new Handle:g_NextMap = INVALID_HANDLE;
new Handle:g_ChangeMap = INVALID_HANDLE;
new Handle:g_NominationMap = INVALID_HANDLE;
new Handle:cv_serverid, Handle:cv_lotto;
new price_nomination = 25;
new price_mapvote = 100;
new price_nextmap = 150;
new price_changelevel = 200;
new String:MapchangeTo[100];
public Plugin:myinfo =
{
name = "Beer System",
author = "Chefe",
description = "System that gives Players Points for they Playtime.",
version = "2.4",
url = "www.the-bos.de"
}
public OnPluginStart()
{
CreateTimer(300.0, Abbrechnung, _, TIMER_REPEAT);
RegConsoleCmd("sm_beer", CommandLP, "Shows you your liter Beer!");
cv_serverid = CreateConVar("sm_beer_serverid", "0", "Serverid for remove liter");
cv_lotto = CreateConVar("sm_beer_lotto", "0", "Lotto I/0");
//HookEvent("player_activate", Event_PlayerActivate);
if (GetConVarBool(cv_lotto))
{
CreateTimer(7200.0, LottoZiehung, _, TIMER_REPEAT);
}
if (CheckCon())
{
PrintToServer("[BEER] Connection sucessfull!");
}
else
{
SetFailState("Can't etablish connection to Database");
}
AutoExecConfig(true);
}
public OnMapStart()
{
MapchangeTo = NULL_STRING;
g_NextMap = BuildMapMenu(Menu_NextMap);
g_ChangeMap = BuildMapMenu(Menu_ChangeMap);
g_NominationMap = BuildMapMenu(Menu_NominateMap);
}
public OnMapEnd()
{
if (g_NextMap != INVALID_HANDLE)
{
CloseHandle(g_NextMap);
g_NextMap = INVALID_HANDLE;
}
if (g_ChangeMap != INVALID_HANDLE)
{
CloseHandle(g_ChangeMap);
g_ChangeMap = INVALID_HANDLE;
}
if (g_NominationMap != INVALID_HANDLE)
{
CloseHandle(g_NominationMap);
g_NominationMap = INVALID_HANDLE;
}
}
Handle:BuildMapMenu(MenuHandler:handel)
{
/* Open the file */
new Handle:file = OpenFile("mapcycle.txt", "rt");
if (file == INVALID_HANDLE)
{
return INVALID_HANDLE;
}
/* Create the menu Handle */
new Handle:menu = CreateMenu(handel);
new String:mapname[255];
while (!IsEndOfFile(file) && ReadFileLine(file, mapname, sizeof(mapname)))
{
if (mapname[0] == ';' || !IsCharAlpha(mapname[0]))
{
continue;
}
/* Cut off the name at any whitespace */
new len = strlen(mapname);
for (new i=0; i<len; i++)
{
if (IsCharSpace(mapname[i]))
{
mapname[i] = '\0';
break;
}
}
/* Check if the map is valid */
if (!IsMapValid(mapname))
{
continue;
}
/* Add it to the menu */
AddMenuItem(menu, mapname, mapname);
}
/* Make sure we close the file! */
CloseHandle(file);
/* Finally, set the title */
SetMenuTitle(menu, "Please select a map:");
return menu;
}
public OnClientAuthorized(client, const String:auth[])
{
new String:sqlstring[255];
Format(sqlstring, sizeof(sqlstring), "SELECT id FROM lp WHERE steamid = '%s'", auth);
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
new Handle:sql = SQL_Query(db, sqlstring);
if (SQL_GetRowCount(sql) == 0)
{
new String:create[250];
Format(create, sizeof(create), "INSERT INTO lp(steamid, points) VALUES ('%s',0)", auth);
SQL_FastQuery(db, create);
}
CloseHandle(sql);
CloseHandle(db);
}
public Action:CommandLP(client, args)
{
new String:s_menu1[100];
Format(s_menu1, sizeof(s_menu1), "SNomination (%i l)", price_nomination);
new String:s_menu2[100];
Format(s_menu2, sizeof(s_menu2), "Force Mapvote (%i l)", price_mapvote);
new String:s_menu3[100];
Format(s_menu3, sizeof(s_menu3), "Set Nextmap (%i l)", price_nextmap);
new String:s_menu4[100];
Format(s_menu4, sizeof(s_menu4), "Change Map (%i l)", price_changelevel);
new Handle:menu = CreateMenu(MenuHandler);
SetMenuTitle(menu, "Loyality Points System");
AddMenuItem(menu, "1", "Show Liter Beer");
AddMenuItem(menu, "2", s_menu1);
AddMenuItem(menu, "3", s_menu2);
AddMenuItem(menu, "4", s_menu3);
AddMenuItem(menu, "5", s_menu4);
new bool:have_rs = HaveClientRS(client);
if (have_rs)
{
new String:s_menu5[100];
Format(s_menu5, sizeof(s_menu5), "Your RS access end in %i min", GetRSMIN(client));
AddMenuItem(menu, "6", s_menu5, ITEMDRAW_DISABLED);
}
else if (!have_rs)
{
AddMenuItem(menu, "7", "Reserved Slot");
}
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public MenuHandler(Handle:menu, MenuAction:action, param1, param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
new String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
switch(StringToInt(info))
{
case 1:
{
new lp = GetLP(param1);
PrintToChatAll("\x04[BEER]\x01 %N, you have %i Liter Beer!", param1, lp);
}
case 2:
{
new lp = GetLP(param1);
if (lp >= price_nomination)
{
DisplayMenu(g_NominationMap, param1, MENU_TIME_FOREVER);
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need %i l to nominate!", lp, price_nomination);
}
}
case 3:
{
new lp = GetLP(param1);
if (lp >= price_mapvote)
{
RemoveLP(param1, price_mapvote);
PrintToChatAll("\x04[BEER]\x01 %N forced Mapvote!", param1)
InitiateMapChooserVote(MapChange_Instant);
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need %i l to force Mapvote!", lp, price_mapvote);
}
}
case 4:
{
new lp = GetLP(param1);
if (lp >= price_nextmap)
{
DisplayMenu(g_NextMap, param1, MENU_TIME_FOREVER);
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need %i l to set Nextmap!", lp, price_nextmap);
}
}
case 5:
{
new lp = GetLP(param1);
if (lp >= price_changelevel)
{
DisplayMenu(g_ChangeMap, param1, MENU_TIME_FOREVER);
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need %i l to change the Map!", lp, price_changelevel);
}
}
case 6:
{
}
case 7:
{
new Handle:menu2 = CreateMenu(MenuRS);
SetMenuTitle(menu2, "Select RS-time");
AddMenuItem(menu2, "1", "1 Day (100 l)");
AddMenuItem(menu2, "2", "5 Days (450 l)");
AddMenuItem(menu2, "3", "14 Days (800 l)");
AddMenuItem(menu2, "4", "30 Days (999 l)");
DisplayMenu(menu2, param1, MENU_TIME_FOREVER);
}
}
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Menu_NextMap(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new String:info[32];
/* Get item info */
GetMenuItem(menu, param2, info, sizeof(info));
RemoveLP(param1, price_nextmap);
PrintToChatAll("\x04[BEER]\x01 %N changed the nextmap to %s!", param1, info);
SetNextMap(info);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Menu_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new String:info[32];
/* Get item info */
GetMenuItem(menu, param2, info, sizeof(info));
RemoveLP(param1, price_changelevel);
PrintToChatAll("\x04[BEER]\x01 %N forced mapchange to %s!", param1, info);
if (!strcmp(MapchangeTo, NULL_STRING, false))
{
MapchangeTo = info;
CreateTimer(5.0, Timer_Changelevel);
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 Mapchange already in Progress");
}
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Action:Timer_Changelevel(Handle:timer)
{
ForceChangeLevel(MapchangeTo, "BEER");
}
public Menu_NominateMap(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new String:info[32];
/* Get item info */
GetMenuItem(menu, param2, info, sizeof(info));
RemoveLP(param1, price_nomination);
PrintToChatAll("\x04[BEER]\x01 %N nominated %s!", param1, info);
NominateMap(info, true, 0);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public MenuRS(Handle:menu, MenuAction:action, param1, param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
new String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
new lp = GetLP(param1)
switch(StringToInt(info))
{
case 1:
{
if (lp >= 100)
{
RemoveLP(param1, 100)
GiveRS(param1, 1440);
if (IsClientInGame(param1))
{
PrintToChat(param1, "\x04[BEER]\x01 You have bouth RS! If Server is full, connect via console, and you can connect!")
}
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need 100 l for 1 Day RS!", lp);
}
}
case 2:
{
if (lp >= 450)
{
RemoveLP(param1, 450)
GiveRS(param1, 7200);
if (IsClientInGame(param1))
{
PrintToChat(param1, "\x04[BEER]\x01 You have bouth RS! If Server is full, connect via console, and you can connect!")
}
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need 450 l for 5 Days RS!", lp);
}
}
case 3:
{
if (lp >= 800)
{
RemoveLP(param1, 800)
GiveRS(param1, 20160);
if (IsClientInGame(param1))
{
PrintToChat(param1, "\x04[BEER]\x01 You have bouth RS! If Server is full, connect via console, and you can connect!")
}
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need 800 l for 14 Days RS!", lp);
}
}
case 4:
{
if (lp >= 100)
{
RemoveLP(param1, 999)
GiveRS(param1, 43200);
if (IsClientInGame(param1))
{
PrintToChat(param1, "\x04[BEER]\x01 You have bouth RS! If Server is full, connect via console, and you can connect!")
}
}
else
{
PrintToChat(param1, "\x04[BEER]\x01 You have %i liter, but you need 999 l for 30 Days RS!", lp);
}
}
}
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Action:Abbrechnung(Handle:timer)
{
new players = GetClientCount(false);
new players_max = GetMaxClients();
if (players <= (players_max / 4))
{
GiveLP(3);
}
else if (players <= (players_max / 2))
{
GiveLP(2);
}
else
{
GiveLP(1);
}
RemoveRSMIN(5)
PrintToChatAll("\x04[Oktoberfest]\x01 Our Server running the \x04Beer!\x01 System to reward Players.");
PrintToChatAll("\x04[BEER]\x01 Type \x04!beer\x01 to get up the Beer! menu with more options.");
PrintHintTextToAll("[BEER] ONLINE");
}
GetLP(client)
{
new String:steamid[125];
GetClientAuthString(client, steamid, sizeof(steamid));
new String:sqlstring[255];
Format(sqlstring, sizeof(sqlstring), "SELECT points FROM lp WHERE steamid = '%s'", steamid);
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
new Handle:sql = SQL_Query(db, sqlstring);
SQL_FetchRow(sql);
new lp = SQL_FetchInt(sql, 0);
CloseHandle(sql);
CloseHandle(db);
return lp;
}
GiveLP(amount)
{
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
new i = 1;
while (i != (MaxClients+1))
{
new client = i;
if (IsClientInGame(client))
{
new String:steamid[50];
GetClientAuthString(client, steamid, sizeof(steamid))
new String:sqlstring[256];
Format(sqlstring, sizeof(sqlstring), "UPDATE lp SET points = points + %i WHERE steamid = '%s'", amount, steamid);
if (!SQL_FastQuery(db, sqlstring))
{
new String:error[255];
SQL_GetError(db, error, sizeof(error));
PrintToServer("Failed to query (error: %s)", error);
}
PrintToServer("[BEER] Gived %N %i l (client %i)", client, amount, i);
}
i = i + 1;
}
CloseHandle(db);
}
RemoveLP(client, amount)
{
if (IsClientInGame(client))
{
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
new String:steamid[50];
GetClientAuthString(client, steamid, sizeof(steamid))
new String:sqlstring[256];
Format(sqlstring, sizeof(sqlstring), "UPDATE lp SET points = points - %i WHERE steamid = '%s'", amount, steamid);
if (!SQL_FastQuery(db, sqlstring))
{
new String:error[255];
SQL_GetError(db, error, sizeof(error));
PrintToServer("Failed to query (error: %s)", error);
}
CloseHandle(db);
}
}
GiveRS(client, min)
{
if (IsClientInGame(client))
{
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
// In die lp-Datenbank eintragen (Step 1)
new String:steamid[50];
GetClientAuthString(client, steamid, sizeof(steamid))
new String:sqlstring[256];
Format(sqlstring, sizeof(sqlstring), "UPDATE lp SET rs = 1, rsmin = %i, serverid = %i WHERE steamid = '%s'", min, GetConVarInt(cv_serverid), steamid);
if (!SQL_FastQuery(db, sqlstring))
{
new String:error[255];
SQL_GetError(db, error, sizeof(error));
PrintToServer("Failed to query (error: %s)", error);
}
// In die Sm-Admin Datenbank eintragen (Step 2)
Format(sqlstring, sizeof(sqlstring), "INSERT INTO sm_admins(authtype, identity, flags, name, immunity) VALUES ('steam','%s', 'b,a', '%N', 5)", steamid, client);
if (!SQL_FastQuery(db, sqlstring))
{
new String:error[255];
SQL_GetError(db, error, sizeof(error));
PrintToServer("Failed to query (error: %s)", error);
}
CloseHandle(db);
ServerCommand("sm_reloadadmins");
}
}
bool:HaveClientRS(client)
{
if (IsClientInGame(client))
{
new String:steamid[50];
GetClientAuthString(client, steamid, sizeof(steamid))
new String:sqlstring[255];
Format(sqlstring, sizeof(sqlstring), "SELECT id FROM lp WHERE steamid = '%s' AND rs = '1'", steamid);
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
new Handle:sql = SQL_Query(db, sqlstring);
new rs_bool = SQL_GetRowCount(sql);
CloseHandle(sql);
CloseHandle(db);
if (rs_bool >= 1)
{
return true;
}
else if (rs_bool == 0)
{
return false;
}
}
else
{
return true;
}
return true;
}
GetRSMIN(client)
{
new String:steamid[50];
GetClientAuthString(client, steamid, sizeof(steamid));
new String:sqlstring[200];
Format(sqlstring, sizeof(sqlstring), "SELECT rsmin FROM lp WHERE steamid = '%s'", steamid);
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
new Handle:sql = SQL_Query(db, sqlstring);
SQL_FetchRow(sql);
new rsmin = SQL_FetchInt(sql, 0);
CloseHandle(sql);
CloseHandle(db);
return rsmin;
}
RemoveRSMIN(min)
{
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
new String:sqlstring[256];
Format(sqlstring, sizeof(sqlstring), "UPDATE lp SET rsmin = rsmin - %i WHERE rs = 1 AND serverid = %i", min, GetConVarInt(cv_serverid));
if (!SQL_FastQuery(db, sqlstring))
{
new String:error[255];
SQL_GetError(db, error, sizeof(error));
PrintToServer("Failed to query (error: %s)", error);
}
new String:sqlstring2[150];
Format(sqlstring2, sizeof(sqlstring2), "SELECT steamid FROM lp WHERE rs = 1 AND serverid = %i AND rsmin <= 0", GetConVarInt(cv_serverid));
new Handle:sql = SQL_Query(db, sqlstring2);
new nummber = SQL_GetRowCount(sql);
if (nummber != 0)
{
for (new a = 0; a != nummber; a++)
{
new String:steamid[256];
SQL_FetchRow(sql);
SQL_FetchString(sql, 0, steamid, sizeof(steamid));
// Aus der LP-Datenbank austragen (Step 1)
new String:sqlstr[256];
Format(sqlstr, sizeof(sqlstr), "UPDATE lp SET rs = 0, rsmin = 0, serverid = 0 WHERE steamid = '%s'", steamid);
if (!SQL_FastQuery(db, sqlstr))
{
new String:ero[255];
SQL_GetError(db, ero, sizeof(ero));
PrintToServer("Failed to query (error: %s)", ero);
}
// Aus der SM-Admin Datenbank austragen (Step 2)
new String:sqlstr2[150];
Format(sqlstr2, sizeof(sqlstr2), "DELETE FROM sm_admins WHERE identity = '%s'", steamid);
if (!SQL_FastQuery(db, sqlstr2))
{
new String:ero2[255];
SQL_GetError(db, ero2, sizeof(ero2));
PrintToServer("Failed to query (error: %s)", ero2);
}
}
ServerCommand("sm_reloadadmins");
}
CloseHandle(sql);
CloseHandle(db);
}
public Action:LottoZiehung(Handle:timer)
{
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
for (new i = 1; i != (GetMaxClients()+1); i++)
{
if (IsClientInGame(i))
{
if (0.25 >= GetRandomFloat(0.1, 1.0))
{
new String:steamid[50];
GetClientAuthString(i, steamid, sizeof(steamid))
new String:sqlstring[256];
Format(sqlstring, sizeof(sqlstring), "UPDATE lp SET points = points + 500 WHERE steamid = '%s'", steamid);
if (!SQL_FastQuery(db, sqlstring))
{
new String:error[255];
SQL_GetError(db, error, sizeof(error));
PrintToServer("Failed to query (error: %s)", error);
}
PrintToChat(i, "\x01[\x04BEER\x01] Congratulations, you have won in the BEER Lottery! You got \x04500 l\x01 add to your beer stock!");
PrintToChatAll("\x01[\x04BEER\x01] %N won in the BEER Lottery!", i);
}
}
}
CloseHandle(db);
}
CheckCon()
{
new String:error_connect[255];
new Handle:db = SQL_Connect("db", false, error_connect, sizeof(error_connect));
if (db != INVALID_HANDLE)
{
CloseHandle(db);
return 1;
}
else
{
CloseHandle(db);
return 0;
}
}