Advertisement
Chip7

[FS] Sistema Bancario por Dialogo

May 26th, 2012
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.37 KB | None | 0 0
  1. /*VISITE NOSSO SITE: http://www.sampknd.com/
  2.   SAMP KND MELHOR BLOG DE SAMP DO BRASIL
  3. */
  4.  
  5. #include <a_samp>
  6. #include <file>
  7. #define dorado 0xFFD700
  8. #define plateado 0xC0C0C0
  9. #define C_Banco_Dialogid 666
  10. #define CAJA_FUERTE "/Afiliados/%s.ini"
  11. forward split(const strsrc[], strdest[][], delimiter);
  12. forward ini_GetKey( line[] );
  13. forward ini_GetValue( line[] );
  14. forward Afiliado_Bancario(playerid);
  15. forward No_Afiliado_Bancario(playerid);
  16.  
  17. enum C_Info
  18. {
  19. C_Banco
  20. }
  21. new PlayerInfo[MAX_PLAYERS][C_Info];
  22. new Pickupid_C_banco_Entrada;
  23. new Pickupid_C_banco_Salida;
  24. new Pickup_C_Banco,Pickup_C_Banco_A,Pickup_C_Banco_B;
  25.  
  26. new Verificacion[MAX_PLAYERS]; //RegistrationStep
  27. new Afiliacion[MAX_PLAYERS];   //gPlayerLogged
  28. ///--------------------------------------------------------------------------///
  29. ///--------------------- [ OnFilterScriptInit ] -----------------------------///
  30. ///--------------------------------------------------------------------------///
  31. public OnFilterScriptInit()
  32. {
  33. print("\n------------------------------------------------");
  34. print("|| Sistema de Banco By: Cesar_Google Cargado ||");
  35. print("------------------------------------------------\n");
  36. Pickupid_C_banco_Entrada  = CreatePickup(1239,1,1420.2372,-1623.8413,13.5469,0);
  37. Pickupid_C_banco_Salida   = CreatePickup(1239,1,2305.6890,-16.0881,26.7496,0);
  38. Pickup_C_Banco            = CreatePickup(1829,2,2310.3286,-8.5272,26.7422,0);
  39. Pickup_C_Banco_A          = CreatePickup(1829,2,2309.9382,-2.1212,26.7422,0);
  40. Pickup_C_Banco_B          = CreatePickup(1829,2,2316.2710,-4.5288,26.7422,0);
  41. return 1;
  42. }
  43. ///--------------------------------------------------------------------------///
  44. ///---------------------- [ OnPlayerConnect ] -------------------------------///
  45. ///--------------------------------------------------------------------------///
  46. public OnPlayerConnect(playerid)
  47. {
  48. new Nombre[MAX_PLAYER_NAME], string[256];
  49. Verificacion[playerid] = 0;
  50. Afiliacion[playerid] = 0;
  51.  
  52. GetPlayerName(playerid, Nombre , sizeof( Nombre ));
  53. format(string, sizeof(string), CAJA_FUERTE , Nombre);
  54.  
  55. if (Verificacion[playerid] == 0 && Afiliacion[playerid] != 1)
  56. {
  57. new sendername[MAX_PLAYER_NAME];
  58. GetPlayerName(playerid, sendername, sizeof(sendername));
  59. format(string, sizeof(string), CAJA_FUERTE , sendername);
  60. new File: hFile = fopen(string, io_read);
  61. if (hFile)
  62. {
  63. Afiliado_Bancario(playerid);
  64. }
  65. }
  66. return 1;
  67. }
  68.  
  69. public OnPlayerCommandText(playerid, cmdtext[])
  70. {
  71. new idx,cmd[256];
  72. cmd = strtok(cmdtext, idx);
  73.  
  74. if(strcmp(cmd, "/mmm", true) == 0)
  75. {
  76. SetPlayerPos(playerid,1423.2372,-1625.8413,13.5469);
  77. return 1;
  78. }
  79. return 1;
  80. }
  81. ///--------------------------------------------------------------------------///
  82. ///------------------------ [ OnPlayerUpdate ] ------------------------------///
  83. ///--------------------------------------------------------------------------///
  84. public OnPlayerUpdate(playerid)
  85. {
  86. new string[64];
  87. new Nombre[MAX_PLAYER_NAME];
  88. GetPlayerName(playerid, Nombre, sizeof( Nombre ) );
  89. format(string , sizeof( string ),CAJA_FUERTE ,Nombre );
  90. new File: Datos = fopen(string ,io_write );
  91. if ( Datos )
  92. {
  93. new var[32];
  94. format(var, 32,"Banco=%d\n", PlayerInfo[playerid][C_Banco]);fwrite(Datos ,var );
  95. fclose( Datos );
  96. }
  97. return 1;
  98. }
  99. ///--------------------------------------------------------------------------///
  100. ///---------------------- [ OnPlayerDisconnect ] ----------------------------///
  101. ///--------------------------------------------------------------------------///
  102. public OnPlayerDisconnect(playerid, reason)
  103. {
  104. new string[64];
  105. new Nombre[MAX_PLAYER_NAME];
  106. GetPlayerName(playerid, Nombre, sizeof( Nombre ) );
  107. format(string , sizeof( string ),CAJA_FUERTE ,Nombre );
  108. new File: Datos = fopen(string ,io_write );
  109. if ( Datos )
  110. {
  111. new var[32];
  112. format(var, 32,"Banco=%d\n", PlayerInfo[playerid][C_Banco]);fwrite(Datos ,var );
  113. fclose( Datos );
  114. }
  115. return 1;
  116. }
  117. ///--------------------------------------------------------------------------///
  118. ///-------------------- [ OnPlayerPickUpPickup ] ----------------------------///
  119. ///--------------------------------------------------------------------------///
  120. public OnPlayerPickUpPickup(playerid, pickupid)
  121. {
  122. if(Pickup_C_Banco == pickupid){ShowPlayerDialog(playerid,C_Banco_Dialogid,DIALOG_STYLE_LIST,"Banco Central","depósito\r\nRemover\r\nBalance","aceitar","Cancelar");}
  123. if(Pickup_C_Banco_A == pickupid){ShowPlayerDialog(playerid,C_Banco_Dialogid,DIALOG_STYLE_LIST,"Banco Central","depósito\r\nRemover\r\nBalance","aceitar","Cancelar");}
  124. if(Pickup_C_Banco_B == pickupid){ShowPlayerDialog(playerid,C_Banco_Dialogid,DIALOG_STYLE_LIST,"Banco Central","depósito\r\nRemover\r\nBalance","aceitar","Cancelar");}
  125. /******************************************************************************/
  126. if(Pickupid_C_banco_Entrada == pickupid)
  127. {
  128. SetPlayerInterior(playerid,0);
  129. SetPlayerPos(playerid,2308.3015,-15.6663,26.7496);
  130. return 1;
  131. }
  132. if(Pickupid_C_banco_Salida == pickupid)
  133. {
  134. SetPlayerInterior(playerid,0);
  135. SetPlayerPos(playerid,1421.9677,-1623.8685,13.5469);
  136. return 1;
  137. }
  138. /******************************************************************************/
  139. return 1;
  140. }
  141. ///--------------------------------------------------------------------------///
  142. ///--------------------- [ OnDialogResponse ] -------------------------------///
  143. ///--------------------------------------------------------------------------///
  144. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  145. {
  146. new string[256];
  147. switch(dialogid == C_Banco_Dialogid)
  148. {
  149. case 1:
  150. {
  151. if(!response)
  152. {
  153. SendClientMessage(playerid, dorado, "transação cancelada.");
  154. return 1;
  155. }
  156. switch(listitem)
  157. {
  158. case 0:
  159. {
  160. ShowPlayerDialog(playerid,C_Banco_Dialogid+1,DIALOG_STYLE_INPUT,"Depositar","Introduza o montante a depositar","Depositar","Cancelar");
  161. }
  162. case 1:
  163. {
  164. ShowPlayerDialog(playerid,C_Banco_Dialogid+2,DIALOG_STYLE_INPUT,"Retirar","Introduza o montante a Retirar","Retirar","Cancelar");
  165. }
  166. case 2:
  167. {
  168. new Balance_Total[128];
  169. format(Balance_Total,128,"O seu saldo é de $%d",PlayerInfo[playerid][C_Banco]);
  170. ShowPlayerDialog(playerid,C_Banco_Dialogid+3,DIALOG_STYLE_MSGBOX,"Balance",Balance_Total,"aceitar","aceitar");
  171. }
  172.   }
  173.  }
  174. }
  175.  
  176. if(dialogid == C_Banco_Dialogid+1)
  177. {
  178. if(response)
  179. {
  180. if(!strlen(inputtext))
  181. {
  182. format(string, sizeof(string), "Servidor: você tem $%d na sua conta.", PlayerInfo[playerid][C_Banco]);
  183. SendClientMessage(playerid, plateado, string);
  184. return 1;
  185. }
  186. new Depositar_Dinero = strval(inputtext);
  187. if(!strlen(inputtext))
  188. {
  189. format(string, sizeof(string), "Servidor: você tem $%d na sua conta.", PlayerInfo[playerid][C_Banco]);
  190. SendClientMessage(playerid, plateado, string);
  191. return 1;
  192. }
  193. if (Depositar_Dinero > GetPlayerMoney(playerid) || Depositar_Dinero < 1)
  194. {
  195. SendClientMessage(playerid, plateado, "Servidor: Você não tem esse montante");
  196. return 1;
  197. }
  198. GivePlayerMoney(playerid,-Depositar_Dinero);
  199. new C_Banco_Val = PlayerInfo[playerid][C_Banco];
  200. PlayerInfo[playerid][C_Banco]=Depositar_Dinero+PlayerInfo[playerid][C_Banco];
  201. SendClientMessage(playerid, plateado, "|___Estado Bancario___|");
  202. format(string, sizeof(string), "Balance Anterior: $%d", C_Banco_Val);
  203. SendClientMessage(playerid, plateado, string);
  204. format(string, sizeof(string), "Deposito: $%d",Depositar_Dinero);
  205. SendClientMessage(playerid, plateado, string);
  206. SendClientMessage(playerid, plateado, "|_____________________|");
  207. format(string, sizeof(string), "novo Balance: $%d", PlayerInfo[playerid][C_Banco]);
  208. SendClientMessage(playerid, plateado, string);
  209. }
  210. }
  211.  
  212. if(dialogid == C_Banco_Dialogid+2)
  213. {
  214. new Retirar_Dinero = strval(inputtext);
  215. if (Retirar_Dinero > PlayerInfo[playerid][C_Banco] || Retirar_Dinero < 1)
  216. {
  217. SendClientMessage(playerid, dorado, "Servidor: Você não tem esse montante!");
  218. return 1;
  219. }
  220. GivePlayerMoney(playerid,Retirar_Dinero);
  221. PlayerInfo[playerid][C_Banco]=PlayerInfo[playerid][C_Banco]-Retirar_Dinero;
  222. format(string, sizeof(string), "  você tem $%d na sua conta: $%d ", Retirar_Dinero,PlayerInfo[playerid][C_Banco]);
  223. SendClientMessage(playerid, dorado, string);
  224. return 1;
  225. }
  226.  
  227. return 1;
  228. }
  229. ///--------------------------------------------------------------------------///
  230. ///---------------------- [ Afiliado_Bancario ] -----------------------------///
  231. ///--------------------------------------------------------------------------///
  232. public Afiliado_Bancario(playerid)
  233. {
  234. new string[64];
  235. new Nombre[MAX_PLAYER_NAME];
  236. new NombreSplit[3][MAX_PLAYER_NAME];
  237. GetPlayerName(playerid, Nombre, sizeof( Nombre ));
  238. split(Nombre, NombreSplit, '_');
  239. format(string, sizeof( string ) ,CAJA_FUERTE , Nombre );
  240. new File: DatosUsuario = fopen(string ,io_read );
  241. if ( DatosUsuario )
  242. {
  243. new key[ 256 ] , val[ 256 ];
  244. new Data[ 256 ];
  245. while ( fread( DatosUsuario , Data , sizeof( Data ) ) )
  246. {
  247. key = ini_GetKey( Data );
  248. if( strcmp( key , "Banco" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][C_Banco] = strval( val ); }
  249. }
  250. fclose( DatosUsuario );
  251. }
  252. return 1;
  253. }
  254. ///--------------------------------------------------------------------------///
  255. ///--------------------- [ No_Afiliado_Bancario ] ---------------------------///
  256. ///--------------------------------------------------------------------------///
  257. public No_Afiliado_Bancario(playerid)
  258. {
  259. new string[64];
  260. new Nombre[MAX_PLAYER_NAME];
  261. GetPlayerName(playerid, Nombre, sizeof( Nombre ) );
  262. format(string , sizeof( string ),CAJA_FUERTE ,Nombre );
  263. new File: Datos = fopen(string ,io_write );
  264. if ( Datos )
  265. {
  266. new var[32];
  267. format(var, 32,"Banco=%d\n", PlayerInfo[playerid][C_Banco]);fwrite(Datos ,var );
  268. fclose( Datos );
  269. }
  270. return 1;
  271. }
  272. ///--------------------------------------------------------------------------///
  273. ///---------------------------- [ split ] -----------------------------------///
  274. ///--------------------------------------------------------------------------///
  275. public split(const strsrc[], strdest[][], delimiter)
  276. {
  277. new i, li;
  278. new aNum;
  279. new len;
  280. while(i <= strlen(strsrc)){
  281. if(strsrc[i]==delimiter || i==strlen(strsrc)){
  282. len = strmid(strdest[aNum], strsrc, li, i, 128);
  283. strdest[aNum][len] = 0;
  284. li = i+1;
  285. aNum++;
  286. }
  287. i++;
  288. }
  289. return 1;
  290. }
  291. ///--------------------------------------------------------------------------///
  292. ///---------------------------- [ stock ] -----------------------------------///
  293. ///--------------------------------------------------------------------------///
  294. stock ini_GetValue( line[] )
  295. {
  296. new valRes[256];
  297. valRes[0]=0;
  298. if ( strfind( line , "=" , true ) == -1 ) return valRes;
  299. strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
  300. return valRes;
  301. }
  302. //------------------------------------------------------------------------------
  303. stock ini_GetKey( line[] )
  304. {
  305. new keyRes[256];
  306. keyRes[0] = 0;
  307. if ( strfind( line , "=" , true ) == -1 ) return keyRes;
  308. strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
  309. return keyRes;
  310. }
  311. ///--------------------------------------------------------------------------///
  312. ///---------------------------- [ strtok ] ----------------------------------///
  313. ///--------------------------------------------------------------------------///
  314. strtok(const string[], &index)
  315. {
  316. new length = strlen(string);
  317. while ((index < length) && (string[index] <= ' '))
  318. {
  319. index++;
  320. }
  321. new offset = index;
  322. new result[20];
  323. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  324. {
  325. result[index - offset] = string[index];
  326. index++;
  327. }
  328. result[index - offset] = EOS;
  329. return result;
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement