Forum

> > CS2D > Scripts > Scripts useful for RP (money & cars)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Scripts useful for RP (money & cars)

44 replies
Page
To the start Previous 1 2 3 Next To the start

moved Scripts useful for RP (money & cars)

goweiwen
User Off Offline

Quote
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

old Re: Scripts useful for RP (money & cars)

goweiwen
User Off Offline

Quote
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.

old Re: Scripts useful for RP (money & cars)

goweiwen
User Off Offline

Quote
@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.

old Re: Scripts useful for RP (money & cars)

Flacko
User Off Offline

Quote
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...

old Re: Scripts useful for RP (money & cars)

Szkieletor
User Off Offline

Quote
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)
1
2
3
4
addhook ("minute", "RPminute")
function RPminute()
		addmoney (id, 1000)
end

old Re: Scripts useful for RP (money & cars)

Jermuk
User Off Offline

Quote
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

old Re: Scripts useful for RP (money & cars)

Flacko
User Off Offline

Quote
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.
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

old Re: Scripts useful for RP (money & cars)

Szkieletor
User Off Offline

Quote
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 >

old Re: Scripts useful for RP (money & cars)

goweiwen
User Off Offline

Quote
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.

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.

old Re: Scripts useful for RP (money & cars)

Flacko
User Off Offline

Quote
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)
To the start Previous 1 2 3 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview