Forum

> > CS2D > Scripts > Scripts useful for RP (money & cars)
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Scripts useful for RP (money & cars)

44 Antworten
Seite
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang

verschoben Scripts useful for RP (money & cars)

goweiwen
User Off Offline

Zitieren
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 >
2× editiert, zuletzt 03.04.10 09:16:12

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

goweiwen
User Off Offline

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

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

goweiwen
User Off Offline

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

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

Flacko
User Off Offline

Zitieren
weiwen hat geschrieben
@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...

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

Szkieletor
User Off Offline

Zitieren
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

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

Jermuk
User Off Offline

Zitieren
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

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

Flacko
User Off Offline

Zitieren
Jermuk hat geschrieben
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

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

Szkieletor
User Off Offline

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

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

goweiwen
User Off Offline

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

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

Flacko
User Off Offline

Zitieren
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)
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht