Advertisement
Guest User

Untitled

a guest
May 25th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 KB | None | 0 0
  1. #include <a_samp>
  2. #include <Dini>
  3. #define PlayerFile "Info/%s.ini"
  4. #define COLOR_RED 0xAA3333AA
  5. #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
  6. enum PLAYER_MAIN {
  7. Deposit,
  8. }
  9. new Pinfo[MAX_PLAYERS][PLAYER_MAIN];
  10. public OnPlayerConnect(playerid)
  11. {
  12. new file[100],Name[MAX_PLAYER_NAME],Ip[16]; GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  13. if(!dini_Exists(file)) {
  14. dini_Create(file);
  15. dini_IntSet(file,"Score",GetPlayerScore(playerid));
  16. dini_IntSet(file,"Deposit",Pinfo[playerid][Deposit]);
  17. }
  18. return 1;
  19. }
  20. public OnPlayerDisconnect(playerid, reason)
  21. {
  22. new file[100],Name[MAX_PLAYER_NAME],Ip[16]; GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  23. dini_IntSet(file,"Score",GetPlayerScore(playerid));
  24. dini_IntSet(file,"Deposit",Pinfo[playerid][Deposit]);
  25. return 1;
  26. }
  27. public OnPlayerCommandText(playerid, cmdtext[])
  28. {
  29. dcmd(deposit,7,cmdtext);
  30. dcmd(withdraw,8,cmdtext);
  31. dcmd(balance,7,cmdtext);
  32. return 1;
  33. }
  34.  
  35. dcmd_deposit(playerid,params[])
  36. {
  37. new file[100],Name[MAX_PLAYER_NAME],Ip[16]; GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  38. new deposit;
  39. if(sscanf(params,"d",deposit)) return SendClientMessage(playerid,COLOR_RED,"Usage : /deposit [Amount]");
  40. else if(deposit > GetPlayerMoney(playerid)) return SendClientMessage(playerid,COLOR_RED,"You Don't Have That Amount!");
  41. else
  42. {
  43. Pinfo[playerid][Deposit] = deposit;
  44. new string[128];
  45. format(string,sizeof(string),"You Have Deposited %d",deposit);
  46. SendClientMessage(playerid,COLOR_RED,string);
  47. dini_IntSet(file,"Deposit",Pinfo[playerid][Deposit]);
  48. }
  49. return 1;
  50. }
  51. dcmd_withdraw(playerid,params[])
  52. {
  53. new file[100],Name[MAX_PLAYER_NAME],Ip[16]; GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  54. new withdraw;
  55. if(sscanf(params,"d",withdraw)) return SendClientMessage(playerid,COLOR_RED,"Usage : /withdraw [Amount]");
  56. else if(withdraw > Pinfo[playerid][Deposit]) return SendClientMessage(playerid,COLOR_RED,"You Don't Have That In Bank!");
  57. else
  58. {
  59. Pinfo[playerid][Deposit] = -withdraw;
  60. new string[128];
  61. format(string,sizeof(string),"You Have Withdrawed %d",withdraw);
  62. SendClientMessage(playerid,COLOR_RED,string);
  63. dini_IntSet(file,"Deposit",Pinfo[playerid][Deposit]);
  64. }
  65. return 1;
  66. }
  67. dcmd_balance(playerid,params[])
  68. {
  69. #pragma unused params
  70. new string[128];
  71. format(string,sizeof(string),"Your Balance Is %d",Pinfo[playerid][Deposit]);
  72. SendClientMessage(playerid,COLOR_RED,string);
  73. return 1;
  74. }
  75.  
  76.  
  77. //------------------[SSCANF]-------------------------------------
  78. stock sscanf(string[], format[], {Float,_}:...)
  79. {
  80. #if defined isnull
  81. if (isnull(string))
  82. #else
  83. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  84. #endif
  85. {
  86. return format[0];
  87. }
  88. #pragma tabsize 4
  89. new
  90. formatPos = 0,
  91. stringPos = 0,
  92. paramPos = 2,
  93. paramCount = numargs(),
  94. delim = ' ';
  95. while (string[stringPos] && string[stringPos] <= ' ')
  96. {
  97. stringPos++;
  98. }
  99. while (paramPos < paramCount && string[stringPos])
  100. {
  101. switch (format[formatPos++])
  102. {
  103. case '\0':
  104. {
  105. return 0;
  106. }
  107. case 'i', 'd':
  108. {
  109. new
  110. neg = 1,
  111. num = 0,
  112. ch = string[stringPos];
  113. if (ch == '-')
  114. {
  115. neg = -1;
  116. ch = string[++stringPos];
  117. }
  118. do
  119. {
  120. stringPos++;
  121. if ('0' <= ch <= '9')
  122. {
  123. num = (num * 10) + (ch - '0');
  124. }
  125. else
  126. {
  127. return -1;
  128. }
  129. }
  130. while ((ch = string[stringPos]) > ' ' && ch != delim);
  131. setarg(paramPos, 0, num * neg);
  132. }
  133. case 'h', 'x':
  134. {
  135. new
  136. num = 0,
  137. ch = string[stringPos];
  138. do
  139. {
  140. stringPos++;
  141. switch (ch)
  142. {
  143. case 'x', 'X':
  144. {
  145. num = 0;
  146. continue;
  147. }
  148. case '0' .. '9':
  149. {
  150. num = (num << 4) | (ch - '0');
  151. }
  152. case 'a' .. 'f':
  153. {
  154. num = (num << 4) | (ch - ('a' - 10));
  155. }
  156. case 'A' .. 'F':
  157. {
  158. num = (num << 4) | (ch - ('A' - 10));
  159. }
  160. default:
  161. {
  162. return -1;
  163. }
  164. }
  165. }
  166. while ((ch = string[stringPos]) > ' ' && ch != delim);
  167. setarg(paramPos, 0, num);
  168. }
  169. case 'c':
  170. {
  171. setarg(paramPos, 0, string[stringPos++]);
  172. }
  173. case 'f':
  174. {
  175.  
  176. new changestr[16], changepos = 0, strpos = stringPos;
  177. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  178. {
  179. changestr[changepos++] = string[strpos++];
  180. }
  181. changestr[changepos] = '\0';
  182. setarg(paramPos,0,_:floatstr(changestr));
  183. }
  184. case 'p':
  185. {
  186. delim = format[formatPos++];
  187. continue;
  188. }
  189. case '\'':
  190. {
  191. new
  192. end = formatPos - 1,
  193. ch;
  194. while ((ch = format[++end]) && ch != '\'') {}
  195. if (!ch)
  196. {
  197. return -1;
  198. }
  199. format[end] = '\0';
  200. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  201. {
  202. if (format[end + 1])
  203. {
  204. return -1;
  205. }
  206. return 0;
  207. }
  208. format[end] = '\'';
  209. stringPos = ch + (end - formatPos);
  210. formatPos = end + 1;
  211. }
  212. case 'u':
  213. {
  214. new
  215. end = stringPos - 1,
  216. id = 0,
  217. bool:num = true,
  218. ch;
  219. while ((ch = string[++end]) && ch != delim)
  220. {
  221. if (num)
  222. {
  223. if ('0' <= ch <= '9')
  224. {
  225. id = (id * 10) + (ch - '0');
  226. }
  227. else
  228. {
  229. num = false;
  230. }
  231. }
  232. }
  233. if (num && IsPlayerConnected(id))
  234. {
  235. setarg(paramPos, 0, id);
  236. }
  237. else
  238. {
  239. #if !defined foreach
  240. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  241. #define __SSCANF_FOREACH__
  242. #endif
  243. string[end] = '\0';
  244. num = false;
  245. new
  246. name[MAX_PLAYER_NAME];
  247. id = end - stringPos;
  248. foreach (Player, playerid)
  249. {
  250. GetPlayerName(playerid, name, sizeof (name));
  251. if (!strcmp(name, string[stringPos], true, id))
  252. {
  253. setarg(paramPos, 0, playerid);
  254. num = true;
  255. break;
  256. }
  257. }
  258. if (!num)
  259. {
  260. setarg(paramPos, 0, INVALID_PLAYER_ID);
  261. }
  262. string[end] = ch;
  263. #if defined __SSCANF_FOREACH__
  264. #undef foreach
  265. #undef __SSCANF_FOREACH__
  266. #endif
  267. }
  268. stringPos = end;
  269. }
  270. case 's', 'z':
  271. {
  272. new
  273. i = 0,
  274. ch;
  275. if (format[formatPos])
  276. {
  277. while ((ch = string[stringPos++]) && ch != delim)
  278. {
  279. setarg(paramPos, i++, ch);
  280. }
  281. if (!i)
  282. {
  283. return -1;
  284. }
  285. }
  286. else
  287. {
  288. while ((ch = string[stringPos++]))
  289. {
  290. setarg(paramPos, i++, ch);
  291. }
  292. }
  293. stringPos--;
  294. setarg(paramPos, i, '\0');
  295. }
  296. default:
  297. {
  298. continue;
  299. }
  300. }
  301. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  302. {
  303. stringPos++;
  304. }
  305. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  306. {
  307. stringPos++;
  308. }
  309. paramPos++;
  310. }
  311. do
  312. {
  313. if ((delim = format[formatPos++]) > ' ')
  314. {
  315. if (delim == '\'')
  316. {
  317. while ((delim = format[formatPos++]) && delim != '\'') {}
  318. }
  319. else if (delim != 'z')
  320. {
  321. return delim;
  322. }
  323. }
  324. }
  325. while (delim > ' ');
  326. return 0;
  327. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement