Advertisement
Cypress

Fighting Styles (UPDATED V1.2)

May 25th, 2011
1,447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.81 KB | None | 0 0
  1. /*
  2.  
  3.                                       Fighting Styles v1.2
  4.                                         by [FRAG]Cypress.
  5.             Please do not remove the credits if you want to re-post it on any other forum.
  6.            
  7.                                          CREDITS:
  8.                          [FRAG]Cypress for whole filterscript.
  9.                          Y_Less for y_ini file reading writing.
  10.             Credits to who made encode, strreplace, set, and ret_memcpy stocks.
  11.                                          
  12.                                          UPDATES v1.2
  13.                     - Now using y_ini for save player fighting style.
  14.                     - Working with lastest SA-MP 0.3c.
  15.  
  16. */
  17.  
  18. #include <a_samp>
  19. #include <YSI\y_ini>
  20.  
  21. #define COLOR_LRED 0xFF1111FF
  22.  
  23. new PlayerFile[13 + MAX_PLAYER_NAME + 1];
  24.  
  25. forward LoadStyles(playerid, name[], value[]);
  26.  
  27. public OnFilterScriptInit()
  28. {
  29.     print("(Fighting Styles) has been loaded...");
  30.     return 1;
  31. }
  32.  
  33. public OnPlayerConnect(playerid)
  34. {
  35.     format(PlayerFile , sizeof PlayerFile, "FightingStyles/%s.ini", Encode(pName(playerid)));
  36.     if(!INI_Exist(pName(playerid)))
  37.     {
  38.        new INI:PlayerFS = INI_Open(PlayerFile);
  39.        INI_WriteInt(PlayerFS, "FightingStyles", 0);
  40.        INI_Close(PlayerFS);
  41.     }
  42.     else if(INI_Exist(pName(playerid)))
  43.     {
  44.        INI_ParseFile(PlayerFile, "LoadStyles", false, true, playerid, true, false);
  45.     }
  46.     return 1;
  47. }
  48.  
  49. public OnPlayerDisconnect(playerid, reason)
  50. {
  51.     if(INI_Exist(pName(playerid)))
  52.     {
  53.         format(PlayerFile , sizeof PlayerFile, "FightingStyles/%s.ini", Encode(pName(playerid)));
  54.         new INI:PlayerFS = INI_Open(PlayerFile);
  55.         INI_WriteInt(PlayerFS, "FightingStyles", GetPVarInt(playerid, "FightingStyle"));
  56.         INI_Close(PlayerFS);
  57.     }
  58.     return 1;
  59. }
  60.  
  61. public OnPlayerSpawn(playerid)
  62. {
  63.     LoadFightStyle(playerid);
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerCommandText(playerid, cmdtext[])
  68. {
  69.     if(strcmp("/fstyles", cmdtext, true, 8) == 0)
  70.     {
  71.         ShowPlayerDialog(playerid, 899, DIALOG_STYLE_INPUT, "Fighting Styles", "ID\tItem\t\t\tPrice\n\n1\tElbow\t\t\t$1000\n2\tBoxing\t\t\t$600\n3\tGrabkick\t\t$800\n4\tKneeHead\t\t$1000\n5\tKungfu\t\t\t$1000\n6\tNormal\t\t\t$100\n", "Buy", "Close");
  72.         return 1;
  73.     }
  74.     return 0;
  75. }
  76.  
  77. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  78. {
  79.     if(dialogid == 899 && response == 1)
  80.     {
  81.         if(inputtext[0] == '1')
  82.         {
  83.            if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_ELBOW) return SendClientMessage(playerid, COLOR_LRED,"You Already Know Elbow.");
  84.            else
  85.            {
  86.                if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn Elbow Fighting.");
  87.                else
  88.                {
  89.                   GivePlayerMoney(playerid, -1000);
  90.                   SetPlayerFightingStyle (playerid, FIGHT_STYLE_ELBOW);
  91.                   SetPVarInt(playerid, "FightingStyle", 1);
  92.                   SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to elbow.");
  93.                }
  94.             }
  95.         }
  96.         else if(inputtext[0] == '2')
  97.         {
  98.            if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_BOXING) return SendClientMessage(playerid, COLOR_LRED,"You Already Know Boxing.");
  99.            else
  100.            {
  101.                if(GetPlayerMoney(playerid) < 600) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn Boxing Fighting.");
  102.                else
  103.                {
  104.                   GivePlayerMoney(playerid, -600);
  105.                   SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
  106.                   SetPVarInt(playerid, "FightingStyle", 2);
  107.                   SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to boxing.");
  108.                }
  109.            }
  110.         }
  111.         else if(inputtext[0] == '3')
  112.         {
  113.            if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_GRABKICK) return SendClientMessage(playerid, COLOR_LRED,"You Already Know GrabKick.");
  114.            else
  115.            {
  116.                if(GetPlayerMoney(playerid) < 800) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn GrabKick Fighting.");
  117.                else
  118.                {
  119.                   GivePlayerMoney(playerid, -800);
  120.                   SetPlayerFightingStyle (playerid, FIGHT_STYLE_GRABKICK);
  121.                   SetPVarInt(playerid, "FightingStyle", 3);
  122.                   SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to GrabKick.");
  123.                }
  124.            }
  125.         }
  126.         else if(inputtext[0] == '4')
  127.         {
  128.             if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_KNEEHEAD) return SendClientMessage(playerid, COLOR_LRED,"You Already Know KneeHead.");
  129.             else
  130.             {
  131.                if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn KneeHead Fighting.");
  132.                else
  133.                {
  134.                   GivePlayerMoney(playerid, -1000);
  135.                   SetPlayerFightingStyle (playerid, FIGHT_STYLE_KNEEHEAD);
  136.                   SetPVarInt(playerid, "FightingStyle", 4);
  137.                   SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to KneeHead.");
  138.                }
  139.             }
  140.         }
  141.         else if(inputtext[0] == '5')
  142.         {
  143.             if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_KUNGFU) return SendClientMessage(playerid, COLOR_LRED,"You Already Know KungFu.");
  144.             else
  145.             {
  146.                if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn KungFu Fighting.");
  147.                else
  148.                {
  149.                   GivePlayerMoney(playerid, -1000);
  150.                   SetPlayerFightingStyle (playerid, FIGHT_STYLE_KUNGFU);
  151.                   SetPVarInt(playerid, "FightingStyle", 5);
  152.                   SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to KungFu.");
  153.                }
  154.             }
  155.         }
  156.         else if(inputtext[0] == '6')
  157.         {
  158.             if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_NORMAL) return SendClientMessage(playerid, COLOR_LRED,"You Already Know Normal.");
  159.             else
  160.             {
  161.                if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn Normal Fighting.");
  162.                else
  163.                {
  164.                   GivePlayerMoney(playerid, -100);
  165.                   SetPlayerFightingStyle (playerid, FIGHT_STYLE_NORMAL);
  166.                   SetPVarInt(playerid, "FightingStyle", 0);
  167.                   SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to Normal.");
  168.                }
  169.             }
  170.         }
  171.         else
  172.         {
  173.             ShowPlayerDialog(playerid, 899, DIALOG_STYLE_INPUT, "Fighting Styles", "ID\tItem\t\t\tPrice\n\n1\tElbow\t\t\t$1000\n2\tBoxing\t\t\t$600\n3\tGrabkick\t\t$800\n4\tKneeHead\t\t$1000\n5\tKungfu\t\t\t$1000\n6\tNormal\t\t\t$100\n", "Buy", "Close");
  174.         }
  175.         return 1;
  176.     }
  177.     return 0;
  178. }
  179.  
  180. public LoadStyles(playerid, name[ ], value[ ])
  181. {
  182.     if(!strcmp(name, "FightingStyles")) SetPVarInt(playerid, "FightingStyle", strval(value));
  183. }
  184.  
  185. stock LoadFightStyle(playerid)
  186. {
  187.     if(GetPVarInt(playerid, "FightingStyle") == 1)
  188.     {
  189.         SetPlayerFightingStyle(playerid, FIGHT_STYLE_ELBOW);
  190.     }
  191.     else if(GetPVarInt(playerid, "FightingStyle") == 2)
  192.     {
  193.         SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
  194.     }
  195.     else if(GetPVarInt(playerid, "FightingStyle") == 3)
  196.     {
  197.         SetPlayerFightingStyle(playerid, FIGHT_STYLE_GRABKICK);
  198.     }
  199.     else if(GetPVarInt(playerid, "FightingStyle") == 4)
  200.     {
  201.         SetPlayerFightingStyle(playerid, FIGHT_STYLE_KNEEHEAD);
  202.     }
  203.     else if(GetPVarInt(playerid, "FightingStyle") == 5)
  204.     {
  205.         SetPlayerFightingStyle(playerid, FIGHT_STYLE_KUNGFU);
  206.     }
  207.     else if(GetPVarInt(playerid, "FightingStyle") == 0)
  208.     {
  209.         SetPlayerFightingStyle(playerid, FIGHT_STYLE_NORMAL);
  210.     }
  211.     return 1;
  212. }
  213.  
  214. stock pName(playerid)
  215. {
  216.     new namep[MAX_PLAYER_NAME];
  217.     GetPlayerName(playerid,namep,sizeof(namep));
  218.     return namep;
  219. }
  220.  
  221. stock INI_Exist(nickname[])
  222. {
  223.     new tmp[255];
  224.     format(tmp,sizeof(tmp),"FightingStyles/%s.ini",Encode(nickname));
  225.     return fexist(tmp);
  226. }
  227.  
  228. stock Encode(nickname[])
  229. {
  230.     new tmp[255];
  231.     set(tmp,nickname);
  232.     tmp=strreplace("_","_00",tmp);
  233.     tmp=strreplace(";","_01",tmp);
  234.     tmp=strreplace("!","_02",tmp);
  235.     tmp=strreplace("/","_03",tmp);
  236.     tmp=strreplace("\\","_04",tmp);
  237.     tmp=strreplace("[","_05",tmp);
  238.     tmp=strreplace("]","_06",tmp);
  239.     tmp=strreplace("?","_07",tmp);
  240.     tmp=strreplace(".","_08",tmp);
  241.     tmp=strreplace("*","_09",tmp);
  242.     tmp=strreplace("<","_10",tmp);
  243.     tmp=strreplace(">","_11",tmp);
  244.     tmp=strreplace("{","_12",tmp);
  245.     tmp=strreplace("}","_13",tmp);
  246.     tmp=strreplace(" ","_14",tmp);
  247.     tmp=strreplace("\"","_15",tmp);
  248.     tmp=strreplace(":","_16",tmp);
  249.     tmp=strreplace("|","_17",tmp);
  250.     tmp=strreplace("=","_18",tmp);
  251.     return tmp;
  252. }
  253.  
  254. stock set(dest[],source[])
  255. {
  256.     new
  257.        count = strlen(source),
  258.        i=0
  259.     ;
  260.     for(i=0;i<count;i++) dest[i]=source[i];
  261.     dest[count]=0;
  262. }
  263.  
  264. stock strreplace(trg[],newstr[],src[])
  265. {
  266.     new
  267.        f=0,
  268.        s1[255],
  269.        tmp[255]
  270.     ;
  271.     format(s1,sizeof(s1),"%s",src);
  272.     f = strfind(s1,trg);
  273.     tmp[0]=0;
  274.     while (f>=0)
  275.     {
  276.        strcat(tmp,ret_memcpy(s1, 0, f));
  277.        strcat(tmp,newstr);
  278.        format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
  279.        f = strfind(s1,trg);
  280.     }
  281.     strcat(tmp,s1);
  282.     return tmp;
  283. }
  284.  
  285. ret_memcpy(source[],index=0,numbytes)
  286. {
  287.     new
  288.        tmp[255],
  289.        i=0
  290.     ;
  291.     tmp[0]=0;
  292.     if(index>=strlen(source)) return tmp;
  293.     if(numbytes+index>=strlen(source)) numbytes=strlen(source)-index;
  294.     if(numbytes<=0) return tmp;
  295.     for(i=index;i<numbytes+index;i++)
  296.     {
  297.         tmp[i-index]=source[i];
  298.         if(source[i]==0) return tmp;
  299.     }
  300.     tmp[numbytes]=0;
  301.     return tmp;
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement