HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5.  
  6. /*
  7.  * SM Bank
  8.  * by MaTTe (mateo10)
  9.  *
  10.  * Fordította: BBk
  11.  */
  12.  
  13.  
  14. #define DWDCOUNT 7
  15. //static String:MoneyCount[ DWDCOUNT ][] = { "1000" , "2000" , "4000" , "8000", "16000"};
  16.  
  17. new LastMenuAction[ MAXPLAYERS + 1 ];
  18. new TargetClientMenu[ MAXPLAYERS + 1 ];
  19. new IHateFloods[ MAXPLAYERS + 1 ];
  20.  
  21. #define VERSION "3.0"
  22.  
  23. public Plugin:myinfo =
  24. {
  25. name = "SM Bank",
  26. author = "MaTTe, edit by Nican",
  27. description = "A jatekos penzt helyezhet el a bankjaban es kiveheti onnan, amikor szuksege van ra",
  28. version = VERSION,
  29. url = "http://www.sourcemod.net/"
  30. };
  31.  
  32. new g_iAccount = -1;
  33.  
  34. #define ALLOWBANK 0
  35. #define MAXBANK 1
  36. #define DEPOSITFEE 2
  37. #define TRANSFER 3
  38. #define INTEREST 4
  39. #define AUTOMONEY 5
  40. #define PISTOLROUND 6
  41. #define DBCONFIG 7
  42. #define DBSAVE 8
  43. #define MENUROUND 9
  44. #define CSSTARTMONEY 10
  45.  
  46.  
  47. new Handle:g_cvars[11];
  48. new maxplayers;
  49. new Handle:db = INVALID_HANDLE;
  50.  
  51. new BankMoney[ MAXPLAYERS + 1];
  52. new DBid[ MAXPLAYERS + 1];
  53.  
  54. public OnPluginStart()
  55. {
  56. CreateConVar("smbank_sql_version", VERSION, "SM Bank Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  57.  
  58. g_cvars[ALLOWBANK] = CreateConVar("sm_bank_allow","1","A bank hasznalatanak engedelyezese/letiltasa");
  59. g_cvars[TRANSFER] = CreateConVar("sm_bank_transfer","1","Penz utalas engedelyezese/letiltasa mas jatekosok szamara");
  60. g_cvars[MAXBANK] = CreateConVar("sm_bank_max","50000","A maximalis penz osszeg, ami elhelyezheto a bankjaikban");
  61. g_cvars[DEPOSITFEE] = CreateConVar("sm_bank_fee","250","Leteti dij erteke, amit meg kell fizetni, amikor a bankba penzt tesz");
  62. g_cvars[INTEREST] = CreateConVar("sm_bank_interest","5.0","A jatekos kamatanak szazaleka (x osszeg y %-a), amit minden korben meg kap");
  63. g_cvars[PISTOLROUND] = CreateConVar("sm_bank_pistol","0","Pisztolykorbe ne engedelyezze a penz kivetelet a bankbol");
  64. g_cvars[DBCONFIG] = CreateConVar("sm_bank_config","default","Adatbazis konfiguracio beallitasa");
  65. g_cvars[DBSAVE] = CreateConVar("sm_bank_save","2","Mentes beallitasa, 1=kikapcsolva, 2=korkezdesnel, 3=minden valtozasnal");
  66. g_cvars[MENUROUND] = CreateConVar("sm_bank_round","500","Hany kort mutasson a plugin a menube");
  67. g_cvars[CSSTARTMONEY] = FindConVar("mp_startmoney");
  68.  
  69. if( g_cvars[CSSTARTMONEY] == INVALID_HANDLE ){
  70. LogMessage("SMBANK: Nem talalhato az mp_startmoney. 800 lesz beallitva.");
  71. }
  72.  
  73. HookConVarChange(g_cvars[DBCONFIG], BankConVarChanged);
  74.  
  75. //g_cvars[AUTOMONEY] = CreateConVar("sm_bank_auto","0","Put 1 if money should be automacicly deposited/extracted");
  76.  
  77. RegAdminCmd("sm_bankadd", Command_AddtoBank, ADMFLAG_CUSTOM4);
  78. RegAdminCmd("sm_bankset", Command_SetBank, ADMFLAG_CUSTOM4);
  79.  
  80. LoadTranslations("plugin.smbank");
  81.  
  82. RegConsoleCmd("deposit", Deposit);
  83. RegConsoleCmd("withdraw", WithDraw);
  84. RegConsoleCmd("bankstatus", BankStatus);
  85. RegConsoleCmd("bank", BankMenu);
  86.  
  87. g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
  88.  
  89. HookEvent("round_start", EventRoundStart);
  90.  
  91. ConnectToMysql();
  92. }
  93.  
  94. public BankConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[]){
  95. ConnectToMysql();
  96. }
  97.  
  98. stock ConnectToMysql(){
  99. if(db != INVALID_HANDLE){
  100. LogMessage("[SM Bank] Megszakadt az adatbazissal a kapcsolat");
  101. CloseHandle(db);
  102. db = INVALID_HANDLE;
  103. }
  104.  
  105. decl String:dbname[64];
  106. GetConVarString(g_cvars[DBCONFIG], dbname, 64);
  107.  
  108. if(!SQL_CheckConfig( dbname )){
  109. LogMessage("[SM Bank] DB konfiguracio '%s' nem alkalmazhato, alapertelmezett visszaallitasa.", dbname );
  110. dbname = "default";
  111. }
  112.  
  113. SQL_TConnect(OnSqlConnect, dbname);
  114. }
  115.  
  116. public OnSqlConnect(Handle:owner, Handle:hndl, const String:error[], any:data)
  117. {
  118.  
  119.  
  120. if (hndl == INVALID_HANDLE)
  121. {
  122. LogError("Adatbazis hiba: %s", error);
  123. } else {
  124. db = hndl;
  125.  
  126. decl String:buffer[1024];
  127.  
  128. SQL_GetDriverIdent( SQL_ReadDriver(db), buffer, sizeof(buffer));
  129. new ismysql = StrEqual(buffer,"mysql", false) ? 1 : 0;
  130.  
  131. if(ismysql == 1){
  132. Format(buffer, sizeof(buffer), "CREATE TABLE IF NOT EXISTS `sm_users` (`id` int(11) NOT NULL auto_increment,`steam` varchar(31) NOT NULL, `money` int(11) NOT NULL,PRIMARY KEY (`id`),UNIQUE KEY `steam` (`steam`))");
  133. }else{
  134. Format(buffer, sizeof(buffer), "CREATE TABLE IF NOT EXISTS sm_users(id INTEGER PRIMARY KEY AUTOINCREMENT, steam TEXT UNIQUE, money INTEGER );");
  135. }
  136.  
  137. SQL_FastQuery(db, buffer);
  138. }
  139. }
  140.  
  141. public OnClientPostAdminCheck(client){
  142. DBid[ client ] = -1;
  143.  
  144. decl String:AuthStr[32];
  145.  
  146. if(IsFakeClient(client)){
  147. return;
  148. }
  149.  
  150. if(!GetClientAuthString(client, AuthStr, 32)){
  151. return;
  152. }
  153.  
  154. decl String:MysqlQuery[512];
  155.  
  156. Format(MysqlQuery, sizeof(MysqlQuery), "SELECT id, money FROM sm_users WHERE steam = '%s'", AuthStr);
  157.  
  158. //LogMessage("%s", MysqlQuery);
  159.  
  160. SQL_TQuery(db, T_NewClientConnected , MysqlQuery, GetClientUserId(client));
  161. }
  162.  
  163. public T_NewClientConnected(Handle:owner, Handle:hndl, const String:error[], any:data)
  164. {
  165. new client;
  166.  
  167. /* Make sure the client didn't disconnect while the thread was running */
  168. if ((client = GetClientOfUserId(data)) == 0)
  169. {
  170. return;
  171. }
  172.  
  173. if (hndl == INVALID_HANDLE)
  174. {
  175. LogError("Query meghiusult! %s", error);
  176. } else if (!SQL_GetRowCount(hndl)) {
  177. decl String:AuthStr[32], String:MysqlQuery[512];
  178. if(!GetClientAuthString(client, AuthStr, 32)){
  179. return;
  180. }
  181.  
  182. //Client no found, add him to the table
  183. Format(MysqlQuery, sizeof(MysqlQuery), "INSERT INTO sm_users(steam) VALUES('%s')", AuthStr);
  184. //LogMessage("%s", MysqlQuery);
  185.  
  186. SQL_FastQuery(db, MysqlQuery);
  187.  
  188. return;
  189. }
  190.  
  191. if(!SQL_FetchRow(hndl))
  192. return;
  193.  
  194. DBid[ client ] = SQL_FetchInt( hndl, 0);
  195. SetBankMoney(client, SQL_FetchInt( hndl, 1));
  196. }
  197.  
  198.  
  199. stock SaveClientInfo(client){
  200. decl String:MysqlQuery[512];
  201.  
  202. if( DBid[ client ] == -1){
  203. decl String:AuthStr[32];
  204. if(!GetClientAuthString(client, AuthStr, 32)){
  205. return;
  206. }
  207.  
  208. Format(MysqlQuery, sizeof(MysqlQuery), "UPDATE sm_users SET money = %d WHERE steam = '%s'", BankMoney[ client ], AuthStr);
  209. } else {
  210. Format(MysqlQuery, sizeof(MysqlQuery), "UPDATE sm_users SET money = %d WHERE id = %d", BankMoney[ client ], DBid[ client ]);
  211. }
  212. //LogMessage("%s", MysqlQuery);
  213. SQL_FastQuery(db, MysqlQuery);
  214. }
  215.  
  216.  
  217.  
  218. public OnMapStart(){
  219. maxplayers = GetMaxClients();
  220. }
  221.  
  222. public Action:Command_AddtoBank(client, args){
  223. if (args < 2){
  224. ReplyToCommand(client, "[SM] Hasznalat: sm_bankadd <#userid|nev> <penz>");
  225. return Plugin_Handled;
  226. }
  227.  
  228. decl String:arg[65];
  229. GetCmdArg(1, arg, sizeof(arg));
  230.  
  231. new target = FindTarget(client, arg, true , false);
  232. if (target == -1)
  233. return Plugin_Handled;
  234.  
  235. decl String:moneys[12];
  236. GetCmdArg(2, moneys, sizeof(moneys));
  237. new money = StringToInt(moneys);
  238.  
  239. SetBankMoney(target, GetBankMoney(target) + money);
  240.  
  241. PrintToChatAll("[NC] \x04[SM Bank]\x01 Az Admin modositotta a penzed");
  242.  
  243. return Plugin_Handled;
  244. }
  245.  
  246. public Action:Command_SetBank(client, args){
  247. if (args < 2){
  248. ReplyToCommand(client, "[SM] Hasznalat: sm_bankset <#userid|nev> <penz>");
  249. return Plugin_Handled;
  250. }
  251.  
  252. decl String:arg[65];
  253. GetCmdArg(1, arg, sizeof(arg));
  254.  
  255. new target = FindTarget(client, arg, true , false);
  256. if (target == -1)
  257. return Plugin_Handled;
  258.  
  259. decl String:moneys[12];
  260. GetCmdArg(2, moneys, sizeof(moneys));
  261. new money = StringToInt(moneys);
  262.  
  263. SetBankMoney(target, money);
  264.  
  265. PrintToChatAll("[NC] \x04[SM Bank]\x01 Az Admin modositotta a penzed");
  266.  
  267. return Plugin_Handled;
  268. }
  269.  
  270. stock SetBankMoney(client, money){
  271. new maxmoney = GetConVarInt(g_cvars[MAXBANK]);
  272.  
  273. if(maxmoney > 0 && money > maxmoney) money = maxmoney;
  274. if(money < 0) money = 0;
  275.  
  276. BankMoney[ client ] = money;
  277.  
  278. if(GetConVarInt(g_cvars[DBSAVE]) == 3){
  279. SaveClientInfo(client);
  280. }
  281. }
  282.  
  283. stock GetBankMoney(client){
  284. return BankMoney[ client ];
  285. }
  286.  
  287. public OnClientDisconnect(client){
  288. if(GetConVarInt(g_cvars[DBSAVE]) <= 2){
  289. SaveClientInfo(client);
  290. }
  291. }
  292.  
  293.  
  294. public EventRoundStart(Handle:event, const String:name[], bool:dontBroadcast){
  295.  
  296. new maxmoney, curmoney, bool:ShouldSave;
  297. decl String:MoneyGain[32];
  298.  
  299. maxmoney = GetConVarInt(g_cvars[MAXBANK]);
  300. //auto = GetConVarBool(g_cvars[AUTOMONEY]);
  301.  
  302. ShouldSave = (GetConVarInt(g_cvars[DBSAVE]) == 2);
  303.  
  304. for(new i = 1; i <= maxplayers ; i ++){
  305. if(!IsClientInGame(i)) continue;
  306. //No spectators...
  307. if(GetClientTeam(i) <= 1) continue;
  308.  
  309. if(IHateFloods[i]){
  310. PrintToChat(i, "%t", "Available commands", "\x04", "\x01");
  311. IHateFloods[i]=false;
  312. }
  313.  
  314. if(ShouldSave){
  315. SaveClientInfo(i);
  316. }
  317.  
  318. //if(auto){
  319. // WithDrawClientMoney(client, "all");
  320. //}
  321.  
  322. //PrintToChat(i, "Adding interest to you!");
  323.  
  324. curmoney = GetBankMoney(i);
  325.  
  326. curmoney += RoundFloat(FloatMul( float (curmoney) , GetConVarFloat(g_cvars[INTEREST]) / 100.0 ));
  327.  
  328.  
  329. if(maxmoney > 0 && curmoney > maxmoney ){
  330. curmoney = maxmoney;
  331. }
  332.  
  333. //PrintToChat(i, "Your gain is: %d", gain);
  334.  
  335. if(curmoney != GetBankMoney(i)){
  336. IntToMoney(curmoney - GetBankMoney(i), MoneyGain, 32);
  337. PrintToChat(i, "%t", "Interested gained", "\x04", "\x01", MoneyGain);
  338. SetBankMoney(i, curmoney);
  339. }
  340.  
  341. //PrintToChat(i, "loop finished!");
  342. }
  343. }
  344.  
  345. public Action:BankMenu(client, args){
  346. if (!GetConVarInt(g_cvars[ALLOWBANK])){
  347. PrintToChat(client, "%t", "Bank Disabled", "\x04", "\x01");
  348. return Plugin_Handled;
  349. }
  350.  
  351. new Handle:menu = CreateMenu(MenuHandler1);
  352. SetMenuTitle(menu, "Bank:");
  353. AddMenuItem(menu, "dep", "Deposit");
  354. AddMenuItem(menu, "wit", "Withdraw");
  355. AddMenuItem(menu, "bal", "Balance");
  356. AddMenuItem(menu, "tran", "Transfer");
  357.  
  358. DisplayMenu(menu, client, 20);
  359.  
  360. return Plugin_Handled;
  361. }
  362.  
  363. public MenuHandler1(Handle:menu, MenuAction:action, client, param2)
  364. {
  365. if (!GetConVarInt(g_cvars[ALLOWBANK])){
  366. PrintToChat(client, "%t", "Bank Disabled", "\x04", "\x01");
  367. CloseHandle(menu);
  368. return;
  369. }
  370.  
  371. /* Either Select or Cancel will ALWAYS be sent! */
  372. if (action == MenuAction_Select)
  373. {
  374. LastMenuAction[client] = param2;
  375. switch( param2 ){
  376. case 0,1: {
  377.  
  378. new Handle:menu2 = CreateMenu(DepositWithMenu);
  379. if(param2 == 0){
  380. SetMenuTitle(menu2, "Bank - Letet:");
  381.  
  382. new maxmoney = GetConVarInt(g_cvars[MAXBANK]);
  383. new bankmoney = GetBankMoney(client);
  384. new curmoney = GetMoney(client);
  385.  
  386. new maxdeposit = maxmoney - bankmoney;
  387.  
  388. if(curmoney == 0){
  389. PrintToChat(client, "[SM Bank] Nincs tobb penzed!");
  390. CloseHandle(menu2);
  391. return;
  392. }
  393.  
  394. if(maxdeposit == 0){
  395. PrintToChat(client, "[SM Bank] A Bankodba nem tehetsz be tobb penzt!");
  396. CloseHandle(menu2);
  397. return;
  398. }
  399.  
  400. if(maxdeposit > curmoney) maxdeposit = curmoney;
  401.  
  402. AddMoneyItems(menu2, maxdeposit);
  403. }else{
  404. SetMenuTitle(menu2, "Bank - Withdraw:");
  405. new maxamount = 16000 - GetMoney(client);
  406. new curmoney = GetBankMoney(client);
  407.  
  408. if(maxamount == 0){
  409. PrintToChat(client, "[SM Bank] Nem tarthatsz tobb penzt!");
  410. CloseHandle(menu2);
  411. return;
  412. }
  413.  
  414. if(curmoney == 0){
  415. PrintToChat(client, "\x04[SM Bank]\x01 Nincs penz a bankodban!");
  416. CloseHandle(menu2);
  417. return;
  418. }
  419.  
  420. if(maxamount > curmoney) maxamount = curmoney;
  421.  
  422. AddMoneyItems(menu2, maxamount);
  423. }
  424.  
  425. DisplayMenu(menu2, client, 20);
  426. }
  427. case 2:{
  428. ShowBankStatus(client);
  429. }
  430. case 3:{
  431. if (!GetConVarInt(g_cvars[TRANSFER])){
  432. PrintToChat(client, "%t", "No Transfer", "\x04", "\x01");
  433. return;
  434. }
  435. //I can not belive I am doing String:id
  436. new Handle:menu2 = CreateMenu(TransferMenu), String:name[64], String:id[8];
  437. SetMenuTitle(menu2, "Bank - Utalas:");
  438.  
  439. new count =0;
  440. for(new i = 1; i <= maxplayers ; i ++){
  441. if(!IsClientInGame(i)) continue;
  442. if(client == i) continue;
  443. if(IsFakeClient(i)) continue;
  444.  
  445. //PrintToChat(client, "Checking passed: %d", i);
  446.  
  447. count++;
  448.  
  449. GetClientName(i, name, sizeof(name));
  450. IntToString(i, id, sizeof(id));
  451. AddMenuItem(menu2, id, name);
  452. }
  453. //PrintToChat(client, "Players found: %d", count);
  454.  
  455. if(count == 0){
  456. PrintToChat(client, "Nincs senki a szerveren");
  457. CloseHandle(menu2);
  458. return;
  459. }
  460.  
  461. DisplayMenu(menu2, client, 20);
  462. }
  463. }
  464. }
  465.  
  466. /* If the menu has ended, destroy it */
  467. if (action == MenuAction_End)
  468. {
  469. CloseHandle(menu);
  470. }
  471. }
  472.  
  473. stock RoundOff(num, dif){
  474. new offset = num % dif;
  475.  
  476. if(offset > (dif/2)){
  477. return num + dif - offset;
  478. }
  479.  
  480. return num - offset;
  481. }
  482.  
  483. public AddMoneyItems(Handle:menu2, Money){
  484. new String:dummy[32], String:dummy2[32];
  485. new testint;
  486.  
  487. new PartialMoney = Money / DWDCOUNT;
  488. new RoundTo = GetConVarInt(g_cvars[MENUROUND]);
  489. new LastValue;
  490.  
  491. for(new i=1; i< DWDCOUNT; i++){
  492. testint = RoundOff(PartialMoney * i, RoundTo);
  493.  
  494. if(testint > Money) testint = Money;
  495. if(testint == LastValue) continue;
  496.  
  497. LastValue = testint;
  498.  
  499. IntToMoney( testint , dummy , sizeof(dummy) );
  500. IntToString( testint, dummy2, sizeof(dummy2) );
  501.  
  502. AddMenuItem(menu2, dummy2, dummy);
  503.  
  504. /*testint = StringToInt( MoneyCount[i] );
  505. if(testint > 0){
  506. IntToMoney( testint , dummy , 32);
  507. AddMenuItem(menu2, MoneyCount[i], dummy);
  508. }
  509. */
  510. }
  511.  
  512. IntToMoney( Money, dummy , sizeof(dummy) );
  513. IntToString( Money, dummy2, sizeof(dummy2) );
  514.  
  515. AddMenuItem(menu2, dummy2, dummy);
  516.  
  517.  
  518. //AddMenuItem(menu2, "all", "All");
  519. }
  520.  
  521. public DepositWithMenu(Handle:menu, MenuAction:action, client, param2)
  522. {
  523. if (!GetConVarInt(g_cvars[ALLOWBANK])){
  524. PrintToChat(client, "%t", "Bank Disabled", "\x04", "\x01");
  525. CloseHandle(menu);
  526. return;
  527. }
  528.  
  529. /* Either Select or Cancel will ALWAYS be sent! */
  530. if (action == MenuAction_Select)
  531. {
  532. new String:info[32];
  533. new bool:found = GetMenuItem(menu, param2, info, sizeof(info));
  534.  
  535. if(!found)
  536. return;
  537.  
  538. switch( LastMenuAction [ client ]){
  539. case 0: {
  540. DepositClientMoney( client, info );
  541. }
  542. case 1: {
  543. WithDrawClientMoney( client, info );
  544. }
  545. case 3:{
  546. if (!GetConVarInt(g_cvars[TRANSFER])){
  547. PrintToChat(client, "%t", "No Transfer", "\x04", "\x01");
  548. CloseHandle(menu);
  549. return;
  550. }
  551. TransferClientMoney( client, TargetClientMenu[ client ], info);
  552. }
  553. }
  554. } else if (action == MenuAction_End)
  555. {
  556. CloseHandle(menu);
  557. }
  558. }
  559.  
  560. public TransferMenu(Handle:menu, MenuAction:action, client, param2){
  561. if (!GetConVarInt(g_cvars[ALLOWBANK])){
  562. PrintToChat(client, "%t", "Bank Disabled", "\x04", "\x01");
  563. CloseHandle(menu);
  564. return;
  565. }
  566.  
  567. if (!GetConVarInt(g_cvars[TRANSFER])){
  568. PrintToChat(client, "%t", "No Transfer", "\x04", "\x01");
  569. CloseHandle(menu);
  570. return;
  571. }
  572.  
  573. /* Either Select or Cancel will ALWAYS be sent! */
  574. if (action == MenuAction_Select)
  575. {
  576. new String:info[32];
  577. if(!GetMenuItem(menu, param2, info, sizeof(info)))
  578. return;
  579.  
  580. TargetClientMenu[ client ] = StringToInt(info);
  581.  
  582. if(!IsClientConnected( TargetClientMenu[ client ] )){
  583. PrintToChat(client, "%t", "False Target", "\x04", "\x01");
  584. CloseHandle(menu);
  585. return;
  586. }
  587.  
  588.  
  589. GetClientName(TargetClientMenu[ client ] , info, sizeof(info));
  590.  
  591. new Handle:menu2 = CreateMenu(DepositWithMenu);
  592. SetMenuTitle(menu2, "Penz utalasa neki: %s", info);
  593.  
  594.  
  595. new targetmoney = GetBankMoney(TargetClientMenu[ client ]);
  596. new clientmoney = GetBankMoney(client);
  597. new maxmoney = GetConVarInt(g_cvars[MAXBANK]);
  598.  
  599. new maxmenu = maxmoney - targetmoney;
  600. if(maxmenu > clientmoney) maxmenu = clientmoney;
  601.  
  602.  
  603. AddMoneyItems(menu2, maxmenu);
  604.  
  605. DisplayMenu(menu2, client, 20);
  606.  
  607. } else if (action == MenuAction_End){
  608. CloseHandle(menu);
  609. }
  610. }
  611.  
  612. public Action:Deposit(client, args)
  613. {
  614. if (!GetConVarInt(g_cvars[ALLOWBANK])){
  615. PrintToChat(client, "%t", "Bank Disabled", "\x04", "\x01");
  616. return Plugin_Handled;
  617. }
  618.  
  619. if(args < 1)
  620. {
  621. PrintToChat(client, "%t", "Deposit usage", "\x04", "\x01");
  622. return Plugin_Handled;
  623. }
  624.  
  625. new String:szCmd[12];
  626. GetCmdArg(1, szCmd, sizeof(szCmd));
  627.  
  628. DepositClientMoney(client, szCmd);
  629.  
  630. return Plugin_Handled;
  631. }
  632.  
  633. public TransferClientMoney( client, target, String:amount[] ){
  634. if(!IsClientConnected(client))
  635. return;
  636. if(!IsClientConnected(target)){
  637. PrintToChat(client, "%t", "No Transfer", "\x04", "\x01");
  638. return;
  639. }
  640. if (!GetConVarInt(g_cvars[TRANSFER])){
  641. PrintToChat(client, "%t", "False Target", "\x04", "\x01");
  642. return;
  643. }
  644.  
  645. //LogMessage("Transfear: %d %d %s", client, target, amount);
  646.  
  647. new deposit,money, maxmoney, targetmoney;
  648.  
  649. money = GetBankMoney(client);
  650. targetmoney = GetBankMoney(target);
  651. maxmoney = GetConVarInt(g_cvars[MAXBANK]);
  652.  
  653. if(StrEqual(amount, "all"))
  654. deposit = money;
  655. else{
  656. deposit = StringToInt(amount);
  657. if(deposit > money){
  658. PrintToChat(client, "%t", "Deposit not enough money", "\x04", "\x01");
  659. return;
  660. }
  661. }
  662.  
  663. if(deposit == 0){ return; }
  664.  
  665. //LogMessage("Transfear2: %d %d %d %d", deposit,money, maxmoney, targetmoney);
  666.  
  667. //LogMessage("client: %d | Target: %d", client, target);
  668. //LogMessage("money: %d | targetmoney: %d | deposit: %d | maxmoney: %d", money, targetmoney, deposit, maxmoney);
  669.  
  670. new String:name[32], String:targetname[32], String:depositstr[12];
  671.  
  672. GetClientName(client , name, sizeof(name));
  673. GetClientName(target , targetname, sizeof(targetname));
  674.  
  675. /*if(maxmoney > 0 && (targetmoney + deposit) > maxmoney){
  676. deposit = maxmoney - targetmoney;
  677. if(deposit <= 0){
  678. PrintToChat(client, "%t" ,"TargetTotalLimit", "\x04", "\x01", targetname);
  679. return;
  680. }
  681. IntToMoney(deposit, depositstr, 12);
  682. PrintToChat(client, "%t" ,"TargetLimit", "\x04", "\x01", targetname, depositstr);
  683. }*/
  684.  
  685. targetmoney += deposit;
  686. money -= deposit;
  687.  
  688. if(maxmoney > 0){
  689. if(targetmoney > maxmoney ){
  690. new difference = targetmoney - maxmoney;
  691.  
  692. targetmoney = maxmoney;
  693.  
  694. money += difference;
  695. }else if(targetmoney == maxmoney ){
  696. PrintToChat(client, "%t" ,"TargetTotalLimit", "\x04", "\x01", targetname);
  697. return;
  698. }
  699. }
  700.  
  701. IntToMoney( GetBankMoney(client) - money ,depositstr, 12);
  702.  
  703. SetBankMoney(client, money);
  704. SetBankMoney(target, targetmoney);
  705.  
  706. PrintToChat(target, "%t", "TargetDeposited","\x04", "\x01", name, depositstr);
  707. PrintToChat(client, "%t", "ClientTargetDeposited","\x04", "\x01", targetname, depositstr);
  708. }
  709.  
  710. public DepositClientMoney(client, String:szCmd[]){
  711. new bankmoney, feemoney, maxmoney, money, deposit;
  712. decl String:feestr[12], String:depositstr[12];
  713.  
  714. money = GetMoney(client);
  715.  
  716. if(StrEqual(szCmd, "all"))
  717. deposit = money;
  718. else
  719. deposit = StringToInt(szCmd);
  720.  
  721. if(deposit > money){
  722. PrintToChat(client, "%t", "Deposit not enough money", "\x04", "\x01");
  723. return;
  724. }
  725.  
  726. bankmoney = GetBankMoney(client);
  727. feemoney = GetConVarInt(g_cvars[DEPOSITFEE]);
  728. maxmoney = GetConVarInt(g_cvars[MAXBANK]);
  729.  
  730. IntToMoney(feemoney, feestr, 12);
  731.  
  732. if(deposit < feemoney){
  733. PrintToChat(client, "%t", "You need at least", feestr ,"\x04", "\x01");
  734. return;
  735. }
  736.  
  737. deposit -= feemoney;
  738. bankmoney += deposit;
  739.  
  740. if(maxmoney > 0 && bankmoney > maxmoney){
  741. PrintToChat(client, "%t", "Bank Full", maxmoney, "\x04", "\x01");
  742. deposit = bankmoney - maxmoney;
  743. bankmoney = maxmoney;
  744. if(deposit == 0)
  745. return;
  746. }
  747.  
  748. SetBankMoney(client, bankmoney);
  749. SetMoney(client, money - deposit - feemoney);
  750.  
  751. //SetMoney(client, -deposit - feemoney + money);
  752. IntToMoney(deposit, depositstr, 12);
  753.  
  754.  
  755. PrintToChat(client, "%t", "Deposit successfully", depositstr, feestr ,"\x04", "\x01");
  756. }
  757.  
  758. public Action:WithDraw(client, args)
  759. {
  760. if (!GetConVarInt(g_cvars[ALLOWBANK])){
  761. PrintToChat(client, "%t", "Bank Disabled", "\x04", "\x01");
  762. return Plugin_Handled;
  763. }
  764.  
  765. if(args < 1)
  766. {
  767. PrintToChat(client, "%t", "Withdraw usage", "\x04", "\x01");
  768. }
  769.  
  770. new String:szCmd[12];
  771. GetCmdArg(1, szCmd, sizeof(szCmd));
  772.  
  773. WithDrawClientMoney(client, szCmd);
  774.  
  775. return Plugin_Handled;
  776. }
  777.  
  778. public WithDrawClientMoney(client, String:szCmd[]){
  779. if (GetConVarInt(g_cvars[PISTOLROUND]) == 1){
  780. if(IsPistolRound()){
  781. PrintToChat(client, "%t", "PistolRoundBlocked", "\x04", "\x01");
  782. return;
  783. }
  784. }
  785.  
  786. new getmoney = GetBankMoney(client);
  787. new AmountToWith;
  788. if(StrEqual(szCmd, "all"))
  789. {
  790. new iBalance = 16000 - GetMoney(client);
  791.  
  792. if(getmoney < iBalance)
  793. {
  794. AmountToWith = getmoney;
  795. }
  796. else
  797. {
  798. AmountToWith = iBalance;
  799. }
  800. }
  801. else
  802. {
  803. new iMoney = StringToInt(szCmd);
  804.  
  805. if(getmoney < iMoney)
  806. {
  807. PrintToChat(client, "%t", "Withdraw not enough money", "\x04", "\x01");
  808. return;
  809. }
  810.  
  811. if(GetMoney(client) + iMoney <= 16000)
  812. {
  813. AmountToWith = iMoney;
  814. }
  815. else
  816. {
  817. PrintToChat(client, "%t", "Withdraw max error", "\x04", "\x01");
  818. return;
  819. }
  820. }
  821.  
  822. SetMoney(client, AmountToWith, true);
  823. SetBankMoney(client, getmoney - AmountToWith);
  824.  
  825.  
  826. new String:WithStr[12];
  827. IntToMoney(AmountToWith, WithStr, 12);
  828.  
  829. PrintToChat(client, "%t", "Withdraw successfully", WithStr, "\x04", "\x01");
  830. }
  831.  
  832. public Action:BankStatus(client, args)
  833. {
  834. ShowBankStatus(client);
  835. return Plugin_Handled;
  836. }
  837.  
  838. stock ShowBankStatus(client){
  839. new String:WithStr[12];
  840. new money;
  841. money = GetBankMoney(client);
  842. IntToMoney( money , WithStr, 12);
  843. //PrintToChat(client, "%d -- %s", money, WithStr);
  844. PrintToChat(client, "%t", "Bankstatus", WithStr, "\x04", "\x01");
  845. }
  846.  
  847. stock SetMoney(client, amount, add = false){
  848. if(add)
  849. amount += GetMoney(client);
  850. if(amount > 16000) amount = 16000;
  851. if(amount < 0) amount = 0;
  852.  
  853. SetEntData(client,g_iAccount,amount,4,true);
  854. }
  855.  
  856. stock GetMoney(client){
  857. return GetEntData(client,g_iAccount,4);
  858. }
  859.  
  860. stock IntToMoney(theint, String:result[], maxlen){
  861. new slen, pointer, String:intstr[maxlen], bool:negative;
  862.  
  863. negative = theint < 0;
  864. if(negative) theint *= -1;
  865.  
  866. IntToString(theint, intstr, maxlen);
  867. slen = strlen(intstr);
  868.  
  869. theint = slen % 3;
  870. if(theint == 0) theint = 3;
  871. Format(result,theint + 1, "%s", intstr);
  872.  
  873. slen -= theint;
  874. pointer = theint + 1;
  875. for(new i = theint; i <= slen ; i += 3){
  876. pointer += 4;
  877. Format(result, pointer, "%s,%s",result, intstr[i]);
  878. }
  879.  
  880. if(negative)
  881. Format(result, maxlen, "$-%s", result);
  882. else
  883. Format(result, maxlen, "$%s", result);
  884. }
  885.  
  886. public OnClientAuthorized(id){
  887. IHateFloods[id] = true;
  888. }
  889.  
  890. stock bool:IsPistolRound(){
  891. new i, startmoney;
  892.  
  893. if( g_cvars[CSSTARTMONEY] != INVALID_HANDLE )
  894. startmoney = GetConVarInt( g_cvars[CSSTARTMONEY] );
  895. else
  896. startmoney = 800;
  897.  
  898.  
  899. for(i=1; i<=maxplayers; i++){
  900. if(IsClientInGame(i))
  901. if(GetMoney(i) > startmoney)
  902. return false;
  903. }
  904. return true;
  905. }
  906.