English Saving Script

18 replies
Goto Page
To the start Previous 1 Next To the start
31.01.15 07:01:22 pm
Up
Louie
User
Offline Off
I want to create a Level system,but my problem is how do i make a save system that automatically saves the users Level and Exp when they exit,and automatically loads their Level and exp when they join?
No system is safe.
31.01.15 07:18:58 pm
Up
KimKat
GAME BANNED
Offline Off
You need to learn Lua to be able to do that.

Once you studied Lua a bit you will figure it out. I did and I can create the thing you're requesting easily.

However, I go by the chinese proverb "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

I hope you get the point I'm making. us

To give you some advice.

1. Learn to store values into variables or even tables.
2. Learn to use/display the variables and tables in in-game hudtexts.
3. Experiment around with the hooks and try to be creative.
4. Gain some more experience in Lua scripting by reading tutorials either on YouTube or on the Lua official website.
31.01.15 09:29:32 pm
Up
Rainoth
Moderator
Offline Off
OR, you could do what everyone else does and use the work of someone else

Check these scripts out:
file cs2d System Level (Rank Mod) (0)
file File does not exist (12888)

OR, you could search the forum and find many more level scripts that you could use. It's that easy

If you wanted to do something on the computer, why didn't you try to make your own OS. Wouldn't that be great? Yet neither of us did because people like to use the work of others.

However, if you want to have something amazing only for YOURSELF, you'll have to follow user KimKat's advice and learn Lua yourself. I highly doubt you'll need that as there's many great scripts out there.

Good luck!
01.02.15 08:42:04 am
Up
Louie
User
Offline Off
I think i'll try to learn it ,its more fun to learn it and then do it myself Thx guys for answering.
EDIT: Ok so i have created an load/save script.
√ Yeah it loads and saves but,
× when i delete my server(dedicated server) then start a new one it doesn't load the file,the gold,level,exp just goes back to 0 wtf? heres my code.
Spoiler >
edited 2×, last 01.02.15 01:36:33 pm
No system is safe.
01.02.15 06:27:24 pm
Up
JeeewNazi
User
Offline Off
Save Script

This thread could help u with that stuff!
02.02.15 07:59:36 am
Up
Louie
User
Offline Off
@user JeeewNazi: Yeah it helped me understand more and i tried to follow what you did there to use
Code:
1
usgn[id] = player(id,'usgn')
though its still the same when i close the server then make another one it doesn't load
No system is safe.
02.02.15 02:07:17 pm
Up
JeeewNazi
User
Offline Off
Code:
1
2
3
"playervalue1" --It seems that u aint gave any value for this.
So use:
"value1"
02.02.15 05:33:51 pm
Up
Inflexion
User
Offline Off
I didn't understand?
weeb
04.02.15 10:39:46 am
Up
Louie
User
Offline Off
user JeeewNazi has written:
Code:
1
2
3
"playervalue1" --It seems that u aint gave any value for this.
So use:
"value1"

I did not get it
No system is safe.
04.02.15 11:37:48 am
Up
Raaj Nadar
User
Offline Off
you need to add a name to the players saved value and use the same value while loading.
04.02.15 03:46:00 pm
Up
Louie
User
Offline Off
Code:
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
30
31
32
33
34
35
36
37
38
39
40
addhook("leave","saveleave")
function saveleave(id)
     if usgn[id] > 0 then
          local file = io.open("sys/lua/MoneyLevel Sys/Save/"..usgn..".txt","w")
          local value1, value2, value3, value4 = gold[id], Levels[id], Exp[id], MaxExp[id]
          file:write(value1.."\n "..value2.."\n "..value3.."\n"..value4)
          file:close()
     end
end

addhook("join","joinload")
function joinload(id)
     if usgn[id] > 0 then
          local file = io.open("sys/lua/MoneyLevel Sys/Save/"..usgn..".txt","r")
          if file then
               local value1, value2 = file:read("*n","*n","*n","*n")
               value1 = gold[id]
               value2 = Levels[id]
               value3 = Exp[id]
               value4 = MaxExp[id]
               msg2(id, "©000255000Succesfully Loaded!")
               file:close()
          else
               -- Set player values to 0, save file not found
               gold[id] = 0
               Levels[id] = 0
               Exp[id] = 0
               MaxExp[id] = 350
               msg2(id, "©255000000Failed to Load!")
          end
     else
          -- No USGN ID found, set player values to 0
               gold[id] = 0
               Levels[id] = 0
               Exp[id] = 0
               MaxExp[id] = 350
               msg2(id, "©255000000No USGN found!")
     end
     
end

√ it saves/loads files
× when i close the server and make/start a new one it doesn't load the files.
No system is safe.
04.02.15 04:13:09 pm
Up
Yates
Reviewer
Offline Off
Load a player on first spawn or team change. Never load on join.

