Guest User

rayner000

a guest
Jul 9th, 2009
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.09 KB | None | 0 0
  1. //////////////////////////////
  2. // corpse's //
  3. // aka //
  4. // c-middia //
  5. // simple banking script //
  6. // credits //
  7. // thanks to Draco Blue //
  8. // for reg/login, //
  9. // dudb & dutils //
  10. // //
  11. // thanks to jerbob1992 //
  12. // for bank stuff //
  13. // //
  14. // you need dudb & dutils //
  15. // in pawno/include //
  16. //////////////////////////////
  17. #include <a_samp>
  18. #include <core>
  19. #include <float>
  20. #include <dutils>
  21. #include <dudb>
  22. #pragma tabsize 0
  23. #define CP_BANK 0
  24. #define CP_BANK_2 2
  25. #define CP_BANK_3 3
  26. #define COLOR_GREY 0xAFAFAFAA //---grey
  27. #define COLOR_GREEN 0x00AA00AA //---green
  28. #define COLOR_RED 0xFF0033AA //--red
  29. #define COLOR_YELLOW 0xFFFF00AA //---yellow
  30. #define COLOR_WHITE 0xFFFFFFAA //---white
  31. #define COLOR_WHITE2 0xFF4080AA //---pinky
  32. #define COLOR_LIGHTBLUE 0x33CCFFAA //---light blue
  33. #define COLOR_ORANGE 0xFF9900AA //---orange
  34. #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
  35. #define GetStringArg(%1,%2) for(new x = 0; getarg(%1,x) != '\0'; x++) %2[x] = getarg(%1,x)
  36. #define COLOR_SYSTEM 0xEFEFF7AA
  37. new PLAYERLIST_authed[MAX_PLAYERS];
  38. forward getCheckpointType(playerID);
  39. forward checkpointUpdate();
  40. forward SendPlayerFormattedText(playerid, const str[], define);
  41. forward SendAllFormattedText(playerid, const str[], define);
  42. forward isPlayerInArea(playerID, Float:data[4]);
  43. new bank[MAX_PLAYERS];
  44. //new pmoney[MAX_PLAYERS];
  45. new playerCheckpoint[MAX_PLAYERS];
  46. new bankcard[MAX_PLAYERS];
  47. #define MAX_POINTS 3
  48. new Float:checkCoords[MAX_POINTS][4] = {
  49. {2317.0745,-17.2064, 2305.8213,-0.2685}, //BANK_1---- I've changed this, to coordinates of bank, in hope it would work, but nothing...
  50. {-37.2183,-91.8006, -14.1099,-74.6845}, //BANK_2
  51. {-34.6621,-31.4095, -2.6782,-25.6232} //BANK_3
  52. };
  53. new Float:checkpoints[MAX_POINTS][3] = {
  54. {2315.3943,-7.8455,26.7422}, // I've changed this too, the place where the checkpoint should be...
  55. {-23.0664,-90.0882,1003.5469},
  56. {-33.9593,-29.0792,1003.5573}
  57. };
  58. new checkpointType[MAX_POINTS] = {
  59. CP_BANK,
  60. CP_BANK_2,
  61. CP_BANK_3
  62. };
  63. #define MAX_GANGS 20
  64. new gangBank[MAX_GANGS];
  65. new playerGang[MAX_PLAYERS];
  66. main()
  67. {
  68. print("\n--------------------------------------");
  69. print("Corpse's Simple Banking FilterScript 0.3");
  70. print("--------------------------------------\n");
  71. }
  72. //-----
  73. //---
  74. stock SystemMsg(playerid,msg[]) {
  75. if ((IsPlayerConnected(playerid))&&(strlen(msg)>0)) {
  76. SendClientMessage(playerid,COLOR_SYSTEM,msg);
  77. }
  78. return 1;
  79. }
  80. stock PlayerName(playerid) {
  81. new name[255];
  82. GetPlayerName(playerid, name, 255);
  83. return name;
  84. }
  85. //---
  86. //--
  87. public OnPlayerConnect(playerid) {
  88. if(udb_Exists(PlayerName(playerid))) return GivePlayerMoney(playerid,dUserINT(PlayerName(playerid)).("money")-GetPlayerMoney(playerid)); SystemMsg(playerid,"Welcome Back, bank soon !.");
  89. //{
  90. // Was loggedin, so give cash
  91. // GivePlayerMoney(playerid,dUserINT(PlayerName(playerid)).("money")-GetPlayerMoney(playerid));
  92. // }
  93. /* if (PLAYERLIST_authed[playerid]) {
  94. // Was loggedin, so save the data!
  95. GivePlayerMoney(playerid,dUserINT(PlayerName(playerid)).("money")-GetPlayerMoney(playerid));
  96. }*/
  97. PLAYERLIST_authed[playerid]=false;
  98. bankcard[playerid]=0;
  99. return false;
  100. }
  101. public OnPlayerDisconnect(playerid)
  102. {
  103. if(udb_Exists(PlayerName(playerid))) return dUserSetINT(PlayerName(playerid)).("money",GetPlayerMoney(playerid));
  104. //{
  105. // Was loggedin, so save the data!
  106. // dUserINT(PlayerName(playerid)).("pmoney");
  107. // dUserSetINT(PlayerName(playerid)).("money",GetPlayerMoney(playerid));
  108. // }
  109. /* if (PLAYERLIST_authed[playerid]) {
  110. // Was loggedin, so save the data!
  111. dUserSetINT(PlayerName(playerid)).("money",GetPlayerMoney(playerid));
  112. }*/
  113. PLAYERLIST_authed[playerid]=false;
  114. bankcard[playerid]=0;
  115. return false;
  116. }
  117. //---
  118. //-----
  119. public isPlayerInArea(playerID, Float:data[4])
  120. {
  121. new Float:X, Float:Y, Float:Z;
  122. GetPlayerPos(playerID, X, Y, Z);
  123. if(X >= data[0] && X <= data[2] && Y >= data[1] && Y <= data[3]) {
  124. return 1;
  125. }
  126. return 0;
  127. }
  128. public checkpointUpdate()
  129. {
  130. for(new i=0; i<MAX_PLAYERS; i++)
  131. {
  132. if(IsPlayerConnected(i)) {
  133. for(new j=0; j < MAX_POINTS; j++) {
  134. if(isPlayerInArea(i, checkCoords[j])) {
  135. if(playerCheckpoint[i]!=j) {
  136. DisablePlayerCheckpoint(i);
  137. SetPlayerCheckpoint(i, checkpoints[j][0],checkpoints[j][1],checkpoints[j][2],2);
  138. playerCheckpoint[i] = j;
  139. }
  140. } else {
  141. if(playerCheckpoint[i]==j) {
  142. DisablePlayerCheckpoint(i);
  143. playerCheckpoint[i] = 999;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. //-----
  151. public getCheckpointType(playerID) {
  152. return checkpointType[playerCheckpoint[playerID]];
  153. }
  154. //-----
  155. /*
  156. * /openaccount password
  157. *
  158. */
  159. dcmd_openaccount(playerid,params[]) {
  160. // must be in bank checkpoint
  161. if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) return SendClientMessage(playerid, COLOR_RED, "You must be at a bank area to use this. ATMs are located in convenience stores.");
  162. // The command shouldn't work if we already are authed
  163. if (PLAYERLIST_authed[playerid]) return SystemMsg(playerid,"Already authed.");
  164. // The command shouldn't work if an account with this
  165. // nick already exists
  166. if (udb_Exists(PlayerName(playerid))) return SystemMsg(playerid,"Account already exists, please use '/icard password'.");
  167. // Did he forgot the password?
  168. if (strlen(params)==0) return SystemMsg(playerid,"Correct usage: '/openaccount password'");
  169. // We save the money to the accstate
  170. if (udb_Create(PlayerName(playerid),params)) return SystemMsg(playerid,"Account successfully created. insert card with '/icard password' now.");
  171. bankcard[playerid]=0;
  172. return true;
  173. }
  174. /*
  175. * /icard password
  176. *
  177. */
  178. dcmd_icard(playerid,params[]) {
  179. // must be in bank checkpoint
  180. if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) return SendClientMessage(playerid, COLOR_ORANGE, "You must be at a bank area to use this. ATMs are located in convenience stores.");
  181. // The command shouldn't work if we already are authed
  182. if (PLAYERLIST_authed[playerid]) return SystemMsg(playerid,"Already authed.");
  183. // The command shouldn't work if an account with this
  184. // nick does not exists
  185. if (!udb_Exists(PlayerName(playerid))) return SystemMsg(playerid,"Account doesn't exist, please use '/openaccount password'.");
  186. // Did he forgot the password?
  187. if (strlen(params)==0) return SystemMsg(playerid,"Correct usage: '/icard password'");
  188. if (udb_CheckLogin(PlayerName(playerid),params)) {
  189. // icard was correct
  190. // Following thing is the same like the missing SetPlayerCommand
  191. // GivePlayerMoney(playerid,dUserINT(PlayerName(playerid)).("bank")-GetPlayerMoney(playerid));
  192. PLAYERLIST_authed[playerid]=true;
  193. bankcard[playerid]=1;
  194. return SystemMsg(playerid,"Successfully authed!");
  195. }
  196. // icard was incorrect
  197. return SystemMsg(playerid,"icard failed!");
  198. }
  199. //-----
  200. //------
  201. public OnPlayerCommandText(playerid, cmdtext[])
  202. {
  203. new string[256];
  204. new cmd[256];
  205. new moneys, idx;
  206. cmd = strtok(cmdtext, idx);
  207. if(strcmp(cmd, "/bank", true) == 0 || strcmp(cmd, "/gbank", true) == 0) {
  208. new gang;
  209. if(strcmp(cmd, "/gbank", true) == 0)
  210. gang = 1;
  211. if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) {
  212. SendClientMessage(playerid, COLOR_YELLOW, "You must be at a bank area to use this. ATMs are located in convenience stores.");
  213. return 1;
  214. }
  215. if(bankcard[playerid]==0){
  216. SendClientMessage(playerid, COLOR_ORANGE, "/openaccount password to start account, /icard password to use account.");
  217. return 1;
  218. }
  219. if(gang && playerGang[playerid]==0) {
  220. SendClientMessage(playerid, COLOR_RED, "You are not in a gang!");
  221. return 1;
  222. }
  223. new tmp[256];
  224. tmp = strtok(cmdtext, idx);
  225. if(!strlen(tmp)) {
  226. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /bank [amount]");
  227. return 1;
  228. }
  229. moneys = strval(tmp);
  230. if(moneys < 1) {
  231. SendClientMessage(playerid, COLOR_YELLOW, "Hey what are you trying to pull here.");
  232. return 1;
  233. }
  234. if(GetPlayerMoney(playerid) < moneys) {
  235. moneys = GetPlayerMoney(playerid);
  236. }
  237. GivePlayerMoney(playerid, 0-moneys);
  238. if(gang)
  239. gangBank[playerGang[playerid]]+=moneys;
  240. else
  241. bank[playerid] = dUserINT(PlayerName(playerid)).("bank");
  242. bank[playerid]+=moneys;
  243. dUserSetINT(PlayerName(playerid)).("bank", bank[playerid]);
  244. if(gang)
  245. format(string, sizeof(string), "You have deposited $%d, your gang's balance is $%d.", moneys, gangBank[playerGang[playerid]]);
  246. else
  247. bank[playerid] = dUserINT(PlayerName(playerid)).("bank");
  248. format(string, sizeof(string), "You have deposited $%d, your current balance is $%d.", moneys, bank[playerid]);
  249. SendClientMessage(playerid, COLOR_GREEN, string);
  250. return 1;
  251. }
  252. //------------------- /withdraw
  253. if(strcmp(cmd, "/withdraw", true) == 0 || strcmp(cmd, "/gwithdraw", true) == 0) {
  254. new gang;
  255. if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) {
  256. SendClientMessage(playerid, COLOR_YELLOW, "You must be at a bank area to use this. ATMs are located in convenience stores.");
  257. return 1;
  258. }
  259. if(bankcard[playerid]==0){
  260. SendClientMessage(playerid, COLOR_ORANGE, "/openaccount password to start account, /icard password to use account.");
  261. return 1;
  262. }
  263. if(strcmp(cmd, "/gwithdraw", true) == 0)
  264. gang = 1;
  265. if(gang && playerGang[playerid]==0) {
  266. SendClientMessage(playerid, COLOR_RED, "You are not in a gang!");
  267. return 1;
  268. }
  269. new tmp[256];
  270. tmp = strtok(cmdtext, idx);
  271. if(!strlen(tmp)) {
  272. SendClientMessage(playerid, COLOR_WHITE, "USAGE: /(g)withdraw [amount]");
  273. return 1;
  274. }
  275. moneys = strval(tmp);
  276.  
  277. if(moneys < 1) {
  278. SendClientMessage(playerid, COLOR_YELLOW, "Hey what are you trying to pull here.");
  279. return 1;
  280. }
  281. if(gang) {
  282. if(moneys > gangBank[playerGang[playerid]])
  283. moneys = gangBank[playerGang[playerid]];
  284. } else {
  285. bank[playerid] = dUserINT(PlayerName(playerid)).("bank");
  286. if(moneys > bank[playerid])
  287. moneys = bank[playerid];
  288. }
  289. GivePlayerMoney(playerid, moneys);
  290. if(gang)
  291. gangBank[playerGang[playerid]] -= moneys;
  292. else
  293. bank[playerid] = dUserINT(PlayerName(playerid)).("bank");
  294. bank[playerid] -= moneys;
  295. dUserSetINT(PlayerName(playerid)).("bank",bank[playerid]);
  296. if(gang)
  297. format(string, sizeof(string), "You have withdrawn $%d, your gang's balance is $%d.", moneys, gangBank[playerGang[playerid]]);
  298. else
  299. format(string, sizeof(string), "You have withdrawn $%d, your current balance is $%d.", moneys, bank[playerid]);
  300. SendClientMessage(playerid, COLOR_GREEN, string);
  301. return 1;
  302. }
  303. //------------------- /balance
  304. if(strcmp(cmd, "/balance", true) == 0 || strcmp(cmd, "/gbalance", true) == 0) {
  305. new gang;
  306. if(strcmp(cmd, "/gbalance", true) == 0)
  307. gang = 1;
  308.  
  309. if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) {
  310. SendClientMessage(playerid, COLOR_YELLOW, "You must be at a bank area to use this. ATMs are located in convenience stores.");
  311. return 1;
  312. }
  313. if(bankcard[playerid]==0){
  314. SendClientMessage(playerid, COLOR_ORANGE, "/openaccount password to start account, /icard password to use account.");
  315. return 1;
  316. }
  317. if(gang && playerGang[playerid]==0) {
  318. SendClientMessage(playerid, COLOR_RED, "You are not in a gang!");
  319. return 1;
  320. }
  321. if(gang)
  322. format(string, sizeof(string), "Your gang has $%d in the bank.", gangBank[playerGang[playerid]]);
  323. else
  324. bank[playerid] = dUserINT(PlayerName(playerid)).("bank");
  325. format(string, sizeof(string), "You have $%d in the bank.", bank[playerid]);
  326. SendClientMessage(playerid, COLOR_GREEN, string);
  327. return 1;
  328. }
  329. dcmd(icard,5,cmdtext);
  330. // because icard has 5 characters
  331. dcmd(openaccount,11,cmdtext);
  332. // because openaccount has 11 characters
  333. return 0;
  334. }
  335. //--strtok
  336. public OnPlayerEnterCheckpoint(playerid)
  337. {
  338. switch(getCheckpointType(playerid))
  339. {
  340. case CP_BANK: {
  341. SendClientMessage(playerid, COLOR_LIGHTBLUE, "You are at an ATM. To store money use '/bank amount', to withdraw");
  342. SendClientMessage(playerid, COLOR_LIGHTBLUE, "money use '/withdraw amount', and '/balance' to see your balance.");
  343. }
  344. case CP_BANK_2: {
  345. SendClientMessage(playerid, COLOR_WHITE2, "You are at an ATM. To store money use '/bank amount', to withdraw");
  346. SendClientMessage(playerid, COLOR_WHITE2, "money use '/withdraw amount', and '/balance' to see your balance.");
  347. }
  348. case CP_BANK_3: {
  349. SendClientMessage(playerid, COLOR_ORANGE, "You are at an ATM. To store money use '/bank amount', to withdraw");
  350. SendClientMessage(playerid, COLOR_ORANGE, "money use '/withdraw amount', and '/balance' to see your balance.");
  351. }
  352. }
  353. }
  354. //--
  355. public OnPlayerLeaveCheckpoint(playerid)
  356. {
  357. PLAYERLIST_authed[playerid]=false;
  358. bankcard[playerid]=0;
  359. return false;
  360. }
  361. //--
  362. public OnFilterScriptInit()
  363. {
  364. SetTimer("checkpointUpdate", 1100, 1);
  365. print("\n--------------------------------------");
  366. print("Corpse's Simple Banking FilterScript 0.3");
  367. print("--------------------------------------\n");
  368. return 1;
  369. }
  370. //---
  371. public OnFilterScriptExit()
  372. {
  373. return 1;
  374. }
Advertisement
Add Comment
Please, Sign In to add comment