Forum

> > CS2D > Scripts > Script Not Save
Forums overviewCS2D overview Scripts overviewLog in to reply

English Script Not Save

6 replies
To the start Previous 1 Next To the start

old Script Not Save

maninja
User Off Offline

Quote
Hello Everyone

Hello this two again I came here on this day of help in this script The previous time I came here to ask for help for save steam now i came here Because this script not save if player Left Game and Join why i want save informaton of player in that but not save please i need help


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
function initArray(m)
    local array = {}
    for i = 1, m do
        array[i]=0
    end
    return array
end

level=initArray(32)
exp=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

function totable(t,match)
    local cmd = {}
    if not match then match = "[^%s]+" end
    for word in string.gmatch(t, match) do
        table.insert(cmd, word)
    end
    return cmd
end 

addhook("ms100","save_hud")
function save_hud()
    for id = 1,32 do
        if (player(id,"exists")) then
            parse('hudtxt2 '..id..' 48 "\169255255128[..]-\169255255255 LEVEL : \169255255000'..level[id]..' " 13 190')
            parse('hudtxt2 '..id..' 49 "\169255255128[..]-\169255255255 EXP : \169255255000'..exp[id]..'/30 " 13 210')
        end
    end
end

addhook("kill","save_kill")
function save_kill(id)
    exp[id] = exp[id] + 1
    if exp[id] == 30 then
        exp[id]=0
        level[id]=level[id]+1
        parse("sv_sound2 "..id.." levelup.wav")
        msg("\169000255000[LEVEL-UP]:\169255255255 "..player(id,"name").." Reached "..level[id].." level!")
    end
end

addhook("leave","save_leave") -- When you leave it saves
function save_leave(id)
    if (player(id,"usgn")>0) then
        io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
        io.write(exp[id].." "..level[id])
        io.close()
elseif (player(id,"steam")>'0') then
        io.output(io.open("sys/lua/saves/steam/"..player(id,"steam")..".txt","w+"))
        io.write(exp[id].." "..level[id])
        io.close()
    end
end

addhook("die","save_die") -- When you die it saves
function save_die(id)
    if (player(id,"usgn")>0) then
        io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
        io.write(exp[id].." "..level[id])
        io.close() 
    elseif (player(id,"steam")>'0') then
        io.output(io.open("sys/lua/saves/steam/"..player(id,"usgn")..".txt","w+"))
        io.write(exp[id].." "..level[id])
        io.close()
    end    
end  

addhook("join","save_join") -- When join load
function save_join(id)
    if (player(id,"usgn")>0) then
        local filename = "sys/lua/saves/%s.txt"
        local file = io.open(filename:format(player(id,"usgn"), "r"))
        local line
        if not file then
            line = {0, 1}
            msg2(id,"\169255255000[SERVER]\169255255255: \169255000000Failed to save!")
        else
            line = file:read("*a"):split()
        end
    elseif (player(id,"steam")>'0') then
        local filename = "sys/lua/saves/steam/%s.txt"
        local file = io.open(filename:format(player(id,"steam"), "r"))
        local line
        if not file then
            line = {0, 1}
            msg2(id,"\169255255000[SERVER]\169255255255: \169255000000Failed to save!")
        else
            line = file:read("*a"):split()       
        end
        exp[id] = tonumber(line[1]) or 0 -- If line[1] is not a number, level[id] becomes 1
        level[id] = tonumber(line[2]) or 1 -- Same as above reasoning (prevents errors)
    else
        msg2(id,"\169255255000[SERVER]: \169255000000Please make sure that you are logged in USGN / Steam!")
        level[id]=1
    end
end

old Re: Script Not Save

mrc
User Off Offline

Quote
You have to remove the join and leave hook, and make it to save when you kill or die. I have this script and I was able to make it work this way.

Also changing the ms100 to second is best.
edited 1×, last 24.01.19 05:26:06 pm

old Re: Script Not Save

maninja
User Off Offline

Quote
@user mrc: Ok Dude but please Fast i need it

Any Someone want do it for me ? please i need help ?
edited 1×, last 25.01.19 03:26:00 pm

old Re: Script Not Save

Vennece
User Off Offline

Quote
@user maninja:
this is my problem in my own tibia private server too..
its not saving while quitting the server or closes it

i have alternate solution.
open admin.cfg (usually in cs2dtibia folder)
put ur usgn id
save it.

while playing, if you want to save the server say !v
done.

but my problem is theres no autosave feature or autosay
autosay every 5 min will solve this

old Re: Script Not Save

Cebra
User Off Offline

Quote
I edited the script at some points:

1. The player doesn't have the field "steam", it is called "steamid".
2. You can't compare a string with '<'/'>'-operator.
3. In your join function the file will not be closed.
4. Why do you want to save in the leave or die function. The data isn't modified at this point in any way, so it is useless to save them there.

I have tested it only for usgn, but it should work for steam as well.

You have to create the folders '/sys/lua/saves/' and
'/sys/lua/saves/steam', otherwise it won't save the data.

@user maninja: Did you write the code by yourself?

Code >
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview