Change dir to where you want to save the players' stats.
Use the function addmoney(id, amount) to add/remove money, just negate the amount if you want to remove. If you try to remove an amount that the player doesn't have, it doesn't remove at all and returns false.
Use getmoney(id) to get the player's money.
Spoiler 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
local dir = "sys/lua/saves/"
PLAYERS = {}
function addmoney(id, amount)
	if PLAYERS[id].money + amount >= 0 then
		parse(string.format("setmoney %i 0", id))
		PLAYERS[id].money = PLAYERS[id].money + amount
		parse(string.format("hudtxt2 %i 49 \"©255100100Money : %i\" 0 100", id, PLAYERS[id].money))
		return true
	end
	return false
end
function getmoney(id)
	return PLAYERS[id].money
end
addhook("join", "RPjoin")
function RPjoin(id)
	local playerfile = io.open(dir..player(id,"usgn")..".txt","r")
	if playerfile then
		PLAYERS[id] = {}
		for v in playerfile:lines() do
			local find = v:find"="
			key = v:sub(1,find-1)
			key = tonumber(key) or key
			val = v:sub(find+1)
			val = tonumber(val) or val
			PLAYERS[id][key] = val
		end
		playerfile:close()
	else
		PLAYERS[id] = {
			money = 0,
		}
	end
end
addhook("second", "RPsecond")
function RPsecond()
	for _, id in ipairs(player(0, "table")) do
		parse(string.format("setmoney %i 0", id))
		if PLAYERS[id] then
			parse(string.format("hudtxt2 %i 49 \"Money : %i\" 0 0", id, PLAYERS[id].money))
		end
	end
end
addhook("leave", "RPleave")
function RPleave(id)
	if PLAYERS[id] and player(id,"usgn") ~= 0 then
		local playerfile = io.open(dir .. player(id,"usgn") .. ".txt","w+") or io.tmpfile()
		local text = ""
		for i, v in pairs(PLAYERS[id]) do
			text = text .. i .. "=" .. tostring(v) .. "\n"
		end
		text = text:sub(1,-2)
		playerfile:write(text)
		playerfile:close()
	end
	PLAYERS[id] = nil
end
addhook("collect", "RPcollect")
function RPcollect(id,iid,type,ain,a,mode)
	if type == 66 then
		addmoney(id, 100)
	elseif type == 67 then
		addmoney(id, 1000)
	elseif type == 68 then
		addmoney(id, 10000)
	end
end
addhook("menu", "RPmenu")
function RPmenu(id, title, button)
	if title == "Drop Money" then
		if button == 0 then
			return
		end
		menu(id, "Drop Money,10,500,1000,5000,10000,50000,100000")
		if button == 1 then
			if addmoney(id, -100) then
				parse(string.format("spawnitem 66 %i %i", player(id, "tilex"), player(id, "tiley")))
			end
		elseif button == 2 then
			if addmoney(id, -500) then
				local spawn = string.format("spawnitem 66 %i %i", player(id, "tilex"), player(id, "tiley"))
				for i = 1, 5 do
					parse(spawn)
				end
			end
		elseif button == 3 then
			if addmoney(id, -1000) then
				parse(string.format("spawnitem 67 %i %i", player(id, "tilex"), player(id, "tiley")))
			end
		elseif button == 4 then
			if addmoney(id, -5000) then
				local spawn = string.format("spawnitem 67 %i %i", player(id, "tilex"), player(id, "tiley"))
				for i = 1, 5 do
					parse(spawn)
				end
			end
		elseif button == 5 then
			if addmoney(id, -10000) then
				parse(string.format("spawnitem 68 %i %i", player(id, "tilex"), player(id, "tiley")))
			end
		elseif button == 6 then
			if addmoney(id, -50000) then
				local spawn = string.format("spawnitem 68 %i %i", player(id, "tilex"), player(id, "tiley"))
				for i = 1, 5 do
					parse(spawn)
				end
			end
		elseif button == 7 then
			if addmoney(id, -100000) then
				local spawn = string.format("spawnitem 68 %i %i", player(id, "tilex"), player(id, "tiley"))
				for i = 1, 10 do
					parse(spawn)
				end
			end
		end
	end
end
addhook("serveraction", "RPserveraction")
function RPserveraction(id,action)
	if action == 2 then
		menu(id, "Drop Money,10,500,1000,5000,10000,50000,100000")
	end
end
addhook("movetile", "RPmovetile")
function RPmovetile(id,x,y)
	if PLAYERS[id].x and PLAYERS[id].y and entity(x, y, "typename") ~= "Info_T" and entity(x, y, "typename") ~= "Info_CT" then
		PLAYERS[id].x, PLAYERS[id].y = x, y
	end
