English Scripts useful for RP (money & cars)

44 replies
Goto Page
To the start Previous 1 2 3 Next To the start
Up
goweiwen
User
Offline Off
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.

Spoiler >


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 >
edited 2×, last 03.04.10 09:16:12 am
02.04.10 08:16:50 am
Up
LV
BANNED
Offline Off
woa thx
Lolz!
02.04.10 10:07:04 am
Up
Sleepin
User
Offline Off
Nice script weiwen,this will be helpful for lua scripters or servers.
IMG:http://www.avatarsdb.com/avatars/gatling_gun.gif
Gattling Gun
02.04.10 12:20:41 pm
Up
DrPyromatic
User
Offline Off
The Car script is so AWESOME!!!But why i get Money when i buy the car lol?
03.04.10 03:55:18 am
Up
Sleepin
User
Offline Off
I got bad argument #1 to pairs on Car script,can you fix it weiwen?
IMG:http://www.avatarsdb.com/avatars/gatling_gun.gif
Gattling Gun
03.04.10 05:02:15 am
Up
goweiwen
User
Offline Off
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.
03.04.10 05:42:45 am
Up
Flacko
User
Offline Off
Code:
1
for id, car in pairs(CARS) do

Maybe you should use ipairs instead?
03.04.10 07:40:33 am
Up
Sleepin
User
Offline Off
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)
IMG:http://www.avatarsdb.com/avatars/gatling_gun.gif
Gattling Gun
03.04.10 09:15:14 am
Up
goweiwen
User
Offline Off
@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.
03.04.10 09:30:01 am
Up
Sleepin
User
Offline Off
Now its stuck on line 40 attempt to index globel 'PLAYERS' (a nil value)....
IMG:http://www.avatarsdb.com/avatars/gatling_gun.gif
Gattling Gun
03.04.10 11:25:04 am
Up
Flacko
User
Offline Off
weiwen has written:
@Flacko
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...
03.04.10 04:20:41 pm
Up
goweiwen
User
Offline Off
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
03.04.10 11:39:59 pm
Up
Flacko
User
Offline Off
Lol, seems like the for loop wins by fatality
Nice link, btw.
20.04.10 05:26:21 pm
Up
Szkieletor
User
Offline Off
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)
Code:
1
2
3
4
addhook ("minute", "RPminute")
function RPminute()
          addmoney (id, 1000)
end
20.04.10 08:50:53 pm
Up
Jermuk
User
Offline Off
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
20.04.10 09:09:37 pm
Up
Flacko
User
Offline Off
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.


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
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
21.04.10 01:57:32 pm
Up
Szkieletor
User
Offline Off
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.
Spoiler >
22.04.10 08:59:53 am
Up
goweiwen
User
Offline Off
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.

Code:
1
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

Remove the comment if you want it to tell everyone that it is payday.
22.04.10 10:16:52 am
Up
Flacko
User
Offline Off
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)
22.04.10 10:55:07 am
Up
goweiwen
User
Offline Off
Right.
Add this at the top of the script, then.
Code:
1
local addmoney = addmoney
To the start Previous 1 2 3 Next To the start