Advertisement
Guest User

FightStyle System

a guest
Jul 20th, 2011
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                              //////////////////////////////
  2.                             //Fighting Styles System by dariumare//
  3.                            //////////////////////////////
  4.  
  5. #include <a_samp>
  6. #define FILTERSCRIPT
  7. #define COLOR_WHITE 0xFFFFFFAA
  8. #define COLOR_GREY 0xAFAFAFAA
  9. #define CORANGE     "{E68C0E}"
  10. #define CBLUE       "{39AACC}"
  11. #define CDGREEN     "{6FA828}"
  12. new DB:Database;
  13. forward OnPlayerRegister(playerid, password[]);
  14. forward FinishFightStyle(playerid);
  15. enum pKnow
  16. {
  17.     BOXING,
  18.     KUNGFU,
  19.     KNEEHEAD,
  20.     GRABKICK,
  21.     ELBOW,
  22. };
  23. new PlayerKnow[MAX_PLAYERS][pKnow];
  24.  
  25. public FinishFightStyle(playerid)
  26. {
  27.     SendClientMessage(playerid, -1, ""#CDGREEN"Impratitor Diplome: "#CORANGE"Bravo, ai invatat destul de bine pentru a lua diploma, te costa $10000!");
  28.     GameTextForPlayer(playerid, "~r~~h~-10000", 5000, 1);
  29.     GivePlayerMoney(playerid, -10000);
  30.     TogglePlayerControllable(playerid, 1);
  31.     return 1;
  32. }
  33. public OnFilterScriptInit()
  34. {
  35.     print("===========================");
  36.     print("dariumare's Fighting Styles System");
  37.     print("===========================");
  38.     Database = db_open("FightStyles.db");
  39.     db_free_result(db_query(Database, "CREATE TABLE IF NOT EXISTS `FightStyles` (`Nume`, `Boxing`, `Kungfu`, `Kneehead`, `Grabkick`, `Elbow`)"));
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerCommandText(playerid, cmdtext[])
  44. {
  45.     new cmd[256];
  46.     new idx;
  47.     cmd = strtok(cmdtext, idx);
  48.     if(strcmp(cmd, "/learn", true) == 0)
  49.     {
  50.         if(!IsPlayerInRangeOfPoint(playerid, 100, 772.111999,-3.898649,1000.728820) || !IsPlayerInRangeOfPoint(playerid, 100, 774.213989,-48.924297,1000.585937) || !IsPlayerInRangeOfPoint(playerid, 100, 773.579956,-77.096694,1000.655029))return SendClientMessage(playerid, COLOR_GREY, " Nu esti la GYM!");
  51.         new Query[256];
  52.         new x_nr[256];
  53.         x_nr = strtok(cmdtext, idx);
  54.         new money;
  55.         money = GetPlayerMoney(playerid);
  56.         if(!strlen(x_nr))
  57.         {
  58.             SendClientMessage(playerid, COLOR_WHITE, "USAGE: /learn [name]");
  59.             SendClientMessage(playerid, COLOR_WHITE, "Available names: Boxing, Kungfu, Kneehead, Grabkick, Elbow");
  60.             return 1;
  61.         }
  62.         if (money <= 10000)
  63.         {
  64.             SendClientMessage(playerid,COLOR_WHITE, "Nu ai destui bani pentru a invata acest stil de lupta!");
  65.             return 1;
  66.         }
  67.         if(strcmp(x_nr,"boxing",true) == 0)
  68.         {
  69.             if(PlayerKnow[playerid][BOXING] == 1)
  70.             {
  71.                 SendClientMessage(playerid,COLOR_WHITE, "Deja stii boxing!");
  72.                 return 1;
  73.             }
  74.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru Boxer: "#CORANGE"Buna, vad ca vrei sa inveti box.");
  75.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru Boxer: "#CORANGE"La cat de bine facut esti imi va lua 1 minut sa te invat totul despre boxing!");
  76.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_BOXING);
  77.             PlayerKnow[playerid][BOXING] = 1;
  78.             format(Query, sizeof(Query), "UPDATE `FightStyles` SET `Boxer` = '%d' WHERE `Nume` = '%s' ", PlayerKnow[playerid][BOXING],Name(playerid));
  79.             db_free_result(db_query(Database, Query));
  80.             TogglePlayerControllable(playerid, 0);
  81.             SetTimer("FinishFightStyle",10000,false);
  82.             return 1;
  83.         }
  84.         else if(strcmp(x_nr,"kungfu",true) == 0)
  85.         {
  86.             if(PlayerKnow[playerid][KUNGFU] == 1)
  87.             {
  88.                 SendClientMessage(playerid,COLOR_WHITE, "Deja stii kungfu!");
  89.                 return 1;
  90.             }
  91.             SendClientMessage(playerid,-1, ""#CBLUE"Maestru KungFu: "#CORANGE"Buna, vad ca vrei sa inveti kungfu.");
  92.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru KungFu: "#CORANGE"La cat de bine facut esti imi va lua 1 minut sa te invat totul despre kungfu!");
  93.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_KUNGFU);
  94.             PlayerKnow[playerid][KUNGFU] = 1;
  95.             format(Query, sizeof(Query), "UPDATE `FightStyles` SET `Kungfu` = '%d' WHERE `Nume` = '%s' ", PlayerKnow[playerid][KUNGFU],Name(playerid));
  96.             db_free_result(db_query(Database, Query));
  97.             SetTimer("FinishFightStyle",10000,false);
  98.             TogglePlayerControllable(playerid, 0);
  99.             return 1;
  100.         }
  101.         else if(strcmp(x_nr,"Kneehead",true) == 0)
  102.         {
  103.             if(PlayerKnow[playerid][KNEEHEAD] == 1)
  104.             {
  105.                 SendClientMessage(playerid,COLOR_WHITE, "Deja stii Kneehead!");
  106.                 return 1;
  107.             }
  108.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru Kneehead: "#CORANGE"Buna, vad ca vrei sa inveti kneehead.");
  109.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru Kneehead: "#CORANGE"La cat de bine facut esti imi va lua 1 minut sa te invat totul despre kneehead!");
  110.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_KNEEHEAD);
  111.             PlayerKnow[playerid][KNEEHEAD] = 1;
  112.             format(Query, sizeof(Query), "UPDATE `FightStyles` SET `Kneehead` = '%d' WHERE `Nume` = '%s' ", PlayerKnow[playerid][KNEEHEAD],Name(playerid));
  113.             db_free_result(db_query(Database, Query));
  114.             SetTimer("FinishFightStyle",10000,false);
  115.             TogglePlayerControllable(playerid, 0);
  116.             return 1;
  117.         }
  118.         else if(strcmp(x_nr,"Grabkick",true) == 0)
  119.         {
  120.             if(PlayerKnow[playerid][GRABKICK] == 1)
  121.             {
  122.                 SendClientMessage(playerid,COLOR_WHITE, "Deja stii Grabkick!");
  123.                 return 1;
  124.             }
  125.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru GrabKick: "#CORANGE"Buna, vad ca vrei sa inveti grabkick.");
  126.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru GrabKick: "#CORANGE"La cat de bine facut esti imi va lua 1 minut sa te invat totul despre grabkick!");
  127.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_GRABKICK);
  128.             PlayerKnow[playerid][GRABKICK] = 1;
  129.             format(Query, sizeof(Query), "UPDATE `FightStyles` SET `Grabkick` = '%d' WHERE `Nume` = '%s' ", PlayerKnow[playerid][GRABKICK],Name(playerid));
  130.             db_free_result(db_query(Database, Query ));
  131.             SetTimer("FinishFightStyle",10000,false);
  132.             TogglePlayerControllable(playerid, 0);
  133.             return 1;
  134.         }
  135.         else if(strcmp(x_nr,"Elbow",true) == 0)
  136.         {
  137.             if(PlayerKnow[playerid][ELBOW] == 1)
  138.             {
  139.                 SendClientMessage(playerid,COLOR_WHITE, "Deja stii Elbow!");
  140.                 return 1;
  141.             }
  142.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru Elbow: "#CORANGE"Buna, vad ca vrei sa inveti grabkick.");
  143.             SendClientMessage(playerid, -1, ""#CBLUE"Maestru Elbow: "#CORANGE"La cat de bine facut esti imi va lua 1 minut sa te invat totul despre grabkick!");
  144.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_ELBOW);
  145.             PlayerKnow[playerid][ELBOW] = 1;
  146.             format(Query, sizeof(Query), "UPDATE `FightStyles` SET `Elbow` = '%d' WHERE `Nume` = '%s' ", PlayerKnow[playerid][ELBOW],Name(playerid));
  147.             db_free_result(db_query(Database, Query));
  148.             SetTimer("FinishFightStyle",10000,false);
  149.             TogglePlayerControllable(playerid, 0);
  150.             return 1;
  151.         }
  152.         return 1;
  153.     }
  154.     if(strcmp(cmd, "/fightstyle", true) == 0)
  155.     {
  156.         new x_nr[256];
  157.         x_nr = strtok(cmdtext, idx);
  158.         if(!strlen(x_nr))
  159.         {
  160.             SendClientMessage(playerid, COLOR_WHITE, "USAGE: /learn [name]");
  161.             SendClientMessage(playerid, COLOR_WHITE, "Available names: Boxing, Kungfu, Kneehead, Grabkick, Elbow, Normal");
  162.             return 1;
  163.         }
  164.         if(strcmp(x_nr,"boxing",true) == 0)
  165.         {
  166.             if(!PlayerKnow[playerid][BOXING]) return SendClientMessage(playerid, COLOR_GREY, "Nu sti Box!");
  167.             SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
  168.             SendClientMessage(playerid,COLOR_WHITE," Acum ai stilul Box!");
  169.             return 1;
  170.         }
  171.         else if(strcmp(x_nr,"kungfu",true) == 0)
  172.         {
  173.             if(!PlayerKnow[playerid][KUNGFU]) return SendClientMessage(playerid, COLOR_GREY, "Nu sti KungFu");
  174.             SetPlayerFightingStyle(playerid, FIGHT_STYLE_KUNGFU);
  175.             SendClientMessage(playerid,COLOR_WHITE," Acum ai stilul KungFu!");
  176.             return 1;
  177.         }
  178.         else if(strcmp(x_nr,"kneehead",true) == 0)
  179.         {
  180.             if(!PlayerKnow[playerid][KNEEHEAD]) return SendClientMessage(playerid, COLOR_GREY, "Nu sti Kneehead!");
  181.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_KNEEHEAD);
  182.             SendClientMessage(playerid,COLOR_WHITE," Acum ai stilul Kneehead!");
  183.             return 1;
  184.         }
  185.         else if(strcmp(x_nr,"grabkick",true) == 0)
  186.         {
  187.             if(!PlayerKnow[playerid][GRABKICK]) return SendClientMessage(playerid, COLOR_GREY, "Nu sti Grabkick!");
  188.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_GRABKICK);
  189.             SendClientMessage(playerid,COLOR_WHITE," Acum ai stilul Grabkick!");
  190.             return 1;
  191.         }
  192.         else if(strcmp(x_nr,"elbow",true) == 0)
  193.         {
  194.             if(!PlayerKnow[playerid][ELBOW]) return SendClientMessage(playerid, COLOR_GREY, "Nu sti Elbow!");
  195.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_ELBOW);
  196.             SendClientMessage(playerid,COLOR_WHITE," Acum ai stilul Elbow!");
  197.             return 1;
  198.         }
  199.         else if(strcmp(x_nr,"normal",true) == 0)
  200.         {
  201.             SetPlayerFightingStyle (playerid, FIGHT_STYLE_NORMAL);
  202.             SendClientMessage(playerid,COLOR_WHITE," Acum ai stilul Normal!");
  203.             return 1;
  204.         }
  205.         return 1;
  206.     }
  207.     return 0;
  208. }
  209. public OnPlayerConnect(playerid)
  210. {
  211.  
  212.         new Query[ 256 ], DBResult:Result;
  213.         format(Query, sizeof(Query), "SELECT * FROM `FightStyles` WHERE `Nume` = '%s'", Name(playerid));
  214.         Result = db_query(Database, Query) ;
  215.  
  216.         if ( db_num_rows( Result ) )
  217.         {
  218.             new Field[30];
  219.             db_get_field_assoc(Result, "Boxing", Field, 30);
  220.             PlayerKnow[playerid][BOXING] = strval(Field);
  221.             db_get_field_assoc(Result, "Kungfu", Field, 30);
  222.             PlayerKnow[playerid][KUNGFU] = strval(Field);
  223.             db_get_field_assoc(Result, "Kneehead", Field, 30);
  224.             PlayerKnow[playerid][KNEEHEAD] = strval(Field);
  225.             db_get_field_assoc(Result, "Grabkick", Field, 30);
  226.             PlayerKnow[playerid][GRABKICK] = strval(Field);
  227.             db_get_field_assoc(Result, "Elbow", Field, 30);
  228.             PlayerKnow[playerid][ELBOW] = strval(Field);
  229.         }
  230.         else
  231.         {
  232.             format(Query, sizeof(Query), "INSERT INTO `FightStyles` (`Nume`, `Boxing`, `Kungfu`, `Kneehead`, `Grabkick`, `Elbow`) VALUES('%s', '%d', '%d', '%d', '%d', '%d')", Name(playerid), 0, 0, 0, 0, 0);
  233.             db_query(Database, Query);
  234.         }
  235.         db_free_result( Result );
  236.         return 1;
  237.     }
  238. strtok(const string[], &index)
  239. {
  240.     new length = strlen(string);
  241.     while ((index < length) && (string[index] <= ' '))
  242.     {
  243.         index++;
  244.     }
  245.  
  246.     new offset = index;
  247.     new result[20];
  248.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  249.     {
  250.         result[index - offset] = string[index];
  251.         index++;
  252.     }
  253.     result[index - offset] = EOS;
  254.     return result;
  255. }
  256. Name(i){
  257.     new n[24];
  258.     GetPlayerName(i,n,24);
  259.     return n;
  260. }
Advertisement
RAW Paste Data Copied
Advertisement