Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Fighting Styles v1.2
- by [FRAG]Cypress.
- Please do not remove the credits if you want to re-post it on any other forum.
- CREDITS:
- [FRAG]Cypress for whole filterscript.
- Y_Less for y_ini file reading writing.
- Credits to who made encode, strreplace, set, and ret_memcpy stocks.
- UPDATES v1.2
- - Now using y_ini for save player fighting style.
- - Working with lastest SA-MP 0.3c.
- */
- #include <a_samp>
- #include <YSI\y_ini>
- #define COLOR_LRED 0xFF1111FF
- new PlayerFile[13 + MAX_PLAYER_NAME + 1];
- forward LoadStyles(playerid, name[], value[]);
- public OnFilterScriptInit()
- {
- print("(Fighting Styles) has been loaded...");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- format(PlayerFile , sizeof PlayerFile, "FightingStyles/%s.ini", Encode(pName(playerid)));
- if(!INI_Exist(pName(playerid)))
- {
- new INI:PlayerFS = INI_Open(PlayerFile);
- INI_WriteInt(PlayerFS, "FightingStyles", 0);
- INI_Close(PlayerFS);
- }
- else if(INI_Exist(pName(playerid)))
- {
- INI_ParseFile(PlayerFile, "LoadStyles", false, true, playerid, true, false);
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(INI_Exist(pName(playerid)))
- {
- format(PlayerFile , sizeof PlayerFile, "FightingStyles/%s.ini", Encode(pName(playerid)));
- new INI:PlayerFS = INI_Open(PlayerFile);
- INI_WriteInt(PlayerFS, "FightingStyles", GetPVarInt(playerid, "FightingStyle"));
- INI_Close(PlayerFS);
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- LoadFightStyle(playerid);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(strcmp("/fstyles", cmdtext, true, 8) == 0)
- {
- 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");
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == 899 && response == 1)
- {
- if(inputtext[0] == '1')
- {
- if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_ELBOW) return SendClientMessage(playerid, COLOR_LRED,"You Already Know Elbow.");
- else
- {
- if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn Elbow Fighting.");
- else
- {
- GivePlayerMoney(playerid, -1000);
- SetPlayerFightingStyle (playerid, FIGHT_STYLE_ELBOW);
- SetPVarInt(playerid, "FightingStyle", 1);
- SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to elbow.");
- }
- }
- }
- else if(inputtext[0] == '2')
- {
- if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_BOXING) return SendClientMessage(playerid, COLOR_LRED,"You Already Know Boxing.");
- else
- {
- if(GetPlayerMoney(playerid) < 600) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn Boxing Fighting.");
- else
- {
- GivePlayerMoney(playerid, -600);
- SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
- SetPVarInt(playerid, "FightingStyle", 2);
- SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to boxing.");
- }
- }
- }
- else if(inputtext[0] == '3')
- {
- if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_GRABKICK) return SendClientMessage(playerid, COLOR_LRED,"You Already Know GrabKick.");
- else
- {
- if(GetPlayerMoney(playerid) < 800) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn GrabKick Fighting.");
- else
- {
- GivePlayerMoney(playerid, -800);
- SetPlayerFightingStyle (playerid, FIGHT_STYLE_GRABKICK);
- SetPVarInt(playerid, "FightingStyle", 3);
- SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to GrabKick.");
- }
- }
- }
- else if(inputtext[0] == '4')
- {
- if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_KNEEHEAD) return SendClientMessage(playerid, COLOR_LRED,"You Already Know KneeHead.");
- else
- {
- if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn KneeHead Fighting.");
- else
- {
- GivePlayerMoney(playerid, -1000);
- SetPlayerFightingStyle (playerid, FIGHT_STYLE_KNEEHEAD);
- SetPVarInt(playerid, "FightingStyle", 4);
- SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to KneeHead.");
- }
- }
- }
- else if(inputtext[0] == '5')
- {
- if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_KUNGFU) return SendClientMessage(playerid, COLOR_LRED,"You Already Know KungFu.");
- else
- {
- if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn KungFu Fighting.");
- else
- {
- GivePlayerMoney(playerid, -1000);
- SetPlayerFightingStyle (playerid, FIGHT_STYLE_KUNGFU);
- SetPVarInt(playerid, "FightingStyle", 5);
- SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to KungFu.");
- }
- }
- }
- else if(inputtext[0] == '6')
- {
- if(GetPlayerFightingStyle(playerid) == FIGHT_STYLE_NORMAL) return SendClientMessage(playerid, COLOR_LRED,"You Already Know Normal.");
- else
- {
- if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, COLOR_LRED, "You Cannot Afford To Learn Normal Fighting.");
- else
- {
- GivePlayerMoney(playerid, -100);
- SetPlayerFightingStyle (playerid, FIGHT_STYLE_NORMAL);
- SetPVarInt(playerid, "FightingStyle", 0);
- SendClientMessage(playerid, COLOR_LRED, "You have changed your fighting style to Normal.");
- }
- }
- }
- else
- {
- 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");
- }
- return 1;
- }
- return 0;
- }
- public LoadStyles(playerid, name[ ], value[ ])
- {
- if(!strcmp(name, "FightingStyles")) SetPVarInt(playerid, "FightingStyle", strval(value));
- }
- stock LoadFightStyle(playerid)
- {
- if(GetPVarInt(playerid, "FightingStyle") == 1)
- {
- SetPlayerFightingStyle(playerid, FIGHT_STYLE_ELBOW);
- }
- else if(GetPVarInt(playerid, "FightingStyle") == 2)
- {
- SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
- }
- else if(GetPVarInt(playerid, "FightingStyle") == 3)
- {
- SetPlayerFightingStyle(playerid, FIGHT_STYLE_GRABKICK);
- }
- else if(GetPVarInt(playerid, "FightingStyle") == 4)
- {
- SetPlayerFightingStyle(playerid, FIGHT_STYLE_KNEEHEAD);
- }
- else if(GetPVarInt(playerid, "FightingStyle") == 5)
- {
- SetPlayerFightingStyle(playerid, FIGHT_STYLE_KUNGFU);
- }
- else if(GetPVarInt(playerid, "FightingStyle") == 0)
- {
- SetPlayerFightingStyle(playerid, FIGHT_STYLE_NORMAL);
- }
- return 1;
- }
- stock pName(playerid)
- {
- new namep[MAX_PLAYER_NAME];
- GetPlayerName(playerid,namep,sizeof(namep));
- return namep;
- }
- stock INI_Exist(nickname[])
- {
- new tmp[255];
- format(tmp,sizeof(tmp),"FightingStyles/%s.ini",Encode(nickname));
- return fexist(tmp);
- }
- stock Encode(nickname[])
- {
- new tmp[255];
- set(tmp,nickname);
- tmp=strreplace("_","_00",tmp);
- tmp=strreplace(";","_01",tmp);
- tmp=strreplace("!","_02",tmp);
- tmp=strreplace("/","_03",tmp);
- tmp=strreplace("\\","_04",tmp);
- tmp=strreplace("[","_05",tmp);
- tmp=strreplace("]","_06",tmp);
- tmp=strreplace("?","_07",tmp);
- tmp=strreplace(".","_08",tmp);
- tmp=strreplace("*","_09",tmp);
- tmp=strreplace("<","_10",tmp);
- tmp=strreplace(">","_11",tmp);
- tmp=strreplace("{","_12",tmp);
- tmp=strreplace("}","_13",tmp);
- tmp=strreplace(" ","_14",tmp);
- tmp=strreplace("\"","_15",tmp);
- tmp=strreplace(":","_16",tmp);
- tmp=strreplace("|","_17",tmp);
- tmp=strreplace("=","_18",tmp);
- return tmp;
- }
- stock set(dest[],source[])
- {
- new
- count = strlen(source),
- i=0
- ;
- for(i=0;i<count;i++) dest[i]=source[i];
- dest[count]=0;
- }
- stock strreplace(trg[],newstr[],src[])
- {
- new
- f=0,
- s1[255],
- tmp[255]
- ;
- format(s1,sizeof(s1),"%s",src);
- f = strfind(s1,trg);
- tmp[0]=0;
- while (f>=0)
- {
- strcat(tmp,ret_memcpy(s1, 0, f));
- strcat(tmp,newstr);
- format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
- f = strfind(s1,trg);
- }
- strcat(tmp,s1);
- return tmp;
- }
- ret_memcpy(source[],index=0,numbytes)
- {
- new
- tmp[255],
- i=0
- ;
- tmp[0]=0;
- if(index>=strlen(source)) return tmp;
- if(numbytes+index>=strlen(source)) numbytes=strlen(source)-index;
- if(numbytes<=0) return tmp;
- for(i=index;i<numbytes+index;i++)
- {
- tmp[i-index]=source[i];
- if(source[i]==0) return tmp;
- }
- tmp[numbytes]=0;
- return tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement