Guest User

DCbank

a guest
Jul 28th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.40 KB | None | 0 0
  1. //credits Made By djcabo an simple bank system made from scratch and special thanks to sa-mp wiki
  2. #include <a_samp>
  3. #include <dini>
  4. #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
  5. #define GREEN 0x33AA33AA
  6. #define RED 0xAA3333AA
  7. #define YELLOW 0xFFFF00AA
  8. #define LIGHTBLUE 0x33CCFFAA
  9. #define ORANGE 0xFF9900AA
  10. #define DCCbank "DCbank/%s.ini"
  11. #pragma tabsize 0
  12. new Bank;
  13.  
  14. enum PLAYER_MAIN
  15. {
  16. PLAYER_BALANCE,
  17. PLAYER_INBANK,
  18. PLAYER_SCORE
  19. };
  20. new pBankInfo[MAX_PLAYERS][PLAYER_MAIN];
  21. new Float:atms[][3] =
  22. {
  23. {2475.4091796875, -1747.2602539063, 13.189774513245},
  24. {2107.5859375, -1790.6883544922, 13.197587013245},
  25. {1919.0524902344, -1765.8768310547, 13.189774513245},
  26. {2397.1623535156, -1244.2271728516, 23.646553039551}
  27. };
  28.  
  29. public OnFilterScriptInit()
  30. {
  31. print("\n---------------------");
  32. print("DCbank by djcabo");
  33. print("-----------------------");
  34. CreateObject(2942, 2475.4091796875, -1747.2602539063, 13.189774513245, 0.000000, 0.000000, 92.780029296875); //object (kmb_atm1) (1)
  35. CreateObject(2942, 2107.5859375, -1790.6883544922, 13.197587013245, 0.000000, 0.000000, 185.85498046875); //object (kmb_atm1) (2)
  36. CreateObject(2942, 1919.0524902344, -1765.8768310547, 13.189774513245, 0.000000, 0.000000, 179.10003662109); //object (kmb_atm1) (3)
  37. CreateObject(2942, 2397.1623535156, -1244.2271728516, 23.646553039551, 0.000000, 0.000000, 0.000000); //object (kmb_atm1) (4)
  38. return 1;
  39. }
  40.  
  41. public OnPlayerConnect(playerid)
  42. {
  43. SetPlayerMapIcon(playerid,22,2475.4091796875, -1747.2602539063, 13.189774513245,36,0);
  44. SetPlayerMapIcon(playerid,24,2107.5859375, -1790.6883544922, 13.197587013245,36,0);
  45. SetPlayerMapIcon(playerid,26,1919.0524902344, -1765.8768310547, 13.189774513245,36,0);
  46. SetPlayerMapIcon(playerid,28,2397.1623535156, -1244.2271728516, 23.646553039551,36,0);
  47. SetPlayerMapIcon(playerid,20,1480.9901,-1771.2242,18.7958,52,0);
  48. SendClientMessage(playerid,GREEN,"DCbank Simple Bank by djcabo");
  49. Bank = CreatePickup(1274,23,1480.9901,-1771.2242,18.7958,0);
  50. new Name[24]; GetPlayerName(playerid,Name,24);
  51. new file[100]; format(file,100,DCCbank,Name);
  52. if(!fexist(file)) {
  53. dini_Create(file);
  54. dini_IntSet(file,"Score",0);
  55. dini_IntSet(file,"Balance",0);
  56. dini_IntSet(file,"InBank",0);
  57. }
  58. else {
  59. pBankInfo[playerid][PLAYER_BALANCE] = dini_Int(file,"Balance");
  60. pBankInfo[playerid][PLAYER_INBANK] = dini_Int(file,"InBank");
  61. pBankInfo[playerid][PLAYER_SCORE] = dini_Int(file,"Score");
  62. }
  63. return 1;
  64. }
  65. public OnPlayerDisconnect(playerid,reason)
  66. {
  67. pBankInfo[playerid][PLAYER_INBANK] = 0;
  68. new Name[24]; GetPlayerName(playerid,Name,24);
  69. new file[100]; format(file,100,dcbank,Name);
  70. dini_IntSet(file,"Balance",pBankInfo[playerid][PLAYER_BALANCE]);
  71. dini_IntSet(file,"InBank",pBankInfo[playerid][PLAYER_INBANK]);
  72. return 1;
  73. }
  74. public OnPlayerCommandText(playerid, cmdtext[])
  75. {
  76. dcmd(bankhelp,8,cmdtext);
  77. dcmd(withdraw,8,cmdtext);
  78. dcmd(deposit,7,cmdtext);
  79. dcmd(wiret,5,cmdtext);
  80. dcmd(balance,7,cmdtext);
  81. dcmd(exit,4,cmdtext);
  82. return 0;
  83. }
  84. dcmd_bankhelp(playerid,params[]) {
  85. #pragma unused params
  86. SendClientMessage(playerid,LIGHTBLUE,"**Type /deposit, /withdraw, and /wiret");
  87. return 1;
  88. }
  89. dcmd_withdraw(playerid,params[]) {
  90. new amount;
  91. if(sscanf(params,"d",amount)) SendClientMessage(playerid,RED,"USAGE: /withdraw [amount]");
  92. else if(amount > pBankInfo[playerid][PLAYER_BALANCE]) return SendClientMessage(playerid,RED,"**Insuficient Funds In Bank");
  93. else if(pBankInfo[playerid][PLAYER_INBANK] == 0)
  94. {
  95. if(IsPlayerInRangeOfPoint(playerid,5.0,atms[0][0],atms[0][1],atms[0][2]))
  96. {
  97. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  98. GivePlayerMoney(playerid,amount);
  99. new str[256];
  100. format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  101. SendClientMessage(playerid,LIGHTBLUE,str);
  102. }
  103. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[1][0],atms[1][1],atms[1][2]))
  104. {
  105. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  106. GivePlayerMoney(playerid,amount);
  107. new str[256];
  108. format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  109. SendClientMessage(playerid,LIGHTBLUE,str);
  110. }
  111. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[2][0],atms[2][1],atms[2][2]))
  112. {
  113. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  114. GivePlayerMoney(playerid,amount);
  115. new str[256];
  116. format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  117. SendClientMessage(playerid,LIGHTBLUE,str);
  118. }
  119. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[3][0],atms[3][1],atms[3][2]))
  120. {
  121. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  122. GivePlayerMoney(playerid,amount);
  123. new str[256];
  124. format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  125. SendClientMessage(playerid,LIGHTBLUE,str);
  126. }
  127. else SendClientMessage(playerid,RED,"**You're not near atm or bank");
  128. }
  129. else if(amount < pBankInfo[playerid][PLAYER_BALANCE]) {
  130. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  131. GivePlayerMoney(playerid,amount);
  132. new str[256];
  133. format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  134. SendClientMessage(playerid,LIGHTBLUE,str);
  135. }
  136. return 1;
  137. }
  138. dcmd_deposit(playerid,params[]) {
  139. new amount;
  140. new pMoney;
  141. pMoney = GetPlayerMoney(playerid);
  142. if(sscanf(params,"d",amount)) SendClientMessage(playerid,RED,"USAGE: /deposit [amount]");
  143. else if(GetPlayerMoney(playerid) < amount) return SendClientMessage(playerid,RED,"**Insufficient funds");
  144. else if(amount > pMoney) return SendClientMessage(playerid,RED,"**Insuficient Funds In Bank");
  145. else if(pBankInfo[playerid][PLAYER_INBANK] == 0)
  146. {
  147. if(IsPlayerInRangeOfPoint(playerid,5.0,atms[0][0],atms[0][1],atms[0][2]))
  148. {
  149. pBankInfo[playerid][PLAYER_BALANCE] += amount;
  150. GivePlayerMoney(playerid,-amount);
  151. new str[256];
  152. format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  153. SendClientMessage(playerid,LIGHTBLUE,str);
  154. }
  155. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[1][0],atms[1][1],atms[1][2]))
  156. {
  157. pBankInfo[playerid][PLAYER_BALANCE] += amount;
  158. GivePlayerMoney(playerid,-amount);
  159. new str[256];
  160. format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  161. SendClientMessage(playerid,LIGHTBLUE,str);
  162. }
  163. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[2][0],atms[2][1],atms[2][2]))
  164. {
  165. pBankInfo[playerid][PLAYER_BALANCE] += amount;
  166. GivePlayerMoney(playerid,-amount);
  167. new str[256];
  168. format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  169. SendClientMessage(playerid,LIGHTBLUE,str);
  170. }
  171. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[3][0],atms[3][1],atms[3][2]))
  172. {
  173. pBankInfo[playerid][PLAYER_BALANCE] += amount;
  174. GivePlayerMoney(playerid,-amount);
  175. new str[256];
  176. format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  177. SendClientMessage(playerid,LIGHTBLUE,str);
  178. }
  179. else SendClientMessage(playerid,RED,"**You are not near an atm or bank");
  180. }
  181. else
  182. {
  183. pBankInfo[playerid][PLAYER_BALANCE] += amount;
  184. GivePlayerMoney(playerid,-amount);
  185. new str[256];
  186. format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
  187. SendClientMessage(playerid,LIGHTBLUE,str);
  188. }
  189. return 1;
  190. }
  191. dcmd_wiret(playerid,params[]) {
  192. new id;
  193. new amount;
  194. if(sscanf(params,"dd",id,amount)) SendClientMessage(playerid,RED,"USAGE: /transfer [id] [amount]");
  195. else if(!IsPlayerConnected(id)) return SendClientMessage(id,RED,"**That player is not online");
  196. else if(amount > pBankInfo[playerid][PLAYER_BALANCE]) return SendClientMessage(playerid,RED,"**Insuficient Funds In Bank");
  197. else if(pBankInfo[playerid][PLAYER_INBANK] == 0)
  198. {
  199. if(IsPlayerInRangeOfPoint(playerid,5.0,atms[0][0],atms[0][1],atms[0][2]))
  200. {
  201. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  202. pBankInfo[id][PLAYER_BALANCE] += amount;
  203. new str[256];
  204. format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
  205. SendClientMessage(playerid,LIGHTBLUE,str);
  206. }
  207. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[1][0],atms[1][1],atms[1][2]))
  208. {
  209. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  210. pBankInfo[id][PLAYER_BALANCE] += amount;
  211. new str[256];
  212. format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
  213. SendClientMessage(playerid,LIGHTBLUE,str);
  214. }
  215. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[2][0],atms[2][1],atms[2][2]))
  216. {
  217. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  218. pBankInfo[id][PLAYER_BALANCE] += amount;
  219. new str[256];
  220. format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
  221. SendClientMessage(playerid,LIGHTBLUE,str);
  222. }
  223. else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[3][0],atms[3][1],atms[3][2]))
  224. {
  225. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  226. pBankInfo[id][PLAYER_BALANCE] += amount;
  227. new str[256];
  228. format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
  229. SendClientMessage(playerid,LIGHTBLUE,str);
  230. }
  231. else SendClientMessage(playerid,RED,"**You're not near atm or bank");
  232. }
  233. else
  234. {
  235. pBankInfo[playerid][PLAYER_BALANCE] -= amount;
  236. pBankInfo[id][PLAYER_BALANCE] += amount;
  237. new str[256];
  238. format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
  239. SendClientMessage(playerid,LIGHTBLUE,str);
  240. }
  241. return 1;
  242. }
  243. dcmd_balance(playerid,params[]) {
  244. #pragma unused params
  245. new name[256];
  246. GetPlayerName(playerid,name,sizeof(name));
  247. new string[256], pBalance;
  248. pBalance = pBankInfo[playerid][PLAYER_BALANCE];
  249. format(string,sizeof(string),"**Bank Operator: Hi, %s, your balance is $%i",name,pBalance);
  250. SendClientMessage(playerid,GREEN,string);
  251. return 1;
  252. }
  253. dcmd_exit(playerid,params[]) {
  254. #pragma unused params
  255. if(pBankInfo[playerid][PLAYER_INBANK] == 1) {
  256. SetPlayerInterior(playerid,0);
  257. SetPlayerPos(playerid,1481.0139,-1763.1412,18.7958);
  258. pBankInfo[playerid][PLAYER_INBANK] = 0;
  259. }
  260. return 1;
  261. }
  262. public OnPlayerPickUpPickup(playerid,pickupid)
  263. {
  264. if(pickupid == Bank) {
  265. SetPlayerInterior(playerid,10);
  266. SetPlayerPos(playerid,6.091180,-29.271898,1003.549988);
  267. pBankInfo[playerid][PLAYER_INBANK] = 1;
  268. GameTextForPlayer(playerid,"~r~/exit ~b~to leave the bank",5000,3);
  269. }
  270. return 1;
  271. }
  272. stock sscanf(string[], format[], {Float,_}:...)
  273. {
  274. new
  275. formatPos = 0,
  276. stringPos = 0,
  277. paramPos = 2,
  278. paramCount = numargs();
  279. while (paramPos < paramCount && string[stringPos])
  280. {
  281. switch (format[formatPos++])
  282. {
  283. case '\0':
  284. {
  285. return 0;
  286. }
  287. case 'i', 'd':
  288. {
  289. new
  290. neg = 1,
  291. num = 0,
  292. ch = string[stringPos];
  293. if (ch == '-')
  294. {
  295. neg = -1;
  296. ch = string[++stringPos];
  297. }
  298. do
  299. {
  300. stringPos++;
  301. if (ch >= '0' && ch <= '9')
  302. {
  303. num = (num * 10) + (ch - '0');
  304. }
  305. else
  306. {
  307. return 1;
  308. }
  309. }
  310. while ((ch = string[stringPos]) && ch != ' ');
  311. setarg(paramPos, 0, num * neg);
  312. }
  313. case 'h', 'x':
  314. {
  315. new
  316. ch,
  317. num = 0;
  318. while ((ch = string[stringPos++]))
  319. {
  320. switch (ch)
  321. {
  322. case 'x', 'X':
  323. {
  324. num = 0;
  325. continue;
  326. }
  327. case '0' .. '9':
  328. {
  329. num = (num << 4) | (ch - '0');
  330. }
  331. case 'a' .. 'f':
  332. {
  333. num = (num << 4) | (ch - ('a' - 10));
  334. }
  335. case 'A' .. 'F':
  336. {
  337. num = (num << 4) | (ch - ('A' - 10));
  338. }
  339. case ' ':
  340. {
  341. break;
  342. }
  343. default:
  344. {
  345. return 1;
  346. }
  347. }
  348. }
  349. setarg(paramPos, 0, num);
  350. }
  351. case 'c':
  352. {
  353. setarg(paramPos, 0, string[stringPos++]);
  354. }
  355. case 'f':
  356. {
  357. new tmp[25];
  358. strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
  359. setarg(paramPos, 0, _:floatstr(tmp));
  360. }
  361. case 's', 'z':
  362. {
  363. new
  364. i = 0,
  365. ch;
  366. if (format[formatPos])
  367. {
  368. while ((ch = string[stringPos++]) && ch != ' ')
  369. {
  370. setarg(paramPos, i++, ch);
  371. }
  372. if (!i) return 1;
  373. }
  374. else
  375. {
  376. while ((ch = string[stringPos++]))
  377. {
  378. setarg(paramPos, i++, ch);
  379. }
  380. }
  381. stringPos--;
  382. setarg(paramPos, i, '\0');
  383. }
  384. default:
  385. {
  386. continue;
  387. }
  388. }
  389. while (string[stringPos] && string[stringPos] != ' ')
  390. {
  391. stringPos++;
  392. }
  393. while (string[stringPos] == ' ')
  394. {
  395. stringPos++;
  396. }
  397. paramPos++;
  398. }
  399. while (format[formatPos] == 'z') formatPos++;
  400. return format[formatPos];
  401. }
Add Comment
Please, Sign In to add comment