Forum

> > CS2D > Scripts > save points error
Forums overviewCS2D overview Scripts overviewLog in to reply

English save points error

3 replies
To the start Previous 1 Next To the start

old save points error

j0kER aR
User Off Offline

Quote
Hello everyone, someone who can help me with this error? it does not work and I do not know where the error is, if anyone can help me solve this, thanks

IMG:https://i.imgur.com/z0L0NIv.jpg


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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
level=initArray(32)
exp=initArray(32)
asd=initArray(32)

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

addhook("ms100","ms_hud")
function ms_hud()
     for id = 1,32 do
          if (player(id,"exists")) then           
            asd[id]=500*level[id]+500                              
               parse('hudtxt2 '..id..' 48 "©000255010 Rank: '..level[id]..' " 13 117')
               parse('hudtxt2 '..id..' 49 "©010255000 Points: '..exp[id]..'/'..asd[id]..' " 13 129')
       end                
      end
end

addhook("objectkill","objectkill")
function objectkill(id,player)
if exp[player] < asd[player] then 
exp[player]=exp[player]+100
end     
if exp[player] == asd[player] or exp[player] > asd[player] then
exp[player]=0
level[player]=level[player]+1
msg2(player,"©000255000Rank up!@C")
msg("©255075000"..player(id,"name").." reached "..level[player].." level!")
end
end

addhook("kill","ms_kill")
function ms_kill(id)
if exp[id] < asd[id] then 
exp[id]=exp[id]+100
end     
if exp[id] == asd[id] or exp[id] > asd[id] then
exp[id]=0
level[id]=level[id]+1
msg2(id,"©000255000Rank up!@C")
msg("©255075000"..player(id,"name").." reached "..level[id].." level!")
end
end

addhook("spawn","pl_spawn")
     function pl_spawn(id)
          if level[id] < 0 then
               id=image("gfx/hat/devil.png",0,0,132+id)
               imagecolor(id,255,255,0)
               imageblend(id,1)
               
          elseif level[id] >=0 and level[id] <4 then
          id=image("gfx/hat/devil.png",0,0,132+id)
               imagecolor(id,255,100,255)
               imageblend(id,1)
               imagealpha(id,0.5)
          elseif level[id] >=5 and level[id] <10 then
          id=image("gfx/hat/devil.png",0,0,132+id)
               imagecolor(id,100,100,100)
               imageblend(id,1)
               imagealpha(id,0.5)
          elseif level[id] >=11 and level[id] < 14 then
          id=image("gfx/hat/devil.png",0,0,132+id)
               imagecolor(id,255,0,255)
               imageblend(id,1)
               imagealpha(id,0.5)
          elseif level[id] >=15 and level[id] < 20 then
          id=image("gfx/hat/devil.png",0,0,132+id)
               imagecolor(id,0,255,255)
               imageblend(id,1)
               imagealpha(id,0.5)
          elseif level[id] >=21 then
               id=image("gfx/sf_rank_06.bmp",0,0,132+id)
               imagecolor(id,255,0,0)
               imageblend(id,1)
               imagealpha(id,0.5)
          end          
end


addhook("leave","save_leave")
function save_die(id)
     if (player(id,"usgn")>0) then
          io.output(io.open("sys/lua/save/"..player(id,"usgn")..".txt","w+"))
          io.write(exp[id].." "..level[id])
          io.close()
     end
end

addhook("die","save_die")
function save_die(id)
     if (player(id,"usgn")>0) then
          io.output(io.open("sys/lua/save/"..player(id,"usgn")..".txt","w+"))
          io.write(exp[id].." "..level[id])
          io.close()
     end
end

addhook("join","save_join")
function save_join(id)
     if (player(id,"usgn")>0) then
          for line in io.lines("sys/lua/save/"..player(id,"usgn")..".txt") do
               line = line:split()
               local ms_exp = tonumber(line[1])
               local ms_level = tonumber(line[2])
               level[id]=ms_level
               exp[id]=ms_exp
          end
     end
end

old Re: save points error

Nekomata
User Off Offline

Quote
The save file it's trying to load in the load hook does not exist.
It's always standard to check if the save file exists first then read off of it, otherwise make a new save file.

Replace your last hook with this and add the new function I've added in here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
addhook("join","save_join")
function save_join(id)
  if (player(id,"usgn")>0) then
    if not file_exists("sys/lua/save/"..player(id,"usgn")..".txt") then
      io.output(io.open("sys/lua/save/"..player(id,"usgn")..".txt","w+"))
      io.write("0 0") -- start from 0 xp and level 0 -- change accordingly
      io.close()
    end
    for line in io.lines("sys/lua/save/"..player(id,"usgn")..".txt") do
         line = line:split()
         local ms_exp = tonumber(line[1])
         local ms_level = tonumber(line[2])
         level[id]=ms_level
         exp[id]=ms_exp
    end
  end
end

function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview