0


hey there. I got a problem with this script ONLY on the dedicated server. It's working absolutely fine on a local "New Server".

here it is:

 function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
level=initArray(32)
exp=initArray(32)
class=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
               parse('hudtxt2 '..id..' 47 "©000100255Level: '..level[id]..' " 13 117')
               parse('hudtxt2 '..id..' 48 "©000100255Exp: '..exp[id]..'/8 " 13 129')
          end
     end
end

addhook("kill","ms_kill")
function ms_kill(id)
exp[id]=exp[id]+1
if exp[id] == 8 then
exp[id]=0
level[id]=level[id]+1
msg2(id,"©000255000Level up!@C")
parse("sv_sound2 "..id.." levelup.wav")
msg("©255075000"..player(id,"name").." reached "..level[id].." level!")
end
end

addhook("leave","save_leave") -- When you leave 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()
     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()
     end
end

addhook("join","save_join") -- When join load
function save_join(id)
     if (player(id,"usgn")>0) then
          for line in io.lines("sys/lua/saves/"..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



addhook("spawn","save_spawn")
addhook("serveraction","sa")
addhook("menu","class_menu")

function sa(id,a)
    if a==1 then
        menu1(id)
    elseif a==3 then
        info(id)
    end
end

function menu1(id)
    menu(id,"Page 1,Soldier|Level 0,Ogre|Level 0,Sparkle|Level 2,Heavy|Level 5,Commando|Level 10,Heavy Gunner|Level 15,Dragoon|Level 20,Assassin|Level 30,Next Page|More Heroes ;)")
end

function menu2(id)
    menu(id,"Page 2,The Chonk|Level 35,Previous Page|The last page..")
end

function info(id)
    msg2(id,"©000255000>>>   F2 opens the Race-Menu")
end

function save_spawn(id)
    -- Soldier
    if class[id]<=1 then
        parse("setmaxhealth "..id.." 125")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Soldier " 13 141')
        return "32,51,1";
    end
    -- Ogre
    if class[id]==2 then
        parse("setmaxhealth "..id.." 150")
        parse("speedmod "..id.." 2")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Ogre " 13 141')
        return "22,3";
    end
    -- Sparkle
    if class[id]==3 then
        parse("speedmod "..id.." 7")
        parse("setmaxhealth "..id.." 80")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Sparkle " 13 141')
        return "23";
    end
    -- Heavy
    if class[id]==4 then
        parse("setmaxhealth "..id.." 150")
        parse("speedmod "..id.." -4")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Heavy " 13 141')
        return "80,21";
    end
    -- Commando
    if class[id]==5 then
        parse("setmaxhealth "..id.." 75")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Commando " 13 141')
        return "81,10";
    end
    -- Heavy Gunner
    if class[id]==6 then
        parse("setmaxhealth "..id.." 150")
        parse("speedmod "..id.." -6")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Heavy Gunner " 13 141')
        return "80,40,51";
    end
    -- Dragoon
    if class[id]==7 then
        parse("setmaxhealth "..id.." 75")
        parse("speedmod "..id.." 6")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Dragoon    " 13 141')
        return "46";
    end
    -- Assassin
    if class[id]==8 then
        parse("setmaxhealth "..id.." 80")
        parse("speedmod "..id.." 13")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: Assassin " 13 141')
        return "69,84";
    end
    -- The Chonk :|
    if class[id]==9 then
        parse("setmaxhealth "..id.." 250")
        parse("speedmod "..id.." -60")
        parse('hudtxt2 '..id..' 49 "©000100000Current Race: The Chonk " 13 141')
        return "83,88,41";
    end
end

function class_menu(id,menu,sel)
    if (menu=="Page 1") then
        if (sel==1) then
            class[id]=1
        elseif (sel==2) then
            class[id]=2
        elseif (sel==3) then
            if level[id] >= 2 then
                class[id]=3
            else
                msg2(id,"You're not level 2, you can't use this race")
            end
        elseif (sel==4) then
            if level[id] >= 5 then
                class[id]=4
            else
                msg2(id,"You're not level 5, you can't use this race")
            end
        elseif (sel==5) then
            if level[id] >= 10 then
                class[id]=5
            else
                msg2(id,"You're not level 10, you can't use this race")
            end
        elseif (sel==6) then
            if level[id] >= 15 then
                class[id]=6
            else
                msg2(id,"You're not level 15, you can't use this race")
            end
        elseif (sel==7) then
            if level[id] >= 20 then
                class[id]=7
            else
                msg2(id,"You're not level 20, you can't use this race")
            end
        elseif (sel==8) then
            if level[id] >= 30 then
                class[id]=8
            else
                msg2(id,"You're not level 30, you can't use this race")
            end
        elseif (sel==9) then
                menu2(id)
        end
    elseif (menu=="Page 2") then
        if (sel==1) then
            if level[id] >= 35 then
                class[id]=9
            else
                msg2(id,"You're not level 35, you can't use this race")
            end
        elseif (sel==2) then
            menu1(id)
        end
    end
end

-- NO CHANGES HERE v --
addhook("buy","abuy")
function abuy()
    return 1
end

addhook("walkover","awalkover")
function awalkover(id,iid,type)
    if (type>=61 and type<=68) then
        return 0
    end
    return 1
end

addhook("drop","adrop")
function adrop()
    return 1
end

addhook("die","adie")
function adie()
    return 1
end

I'd thank you very much if you got a solution to my problem. Known issues: Error at joining because if there's not a file to read in the /saves/ folder.

sicerly, Skipper.

flag offensive
asked 2010-10-13 18:22:06.593688
1
add comment
1 Answers:
0


addhook("join","save_join") -- When join load
function save_join(id)
     if (player(id,"usgn")>0) then
          for line in io.lines("sys/lua/saves/"..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

You need to check to see if the file actually exists before buffering the file into Lua.

local filename = "sys/lua/saves/%s.txt"
local file = io.open(filename:format(player(id,"usgn"), "r")
local line
if not file then
    line = {1, 0}
else
    line = file:read("*a"):split()
end
level[id] = tonumber(line[1]) or 1 -- If line[1] is not a number, level[id] becomes 1
exp[id] = tonumber(line[2]) or 0 -- Same as above reasoning (prevents errors)

*nix servers handle line buffering differently. While windows denote newlines via /r/n, linux requires only /n. While it's not a big deal in this case, you do need to keep that in mind when dealing with io.lines.

Also, you declared savedie twice (I think that you meant to declare the first function as saveleave):

addhook("leave","save_leave") -- When you leave 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()
     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()
     end
end
permanent link | flag offensive
answered 2010-10-14 14:11:22.210592
41
add comment
Your answer:
You are now not logged in but you can answer first and then login
toggle preview



Made with Django.