Face9000

[Face9000] Simple Sausage System

Jan 23rd, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.36 KB | None | 0 0
  1. #include <a_samp>
  2. #include <YSI\y_ini>
  3. #include <zcmd>
  4. #include <sscanf2>
  5.  
  6. #define DIALOG_REGISTER 1
  7. #define DIALOG_LOGIN 2
  8. #define DIALOG_SUCCESS_1 3
  9. #define DIALOG_SUCCESS_2 4
  10. #define PATH "/Users/%s.ini"
  11.  
  12. #define COL_WHITE "{FFFFFF}"
  13. #define COL_RED "{F81414}"
  14. #define COL_GREEN "{00FF22}"
  15. #define COL_LIGHTBLUE "{00CED1}"
  16. #define yellow 0xFFFF00AA
  17. #define orange 0xFF9900AA
  18. #define red 0xFF0000AA
  19. #define green 0x33AA33AA
  20.  
  21. enum pInfo
  22. {
  23.     pPass,
  24.     pSausage
  25. }
  26. new PlayerInfo[MAX_PLAYERS][pInfo];
  27. new Text:SausagesTxd[MAX_PLAYERS];
  28.  
  29. main()
  30. {
  31.     print("\n----------------------------------");
  32.     print("Sausage System by Logitech90");
  33.     print("----------------------------------\n");
  34. }
  35.  
  36. forward SasUpdate(playerid);
  37. public SasUpdate()
  38. {
  39.     new string[128];
  40.     for( new u; u < MAX_PLAYERS; u ++)
  41.     {
  42.         format(string, sizeof(string), "Sausages: %d", PlayerInfo[u][pSausage]);
  43.         TextDrawSetString(SausagesTxd[u], string);
  44.     }
  45. }
  46.  
  47. forward LoadUser_data(playerid,name[],value[]);
  48. public LoadUser_data(playerid,name[],value[])
  49. {
  50.     INI_Int("Password",PlayerInfo[playerid][pPass]);
  51.     INI_Int("Sausages",PlayerInfo[playerid][pSausage]);
  52.     return 1;
  53. }
  54.  
  55. stock UserPath(playerid)
  56. {
  57.     new string[128],playername[MAX_PLAYER_NAME];
  58.     GetPlayerName(playerid,playername,sizeof(playername));
  59.     format(string,sizeof(string),PATH,playername);
  60.     return string;
  61. }
  62.  
  63. /*Credits to Dracoblue*/
  64. stock udb_hash(buf[]) {
  65.     new length=strlen(buf);
  66.     new s1 = 1;
  67.     new s2 = 0;
  68.     new n;
  69.     for (n=0; n<length; n++)
  70.     {
  71.        s1 = (s1 + buf[n]) % 65521;
  72.        s2 = (s2 + s1)     % 65521;
  73.     }
  74.     return (s2 << 16) + s1;
  75. }
  76.  
  77. CMD:sshop(playerid,params[])
  78. {
  79.      if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
  80.      {
  81.      SendClientMessage(playerid,red,"You can't access the sausages shop if you are in a vehicle.");
  82.      return 1;
  83.      }
  84.      new dt[128];
  85.      strcat(dt,"5 Sausages{53C506}1500$\n");
  86.      strcat(dt,"10 Sausages{53C506}2500$\n");
  87.      strcat(dt,"25 Sausages{53C506}5000$\n");
  88.      ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST, "{53C506}Sausages Shop",dt,"Buy!","Nah!");
  89.      return 1;
  90. }
  91.  
  92. CMD:sausage(playerid,params[])
  93. {
  94.     if(PlayerInfo[playerid][pSausage] == 0) return SendClientMessage(playerid,0xFF0000FF,"You dont have any sausage! Buy it from /sshop");
  95.     if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,red,"You can't eat sausages if you are in a vehicle.");
  96.     if(GetPVarInt(playerid,"SausageTime")>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"Please wait 1 minute before eating a sausage again.");
  97.     new Float:phealth;
  98.     GetPlayerHealth(playerid,phealth);
  99.     if(phealth == 90)
  100.     {
  101.         SendClientMessage(playerid,red,"Your health is already full.Why do you need to eat any sausage?");
  102.         return 1;
  103.     }
  104.     ApplyAnimation(playerid, "FOOD", "EAT_Burger", 3.0, 0, 0, 0, 0, 0);
  105.     SendClientMessage(playerid,yellow,"***Sausage Eaten***");
  106.     SendClientMessage(playerid,yellow,"***You have eaten a sausage and it has healed you slightly.You feel abit better!***");
  107.     SetPlayerHealth(playerid,phealth+25);
  108.     GameTextForPlayer(playerid, "~w~~h~Umh,yummi!!", 5000, 5);
  109.     PlayerInfo[playerid][pSausage] --;
  110.     SetPVarInt(playerid,"SausageTime",GetTickCount()+60000);
  111.     return 1;
  112. }
  113.  
  114. CMD:gs(playerid, params[])
  115. {
  116.     new Destinationid,Ammount,PlayerName[24],DestName[24],String[128];
  117.     new Year, Month, Day, Hour, Minute, Second;
  118.     getdate(Year, Month, Day);
  119.     gettime(Hour, Minute, Second);
  120.     if(GetPVarInt(playerid,"GsTime")>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"Please wait 5 seconds before giving sausages again.");
  121.     if (sscanf(params, "ui", Destinationid, Ammount)) return SendClientMessage(playerid, -1, "Usage: /givesausage <playerid> <sausage number>");
  122.     if (!IsPlayerConnected(Destinationid)) return SendClientMessage(playerid, -1, "Player is not connected.");
  123.     if(PlayerInfo[playerid][pSausage] == 0) return SendClientMessage(playerid,0xFF0000FF,"You dont have any sausage to send!");
  124.     if(PlayerInfo[playerid][pSausage] < Ammount) return SendClientMessage(playerid,0xFF0000FF,"You don't have this number of sausages to send!");
  125.     if(playerid == Destinationid) return SendClientMessage(playerid,red, "You can't send sausages to yourself.");
  126.     GetPlayerName(playerid, PlayerName, 24);
  127.     GetPlayerName(Destinationid, DestName, 24);
  128.     format(String, 128, "%s (%d) has sent you %d sausages!", PlayerName, playerid, Ammount);
  129.     SendClientMessage(Destinationid, yellow, String);
  130.     new gmsent[128];
  131.     format(gmsent,sizeof(gmsent),"Sent %d sausages to %s (%d)", Ammount,DestName,Destinationid);
  132.     GameTextForPlayer(playerid,gmsent,3000,5);
  133.     format(String, 128, "You've sent %d sausages to %s (%d)", Ammount, DestName, Destinationid);
  134.     SendClientMessage(playerid, yellow, String);
  135.     new gmrec[128];
  136.     format(gmrec,sizeof(gmrec),"Received %d sausages from %s (%d)", Ammount,PlayerName,Destinationid);
  137.     GameTextForPlayer(Destinationid,gmrec,3000,5);
  138.     PlayerInfo[playerid][pSausage] -=Ammount;
  139.     PlayerInfo[Destinationid][pSausage] +=Ammount;
  140.     SetPVarInt(playerid,"GsTime",GetTickCount()+5000);
  141.     return 1;
  142. }
  143.  
  144. public OnGameModeInit()
  145. {
  146.     SetTimer("SasUpdate", 1000, 1);
  147.    
  148.     for(new i=0;i<MAX_PLAYERS;i++)
  149.     {
  150.     SausagesTxd[i] = TextDrawCreate(458.000000, 430.000000, "Sausages");
  151.     TextDrawBackgroundColor(SausagesTxd[i], 255);
  152.     TextDrawFont(SausagesTxd[i], 2);
  153.     TextDrawLetterSize(SausagesTxd[i], 0.400000, 1.000000);
  154.     TextDrawColor(SausagesTxd[i], -1);
  155.     TextDrawSetOutline(SausagesTxd[i], 1);
  156.     TextDrawSetProportional(SausagesTxd[i], 1);
  157.     TextDrawUseBox(SausagesTxd[i], 1);
  158.     TextDrawBoxColor(SausagesTxd[i], 80);
  159.     TextDrawTextSize(SausagesTxd[i], 638.000000, 18.000000);
  160.     }
  161.    
  162.     SetGameModeText("Sausage System");
  163.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  164.     return 1;
  165. }
  166.  
  167. public OnGameModeExit()
  168. {
  169.     return 1;
  170. }
  171.  
  172. public OnPlayerConnect(playerid)
  173. {
  174.     TextDrawShowForPlayer(playerid, SausagesTxd[playerid]);
  175.     if(fexist(UserPath(playerid)))
  176.     {
  177.         INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  178.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
  179.     }
  180.     else
  181.     {
  182.         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");
  183.     }
  184.     return 1;
  185. }
  186.  
  187. public OnPlayerDisconnect(playerid, reason)
  188. {
  189.     new INI:File = INI_Open(UserPath(playerid));
  190.     INI_WriteInt(File,"Sausages",PlayerInfo[playerid][pSausage]);
  191.     INI_Close(File);
  192.     return 1;
  193. }
  194.  
  195. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  196. {
  197.     switch( dialogid )
  198.     {
  199.         case DIALOG_REGISTER:
  200.         {
  201.             if (!response) return Kick(playerid);
  202.             if(response)
  203.             {
  204.                 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");
  205.                 new INI:File = INI_Open(UserPath(playerid));
  206.                 INI_SetTag(File,"data");
  207.                 INI_WriteInt(File,"Sausages",0);
  208.                 INI_WriteInt(File,"Password",udb_hash(inputtext));
  209.                 INI_Close(File);
  210.                 SpawnPlayer(playerid);
  211.                 ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Now your sausages are saved!","Ok","");
  212.             }
  213.         }
  214.  
  215.         case DIALOG_LOGIN:
  216.         {
  217.             if ( !response ) return Kick ( playerid );
  218.             if( response )
  219.             {
  220.                 if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
  221.                 {
  222.                     INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  223.                     ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Logged in! Sausages loaded!","Ok","");
  224.                 }
  225.                 else
  226.                 {
  227.                     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");
  228.                 }
  229.                 return 1;
  230.             }
  231.         }
  232.     }
  233.    
  234.     if(dialogid == 6)
  235.     {
  236.         if(response)
  237.         {
  238.             if(listitem == 0) //5 Sausages
  239.             {
  240.             if(GetPlayerMoney(playerid) >= 1500) {
  241.             GivePlayerMoney(playerid,-1500);
  242.             SendClientMessage(playerid, green,"You bought 5 sausages.Use /sausage to eat them or /gs to give sausages to a player");
  243.             PlayerInfo[playerid][pSausage] +=5;
  244.             }
  245.             else return SendClientMessage(playerid, red, "You can't afford 1500$ to buy 5 sausages!");
  246.             }
  247.             if(listitem == 1) //10 Sausages
  248.             {
  249.             if(GetPlayerMoney(playerid) >= 2500) {
  250.             GivePlayerMoney(playerid,-2500);
  251.             SendClientMessage(playerid, green,"You bought 10 sausages.Use /sausage to eat them or /gs to give sausages to a player");
  252.             PlayerInfo[playerid][pSausage] +=10;
  253.             }
  254.             else return SendClientMessage(playerid, red, "You can't afford 2500$ to buy 10 sausages!");
  255.             }
  256.             if(listitem == 2) //25 Sausages
  257.             {
  258.             if(GetPlayerMoney(playerid) >= 5000) {
  259.             GivePlayerMoney(playerid,-5000);
  260.             SendClientMessage(playerid, green,"You bought 25 sausages.Use /sausage to eat them or /gs to give sausages to a player");
  261.             PlayerInfo[playerid][pSausage] +=25;
  262.             }
  263.             else return SendClientMessage(playerid, red, "You can't afford 2500$ to buy 25 sausages!");
  264.             }
  265.             return 1;
  266.         }
  267.     }
  268.     return 1;
  269. }
  270.  
  271. public OnPlayerRequestClass(playerid, classid)
  272. {
  273.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  274.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  275.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  276.     return 1;
  277. }
  278.  
  279. public OnPlayerCommandText(playerid, cmdtext[])
  280. {
  281.     return 0;
  282. }
Advertisement
Add Comment
Please, Sign In to add comment