Forum

> > CS2D > Scripts > Save System
Forums overviewCS2D overview Scripts overviewLog in to reply

English Save System

21 replies
Page
To the start Previous 1 2 Next To the start

old Save System

G3tWr3ck3d
User Off Offline

Quote
Hello, I was wondering how to create a save system for a mute command that can save the time left before unmute and save the player money and load them on join. I already have one but is way too low and unprofessional.

old For money

Ace Howl
User Off Offline

Quote
About money, I'm sure that you mean virtual money (not money for buymenu).

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
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
FYI, USGN is essential in saving. If you include no USGN savings, another player with no USGN will also use same profile

P/S: I will lookup how the muting timing works, or someone will answer that for you

old Re: Save System

Ajmin
User Off Offline

Quote
Plse use usgn of a player as variable or it will leads to bug.
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

old Re: Save System

Joni And Friends
User Off Offline

Quote
@user Ajmin: simple, just make the load player data on spawn hook, it will not make bug, i has try it and not be bug but you must make var for stop load when spawn

old Re: Save System

Ajmin
User Off Offline

Quote
Jaf what u told is 100% poor.

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.

@user 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
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

old Re: Save System

Joni And Friends
User Off Offline

Quote
@user Ajmin: Use the var "for stop load spawn" for the save system, if the var "for stop load spawn"==true then the system can save your data and stop for load in spawn and if "for stop load spawn"==false system can't save your data and load in spawn is active
edited 1×, last 15.11.14 01:26:29 pm

old Re: Save System

Ajmin
User Off Offline

Quote
U mean using a variable loaded?

(after loading)
1
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

old Re: Save System

Ajmin
User Off Offline

Quote
So why cant we use join hook instead of spawn hook for a sharp saving/loading?

Ofcourse its possible in my view.

@user 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

old Re: Save System

Yates
Reviewer Off Offline

Quote
@user Ajmin: Because when you join, and your connection times out, you save over your save file. Thus deleting all your stats.

old Re: Save System

Ajmin
User Off Offline

Quote
@user Yates: Thats what I am explaining.

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

old Re: Save System

Raaj Nadar
User Off Offline

Quote
@user Ajmin: You are exactly right never use this player(id,"usgn") reason when two players join at the same time (Rare chance) as so as the function triggers and the scripts it self gets confused and can create a mess.

If u use "..usgn.." string(or anything else) it will be better the script will parse one by one.

@user Yates: you also has a point. ∗

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

@user Ace Howl: I posted your same topic in my 1st post lol.

@user G3tWr3ck3d: Thanks and hope it helped a lot.

@user Joni And Friends: or @user 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).

old Re: Save System

Ajmin
User Off Offline

Quote
I disagree to use spawn hook 100%

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

old Re: Save System

Raaj Nadar
User Off Offline

Quote
Can you explain your point of view.
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.

old Re: Save System

Ajmin
User Off Offline

Quote
When a player is connected and if he is verifying the server it is not treated as join.

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