Give Money script
17 replies



Code:
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
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
Here you go.
edited 2×, last 07.02.16 10:43:04 pm
Code:
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.
]]
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 08:22:15 am
Talented Doge





Code:
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")
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 09:31:03 am
I'm awesome ... and I really like cookies.
Why do you use always hook? This hook is created for local gameplay.Set money by spawn hook is the best in this problem.
@
Gaios: The reason why @
Ortimh 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.


So by the spawn hook, it will not give 16000 immediately if the player's money is 0, unless he re-spawned again.
I don't know what I'm doing with my life.
@
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.
@
Ortimh: 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.



This time it will only create


Code:
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")
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 07:07:29 am
I'm awesome ... and I really like cookies.
@
Ortimh: Yet Lua triggers a problem with this script because in 12 line you haven't finished the string by completing the last double quote.

Code:
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")
minmoney = 0
function OnSpawn(id)
if player(id,'money') <= minmoney then
parse("setmoney "..id.." "..valuemoney.."")
end
end
addhook("spawn","OnSpawn")
Paulo Henrique
@
Paulo49:
On 8 line, even though Lua will not recognize any issue but the last two double quotes are useless because you already defined a certain value of how much money should be given to players by valuemoney character in the string. Also, it'd be appreciated if you could refrain at posting codes without reading thread posts.
Ortimh's code is quite more efficiently in comparison than yours.

Code:
1
parse("setmoney "..id.." "..valuemoney.."")
On 8 line, even though Lua will not recognize any issue but the last two double quotes are useless because you already defined a certain value of how much money should be given to players by valuemoney character in the string. Also, it'd be appreciated if you could refrain at posting codes without reading thread posts.