You can use a variable to check if someone has spawned for the first time and set it to 1 so it doesn't trigger load again.
04.02.15 04:23:32 pm
Up
Louie
User
Offline Off
@user Yates: Ok i'll have to try that
EDIT: I've been getting these errors, somethingl like attempt to concatenate '?' (a nil value) and i also get attempt to concatenate global 'usgn' (a nil value)
though i don't know what those errors mean ,help please.
edited 1×, last 05.02.15 07:24:44 am
No system is safe.
05.02.15 09:50:58 am
Up
Bowlinghead
User
Offline Off
The compiler also shows the line where the error is. Is everything right in this line? You maybe forgot a charakter like ")" or something.
Maybe it is because you take "usgn" as variable name because it is already reserved.
Share time limited free games here
05.02.15 10:20:35 am
Up
Rainoth
Moderator
Offline Off
If that's your full script, you're missing the tables themselves.
05.02.15 10:41:37 am
Up
JeeewNazi
User
Offline Off
See this Error!
Code:
1
local file = io.open("sys/lua/MoneyLevel Sys/Save/"..usgn..".txt","w")


The correct one:
Code:
1
local file = io.open("sys/lua/MoneyLevel Sys/Save/"..usgn[id]..".txt","w")


You coded "usgn" instead of "usgn[id]" !!

Edit:
Completely fixed script:
Code:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function initArray(m)
     local array = {}
          for i = 1, m do
               array[i]=0
          end
return array
end

function string.split(text,b)
local cmd = {}
if b then
b = b
else
b = "%s"
end
b = "[^"..b.."]+"
for o in string.gmatch(text,b) do
table.insert(cmd,o)
end
return cmd
end



gold =initArray(32)
Levels=initArray(32)
Exp=initArray(32)
MaxExp=initArray(32)
usgn=initArray(32)


addhook("join","joinload")
function joinload(id)
usgn[id]=player(id,"usgn")
     if usgn[id] > 0 then
      if Exist("sys/lua/MoneyLevel Sys/Save/"..usgn[id]..".txt") then
          for line in io.lines("sys/lua/MoneyLevel Sys/Save/"..usgn[id]..".txt") do
               line = line:split()
local value1 = tonumber(line[1])
                    local value2 = tonumber(line[2])
                    local value3 = tonumber(line[3])
                                local value4 = tonumber(line[4])
               gold[id]=value1
               Levels[id]=value2 
              Exp[id]=value3
               MaxExp[id]=value4
               msg2(id, "©000255000Succesfully Loaded!")
              end
          else
               -- Set player values to 0, save file not found
               gold[id] = 0
               Levels[id] = 0
               Exp[id] = 0
               MaxExp[id] = 350
               msg2(id, "©255000000Save Fail Not found!")
          end
     else
          -- No USGN ID found, set player values to 0
               gold[id] = 0
               Levels[id] = 0
               Exp[id] = 0
               MaxExp[id] = 350
               msg2(id, "©255000000No USGN found!")
     end
     
end

addhook("ms100","hud")
function hud()
     for id = 1,32 do  
               parse('hudtxt2 '..id..' 1 "©000177255Gold :: '..gold[id]..'" 13 120 0')
               parse('hudtxt2 '..id..' 2 "©000255150Level :: '..Levels[id]..' " 13 140 0')
            parse('hudtxt2 '..id..' 5 "©255255000EXP :: '..Exp[id]..' / '..MaxExp[id]..'" 13 160 0')       
     end
end






addhook("leave","saveleave")
function saveleave(id)
     if usgn[id] > 0 then
          io.output(io.open("sys/lua/MoneyLevel Sys/Save/"..usgn[id]..".txt","w+"))
          io.write(gold[id].."  "..Levels[id].." "..MaxExp[id].." "..Exp[id])
          io.close()
          msg2(id,"©000255000Succesfully Saved!")
     else
          msg2(id,"©255000000Failed to save, you're not logged in")
     end
end

function Exist(location)
     local f=io.open(location)
     if f~=nil then
          io.close(f)
     end
     return f~=nil
end


Its fully guaranteed script!
It will never give any error!
Even if i use "Join" and "Leave" hook!
It wont
edited 2×, last 05.02.15 11:41:09 am
05.02.15 11:59:29 am
Up
Louie
User
Offline Off
@user JeeewNazi: Yea it loads and saves but it only loads when i:
1. Join server(dedicated server)
2. Get a few kills to lvl up
3. leave
4. rejoin
5. the files get loaded
however if i do:
1 Join server
2. Get a few kills to lvl up
3. leave and close down server
4. create server again
5. doesn't load files if i do that way.
but at least im not getting any error messages in the console √
No system is safe.
05.02.15 12:13:12 pm
Up
JeeewNazi
User
Offline Off
Yeh its a simple error! (Actually We cannot treat it as a error!)

Shutting down server is not leave (Leave == Save)!
Hence,It wont save!

U must use "second" save or "minute" save for that!
Or simply save players lvl etc when it gets increased. (Best Way)

Else u could also add a cmd for save function!
When u need to shutdown your server type the cmd and then shutdown it.
06.02.15 12:04:56 pm
Up
Louie
User
Offline Off
@user JeeewNazi: ok i'll try the second or minute save
No system is safe.
To the start Previous 1 Next To the start