Scripts useful for RP (money & cars)
44 replies31.03.10 03:54:35 pm
This is a script to save money & player's location, also allows players to have any finite amount of money.
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.
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.
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.
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.
edited 2×, last 03.04.10 09:16:12 am
I don't know where that error came from. Do you have any script that overrides the CARS variable by any chance? If not, try using the updated script, at the first post.
Yep,its fixed but it GIVES you money........ How do you fix it???
EDIT:Now money script doesnt work. it says attempt to index field ? (a nil value)
EDIT:Now money script doesnt work. it says attempt to index field ? (a nil value)


@Flacko
Nope, when cars get destroyed, it creates a hole in the table, so I just use pairs instead.
@banana200000
You need to use it on a dedicated server, it's not going to work if you just run it with a listen server because it uses the join hook. I'm not sure how to get around that.
oops, i realised that the indentation is gone, going to update it again.
Nope, when cars get destroyed, it creates a hole in the table, so I just use pairs instead.
@banana200000
You need to use it on a dedicated server, it's not going to work if you just run it with a listen server because it uses the join hook. I'm not sure how to get around that.
oops, i realised that the indentation is gone, going to update it again.
weiwen has written:
@Flacko
Nope, when cars get destroyed, it creates a hole in the table, so I just use pairs instead.
Nope, when cars get destroyed, it creates a hole in the table, so I just use pairs instead.
table.remove?
Maybe it could improve the perfomance...
I had actually wanted to recognise the cars by IDs, but I think I didn't in the end. Anyway, the speed of ipairs is roughly the same as pairs, if I benchmarked them correctly.
edit:
researched a bit, http://www.facepunch.com/showthread.php?p=19526763
edit:
researched a bit, http://www.facepunch.com/showthread.php?p=19526763
I want every minute each player on server to get +1000$. I tried to code it myself, but I'm not a scripter... Can you help me with this code? It just don't work.
I put this after hook second(after end of all belonging to that hook)
I put this after hook second(after end of all belonging to that hook)
Code:
1
2
3
4
2
3
4
addhook ("minute", "RPminute")
function RPminute()
addmoney (id, 1000)
end
function RPminute()
addmoney (id, 1000)
end
What is id?
You should change it, because there are lots of hooks with parameter "id".
If you want, that everyone gets 1000$ a minute its better to use Global Arrays and connect/disconnect hooks or what is not good programming style, with a for-loop. Start with 1 and count to 32, but this is really bad programming style.
I hope this helped you!
Jermuk aka Dönarmaster
You should change it, because there are lots of hooks with parameter "id".
If you want, that everyone gets 1000$ a minute its better to use Global Arrays and connect/disconnect hooks or what is not good programming style, with a for-loop. Start with 1 and count to 32, but this is really bad programming style.
I hope this helped you!
Jermuk aka Dönarmaster
Jermuk has written:
What is id?
You should change it, because there are lots of hooks with parameter "id".
If you want, that everyone gets 1000$ a minute its better to use Global Arrays and connect/disconnect hooks or what is not good programming style, with a for-loop. Start with 1 and count to 32, but this is really bad programming style.
You should change it, because there are lots of hooks with parameter "id".
If you want, that everyone gets 1000$ a minute its better to use Global Arrays and connect/disconnect hooks or what is not good programming style, with a for-loop. Start with 1 and count to 32, but this is really bad programming style.
Lol?

Global arrays and fucking with hooks just for giving every player 1000$ per minute?
You obviously have to use a loop.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook("minute","asd")
function asd()
local p = function(id)
if player(id,"exists") then return true end
return nil
end
local give = function(id,ammount)
local cash = player(id,"money")
parse("setmoney "..id.." "..(cash+ammount))
end
for id=1,32 do
if p(id) then
give(id,1000)
end
end
end
function asd()
local p = function(id)
if player(id,"exists") then return true end
return nil
end
local give = function(id,ammount)
local cash = player(id,"money")
parse("setmoney "..id.." "..(cash+ammount))
end
for id=1,32 do
if p(id) then
give(id,1000)
end
end
end
I slightly modified it to be compatible with script above(I posted it here to get script compatible with one above, otherwise it should be in Lua scripts help thread) and it works. Thanks.
Flacko did it right but he wanted to do it with the money system I made.
It can be optimised a lot, too.
You can use the function player(0, 'table') to get a table with all the player ids. player(id, 'exists') also return true/false (iirc) so you do not need a new function to do it.
Remove the comment if you want it to tell everyone that it is payday.
It can be optimised a lot, too.
You can use the function player(0, 'table') to get a table with all the player ids. player(id, 'exists') also return true/false (iirc) so you do not need a new function to do it.
Code:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
addhook("minute","RPminute")
function RPminute()
for _, id in ipairs(player(0, 'table') do
if not player(id, 'idle') then
addmoney(id, 1000)
end
end
--msg('Payday! Everyone gets $1000')
end
function RPminute()
for _, id in ipairs(player(0, 'table') do
if not player(id, 'idle') then
addmoney(id, 1000)
end
end
--msg('Payday! Everyone gets $1000')
end
Remove the comment if you want it to tell everyone that it is payday.
You should make a local copy of your addmoney function since "getglobal'ing" it would waste some time, especially when you know that you will call it more than one time (loop)