end
addhook("spawn", "RPspawn")
function RPspawn(id)
	if PLAYERS[id].x and PLAYERS[id].y then
		parse(string.format("setpos %i %i %i", id, PLAYERS[id].x*32+16, PLAYERS[id].y*32+16))
	end
	return ""
end
addhook("die", "RPdie")
function RPdie(victim,killer,weapon,x,y)
	PLAYERS[victim].x, PLAYERS[victim].y = nil, nil
end
This other script is a car script. Nothing special, but can be implemented into other scripts easily.
Use Use to enter the car, default E. (pun intended)
There is a command, !car, that allows you to buy cars, compatible with the above script. CARS_PRICE is the price of buying a car.
As before, edit CARS_IMAGEPATH for the image path of the car. I'm not going to provide you with one, use Google if you don't have any.
CARS_MAXSPEED is the top speed of cars, in pixels/100ms.
If you want to use this script in yours, you can use the function addcar(x, y), in pixels, to create cars and comment out the say hook.
Spoiler 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
CARS = {}
CARS_MAXSPEED = 25
CARS_ACCELERATION = function(speed) return speed/2 + 1 end
CARS_DECELERATION = function(speed) return -speed/2 - 1 end
CARS_IMAGEPATH = "gfx/weiwen/car.png"
CARS_PRICE = 10000
if not addmoney then
	function addmoney(id, amount)
		if player(id, 'money') >= amount then
			parse(string.format("setmoney %i %i", id, player(id, 'money') - amount))
			return true
		end
		return false
	end
end
function addcar(x, y)
	table.insert(CARS, {x = x, y = y, speed = 0, image = image(CARS_IMAGEPATH, x, y, 0), rot = 0})
end
function carpos(car, x, y)
	local tilex, tiley = math.floor(car.x/32), math.floor(car.y/32)
	if not tile(tilex, tiley, 'walkable') then
		return false
	end
	for _, id in ipairs(player(0, 'table')) do
		if car.driver and car.driver ~= id and player(id, 'health') > 0 and math.abs(x - player(id, 'x')) < 16 and math.abs(y - player(id, 'y')) < 16 then
			parse(string.format("customkill %i Car %i", car.driver, id))
		end
	end
	car.x, car.y = x, y
	if car.driver then
		parse(string.format("setpos %i %i %i", car.driver, x, y))
	else
		imagepos(car.image, x, y, car.rot)
	end
	return true
end
addhook("ms100", "CARms100")
function CARms100()
	for id, car in pairs(CARS) do
		if car.driver then
			if not player(car.driver, 'exists') or player(car.driver, 'health') <= 0 then
				car.driver = nil
				car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
			else
				car.rot = player(car.driver, 'rot')
				car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_ACCELERATION(car.speed))
			end
		elseif car.speed > 0 then
			car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
		end
		if car.speed > 0 then
			local rot = math.rad(car.rot - 180)
			if not carpos(car, car.x - math.sin(rot)*car.speed, car.y + math.cos(rot)*car.speed) then
				if car.driver then
					parse(string.format("customkill %i Car %i", car.driver, car.driver))
				end
				freeimage(car.image)
				parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver or 0))
				parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
				CARS[id] = nil
			end
		end
	end
end
addhook("use", "CARuse")
function CARuse(id,event,data,x,y)
	x, y = player(id, 'x'), player(id, 'y')
	for _, car in pairs(CARS) do
		if not car.driver and math.abs(car.x - x) < 32 and math.abs(car.y - y) < 32 then
			car.speedmod = player(id, 'speedmod')
			parse(string.format("speedmod %i 0", id))
			car.driver = id
			freeimage(car.image)
			car.image = image(CARS_IMAGEPATH, 1, 0, 200+id)
			 break
		elseif car.driver == id then
			parse(string.format("speedmod %i %i", id, car.speedmod))
			car.driver = nil
			freeimage(car.image)
			car.image = image(CARS_IMAGEPATH, player(id, 'x'), player(id, 'y'), 0)
			 break
		end
	end
end
addhook("die", "CARdie")
function CARdie(id,killer,weapon,x,y)
	x, y = player(id, 'tilex'), player(id, 'tiley')
	for id, car in pairs(CARS) do
		if car.driver == id then
			freeimage(car.image)
			parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver))
			parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
			CARS[id] = nil
			 break
		end
	end
end
local bought, nomoney = "You have bought a car for $" .. CARS_PRICE .. ".", "You do not have enough money to buy a car. ($" .. CARS_PRICE .. ")"
addhook("say", "CARsay")
function CARsay(id,message)
	if message == "!car" then
		if addmoney(id, -CARS_PRICE) then
			addcar(player(id, 'x'), player(id, 'y'))
			msg2(id, bought)
		else
			msg2(id, nomoney)
		end
		return 1
	end
end
edited 2×, last 03.04.10 07:16:12 am
Scripts useful for RP (money & cars)
1 
Scripts useful for RP (money & cars)
Offline
