Forum

> > CS2D > Scripts > savesystem
Forums overviewCS2D overview Scripts overviewLog in to reply

English savesystem

9 replies
To the start Previous 1 Next To the start

old savesystem

Ghost-Rider
BANNED Off Offline

Quote
Possible to save position into file and load when jo rejoin to server?

old Re: savesystem

Alistaire
User Off Offline

Quote
Yes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pos = {}

addhook('join', 'AA_join')
addhook('leave', 'AA_leave')
addhook('spawn', 'AA_spawn')

function AA_join(id)
	if io.open('sys/lua/saves/pos'..player(id, 'usgn')..'.lua') then
		dofile('sys/lua/saves/pos'..player(id, 'usgn')..'.lua')
		os.remove('sys/lua/saves/pos'..player(id, 'usgn')..'.lua')
	end
end

function AA_leave(id)
	local file = io.open('sys/lua/saves/pos'..player(id, 'usgn')..'.lua', 'w')
	file:write('pos['..player(id, 'usgn')..'] = {'..player(id, 'x')..','..player(id, 'y')..'}')
end

function AA_spawn(id)
	if io.open('sys/lua/saves/pos'..player(id, 'usgn')..'.lua') then
		parse('setpos '..id..' '..pos[player(id, 'usgn')][1]..' '..pos[player(id, 'usgn')][2])
	end
end
edited 5×, last 12.07.12 11:06:34 am

old Re: savesystem

Xavis
User Off Offline

Quote
is possible tht if u kill player thn player respawns in same pos like he died ?

old Re: savesystem

Alistaire
User Off Offline

Quote
user Xavis has written
is possible tht if u kill player thn player respawns in same pos like he died ?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sppos = {}
for i = 1, 32 do sppos[i] = {0, 0} end

addhook('kill', 'AA_kill')
addhook('spawn', 'AA_spawn')

function AA_kill(id, victim)
	sppos[victim][1] = player(victim, 'x')
	sppos[victim][2] = player(victim, 'y')
end

function AA_spawn(id)
	if sppos[id][1] and sppos[id][2] then
		parse('setpos '..id..' '..sppos[id][1]..' '..sppos[id][2])
	end
end
edited 1×, last 12.07.12 11:06:18 am

old Re: savesystem

Yates
Reviewer Off Offline

Quote
Alistaire has written
1
addhook('spawn' 'AA_spawn')


You forgot a comma there.

old Re: savesystem

hancocok
User Off Offline

Quote
can you make a script for me that use for saving a rank or save level and exp for offline playing
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview