Advertisement
yvoms

Bribe System 1.0

Oct 18th, 2016
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.84 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <zcmd>
  4. #include <streamer>
  5. #include <YSI\y_iterate>
  6. #include <sscanf2>
  7.  
  8. #define Filterscript
  9.  
  10. #define     MYSQL_HOST      "localhost" //IP or Domain of the Mysql Host. DEFAULT:LOCALHOST
  11. #define     MYSQL_USER      "root"      //The account you made. DEFAULT:ROOT
  12. #define     MYSQL_PASS      ""          //The password you created for the account. DEFAULT:BLANK
  13. #define     MYSQL_DBNAME    "sampdb"    //The san andreas database you made.
  14. #define     MYSQL_PORT      3306        //The Mysql Port. DEFAULT:3306
  15.  
  16. #define     MAX_BRIBE    (50)  //How many briberies can there be ingame, I set the limit to 50 because i like the number.
  17. #define     BRIBE_USE    (120) //How often can the same bribe be used in secconds Default 120 : once in 2 minutes.
  18.  
  19. new Iterator: bribes<MAX_BRIBE>;
  20. new BribeSQLHandle = -1;
  21.  
  22. enum    E_BRIBE
  23. {
  24.     // saved
  25.     Float: BribeX,
  26.     Float: BribeY,
  27.     Float: BribeZ,
  28.     Float: BribeA,
  29.     BribeVw,
  30.     Text3D: BribeLabel,
  31.     BribeIcon,
  32.     brid
  33. };
  34.  
  35. new BribeData[MAX_BRIBE][E_BRIBE];
  36.  
  37. public OnFilterScriptInit()
  38. {
  39.     BribeSQLHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DBNAME, MYSQL_PASS, MYSQL_PORT);
  40.     mysql_log(LOG_ALL);
  41.     mysql_tquery(BribeSQLHandle, "CREATE TABLE IF NOT EXISTS `bribes` (\
  42.       `ID` int(11) NOT NULL,\
  43.       `PosX` float NOT NULL,\
  44.       `PosY` float NOT NULL,\
  45.       `PosZ` float NOT NULL,\
  46.       `PosA` float NOT NULL\
  47.       `vw` int(11) NOT NULL\
  48.       PRIMARY KEY  (`ID`)\
  49.     ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  50.  
  51.     if(mysql_errno()) return printf("  [Bribe System] Can't connect to MySQL. (Error #%d)", mysql_errno());
  52.     print("\n--------------------------------------");
  53.     print("---------Bribe System 1.0 By yvoms------");
  54.     print("--------------------------------------\n");
  55.     print("  [Bribe System] Connected to MySQL, loading data...");
  56.     mysql_tquery(BribeSQLHandle, "SELECT * FROM bribe", "LoadBribes");
  57.     return 1;
  58. }
  59.  
  60. public OnFilterScriptExit()
  61. {
  62.     print("  [Bribe System] Unloaded.");
  63.     mysql_close(BribeSQLHandle);
  64.     return 1;
  65. }
  66.  
  67. forward LoadBribes();
  68. public LoadBribes()
  69. {
  70.     new rows = cache_num_rows();
  71.     if(rows)
  72.     {
  73.         new id, label_string[64];
  74.         for(new i; i < rows; i++)
  75.         {
  76.             id = cache_get_field_content_int(i, "ID");
  77.             BribeData[id][BribeX] = cache_get_field_content_float(i, "PosX");
  78.             BribeData[id][BribeY] = cache_get_field_content_float(i, "PosY");
  79.             BribeData[id][BribeZ] = cache_get_field_content_float(i, "PosZ");
  80.             BribeData[id][BribeA] = cache_get_field_content_float(i, "PosA");
  81.             BribeData[id][BribeVw] = cache_get_field_content_int(i,"vw");
  82.  
  83.             BribeData[id][BribeIcon] = CreateDynamicPickup(1247, 1, BribeData[id][BribeX], BribeData[id][BribeY], BribeData[id][BribeZ]);
  84.             format(label_string, sizeof(label_string), "[Bribe %d]", id);
  85.             BribeData[id][BribeLabel] = CreateDynamic3DTextLabel(label_string, 0x1ABC9CFF, BribeData[id][BribeX], BribeData[id][BribeY], BribeData[id][BribeZ] + 0.25, 5.0, .testlos = 1);
  86.  
  87.             Iter_Add(bribes, id);
  88.         }
  89.     }
  90.    
  91.     printf("[Bribe System] Loaded %d Bribes.", Iter_Count(bribes));
  92.     return 1;
  93. }
  94.  
  95. static DelayTick[MAX_PLAYERS];
  96. hook OnPlayerPickUpPickup(playerid, pickupid)
  97. {
  98.     new id;
  99.     if((gettime() - DelayTick[playerid]) < BRIBE_USE) return 1;
  100.     if(pickupid == BribeData[id][brid])
  101.     {
  102.     DelayTick[playerid] = gettime();
  103.     SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) -2);
  104.     SendClientMessage(playerid, 0xFFFFFFAA, "{ABD182}[Notice]:{FAFAFA} Your wanted level has decreased by 2 since your picked up a bribe star!");
  105.     return 1;
  106.     }
  107.     return 1;
  108. }
  109.  
  110. CMD:createbribe(playerid, params[])
  111. {
  112.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFAA, "{ff0000}[Error]:{ffffff} Only RCON admins can use this command.");
  113.     new id = Iter_Free(bribes);
  114.     if(id == -1) return SendClientMessage(playerid, 0xFFFFFFAA, "{ff0000}[Error]:{ffffff} MAX_BRIBE reached, check the filterscript.");
  115.     new skin;
  116.     GetPlayerPos(playerid, BribeData[id][BribeX], BribeData[id][BribeY], BribeData[id][BribeZ]);
  117.     GetPlayerFacingAngle(playerid, BribeData[id][BribeA]);
  118.     BribeData[id][BribeVw] = GetPlayerVirtualWorld(playerid);
  119.     SetPlayerPos(playerid, BribeData[id][BribeX] + (1.0 * floatsin(-BribeData[id][BribeA], degrees)), BribeData[id][BribeY] + (1.0 * floatcos(-BribeData[id][BribeA], degrees)), BribeData[id][BribeZ]);
  120.  
  121.     new label_string[64];
  122.     BribeData[id][BribeIcon] = CreateDynamicPickup(1247, 1, BribeData[id][BribeX], BribeData[id][BribeY], BribeData[id][BribeZ]);
  123.     format(label_string, sizeof(label_string), "[Bribe %d]", id);
  124.     BribeData[id][BribeLabel] = CreateDynamic3DTextLabel(label_string, 0x1ABC9CFF, BribeData[id][BribeX], BribeData[id][BribeY], BribeData[id][BribeZ] + 0.25, 5.0, .testlos = 1);
  125.  
  126.     new query[144];
  127.     mysql_format(BribeSQLHandle, query, sizeof(query), "INSERT INTO bribes SET ID=%d, PosX='%f', PosY='%f', PosZ='%f', PosA='%f', vw='%d'", id, skin, BribeData[id][BribeX], BribeData[id][BribeY], BribeData[id][BribeZ], BribeData[id][BribeA], BribeData[id][BribeVw]);
  128.     mysql_tquery(BribeSQLHandle, query);
  129.    
  130.     Iter_Add(bribes, id);
  131.     return 1;
  132. }
  133.  
  134. CMD:removebribe(playerid, params[])
  135. {
  136.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFAA, "{ff0000}[Error]:{ffffff} Only RCON admins can use this command.");
  137.     new id;
  138.     if(sscanf(params, "i", id)) return SendClientMessage(playerid, 0xFFFFFFAA, "{ff0000}[Error]:{ffffff} /removebribe [bribe id]");
  139.     if(!Iter_Contains(bribes, id)) return SendClientMessage(playerid, 0xFFFFFFAA, "{ff0000}[Error]:{ffffff} Invalid bribe ID.");
  140.     if(IsValidDynamic3DTextLabel(BribeData[id][BribeLabel])) DestroyDynamic3DTextLabel(BribeData[id][BribeLabel]);
  141.     BribeData[id][BribeLabel] = Text3D: -1;
  142.     DestroyDynamicPickup(BribeData[id][BribeIcon]);
  143.     Iter_Remove(bribes, id);
  144.     new query[48];
  145.     mysql_format(BribeSQLHandle, query, sizeof(query), "DELETE FROM bribes WHERE ID=%d", id);
  146.     mysql_tquery(BribeSQLHandle, query);
  147.     return 1;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement