/*
////////////////////// ///////////////////
// // // //
// // // //
// // // //
// // // //
// // // //////
///////////////////// ////////////
// // // //
// // // //
// // // //
// // // //
// // // //
///////////////////// // //
Bullet RAJA & Wherethescripters
cyber_punk: Merandom
Zeex: ZCMD
Incognito: sscanf2
*/
//Merandom Download http://forum.sa-mp.com/showthread.php?t=109196
#define FILTERSCRIPT
#include <a_samp>
#include <sscanf2>
#include <Dini>
#include <zcmd>
#include <merrandom>
/* Dialogs */
#define DIALOG_RULES 1
#define DIALOG_RULE_DELETE 2
#define DIALOG_RULE_DELETE_CONFIRM 3
#define DIALOG_RULE_VIEW 4
/* Defines */
#define MAX_RULES 10
/* folders & files */
#define rulesfolder "R"
#define rules "rules"
/* COLORS */
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_RED 0xFF0000FF
#define COLOR_ORANGE 0xFF9900FF
/* Automatic Rules Sending System */
forward rulestimer();
public rulestimer()
{
new bb = dini_Int(PlaceDirectory(rulesfolder, rules), "rules");
if (bb == 0) return 1;
new tmp[6];
for (new i = 0; i < MAX_PLAYERS; i++) {
if (IsPlayerConnected(i)) {
format(tmp, 6, "rule%d", MRandom(bb)+1);
ReturnMessage(i, COLOR_YELLOW, "Rule: {FF0000}%s.", dini_Get(PlaceDirectory(rulesfolder, rules), tmp), "");
}
}
return 1;
}
/* Directory For Files */
PlaceDirectory(directory[], filename[])
{
new newname[128];
format(newname, sizeof(newname), "%s/%c/%s.ini", directory, filename[0] != '.' ? filename[0] : '#', filename);
return newname;
}
ReturnMessage(playerid, color, str[], msg[], msg2[])
{
new pstr[256];
format(pstr, 256, str, msg, msg2);
SendClientMessage(playerid, color, pstr);
return 1;
}
ReturnAll(color, str[], msg[], msg2[])
{
new pstr[256];
format(pstr, 256, str, msg, msg2);
SendClientMessageToAll(color, pstr);
return 1;
}
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Script by Bulletraja & Wherethescripts");
print("--------------------------------------\n");
SetTimer("rulestimer", 300000, 1);
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new tmp2[256], tmp[256];
if (dialogid == DIALOG_RULE_DELETE)
{
if (response)
{
SetPVarInt(playerid, "ruleselect", listitem+1);
format(tmp, 6, "rule%d", listitem+1);
if (!dini_Isset(PlaceDirectory(rulesfolder, rules), tmp))
return SendClientMessage(playerid, COLOR_RED, "Rule doesn't exist.");
format(tmp2, sizeof(tmp2), "%s.\n\nDo you want to delete this rule?", dini_Get(PlaceDirectory(rulesfolder, rules), tmp));
ShowPlayerDialog(playerid, DIALOG_RULE_DELETE_CONFIRM, DIALOG_STYLE_MSGBOX, "Delete rule", tmp2, "Delete", "Cancel");
}
return 1;
}
if (dialogid == DIALOG_RULE_DELETE_CONFIRM)
{
if (response)
{
format(tmp, 6, "rule%d", GetPVarInt(playerid, "ruleselect"));
if (!dini_Isset(PlaceDirectory(rulesfolder, rules), tmp))
return SendClientMessage(playerid, COLOR_RED, "Rule doesn't exist.");
new bb = dini_Int(PlaceDirectory(rulesfolder, rules), "rules");
if (GetPVarInt(playerid, "ruleselect") != bb) {
format(tmp2, 6, "rule%d", bb);
dini_Set(PlaceDirectory(rulesfolder, rules), tmp, dini_Get(PlaceDirectory(rulesfolder, rules), tmp2));
dini_Unset(PlaceDirectory(rulesfolder, rules), tmp2);
}
else {
dini_Unset(PlaceDirectory(rulesfolder, rules), tmp);
}
dini_IntSet(PlaceDirectory(rulesfolder, rules), "rules", bb-1);
SendClientMessage(playerid, COLOR_ORANGE, "Rule deleted.");
}
else {
new bb = dini_Int(PlaceDirectory(rulesfolder, rules), "rules");
new tmp3[2048];
for (new t = 1; t <= bb; t++) {
format(tmp2, 6, "rule%d", t);
format(tmp2, sizeof(tmp2), "%s", dini_Get(PlaceDirectory(rulesfolder, rules), tmp2));
if (strlen(tmp2) > 64) {
strmid(tmp2, tmp2, 0, 61);
format(tmp2, sizeof(tmp2), "%s...", tmp2);
}
format(tmp3, sizeof(tmp3), "%s%s\n", tmp3, tmp2);
}
ShowPlayerDialog(playerid, DIALOG_RULE_DELETE, DIALOG_STYLE_LIST, "Rules", tmp3, "Select", "Cancel");
}
return 1;
}
if (dialogid == DIALOG_RULES)
{
if (response)
{
}
return 1;
}
if (dialogid == DIALOG_RULE_VIEW)
{
if (response)
{
new bb = dini_Int(PlaceDirectory(rulesfolder, rules), "rules");
if (bb == 0)
return SendClientMessage(playerid, COLOR_RED, "There are no rules created.");
new tmp3[2048];
for (new t = 1; t <= bb; t++) {
format(tmp2, 6, "rule%d", t);
format(tmp2, sizeof(tmp2), "%s", dini_Get(PlaceDirectory(rulesfolder, rules), tmp2));
if (strlen(tmp2) > 64) {
strmid(tmp2, tmp2, 0, 61);
format(tmp2, sizeof(tmp2), "%s...", tmp2);
}
format(tmp3, sizeof(tmp3), "%s%s\n", tmp3, tmp2);
}
ShowPlayerDialog(playerid, DIALOG_RULES, DIALOG_STYLE_LIST, "Rules", tmp3, "Select", "Cancel");
}
return 1;
}
return 1;
}
CMD:rules(playerid, params[])
{
new tmp[256];
new bb = dini_Int(PlaceDirectory(rulesfolder, rules), "rules");
if (bb == 0) return SendClientMessage(playerid, COLOR_RED, "There are no rules created.");
new tmp3[2048];
for (new t = 1; t <= bb; t++)
{
format(tmp, 6, "rule%d", t);
format(tmp, sizeof(tmp), "%s", dini_Get(PlaceDirectory(rulesfolder, rules), tmp));
format(tmp3, sizeof(tmp3), "%s%s\n", tmp3, tmp);
}
ShowPlayerDialog(playerid, DIALOG_RULES, DIALOG_STYLE_MSGBOX, "Rules", tmp3, "Accept", "");
return 1;
}
CMD:addrule(playerid, params[])
{
new tmp[256], tmp2[256], playername[25];
if (sscanf(params, "s[128]", tmp)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /addrule [rule]");
new bb = dini_Int(PlaceDirectory(rulesfolder, rules), "rules");
if (bb == MAX_RULES)
{
format(tmp2, sizeof(tmp2), "Error: You have created the maximum of %d rules.", MAX_RULES);
SendClientMessage(playerid, COLOR_RED, tmp2);
return 1;
}
dini_IntSet(PlaceDirectory(rulesfolder, rules), "rules", bb+1);
format(tmp2, 6, "rule%d", bb+1);
dini_Set(PlaceDirectory(rulesfolder, rules), tmp2, tmp);
ReturnMessage(playerid, COLOR_ORANGE, "Rule '%s' created.", tmp, "");
GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
ReturnAll(COLOR_YELLOW, "%s has added a new rule. Type /rules to view the list of rules.", playername, "");
return 1;
}
CMD:delrule(playerid, params[])
{
new tmp[256];
new bb = dini_Int(PlaceDirectory(rulesfolder, rules), "rules");
if (bb == 0) return SendClientMessage(playerid, COLOR_RED, "There are no rules created.");
new tmp3[2048];
for (new t = 1; t <= bb; t++)
{
format(tmp, 6, "rule%d", t);
format(tmp, sizeof(tmp), "%s", dini_Get(PlaceDirectory(rulesfolder, rules), tmp));
if (strlen(tmp) > 64)
{
strmid(tmp, tmp, 0, 61);
format(tmp, sizeof(tmp), "%s...", tmp);
}
format(tmp3, sizeof(tmp3), "%s%s\n", tmp3, tmp);
}
ShowPlayerDialog(playerid, DIALOG_RULE_DELETE, DIALOG_STYLE_LIST, "Rules", tmp3, "Select", "Cancel");
return 1;
}