Forum

> > CS2D > Scripts > lua request(kind of inventory)
Forums overviewCS2D overview Scripts overviewLog in to reply

English lua request(kind of inventory)

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

old Re: lua request(kind of inventory)

Alistaire
User Off Offline

Quote
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
AA_defaultinv = {
}

function AA_join(id)
	local usgn = player(id, 'usgn')
	AA_inv[usgn] = {}
	-- Dofile and create file on join
	if io.open('sys/lua/savefile/'..usgn..'.lua') then
		dofile('sys/lua/savefile/'..usgn..'.lua')
	else
		local file = io.open
		('sys/lua/savefile/'..usgn..'.lua', 'w')
		file:write('AA_inv['..usgn..'] = '..AA_print(AA_defaultinv))
		file:close()
		dofile('sys/lua/savefile/'..usgn..'.lua')
	end
end

function AA_print(tbl,i)
    if not i then i=1 end
    local fi=i-1
    if type(tbl)=="table" then
        local tblt="{\n"
        for k,v in pairs(tbl) do
            for n=1,i do
                tblt=tblt.."	"
            end
			if type(k)=="string" then
				tblt=tblt..k.." = "
			else
				tblt=tblt.."["..k.."] = "
			end
            if type(v)=="table" then
                tblt=tblt..FM_print(v,i+1)..",\n"
            else
				if type(v)~="number" and type(v)~="boolean" then
					tblt=tblt.."\""
				end
				tblt=tblt..tostring(v)
				if type(v)~="number" and type(v)~="boolean" then
					tblt=tblt.."\""
				end
				tblt=tblt..",\n"
            end
        end
        for n=1,fi do
            tblt=tblt.."    "
        end
        tblt=tblt.."}"
        return tblt
    end
    return tostring(tbl)
end

Easy save and load system with table create on unknown join and tableload on known join.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview