Forum
CS2D Scripts Save SystemSave System
21 replieshttp://unrealsoftware.de/forum_posts.php?post=380757#jn
Check this post for details.
Remember for that you even need to have a advanced muting system.
With multi variable saving you can save many things like.
Money
Death
Kills
Mute Timer
Ban Timer
Etc.
This is how you save/load money:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Money = {} for id = 1,32 do 	Money[id] = 0 end addhook("join","loadm") function loadm(id) 	if (player(id,"usgn") ~= 0) then 		local file = ("directory/"..player(id,"usgn")..".txt","r") 		if file then 			Money[id] = file:read("*n") 			movevariable[id] = file:read("*n") 			movevariable2[id] = file:read("*n") 			file:close() 		end 	else 		-- put parse for player with no USGN 	end end addhook("leave","savem") function savem(id) 	if (player(id,"usgn") ~= 0) then 		local file = ("directory/"..player(id,"usgn")..".txt","w") 		file:write(Money[id].."/n"..morevariable[id].."/n"..morevariable2[id]..) 		file:close(id) 	end end
P/S: I will lookup how the muting timing works, or someone will answer that for you
When a player verifies server on joining,it will not trigger the join hook so player's money will be 0,and if player leave itself while veryfying it will be treated as leaving and therefore his money will be set to 0.
Solution is dont use player(id'usgn') instead set a particular variable for it.
edited 1×, last 15.11.14 05:00:21 pm
@ Ace Howl: something like player(id,"money"). Anyways I found out how to do it, thanks.
the error is if player joined the server.
His money will be 0 or default untill he spawn.
Before spawn if he leave then his money will be set to 0 or the default amount.
Cuz when player leaves it saves.
@ G3tWr3ck3d: Here is a code which can help u.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
money={} muted={} usgn={} addhook('join,'joiner') joiner(id) usgn[id]=player(id,'usgn') money[id]=100 load(id) end function load(id) if usgn[id]>0 then ---load script here---- end end function save(id) if usgn[id]>0 then ----never use player(id,'usgn') here surely leads to bug!! ---save script here--- --------- end end end addhook('leave',leaver') function leaver(id) save(id) end
edited 1×, last 15.11.14 01:22:13 pm
edited 1×, last 15.11.14 01:26:29 pm
(after loading)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
-------- loaded={} function load(id) loaded[id]=1 --- end function save(id) if loaded[id]==1 then ------- end end
edited 1×, last 15.11.14 01:33:50 pm
Ofcourse its possible in my view.
@ Ace Howl: its too easy to do that.
I think he can do it.
player(id,'money')=player(id,'money')+money[id]
edited 1×, last 15.11.14 01:55:00 pm
But join hook doesnt play any role here but "leave" hook.
The join hook doesnt trigger correctly when player verifies the server.
But leave hook triggers also when player leaves while verifying.
I can give u a example try making a public msg when player join and leave.
when u verifies the server the join msg dnt appears,but if u leave then leave msg appears.
Leave msg appears without join msg
If u use "..usgn.." string(or anything else) it will be better the script will parse one by one.
@ Yates: you also has a point.
@ Ajmin: About you last post join hook does its job correctly and leave also.And you can never see the leave msg because you will be out of server and the function will be triggered.
@ Ace Howl: I posted your same topic in my 1st post lol.
@ G3tWr3ck3d: Thanks and hope it helped a lot.
@ Joni And Friends: or @ Ajmin: good idea about spawn but remember the function of loading should end as soon as a he spawn once.And save should be on through out.
Normally I use Join(Loading),Leave(Saving)& die(saving).
Join and leave hook with the solution is cool.
Also use map change hook because map change is not treated as leaving the server.
------------------------------------------------------------------------------
Only thing is that why join hook doesnt triggers while verifying. But leave hook triggers at any time.
Leave is possible without joining? lol
edited 1×, last 15.11.14 05:05:39 pm
Assume a player joins and the join hook does not trigger from u r view then how will the leave hook trigger unless the player is considered as joined.
I think you know true anf false function and u even might have used while scripting if a function is considered true then if u use else function is used the server will consider as false as it is naturall thing.If a thing cannot be true then it will be false of course.
Thats fine.
But if player cancel the joining while he is verifying or dwnloading it will trigger the leave hook.
Example:
You are joining a server with a public msg while a player joins and leaves.
Example:
Raj nadar joins server.
Raj nadar leaves server.
And u started joining,u are currently dwnloading files and u are stucked while dwnloading so u cancelled joining .
For the players who are playing in the server will experience that a player is leaving the server without joining.
Without join msg it shws:
Raj nadar leaves the server