Guest User

Untitled

a guest
Jan 11th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.92 KB | None | 0 0
  1. #include <a_samp>
  2. #include <Dini>
  3. #define PlayerFile "Bank/%s.ini"
  4. #define COLOR_RED 0xAA3333AA
  5. #define COLOR_YELLOW 0xFFFF00AA
  6. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  7. enum PLAYER_MAIN {
  8. Deposit,
  9. };
  10. new pInfo[MAX_PLAYERS][PLAYER_MAIN];
  11. new GetinBank;
  12. new GetoutBank;
  13. new chosenpid;
  14. public OnFilterScriptInit()
  15. {
  16. print("\n**************");
  17. print("*EBank Loaded*");
  18. print("**************\n");
  19. GetinBank = CreatePickup(1318, 1, 1481.283813, -1770.431152, 18.795755, 0);
  20. GetoutBank = CreatePickup(1318, 1, 2304.675537, -16.035686, 26.742187, 0);
  21. SetTimer("CallConnect",1,0);
  22. return 1;
  23. }
  24. forward CallConnect(playerid);
  25. public CallConnect(playerid)
  26. {
  27. for(new i = 0; i < MAX_PLAYERS; i++)
  28. {
  29. OnPlayerConnect(i);
  30. }
  31. return 1;
  32. }
  33. public OnPlayerConnect(playerid)
  34. {
  35. SendClientMessage(playerid,COLOR_YELLOW,"This Server Use Etch's EBank");
  36. SetPlayerMapIcon(playerid, 12, 1481.283813, -1770.431152, 18.795755, 52, 1);
  37. new file[100],Name[MAX_PLAYER_NAME]; GetPlayerName(playerid,Name,sizeof(Name)); format(file,sizeof(file),PlayerFile,Name);
  38. if(!dini_Exists(file)) {
  39. dini_Create(file);
  40. dini_IntSet(file,"Deposit",pInfo[playerid][Deposit]);
  41. }
  42. else if(dini_Exists(file))
  43. {
  44. pInfo[playerid][Deposit] = dini_Int(file,"Deposit");
  45. }
  46. return 1;
  47. }
  48.  
  49. public OnPlayerSpawn(playerid)
  50. {
  51. return 1;
  52. }
  53. public OnPlayerPickUpPickup(playerid,pickupid)
  54. {
  55. if(pickupid == GetinBank)
  56. {
  57. SetPlayerPos(playerid,2313,-4, 27);
  58. SendClientMessage(playerid,COLOR_YELLOW,"Wpisz /bank");
  59. SetCameraBehindPlayer(playerid);
  60. return 0;
  61. }
  62. if(pickupid == GetoutBank)
  63. {
  64. SetPlayerPos(playerid,1481.130371,-1763.401000, 18.795755);
  65. SetPlayerFacingAngle(playerid,0.0);
  66. SetCameraBehindPlayer(playerid);
  67. return 0;
  68. }
  69. return 1;
  70. }
  71. public OnPlayerDisconnect(playerid, reason)
  72. {
  73. new file[100],Name[MAX_PLAYER_NAME]; GetPlayerName(playerid,Name,sizeof(Name)); format(file,sizeof(file),PlayerFile,Name);
  74. dini_IntSet(file,"Deposit",pInfo[playerid][Deposit]);
  75. return 1;
  76. }
  77. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  78. {
  79. if(dialogid == 1122) //deposit
  80. {
  81. new file[100],Name[MAX_PLAYER_NAME]; GetPlayerName(playerid,Name,sizeof(Name)); format(file,sizeof(file),PlayerFile,Name);
  82. if(!response) return ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  83. else if(strval(inputtext) > GetPlayerMoney(playerid)) return SendClientMessage(playerid,COLOR_RED,"Nie masz takiej kwoty w banku!");
  84. else if(!IsNumeric(inputtext))
  85. {
  86. new string[128];
  87. format(string,sizeof(string),"Aktualny stan konta wynosi :%d$\nWprowadz ponizej kwote ktora chcesz wplacic :",pInfo[playerid][Deposit]);
  88. ShowPlayerDialog(playerid,1122,DIALOG_STYLE_INPUT,"Wplac",string,"Wplac","Wstecz");
  89. SendClientMessage(playerid,COLOR_RED,"Prosimy uzywac liczb");
  90. }
  91. else
  92. {
  93. GivePlayerMoney(playerid,-strval(inputtext));
  94. pInfo[playerid][Deposit] += strval(inputtext);
  95. new string[128];
  96. format(string,sizeof(string),"Masz wplacone : %d$",strval(inputtext));
  97. SendClientMessage(playerid,COLOR_YELLOW,string);
  98. dini_IntSet(file,"Wplac",pInfo[playerid][Deposit]);
  99. new string2[128]; format(string2,128,"Twoje nowe saldo wynosi : %d$",pInfo[playerid][Deposit]);
  100. SendClientMessage(playerid,COLOR_YELLOW,string2);
  101. ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  102. }
  103. return 1;
  104. }
  105. if(dialogid == 1123) //withdraw
  106. {
  107. new file[100],Name[MAX_PLAYER_NAME]; GetPlayerName(playerid,Name,sizeof(Name)); format(file,sizeof(file),PlayerFile,Name);
  108. if(!response) return ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  109. else if(strval(inputtext) > pInfo[playerid][Deposit]) return SendClientMessage(playerid,COLOR_RED,"Nie masz takiej kwoty w banku!");
  110. else if(!IsNumeric(inputtext))
  111. {
  112. new string[128];
  113. format(string,sizeof(string),"Aktualny stan konta wynosi :%d$\nWprowadz ponizej kwote ktora chcesz wyplacic :",pInfo[playerid][Deposit]);
  114. ShowPlayerDialog(playerid,1123,DIALOG_STYLE_INPUT,"Wyplac",string,"Wyplac","Wstecz");
  115. SendClientMessage(playerid,COLOR_RED,"Prosze uzywac liczb");
  116. }
  117. else
  118. {
  119. GivePlayerMoney(playerid,strval(inputtext));
  120. pInfo[playerid][Deposit] -= strval(inputtext);
  121. new string[128];
  122. format(string,sizeof(string),"Wyplaciles : %d$",strval(inputtext));
  123. SendClientMessage(playerid,COLOR_YELLOW,string);
  124. dini_IntSet(file,"Wplac",pInfo[playerid][Deposit]);
  125. new string2[128]; format(string2,128,"Twoje nowe saldo wynosi : %d$",pInfo[playerid][Deposit]);
  126. SendClientMessage(playerid,COLOR_YELLOW,string2);
  127. ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  128. }
  129. return 1;
  130. }
  131. if(dialogid == 1124)
  132. {
  133. if(!response) return ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  134. else
  135. {
  136. ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  137. }
  138. return 1;
  139. }
  140. if(dialogid == 1130) //transfer (choose playerid)
  141. {
  142. if(!response) return ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  143. else if(strval(inputtext) == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Gracz nie jest dostepny");
  144. else if(!IsNumeric(inputtext))
  145. {
  146. new string[128];
  147. format(string,sizeof(string),"Aktualny stan konta wynosi :%d$\nWprowadz ponizej kwote ktora chcesz wplacic :",pInfo[playerid][Deposit]);
  148. ShowPlayerDialog(playerid,1130,DIALOG_STYLE_INPUT,"Transfer",string,"Dalej","Wstecz");
  149. SendClientMessage(playerid,COLOR_RED,"Prosimy uzyc ID gracza a nie nazwe");
  150. }
  151. else
  152. {
  153. chosenpid = strval(inputtext);
  154. new string[128];
  155. format(string,sizeof(string),"Saldo : %d\nWybrano ID gracza : %d\nTeraz wprowadz kwote ktora chcesz przelac",pInfo[playerid][Deposit],chosenpid);
  156. ShowPlayerDialog(playerid,1131,DIALOG_STYLE_INPUT,"Transfer",string,"Transfer","Wstecz");
  157. }
  158. return 1;
  159. }
  160. if(dialogid == 1131) //transfer (choose amount)
  161. {
  162. new file[100],Name[MAX_PLAYER_NAME]; GetPlayerName(playerid,Name,sizeof(Name)); format(file,sizeof(file),PlayerFile,Name);
  163. if(!response) return ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  164. else if(strval(inputtext) > pInfo[playerid][Deposit]) return SendClientMessage(playerid,COLOR_RED,"Nie masz takiej kwoty w banku, aby dokonac przelewu");
  165. else if(!IsNumeric(inputtext))
  166. {
  167. new string[128];
  168. format(string,sizeof(string),"Wybrano ID gracza : %d\nWpisz kwote ktora chcesz przelac",chosenpid);
  169. ShowPlayerDialog(playerid,1131,DIALOG_STYLE_INPUT,"Transfer",string,"Transfer","Wstecz");
  170. SendClientMessage(playerid,COLOR_RED,"Prosimy używac liczb");
  171. }
  172. else
  173. {
  174. pInfo[playerid][Deposit] -= strval(inputtext);
  175. pInfo[chosenpid][Deposit] += strval(inputtext);
  176. new string[128];
  177. format(string,sizeof(string),"Przeslales %d$ na ID %d",strval(inputtext),chosenpid);
  178. SendClientMessage(playerid,COLOR_YELLOW,string);
  179. dini_IntSet(file,"Wplac",pInfo[playerid][Deposit]);
  180. new string2[128]; format(string2,128,"Twoje nowe saldo : %d$",pInfo[playerid][Deposit]);
  181. SendClientMessage(playerid,COLOR_YELLOW,string2);
  182. new string3[128]; format(string3,128,"ID : %d Przeniesiono %d$ na Twoje konto bankowe",playerid,strval(inputtext));
  183. SendClientMessage(chosenpid,COLOR_YELLOW,string3);
  184. new string4[128]; format(string4,128,"Twoje nowe saldo : %d$",pInfo[chosenpid][Deposit]);
  185. SendClientMessage(chosenpid,COLOR_YELLOW,string4);
  186. ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nSaldo\nTransfer","Wybierz","Anuluj");
  187. }
  188. return 1;
  189. }
  190. if(dialogid == 1125 && response) // /bank
  191. {
  192. switch(listitem)
  193. {
  194. case 0:
  195. {
  196. new string[128];
  197. format(string,sizeof(string),"Aktualny stan konta wynosi :%d$\nWprowadz ponizej kwote ktora chcesz wplacic :",pInfo[playerid][Deposit]);
  198. ShowPlayerDialog(playerid,1122,DIALOG_STYLE_INPUT,"Wplac",string,"Wplac","Wstecz");
  199.  
  200. }
  201. case 1:
  202. {
  203. new string[128];
  204. format(string,sizeof(string),"Aktualny stan konta wynosi :%d$\nWprowadz ponizej kwote ktora chcesz wyplacic :",pInfo[playerid][Deposit]);
  205. ShowPlayerDialog(playerid,1123,DIALOG_STYLE_INPUT,"Wyplac",string,"Wyplac","Wstecz");
  206. }
  207. case 2:
  208. {
  209. new string[128];
  210. format(string,sizeof(string),"Saldo na koncie wynosi %d$",pInfo[playerid][Deposit]);
  211. ShowPlayerDialog(playerid,1124,DIALOG_STYLE_MSGBOX,"Saldo",string,"Ok","Wstecz");
  212. }
  213. case 3:
  214. {
  215. new string[128];
  216. format(string,sizeof(string),"Aktualny stan konta wynosi :%d$\nWprowadz ponizej ID gracza ktoremu chcesz przelac pieniadze :",pInfo[playerid][Deposit]);
  217. ShowPlayerDialog(playerid,1130,DIALOG_STYLE_INPUT,"Transfer",string,"Dalej","Wstecz");
  218. }
  219. }
  220. }
  221. return 0;
  222. }
  223. public OnPlayerCommandText(playerid, cmdtext[])
  224. {
  225. dcmd(bank,4,cmdtext);
  226. dcmd(banktele,8,cmdtext);
  227. return 0;
  228. }
  229. dcmd_bank(playerid,params[])
  230. {
  231. #pragma unused params
  232. if(!IsPlayerInRangeOfPoint(playerid,15.0,2313,-4, 27)) return SendClientMessage(playerid,COLOR_RED,"Musisz być w banku");
  233. else
  234. {
  235. ShowPlayerDialog(playerid,1125,DIALOG_STYLE_LIST,"Bank","Wplac\nWyplac\nStan konta\nTransfer","Wybierz","Anuluj");
  236. }
  237. return 1;
  238. }
  239. dcmd_banktele(playerid,params[])
  240. {
  241. #pragma unused params
  242. SetPlayerPos(playerid,1481.049804,-1745.565673,13.667258);
  243. SendClientMessage(playerid,COLOR_YELLOW,"Witamy w banku");
  244. SetPlayerFacingAngle(playerid,180.0);
  245. SetCameraBehindPlayer(playerid);
  246. return 1;
  247. }
  248.  
  249.  
  250. //------------------[SSCANF]-------------------------------------
  251. stock sscanf(string[], format[], {Float,_}:...)
  252. {
  253. #if defined isnull
  254. if (isnull(string))
  255. #else
  256. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  257. #endif
  258. {
  259. return format[0];
  260. }
  261. #pragma tabsize 4
  262. new
  263. formatPos = 0,
  264. stringPos = 0,
  265. paramPos = 2,
  266. paramCount = numargs(),
  267. delim = ' ';
  268. while (string[stringPos] && string[stringPos] <= ' ')
  269. {
  270. stringPos++;
  271. }
  272. while (paramPos < paramCount && string[stringPos])
  273. {
  274. switch (format[formatPos++])
  275. {
  276. case '\0':
  277. {
  278. return 0;
  279. }
  280. case 'i', 'd':
  281. {
  282. new
  283. neg = 1,
  284. num = 0,
  285. ch = string[stringPos];
  286. if (ch == '-')
  287. {
  288. neg = -1;
  289. ch = string[++stringPos];
  290. }
  291. do
  292. {
  293. stringPos++;
  294. if ('0' <= ch <= '9')
  295. {
  296. num = (num * 10) + (ch - '0');
  297. }
  298. else
  299. {
  300. return -1;
  301. }
  302. }
  303. while ((ch = string[stringPos]) > ' ' && ch != delim);
  304. setarg(paramPos, 0, num * neg);
  305. }
  306. case 'h', 'x':
  307. {
  308. new
  309. num = 0,
  310. ch = string[stringPos];
  311. do
  312. {
  313. stringPos++;
  314. switch (ch)
  315. {
  316. case 'x', 'X':
  317. {
  318. num = 0;
  319. continue;
  320. }
  321. case '0' .. '9':
  322. {
  323. num = (num << 4) | (ch - '0');
  324. }
  325. case 'a' .. 'f':
  326. {
  327. num = (num << 4) | (ch - ('a' - 10));
  328. }
  329. case 'A' .. 'F':
  330. {
  331. num = (num << 4) | (ch - ('A' - 10));
  332. }
  333. default:
  334. {
  335. return -1;
  336. }
  337. }
  338. }
  339. while ((ch = string[stringPos]) > ' ' && ch != delim);
  340. setarg(paramPos, 0, num);
  341. }
  342. case 'c':
  343. {
  344. setarg(paramPos, 0, string[stringPos++]);
  345. }
  346. case 'f':
  347. {
  348.  
  349. new changestr[16], changepos = 0, strpos = stringPos;
  350. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  351. {
  352. changestr[changepos++] = string[strpos++];
  353. }
  354. changestr[changepos] = '\0';
  355. setarg(paramPos,0,_:floatstr(changestr));
  356. }
  357. case 'p':
  358. {
  359. delim = format[formatPos++];
  360. continue;
  361. }
  362. case '\'':
  363. {
  364. new
  365. end = formatPos - 1,
  366. ch;
  367. while ((ch = format[++end]) && ch != '\'') {}
  368. if (!ch)
  369. {
  370. return -1;
  371. }
  372. format[end] = '\0';
  373. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  374. {
  375. if (format[end + 1])
  376. {
  377. return -1;
  378. }
  379. return 0;
  380. }
  381. format[end] = '\'';
  382. stringPos = ch + (end - formatPos);
  383. formatPos = end + 1;
  384. }
  385. case 'u':
  386. {
  387. new
  388. end = stringPos - 1,
  389. id = 0,
  390. bool:num = true,
  391. ch;
  392. while ((ch = string[++end]) && ch != delim)
  393. {
  394. if (num)
  395. {
  396. if ('0' <= ch <= '9')
  397. {
  398. id = (id * 10) + (ch - '0');
  399. }
  400. else
  401. {
  402. num = false;
  403. }
  404. }
  405. }
  406. if (num && IsPlayerConnected(id))
  407. {
  408. setarg(paramPos, 0, id);
  409. }
  410. else
  411. {
  412. #if !defined foreach
  413. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  414. #define __SSCANF_FOREACH__
  415. #endif
  416. string[end] = '\0';
  417. num = false;
  418. new
  419. name[MAX_PLAYER_NAME];
  420. id = end - stringPos;
  421. foreach (Player, playerid)
  422. {
  423. GetPlayerName(playerid, name, sizeof (name));
  424. if (!strcmp(name, string[stringPos], true, id))
  425. {
  426. setarg(paramPos, 0, playerid);
  427. num = true;
  428. break;
  429. }
  430. }
  431. if (!num)
  432. {
  433. setarg(paramPos, 0, INVALID_PLAYER_ID);
  434. }
  435. string[end] = ch;
  436. #if defined __SSCANF_FOREACH__
  437. #undef foreach
  438. #undef __SSCANF_FOREACH__
  439. #endif
  440. }
  441. stringPos = end;
  442. }
  443. case 's', 'z':
  444. {
  445. new
  446. i = 0,
  447. ch;
  448. if (format[formatPos])
  449. {
  450. while ((ch = string[stringPos++]) && ch != delim)
  451. {
  452. setarg(paramPos, i++, ch);
  453. }
  454. if (!i)
  455. {
  456. return -1;
  457. }
  458. }
  459. else
  460. {
  461. while ((ch = string[stringPos++]))
  462. {
  463. setarg(paramPos, i++, ch);
  464. }
  465. }
  466. stringPos--;
  467. setarg(paramPos, i, '\0');
  468. }
  469. default:
  470. {
  471. continue;
  472. }
  473. }
  474. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  475. {
  476. stringPos++;
  477. }
  478. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  479. {
  480. stringPos++;
  481. }
  482. paramPos++;
  483. }
  484. do
  485. {
  486. if ((delim = format[formatPos++]) > ' ')
  487. {
  488. if (delim == '\'')
  489. {
  490. while ((delim = format[formatPos++]) && delim != '\'') {}
  491. }
  492. else if (delim != 'z')
  493. {
  494. return delim;
  495. }
  496. }
  497. }
  498. while (delim > ' ');
  499. return 0;
  500. }
  501. stock IsNumeric(string[])
  502. {
  503. for (new i = 0, j = strlen(string); i < j; i++)
  504. {
  505. if (string[i] > '9' || string[i] < '0') return 0;
  506. }
  507. return 1;
  508. }
Advertisement
Add Comment
Please, Sign In to add comment