Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI\y_ini>
- #include <zcmd>
- #include <sscanf2>
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- #define DIALOG_SUCCESS_1 3
- #define DIALOG_SUCCESS_2 4
- #define PATH "/Users/%s.ini"
- #define COL_WHITE "{FFFFFF}"
- #define COL_RED "{F81414}"
- #define COL_GREEN "{00FF22}"
- #define COL_LIGHTBLUE "{00CED1}"
- #define yellow 0xFFFF00AA
- #define orange 0xFF9900AA
- #define red 0xFF0000AA
- #define green 0x33AA33AA
- enum pInfo
- {
- pPass,
- pSausage
- }
- new PlayerInfo[MAX_PLAYERS][pInfo];
- new Text:SausagesTxd[MAX_PLAYERS];
- main()
- {
- print("\n----------------------------------");
- print("Sausage System by Logitech90");
- print("----------------------------------\n");
- }
- forward SasUpdate(playerid);
- public SasUpdate()
- {
- new string[128];
- for( new u; u < MAX_PLAYERS; u ++)
- {
- format(string, sizeof(string), "Sausages: %d", PlayerInfo[u][pSausage]);
- TextDrawSetString(SausagesTxd[u], string);
- }
- }
- forward LoadUser_data(playerid,name[],value[]);
- public LoadUser_data(playerid,name[],value[])
- {
- INI_Int("Password",PlayerInfo[playerid][pPass]);
- INI_Int("Sausages",PlayerInfo[playerid][pSausage]);
- return 1;
- }
- stock UserPath(playerid)
- {
- new string[128],playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid,playername,sizeof(playername));
- format(string,sizeof(string),PATH,playername);
- return string;
- }
- /*Credits to Dracoblue*/
- stock udb_hash(buf[]) {
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++)
- {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- }
- CMD:sshop(playerid,params[])
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
- {
- SendClientMessage(playerid,red,"You can't access the sausages shop if you are in a vehicle.");
- return 1;
- }
- new dt[128];
- strcat(dt,"5 Sausages{53C506}1500$\n");
- strcat(dt,"10 Sausages{53C506}2500$\n");
- strcat(dt,"25 Sausages{53C506}5000$\n");
- ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST, "{53C506}Sausages Shop",dt,"Buy!","Nah!");
- return 1;
- }
- CMD:sausage(playerid,params[])
- {
- if(PlayerInfo[playerid][pSausage] == 0) return SendClientMessage(playerid,0xFF0000FF,"You dont have any sausage! Buy it from /sshop");
- if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,red,"You can't eat sausages if you are in a vehicle.");
- if(GetPVarInt(playerid,"SausageTime")>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"Please wait 1 minute before eating a sausage again.");
- new Float:phealth;
- GetPlayerHealth(playerid,phealth);
- if(phealth == 90)
- {
- SendClientMessage(playerid,red,"Your health is already full.Why do you need to eat any sausage?");
- return 1;
- }
- ApplyAnimation(playerid, "FOOD", "EAT_Burger", 3.0, 0, 0, 0, 0, 0);
- SendClientMessage(playerid,yellow,"***Sausage Eaten***");
- SendClientMessage(playerid,yellow,"***You have eaten a sausage and it has healed you slightly.You feel abit better!***");
- SetPlayerHealth(playerid,phealth+25);
- GameTextForPlayer(playerid, "~w~~h~Umh,yummi!!", 5000, 5);
- PlayerInfo[playerid][pSausage] --;
- SetPVarInt(playerid,"SausageTime",GetTickCount()+60000);
- return 1;
- }
- CMD:gs(playerid, params[])
- {
- new Destinationid,Ammount,PlayerName[24],DestName[24],String[128];
- new Year, Month, Day, Hour, Minute, Second;
- getdate(Year, Month, Day);
- gettime(Hour, Minute, Second);
- if(GetPVarInt(playerid,"GsTime")>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"Please wait 5 seconds before giving sausages again.");
- if (sscanf(params, "ui", Destinationid, Ammount)) return SendClientMessage(playerid, -1, "Usage: /givesausage <playerid> <sausage number>");
- if (!IsPlayerConnected(Destinationid)) return SendClientMessage(playerid, -1, "Player is not connected.");
- if(PlayerInfo[playerid][pSausage] == 0) return SendClientMessage(playerid,0xFF0000FF,"You dont have any sausage to send!");
- if(PlayerInfo[playerid][pSausage] < Ammount) return SendClientMessage(playerid,0xFF0000FF,"You don't have this number of sausages to send!");
- if(playerid == Destinationid) return SendClientMessage(playerid,red, "You can't send sausages to yourself.");
- GetPlayerName(playerid, PlayerName, 24);
- GetPlayerName(Destinationid, DestName, 24);
- format(String, 128, "%s (%d) has sent you %d sausages!", PlayerName, playerid, Ammount);
- SendClientMessage(Destinationid, yellow, String);
- new gmsent[128];
- format(gmsent,sizeof(gmsent),"Sent %d sausages to %s (%d)", Ammount,DestName,Destinationid);
- GameTextForPlayer(playerid,gmsent,3000,5);
- format(String, 128, "You've sent %d sausages to %s (%d)", Ammount, DestName, Destinationid);
- SendClientMessage(playerid, yellow, String);
- new gmrec[128];
- format(gmrec,sizeof(gmrec),"Received %d sausages from %s (%d)", Ammount,PlayerName,Destinationid);
- GameTextForPlayer(Destinationid,gmrec,3000,5);
- PlayerInfo[playerid][pSausage] -=Ammount;
- PlayerInfo[Destinationid][pSausage] +=Ammount;
- SetPVarInt(playerid,"GsTime",GetTickCount()+5000);
- return 1;
- }
- public OnGameModeInit()
- {
- SetTimer("SasUpdate", 1000, 1);
- for(new i=0;i<MAX_PLAYERS;i++)
- {
- SausagesTxd[i] = TextDrawCreate(458.000000, 430.000000, "Sausages");
- TextDrawBackgroundColor(SausagesTxd[i], 255);
- TextDrawFont(SausagesTxd[i], 2);
- TextDrawLetterSize(SausagesTxd[i], 0.400000, 1.000000);
- TextDrawColor(SausagesTxd[i], -1);
- TextDrawSetOutline(SausagesTxd[i], 1);
- TextDrawSetProportional(SausagesTxd[i], 1);
- TextDrawUseBox(SausagesTxd[i], 1);
- TextDrawBoxColor(SausagesTxd[i], 80);
- TextDrawTextSize(SausagesTxd[i], 638.000000, 18.000000);
- }
- SetGameModeText("Sausage System");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- TextDrawShowForPlayer(playerid, SausagesTxd[playerid]);
- if(fexist(UserPath(playerid)))
- {
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account and save sausages.","Register","Quit");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new INI:File = INI_Open(UserPath(playerid));
- INI_WriteInt(File,"Sausages",PlayerInfo[playerid][pSausage]);
- INI_Close(File);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch( dialogid )
- {
- case DIALOG_REGISTER:
- {
- if (!response) return Kick(playerid);
- if(response)
- {
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
- new INI:File = INI_Open(UserPath(playerid));
- INI_SetTag(File,"data");
- INI_WriteInt(File,"Sausages",0);
- INI_WriteInt(File,"Password",udb_hash(inputtext));
- INI_Close(File);
- SpawnPlayer(playerid);
- ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Now your sausages are saved!","Ok","");
- }
- }
- case DIALOG_LOGIN:
- {
- if ( !response ) return Kick ( playerid );
- if( response )
- {
- if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
- {
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Logged in! Sausages loaded!","Ok","");
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
- }
- return 1;
- }
- }
- }
- if(dialogid == 6)
- {
- if(response)
- {
- if(listitem == 0) //5 Sausages
- {
- if(GetPlayerMoney(playerid) >= 1500) {
- GivePlayerMoney(playerid,-1500);
- SendClientMessage(playerid, green,"You bought 5 sausages.Use /sausage to eat them or /gs to give sausages to a player");
- PlayerInfo[playerid][pSausage] +=5;
- }
- else return SendClientMessage(playerid, red, "You can't afford 1500$ to buy 5 sausages!");
- }
- if(listitem == 1) //10 Sausages
- {
- if(GetPlayerMoney(playerid) >= 2500) {
- GivePlayerMoney(playerid,-2500);
- SendClientMessage(playerid, green,"You bought 10 sausages.Use /sausage to eat them or /gs to give sausages to a player");
- PlayerInfo[playerid][pSausage] +=10;
- }
- else return SendClientMessage(playerid, red, "You can't afford 2500$ to buy 10 sausages!");
- }
- if(listitem == 2) //25 Sausages
- {
- if(GetPlayerMoney(playerid) >= 5000) {
- GivePlayerMoney(playerid,-5000);
- SendClientMessage(playerid, green,"You bought 25 sausages.Use /sausage to eat them or /gs to give sausages to a player");
- PlayerInfo[playerid][pSausage] +=25;
- }
- else return SendClientMessage(playerid, red, "You can't afford 2500$ to buy 25 sausages!");
- }
- return 1;
- }
- }
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment