Forum
Scripts
Give Money script
Give Money script
17 replies
1

i feel stupid now.
edited 2×, last 07.02.16 09:41:56 pm
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
seconds = 3 -- You can change this if you wish
addhook("second", "_second")
function _second()
	local playerlist = player(0,"tableliving")
	for _, id in pairs(playerlist) do
		if player(id,"money") == 0 then
			timer(seconds*1000, "parse", "setmoney "..id.." 16000")
		end
	end
end
edited 2×, last 07.02.16 09:43:04 pm
File does not exist (10521) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
spawn_money = true
spawnmoney =
{
[1] = game("mp_startmoney");
[2] = 16000;
}
spawn_money_type = 2
spawn_money = true
addhook("spawn", "_s")
function _s(id)
	if spawn_money then
		parse("setmoney "..id.." "..spawnmoney[spawn_money_type])
	end
end
--[[
1 for set money
2 for 16000 money, you may also set it to any value you like.
If you want normal money, set spawn_money to false.
]]
edited 1×, last 08.02.16 07:22:15 am
TopNotch's code will loop at every second and iterate through living players, if player with given id has 0 on money then
timer will be created and will trigger
parse after 3 seconds. But
timer will be recreated again around 2-3 times (he's using
second hook) because player with given id still has 0 on money until 3 seconds passed. I can't confirm that my prediction is right. Here's a fix from me:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local togive = {}
for id = 1, 32 do
	togive[id] = false
end
function givemoney(id)
	id = tonumber(id)
	togive[id] = false
	
	parse("setmoney " .. id .. " 16000")
end
function alwayshook()
	for index, id in ipairs(player(0, "tableliving")) do
		if (player(id, "money") == 0 and not togive[id]) then
			togive[id] = true
			
			timer(3000, "givemoney", id)
		end
	end
end
addhook("always", "alwayshook")
edited 1×, last 08.02.16 08:31:03 am
Dousea: You are right, but, line 11 will cause a bug.
Dousea:
TopNotch is right at this point. You've forgot another double quote to finish the string. In this case, this should be like this:1
parse("setmoney " .. id .. " 16000")
Gaios: The reason why @
Dousea put the always hook is to make it interactive and concurrent.So by the spawn hook, it will not give 16000 immediately if the player's money is 0, unless he re-spawned again.
THEMUD: we always can make buy hook with timer.
Gaios: I appreciate your approach, but there are too many ways a player can spend or lose money. Most buggy is the "setmoney" command issued by other scripts.@
Dousea: yet I can't justify the use of
always. If you care so much about ±1s time delay, why don't use
ms100 instead, where it would be nearly insignificant?
VADemon: Sure, you can use
ms100 and even
second.This time it will only create
timer when using command
setmoney and buying if you care so much about performance impact or anything else. Can't guarantee it will work. Make sure this script is loaded first before any other scripts.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
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
local togive = {}
local oldparse = parse
for id = 1, 32 do
	togive[id] = false
end
function givemoney(id)
	id = tonumber(id)
	togive[id] = false
	
	parse("setmoney " .. id .. " 16000")
end
function checkmoney(id)
	if (player(id, "money") == 0 and not togive[id]) then
		togive[id] = true
		
		timer(3000, "givemoney", id)
	end
end
function buyhook(id)
	checkmoney(id)
end
function string:split(delimiter)
	local strs = {}
	
	for index, str in string:gmatch("[^" .. delimiter .. "]+") do
		strs[#strs + 1] = str
	end
	
	return strs
end
function parse(commands, stop)
	if (stop == 0 and commands:find(";")) then
		for index, str in ipairs(commands:split(";")) do
			local starts, ends = str:find("setmoney")
			
			if (starts and ends) then
				checkmoney(tonumber(str:split("%s")[2]))
			end
		end
	else
		local starts, ends = commands:find("setmoney")
		
		if (starts and ends) then
			checkmoney(tonumber(commands:split("%s")[2]))
		end
	end
	
	return oldparse(commands, stop)
end
addhook("buy", "buyhook")
edited 2×, last 09.02.16 06:07:29 am
Dousea: Yet Lua triggers a problem with this script because in 12 line you haven't finished the string by completing the last double quote.
GeoB99: Same error again? Fu*k. Thanks. 1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
valuemoney = 16000
minmoney = 0
function OnSpawn(id)
	if player(id,'money') <= minmoney then
		parse("setmoney "..id.." "..valuemoney.."")
	end
end
addhook("spawn","OnSpawn")
Paulo49: 1
parse("setmoney "..id.." "..valuemoney.."")
Dousea's code is quite more efficiently in comparison than yours.
GeoB99: custom 1
"..variable.." == "..variable
is my custom
1

Offline