Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Copyright (c) 2015-2016 Money Bag System
- *
- * This program is free software: you can Ristribute 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 (at your option) any later version.
- *
- * This program 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 program.
- * If not, see <http://www.gnu.org/licenses/>.
- */
- /*****************************
- * Author: *
- * -TitanX *
- * Credits: *
- * - SA-MP Team *
- * - Blue-G *
- * - Zeex *
- * - [HiC]TheKiller *
- * - Jelly23 *
- * *
- *****************************/
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- // --------------< this must be edited without it FS will not work >--------------
- #define USE_MYSQL 1 // un-comment this and comment USE_SQLITE to use MySQL
- #define USE_SQLITE 0 // un-comment this and comment USE_MYSQL to use SQLite
- #if defined USE_MYSQL
- #define MySQL_Host "localhost" // hostname of your mysql server if you are using xampp use "localhost"
- #define MySQL_User "root" // username for your mysql database
- #define MySQL_Database "test" // database that server will connect to it
- #define MySQL_Password "" // password of the database (user) that server will connect to it
- #endif
- // --------------< you can edit this if you want >--------------
- #define MAX_MONEYBAGS 150 // max moneybags that can be stored in database
- #define MB_DELAY 30 // how many time moneybag re-spawn
- #define MAX_MONEYBAG_MONEY 37000 // Max of money that can moneybag handle
- #define MIN_MONEYBAG_MONEY 13000 // Min of money that can moneybag handle
- //#define WEAPONS_BOUNS // un-comment this if you want player get weapons bouns from moneybag
- #if defined WEAPONS_BOUNS
- #define MAX_WEAPONS_AMMO 1500 // Min of ammo that can be given to a player
- #define MIN_WEAPONS_AMMO 200 // Max of ammo that can be given to a player
- static WeaponsBouns[] = // weapons that can be give to the player after founding the moneybag
- {
- 9, // Chainsaw
- 16, // Grenade
- 24, // Desert Eagle
- 26, // Shotgun Sawn-off
- 27, // Combat-Shotgun
- 29, // MP5
- 31, // M4
- 34 // Sniper Rifle
- };
- #if MAX_WEAPONS_AMMO < MIN_WEAPONS_AMMO
- #error Fail: MAX_* must be highter than MIN_*
- #endif
- #endif
- // --------------< Now you can stop editing >--------------
- #if USE_MYSQL == 1 && USE_SQLITE == 1
- #error Fail: 2 Saving system load, please choose one of them
- #endif
- #if USE_MYSQL == 0 && USE_SQLITE == 0
- #error Fail: no saving system loaded, please choose one
- #endif
- #if !defined USE_MYSQL || !defined USE_SQLITE
- #error Fail: USE_MYSQL or USE_SQLITE Not defined in top of script
- #endif
- #if MAX_MONEYBAG_MONEY < MIN_MONEYBAG_MONEY
- #error Fail: MAX_* must be highter than MIN_*
- #endif
- enum ENUM_MB_INFO
- {
- Float:XPOS,
- Float:YPOS,
- Float:ZPOS,
- Name[24]
- };
- static
- MBInfo[MAX_MONEYBAGS][ENUM_MB_INFO],
- bool:m_Found = true,
- bool:m_Toggle = false,
- #if USE_MYSQL == 1
- MySQL:handle,
- #endif
- #if USE_SQLITE == 1
- DB:handle
- #endif
- m_Location[24],
- m_Pickup,
- m_Timer,
- m_Count = 0
- ;
- forward OnMoneyBagUpdate();
- public OnFilterScriptInit()
- {
- m_Timer = SetTimer("OnMoneyBagUpdate", MB_DELAY*1000, true);
- #if USE_MYSQL == 1
- handle = mysql_connect(MySQL_Host, MySQL_User, MySQL_Password, MySQL_Database);
- mysql_log(ALL);
- if(mysql_errno() != 0)
- {
- print(" [Moneybag]: Failed to load the moneybag system.");
- print(" [MoneyBag Error]: MySQL Connection Failed. ");
- print(" MoneyBag System By Titanx 2016 - 2017 ");
- return 1;
- }
- else
- {
- print(" [MoneyBag Notice]: MySQL connection success.");
- mysql_query(handle, "CREATE TABLE IF NOT EXISTS `MoneyBag` (`Name` VARCHAR(24), `PosX` FLOAT(10), `PosY` FLOAT(10), `PosZ` FLOAT(10))");
- print(" [MoneyBag Notice]: Tables created.");
- #if defined WEAPONS_BOUNS
- print(" [MoneyBag Notice]: Weapons Bouns has been Activated.");
- #endif
- print(" [MoneyBag Notice]: Loading Moneybags Names and Positions");
- LoadMoneyBags();
- print(" *---------------------------------*");
- print(" | Moneybag System has been loaded |");
- print(" |---------------------------------|");
- print(" | Author: TitanX | Version: 1.0 |");
- print(" *---------------------------------*");
- return 1;
- }
- #endif
- #if USE_SQLITE == 1
- handle = db_open("moneybag.db");
- if(handle == 0)
- {
- print(" [Moneybag]: Failed to load the moneybag system.");
- print(" [MoneyBag Error]: SQLite Connection Failed. ");
- print(" MoneyBag System By Titanx 2016 - 2017 ");
- return 1;
- }
- else
- {
- static DBResult:query[2];
- print(" [MoneyBag Notice]: SQLite connection success.");
- query[0] = db_query(handle, "PRAGMA synchronous = OFF");
- query[1] = db_query(handle, "CREATE TABLE IF NOT EXISTS `MoneyBag` (`Name` VARCHAR(24), `PosX` FLOAT(10), `PosY` FLOAT(10), `PosZ` FLOAT(10))");
- db_free_result(query[0]);
- db_free_result(query[1]);
- print(" [MoneyBag Notice]: Tables created.");
- #if defined WEAPONS_BOUNS
- print(" [MoneyBag Notice]: Weapons Bouns has been Activated.");
- #endif
- print(" [MoneyBag Notice]: Loading Moneybags Names and Positions");
- LoadMoneyBags();
- print(" *---------------------------------*");
- print(" | Moneybag System has been loaded |");
- print(" |---------------------------------|");
- print(" | Author: TitanX | Version: 1.0 |");
- print(" *---------------------------------*");
- return 1;
- }
- #endif
- }
- public OnFilterScriptExit()
- {
- #if USE_MYSQL == 1
- mysql_close(handle);
- #endif
- #if USE_SQLITE == 1
- db_close(Database);
- #endif
- KillTimer(m_Timer);
- if(!m_Found) DestroyPickup(m_Pickup);
- print(" *-----------------------------------*");
- print(" | Moneybag System has been unloaded |");
- print(" |-----------------------------------|");
- print(" | Author: TitanX | Version: 1.0 |");
- print(" *-----------------------------------*");
- return 1;
- }
- public OnMoneyBagUpdate()
- {
- static st[114];
- if(m_Count == 0) print("[MoneyBag Error]: there no moneybags loaded to start one");
- if(!m_Found)
- {
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- format(st, sizeof(st), " {B7FF00}Money Bag {00C0FF}has not been found and it is still hidden in {B7FF00}%s", m_Location);
- SendClientMessageToAll(-1, st);
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- }
- else if(m_Found)
- {
- static randombag;
- m_Found = false;
- randombag = random(sizeof(m_Count));
- if(MBInfo[randombag][XPOS] == 0.0) randombag = random(sizeof(m_Count));
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- format(st, sizeof(st), " {B7FF00}Money Bag {00C0FF}has been hidden in {B7FF00}%s!", MBInfo[randombag][Name]);
- SendClientMessageToAll(-1, st);
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- format(m_Location, sizeof(m_Location), "%s", MBInfo[randombag][Name]);
- m_Pickup = CreatePickup(1550, 2, MBInfo[randombag][XPOS], MBInfo[randombag][YPOS], MBInfo[randombag][ZPOS], -1);
- }
- return 1;
- }
- CMD:tmb(playerid, params[]) return cmd_togglemb(playerid, params);
- CMD:togglemb(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- if(!strcmp(params, "off", true))
- {
- if(m_Toggle) return SendClientMessage(playerid, -1, "*{FF0000}Error: Moneybag already disabled");
- if(!m_Found) DestroyPickup(m_Pickup);
- KillTimer(m_Timer);
- m_Toggle = true;
- SendClientMessage(playerid, -1, "* Money bag has been {FF0000}disabled");
- return 1;
- }
- if(!strcmp(params, "on", true))
- {
- if(!m_Toggle) return SendClientMessage(playerid, -1, "*{FF0000}Error: Moneybag already enabled");
- m_Timer = SetTimer("MoneyBag", MB_DELAY, true);
- m_Toggle = false;
- SendClientMessage(playerid, -1, "* Money bag has been {33FF66}enabled!");
- return 1;
- }
- else return SendClientMessage(playerid, -1, "*{FF0000}Error: /togglemb [on/off] or /tmb [on/off]");
- }
- CMD:mb(playerid) return cmd_moneybag(playerid);
- CMD:moneybag(playerid)
- {
- static string[81];
- if(!m_Found) format(string, sizeof(string), " {B7FF00}Money Bag {00C0FF}has been hidden in {B7FF00}%s!", m_Location);
- if(m_Found) format(string, sizeof(string), "*{FF0000} There no money bag running at moment");
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- SendClientMessage(playerid, -1, string);
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- return 1;
- }
- CMD:savemb(playerid, params[]) return cmd_savemoneybag(playerid, params);
- CMD:savemoneybag(playerid, params[])
- {
- if(isnull(params)) return SendClientMessage(playerid, -1, "*{FF0000}Error: /savemoneybag [location name (clue)] or /savemb [location name (clue)]");
- if(strlen(params) > 24) return SendClientMessage(playerid, -1, "*{FF0000}Error: Location/clue must be less or equal 24 char");
- if(m_Count == MAX_MONEYBAGS) return SendClientMessage(playerid, -1, "*{FF0000}Error: Cannot add more moneybags, please increase MAX_MONEYBAGS value");
- static
- Float:X,
- Float:Y,
- Float:Z
- ;
- GetPlayerPos(playerid, X,Y,Z);
- SaveMoneyBag(params, X, Y, Z);
- SendClientMessageToAll(-1, "*{B7FF00}Success: this position has been saved in the database !");
- printf(" [MoneyBag Notice]: New Money bag saved at X: %f Y: %f Z: %s, under name: %s", X, Y, Z, params);
- return 1;
- }
- CMD:delmb(playerid, params[]) return cmd_deletemoneybag(playerid, params);
- CMD:deletemoneybag(playerid, params[])
- {
- if(isnull(params)) return SendClientMessage(playerid, -1, "*{FF0000}Error: /savemoneybag [location name (clue)] or /delmb [location name (clue)]");
- if(strlen(params) > 24) return SendClientMessage(playerid, -1, "*{FF0000}Error: Location/clue must be less or equal 24 char");
- if(DeleteMoneyBag(params)) SendClientMessage(playerid, -1, "*Success: this moneybag has been deleted");
- else SendClientMessage(playerid, -1, "*{FF0000}Error: this moneybag not exists on database");
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- if(pickupid == m_Pickup)
- {
- new
- string[170],
- pname[24],
- money = random(MAX_MONEYBAG_MONEY - MIN_MONEYBAG_MONEY) + MIN_MONEYBAG_MONEY
- ;
- GetPlayerName(playerid, pname, 24);
- DestroyPickup(m_Pickup);
- GivePlayerMoney(playerid, money);
- #if defined WEAPONS_BOUNS
- new
- weapon = random(sizeof(WeaponsBouns)),
- ammo = random(MAX_WEAPONS_AMMO - MIN_WEAPONS_AMMO) + MIN_WEAPONS_AMMO
- ;
- GivePlayerWeapon(playerid, WeaponsBouns[weapon], ammo);
- #endif
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- format(string, sizeof(string), " {B7FF00}%s{00C0FF} has found the {B7FF00}money bag{00C0FF} that had {B7FF00}$%d {00C0FF}inside, located in {B7FF00}%s", pname, money, m_Location);
- SendClientMessageToAll(-1, string);
- SendClientMessageToAll(-1, "{6EF83C}------------------------------------------------");
- m_Found = true;
- }
- return 1;
- }
- stock SaveMoneyBag(moneybagname[], Float:posx, Float:posy, Float:posz)
- {
- static
- query[133];
- #if USE_MYSQL == 1
- mysql_format(handle, query, sizeof(query), "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('%e', %f, %f, %f)", moneybagname, posx, posy, posz);
- mysql_query(handle, query);
- #endif
- #if USE_SQLITE == 1
- format(query, sizeof(query), "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('%q', %f, %f, %f)", moneybagname, posx, posy, posz);
- db_query(handle, query);
- #endif
- m_Count++;
- format(MBInfo[m_Count][Name], 24, "%s", moneybagname);
- MBInfo[m_Count][XPOS] = posx;
- MBInfo[m_Count][YPOS] = posy;
- MBInfo[m_Count][ZPOS] = posz;
- return 1;
- }
- stock DeleteMoneyBag(moneybagname[])
- {
- static
- rows = 0,
- query[66]
- ;
- #if USE_MYSQL == 1
- static
- Cache:getCache;
- mysql_format(handle, query, sizeof(query), "SELECT * FROM `MoneyBag` WHERE `Name` = '%e'", moneybagname);
- getCache = mysql_query(handle, query);
- cache_get_row_count(rows);
- if(rows > 0)
- {
- mysql_format(handle, query, sizeof(query), "DELETE * FROM `MoneyBag` WHERE `Name` = '%e'", moneybagname);
- mysql_query(handle, query);
- for(new iax = 0; iax < m_Count; iax++) // Sorry for this but it required to detect the target moneybag
- {
- if(!strcmp(MBInfo[iax][Name], moneybagname))
- {
- MBInfo[iax][XPOS] = 0.0;
- MBInfo[iax][YPOS] = 0.0;
- MBInfo[iax][ZPOS] = 0.0;
- format(MBInfo[iax][Name], 24, "");
- m_Count--;
- break;
- }
- }
- cache_delete(getCache);
- return 1;
- }
- else
- {
- cache_delete(getCache);
- return 0;
- }
- #endif
- #if USE_SQLITE == 1
- static
- DBResult:getCache;
- format(query, sizeof(query), "SELECT * FROM `MoneyBag` WHERE `Name` = '%q'", moneybagname);
- getCache = db_query(handle, query);
- rows = db_num_rows(getCache);
- if(rows > 0)
- {
- format(query, sizeof(query), "DELETE * FROM `MoneyBag` WHERE `Name` = '%q'", moneybagname);
- db_query(handle, query);
- for(new i = 0; i < m_Count; i++) // Sorry for this but it required to detect the target moneybag
- {
- if(!strcmp(MBInfo[i][Name], moneybagname)
- {
- MBInfo[i][XPOS] = 0.0;
- MBInfo[i][YPOS] = 0.0;
- MBInfo[i][ZPOS] = 0.0;
- MBInfo[i][Name] = "";
- m_Count--;
- break;
- }
- }
- return 1;
- }
- else
- {
- SendClientMessage(playerid, -1, "*{FF0000}Error: this moneybag not exists on database");
- return 0;
- }
- db_free_result(getCache);
- #endif
- }
- stock LoadMoneyBags()
- {
- static
- rows = 0;
- #if USE_MYSQL == 1
- static
- Cache:getCache;
- getCache = mysql_query(handle, "SELECT * FROM `MoneyBag`");
- cache_get_row_count(rows);
- if(rows >= MAX_MONEYBAGS) return print(" [MoneyBag Error]: Array out bound, number of rows is larger than MAX_MONEYBAGS value");
- if(rows > 0)
- {
- for(new ix = 0; ix < rows; ix++)
- {
- cache_get_value_name(ix, "Name", MBInfo[ix][Name], 24);
- cache_get_value_name_float(ix, "PosX", MBInfo[ix][XPOS]);
- cache_get_value_name_float(ix, "PosY", MBInfo[ix][YPOS]);
- cache_get_value_name_float(ix, "PosZ", MBInfo[ix][ZPOS]);
- m_Count++;
- }
- printf(" [MoneyBag Notice]: %d Positions has been loaded from database", m_Count);
- }
- else
- {
- mysql_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Montgomery', 1397.934692, 289.888427, 23.555511)");
- mysql_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Verdant Meadows', 209.578689, 2415.689697, 16.322700)");
- mysql_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Fort Carson', -172.726379, 1182.572753, 26.504249)");
- mysql_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Las Barrancas', -778.594482, 1477.787719, 28.764667)");
- mysql_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Area 69', 266.978424, 1858.773071, 8.757812)");
- mysql_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('The Quarry', 266.978424, 1858.773071, 8.757812)");
- print(" [MoneyBag Notice]: the database empty, exemples of moneybags has been loaded.");
- m_Count = 6;
- }
- cache_delete(getCache);
- return 1;
- #endif
- #if USE_SQLITE == 1
- static
- DBResult:getCache;
- getCache = db_query(handle, "SELECT * FROM `MoneyBag`");
- rows = db_num_rows(getCache);
- if(rows >= MAX_MONEYBAGS) return print(" [MoneyBag Error]: Array out bound, number of rows is larger than MAX_MONEYBAGS value");
- if(rows > 0)
- {
- for(new i = 0; i < rows; i++)
- {
- db_get_field_assoc(getCache, "Name", MBInfo[i][Name], 24);
- MBInfo[i][XPOS] = db_get_field_float(getCache, "PosX");
- MBInfo[i][YPOS] = db_get_field_float(getCache, "PosY");
- MBInfo[i][ZPOS] = db_get_field_float(getCache, "PosZ");
- m_Count++;
- }
- printf(" [MoneyBag Notice]: %d Positions has been loaded from database", m_Count);
- }
- else
- {
- db_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Montgomery', 1397.934692, 289.888427, 23.555511)");
- db_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Verdant Meadows', 209.578689, 2415.689697, 16.322700)");
- db_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Fort Carson', -172.726379, 1182.572753, 26.504249)");
- db_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Las Barrancas', -778.594482, 1477.787719, 28.764667)");
- db_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('Area 69', 266.978424, 1858.773071, 8.757812)");
- db_query(handle, "INSERT INTO `Moneybag` (`Name`, `PosX`, `PosY`, `PosZ`) VALUES ('The Quarry', 266.978424, 1858.773071, 8.757812)");
- print(" [MoneyBag Notice]: the database empty, exemples of moneybags has been loaded.");
- m_Count = 6;
- }
- db_free_result(getCache);
- return 1;
- #endif
- }
Add Comment
Please, Sign In to add comment