Raised This Month: $ Target: $400
 0% 

[HELP] Bank on map change small amount of money is disappearing!


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Stranged
Junior Member
Join Date: May 2015
Old 05-30-2015 , 17:57   [HELP] Bank on map change small amount of money is disappearing!
Reply With Quote #1

Hello Scripters!
I'm back with another request/help for bank plugin.
So the problem is that if I change the map and if I have 35,000$ in the bank before I change the map, after I change it, I will have 20,000$ - I've been thinking for some hours now that the problem is that I need to put 'public plugin_end()' but I still don't realize how to make it work.
Here's the whole plugin:
Code:
/*
*   _______     _      _  __          __
*  | _____/    | |    | | \ \   __   / /
*  | |         | |    | |  | | /  \ | |
*  | |         | |____| |  | |/ __ \| |
*  | |   ___   | ______ |  |   /  \   |
*  | |  |_  |  | |    | |  |  /    \  |
*  | |    | |  | |    | |  | |      | |
*  | |____| |  | |    | |  | |      | |
*  |_______/   |_|    |_|  \_/      \_/
*
*
*
*  Last Edited: 12-31-07
*
*  ============
*   Changelog:
*  ============
*
*  v2.1
*    -Changed Bank to keep the balance @ 16,000
*
*  v2.0
*    -Added ML
*
*  v1.5
*    -Optimized Reading/Writing Files
*
*  v1.2
*    -Misc. Bug Fixes
*
*  v1.0
*    -Initial Release
*
*/

#define VERSION	"2.1"

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

new bank[33]
new configfile[200]
new pcvar
new szIP[40];

public plugin_init()
{
	register_plugin("Simple CS Bank",VERSION,"GHW_Chronic")
	pcvar = register_cvar("bank_save","1")
	
	new configsdir[200]
	get_configsdir(configsdir,199)
	format(configfile,199,"%s/cs_bank.ini",configsdir)

	register_dictionary("GHW_CS_Bank.txt")
}

public client_putinserver(id)
{
	if(!is_user_bot(id)) set_task(5.0,"client_authorized2",id)
}

public client_authorized2(id)
{
	bank[id] = 0
	if(get_pcvar_num(pcvar))
		set_task(10.0,"read_file2",id)
	set_task(0.1,"cpt",id,"",0,"b")
}

public client_disconnect(id)
{
	if(!is_user_bot(id) && get_pcvar_num(pcvar))
		save_money(id)
}

public plugin_end()
{
	// Here Help Please xD
}

public cpt(id)
{
	if(is_user_alive(id))
	{
		if(cs_get_user_money(id)>16000)
		{
			bank[id]+= cs_get_user_money(id) - 16000
			cs_set_user_money(id,16000)
		}
		if(cs_get_user_money(id)<16000)
		{
			if(bank[id] < 16000 - cs_get_user_money(id))
			{
				cs_set_user_money(id,cs_get_user_money(id)+bank[id])
				bank[id]=0
			}
			else
			{
				bank[id]-=  16000 - cs_get_user_money(id)
				cs_set_user_money(id,16000)
			}
		}
		set_hudmessage(0, 255, 0, 0.7, 0.87, 0, 6.0, 0.1, 0.1, 0.2, next_hudchannel(id) )
		show_hudmessage(id,"%L",id,"MSG_BANK",bank[id])
	}
}

public read_file2(id)
{
	if(is_user_connected(id) && file_exists(configfile))
	{
		new read[32]
		get_user_ip(id, szIP, charsmax(szIP) , 1 ); // Get player's IP
		new filepointer = fopen(configfile,"r")
		while(fgets(filepointer,read,31))
		{
			replace(read,31,"^n","")
			if(equali(read,szIP))
			{
				fgets(filepointer,read,31)
				if(cs_get_user_money(id)<16000)
				{
					if(cs_get_user_money(id) + str_to_num(read)<=16000)
					{
						cs_set_user_money(id,cs_get_user_money(id) + str_to_num(read))
					}
					if(cs_get_user_money(id) + str_to_num(read)>16000)
					{
						bank[id] += (str_to_num(read) + cs_get_user_money(id)) - 16000
						cs_set_user_money(id,16000)
					}
				}
				else
				{
					bank[id] += str_to_num(read)
				}
				break;
				
			}
		}
		fclose(filepointer)
	}
}

public save_money(id)
{
	new string[32]
	get_user_ip(id, szIP, charsmax(szIP) , 1 ); // Get player's IP
	format(string,31,"%d",bank[id])
	new i, line
	new filepointer = fopen(configfile,"r")
	if(filepointer)
	{
		new read[32]
		while(fgets(filepointer,read,31))
		{
			replace(read,31,"^n","")
			server_print("%d. %s",i,read)
			if(equali(read,szIP))
			{
				line=1
				break;
			}
			i++
		}
	}
	fclose(filepointer)
	if(!line) write_file(configfile,szIP,i)
	write_file(configfile,string,i+1)
}
Stranged is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode