GustavoAraujo

Bank System

Nov 1st, 2013
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.75 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <Bini>
  4.  
  5. #define DCRIARCONTA 142
  6. #define DSENHACONTA 143
  7. #define DSENHA 144
  8. #define DSACAR 145
  9. #define DDEPOSITAR 146
  10. #define DSENHADEPOSITAR 147
  11. #define DSENHACONFIRMAR 148
  12. #define DMUDARSENHA 149
  13. #define DSALDO 150
  14. #define DTRANSFERIR 151
  15. #define DTRANSFERIRNUMERO 152
  16. #define DTRANSFERIRVALOR 153
  17. #define DINFO 154
  18.  
  19. new nome[MAX_PLAYER_NAME];
  20. new arquivo[49];
  21. new string[128];
  22. enum PP
  23. {
  24.     Conta,
  25.     Numero,
  26.     Depositado,
  27.     Senha
  28. }
  29. new BancoInfo[MAX_PLAYERS][PP];
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     CreateObject(2942, 1550.5789794922, -1669.7015380859, 13.204420089722, 0, 0, 270);
  34.     CreateObject(2942, 1550.6994628906, -1681.2255859375, 13.204420089722, 0, 0, 270);
  35.     return 1;
  36. }
  37.  
  38. public OnFilterScriptExit()
  39. {
  40.     return 1;
  41. }
  42. public OnPlayerConnect(playerid)
  43. {
  44.     Carregar(playerid);
  45.     return 1;
  46. }
  47. public OnPlayerDisconnect(playerid, reason)
  48. {
  49.     Salvar(playerid);
  50.     return 1;
  51. }
  52. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  53. {
  54.     if(dialogid == DSENHA)
  55.     {
  56.         if(response)
  57.         {
  58.         new Gustavo = strval(inputtext);
  59.         if(Gustavo != BancoInfo[playerid][Senha]) return SendClientMessage(playerid,0xFF0000AA,"Senha Incorreta!");
  60.         ShowPlayerDialog(playerid,DSACAR,DIALOG_STYLE_INPUT,"Sacar","Digite a Quantidade a ser Sacada","Sacar","Cancelar");
  61.         }
  62.     }
  63.     if(dialogid == DSENHACONFIRMAR)
  64.     {
  65.         if(response)
  66.         {
  67.         new Gustavo = strval(inputtext);
  68.         if(Gustavo != BancoInfo[playerid][Senha]) return SendClientMessage(playerid,0xFF0000AA,"Senha Incorreta!");
  69.         ShowPlayerDialog(playerid,DMUDARSENHA,DIALOG_STYLE_INPUT,"Mudar Senha","Digite a Sua Nova Senha","Ok","Cancelar");
  70.         }
  71.     }
  72.     if(dialogid == DMUDARSENHA)
  73.     {
  74.         if(response)
  75.         {
  76.         new Gustavo = strval(inputtext);
  77.         format(string,50,"Senha Mudada a %i",Gustavo);
  78.         SendClientMessage(playerid,0x008000AA,string);
  79.         BancoInfo[playerid][Senha] = Gustavo;
  80.         Salvar(playerid);
  81.         }
  82.     }
  83.     if(dialogid == DSACAR)
  84.     {
  85.         if(response)
  86.         {
  87.         new Gustavo = strval(inputtext);
  88.         if(Gustavo > BancoInfo[playerid][Depositado]) return SendClientMessage(playerid,0xFF0000AA,"Voce nao tem tudo isso na sua conta do banco");
  89.         GivePlayerMoney(playerid,Gustavo);
  90.         BancoInfo[playerid][Depositado] -= Gustavo;
  91.         format(string,60,"Voce Sacou $%d",Gustavo);
  92.         SendClientMessage(playerid,-1,string);
  93.         Salvar(playerid);
  94.         }
  95.     }
  96.     if(dialogid == DDEPOSITAR)
  97.     {
  98.         if(response)
  99.         {
  100.         new Gustavo = strval(inputtext);
  101.         if(Gustavo > GetPlayerMoney(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce nao tem tudo isso");
  102.         GivePlayerMoney(playerid,-Gustavo);
  103.         BancoInfo[playerid][Depositado] += Gustavo;
  104.         Salvar(playerid);
  105.         format(string,50,"Voce depositou $%i",Gustavo);
  106.         SendClientMessage(playerid,-1,string);
  107.         }
  108.     }
  109.     if(dialogid == DSALDO)
  110.     {
  111.         if(response)
  112.         {
  113.         new Gustavo = strval(inputtext);
  114.         if(Gustavo != BancoInfo[playerid][Senha]) return SendClientMessage(playerid,0xFF0000AA,"Senha Incorreta!");
  115.         format(string,100,"o Seu Saldo Bancario e de $%d",BancoInfo[playerid][Depositado]);
  116.         SendClientMessage(playerid,-1,string);
  117.         }
  118.     }
  119.     if(dialogid == DSENHADEPOSITAR)
  120.     {
  121.         if(response)
  122.         {
  123.         new Gustavo = strval(inputtext);
  124.         if(Gustavo != BancoInfo[playerid][Senha]) return SendClientMessage(playerid,0xFF0000AA,"Senha Incorreta!");
  125.         ShowPlayerDialog(playerid,DDEPOSITAR,DIALOG_STYLE_INPUT,"Depositar","Digite a Quantidade a ser Depositada","Depositar","Cancelar");
  126.         }
  127.     }
  128.     if(dialogid == DTRANSFERIR)
  129.     {
  130.         if(response)
  131.         {
  132.         new Gustavo = strval(inputtext);
  133.         if(Gustavo != BancoInfo[playerid][Senha]) return SendClientMessage(playerid,0xFF0000AA,"Senha Incorreta!");
  134.         ShowPlayerDialog(playerid,DTRANSFERIRNUMERO,DIALOG_STYLE_INPUT,"Numero da Conta","Digite o Numero da conta na qual voce quer Transferir","Ok","Cancelar");
  135.         }
  136.     }
  137.     if(dialogid == DTRANSFERIRNUMERO)
  138.     {
  139.         if(response)
  140.         {
  141.             SetPVarInt(playerid, "ReceptorDeposito", strval(inputtext));
  142.             ShowPlayerDialog(playerid, DTRANSFERIRVALOR, DIALOG_STYLE_INPUT, "Depósito bancário", "Digite o valor à ser depositado", "Ok", "Cancelar");
  143.         }
  144.     }
  145.     if(dialogid == DTRANSFERIRVALOR)
  146.     {
  147.         if(response)
  148.         {
  149.         new Gustavo = strval(inputtext);
  150.         if(BancoInfo[playerid][Depositado] < Gustavo) return SendClientMessage(playerid,-1,"Voce Nao tem tudo isso na sua conta");
  151.         new receptor = GetPVarInt(playerid, "ReceptorDeposito");
  152.  
  153.         for(new i = 0; i < MAX_PLAYERS; i++)
  154.  
  155.         {
  156.             if(receptor == BancoInfo[i][Numero]) //Esse [numero] é o numero da conta do cara
  157.             {
  158.                 DeletePVar(playerid, "ReceptorDeposito");
  159.                 BancoInfo[i][Depositado] += Gustavo;
  160.                 BancoInfo[playerid][Depositado] -= Gustavo;
  161.                 format(string,50,"Voce Transferiu $%d",Gustavo);
  162.                 SendClientMessage(playerid,-1,string);
  163.                 break;
  164.             }
  165.         }
  166.  
  167.         }
  168.     }
  169.  
  170.     if(dialogid == DCRIARCONTA)
  171.     {
  172.         if(response)
  173.         {
  174.         ShowPlayerDialog(playerid,DSENHACONTA,DIALOG_STYLE_INPUT,"Criar Conta No Banco","Digite Uma Senha para criar sua Conta no Banco","Sim","Não");
  175.         }
  176.     }
  177.     if(dialogid == DSENHACONTA)
  178.     {
  179.         if(response)
  180.         {
  181.         new NConta = 1000 + random(999999);
  182.         new Gustavo = strval(inputtext);
  183.         BancoInfo[playerid][Numero] = NConta;
  184.         BancoInfo[playerid][Senha] = Gustavo;
  185.         BancoInfo[playerid][Conta] = 1;
  186.         SendClientMessage(playerid,0x008000AA,"Conta Criada Com Sucesso!,use /ajudabanco para ver os comandos");
  187.         GetPlayerName(playerid,nome,24);
  188.         format(arquivo, sizeof(arquivo),"Banco/%s.ini", nome);
  189.         INI_Create(arquivo);
  190.         INI_Open(arquivo);
  191.         INI_WriteInt("Senha",Gustavo);
  192.         INI_WriteInt("Numero",NConta);
  193.         INI_WriteInt("Conta",BancoInfo[playerid][Conta]);
  194.         INI_WriteInt("Depositado",0);
  195.         INI_Save();
  196.         INI_Close();
  197.         format(string,50,"O Numero da sua Conta é: %d",BancoInfo[playerid][Numero]);
  198.         SendClientMessage(playerid,-1,string);
  199.         }
  200.     }
  201.     return 1;
  202. }
  203. /*MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  204. MMMMMMMMMMMMMMMMMMMMMMM| Comandos do Bank System |MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  205. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM*/
  206. CMD:saldo(playerid,params[])
  207. {
  208. if(!IsPlayerInBank(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao Esta em um Banco!");
  209. if(BancoInfo[playerid][Conta] == 0) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao tem Uma Conta!");
  210. ShowPlayerDialog(playerid,DSALDO,DIALOG_STYLE_INPUT,"Digite Sua Senha","Digite Sua Senha Para Poder ver o seu Saldo","Ok","Cancelar");
  211. return 1;
  212. }
  213. CMD:criarconta(playerid,params[])
  214. {
  215. if(!IsPlayerInBank(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao Esta em um Banco!");
  216. if(BancoInfo[playerid][Conta] >= 1) return SendClientMessage(playerid,-1,"Voce ja tem Uma Conta!");
  217. ShowPlayerDialog(playerid,DCRIARCONTA,DIALOG_STYLE_MSGBOX,"Criar Conta No Banco","Ola,Voce Deseja Criar uma conta no Banco?","Sim","Não");
  218. return 1;
  219. }
  220. CMD:sacar(playerid,params[])
  221. {
  222. if(!IsPlayerInBank(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao Esta em um Banco!");
  223. if(BancoInfo[playerid][Conta] == 0) return ShowPlayerDialog(playerid,DCRIARCONTA,DIALOG_STYLE_MSGBOX,"Conta no Banco","Voce nao tem uma conta no Banco,Deseja Criar Uma?","Sim","Não");
  224. ShowPlayerDialog(playerid,DSENHA,DIALOG_STYLE_INPUT,"Digitar Senha","Digite a Sua Senha Para Poder Sacar","Ok","Cancelar");
  225. return 1;
  226. }
  227. CMD:depositar(playerid,params[])
  228. {
  229. if(!IsPlayerInBank(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao Esta em um Banco!");
  230. if(BancoInfo[playerid][Conta] == 0) return ShowPlayerDialog(playerid,DCRIARCONTA,DIALOG_STYLE_MSGBOX,"Conta no Banco","Voce nao tem uma conta no Banco,Deseja Criar Uma?","Sim","Não");
  231. ShowPlayerDialog(playerid,DSENHADEPOSITAR,DIALOG_STYLE_INPUT,"Digitar Senha","Digite a Sua Senha Para Poder Depositar","Ok","Cancelar");
  232. return 1;
  233. }
  234. CMD:mudarsenha(playerid,params[])
  235. {
  236. if(!IsPlayerInBank(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao Esta em um Banco!");
  237. if(BancoInfo[playerid][Conta] == 0) return ShowPlayerDialog(playerid,DCRIARCONTA,DIALOG_STYLE_MSGBOX,"Conta no Banco","Voce nao tem uma conta no Banco,Deseja Criar Uma?","Sim","Não");
  238. ShowPlayerDialog(playerid,DSENHACONFIRMAR,DIALOG_STYLE_INPUT,"Digitar Senha","Digite a Sua Senha Atual Para poder Muda-la","Ok","Cancelar");
  239. return 1;
  240. }
  241. CMD:fecharconta(playerid,params[])
  242. {
  243. if(!IsPlayerInBank(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao Esta em um Banco!");
  244. if(BancoInfo[playerid][Conta] == 0) return SendClientMessage(playerid,-1,"Voce nao tem conta,ou ja fechou ou ainda nao criou.");
  245. GivePlayerMoney(playerid,BancoInfo[playerid][Depositado]);
  246. BancoInfo[playerid][Conta] = 0;
  247. SendClientMessage(playerid,-1,"Conta fechada!");
  248. Salvar(playerid);
  249. return 1;
  250. }
  251. CMD:transferir(playerid,params[])
  252. {
  253. if(!IsPlayerInBank(playerid)) return SendClientMessage(playerid,0xFF0000AA,"Voce Nao Esta em um Banco!");
  254. if(BancoInfo[playerid][Conta] == 0) return ShowPlayerDialog(playerid,DCRIARCONTA,DIALOG_STYLE_MSGBOX,"Conta no Banco","Voce nao tem uma conta no Banco,Deseja Criar Uma?","Sim","Não");
  255. ShowPlayerDialog(playerid,DTRANSFERIR,DIALOG_STYLE_INPUT,"Transferir dinheiro","Coloque a Sua Senha do Banco para poder Transferir","Ok","Cancelar");
  256. return 1;
  257. }
  258. CMD:info(playerid,params[])
  259. {
  260. if(BancoInfo[playerid][Conta] == 0) return SendClientMessage(playerid,-1,"Voce nao tem Conta ainda");
  261. format(string,128,"Numero da Conta: %d",BancoInfo[playerid][Numero]);
  262. ShowPlayerDialog(playerid,DINFO,DIALOG_STYLE_MSGBOX,"Informaçoes de Sua Conta",string,"Ok","");
  263. return 1;
  264. }
  265.  
  266. CMD:ajudabanco(playerid,params[])
  267. {
  268. SendClientMessage(playerid,-1,"___________________________________________________________________");
  269. SendClientMessage(playerid,0x008000AA,"/saldo,/criarconta,/sacar,/depositar,/mudarsenha,/fecharconta /info");
  270. SendClientMessage(playerid,-1,"___________________________________________________________________");
  271. return 1;
  272. }
  273. forward IsPlayerInBank(playerid);
  274. public IsPlayerInBank(playerid)
  275. {
  276.     if(IsPlayerInRangeOfPoint(playerid,1.3,1550.5789794922, -1669.7015380859, 13.204420089722)) return 1; //Caixa eletronico em Frente a DP
  277.     else if(IsPlayerInRangeOfPoint(playerid,1.3,1550.6994628906, -1681.2255859375, 13.204420089722)) return 1;  //Caixa eletronico em Frente a DP
  278.     return 0;
  279. }
  280. stock Salvar(playerid)
  281. {
  282.     format(arquivo, sizeof(arquivo),"Banco/%s.ini", nome);    
  283.     INI_Open(arquivo);
  284.     INI_WriteInt("Senha",BancoInfo[playerid][Senha]);
  285.     INI_WriteInt("Numero",BancoInfo[playerid][Numero]);
  286.     INI_WriteInt("Conta",BancoInfo[playerid][Conta]);
  287.     INI_WriteInt("Depositado",BancoInfo[playerid][Depositado]);
  288.     INI_Save();
  289.     INI_Close();
  290.     return 1;
  291. }
  292. stock Carregar(playerid)
  293. {
  294.     GetPlayerName(playerid,nome,24);
  295.     format(arquivo, sizeof(arquivo),"Banco/%s.ini", nome);
  296.     if(!fexist(arquivo)) return 0x1;
  297.     INI_Open(arquivo);
  298.     BancoInfo[playerid][Senha] = INI_ReadInt("Senha");
  299.     BancoInfo[playerid][Numero] = INI_ReadInt("Numero");
  300.     BancoInfo[playerid][Conta] = INI_ReadInt("Conta");
  301.     BancoInfo[playerid][Depositado] = INI_ReadInt("Depositado");
  302.     INI_Close();
  303.     return 1;
  304. }
Add Comment
Please, Sign In to add comment