English Load USGN

6 replies
Goto Page
To the start Previous 1 Next To the start
13.04.12 07:31:22 pm
Up
Jhony
User
Offline Off
More >


example

@give + <USGN>

@give 1

when player join , with usgn <1>
load a data user

help me ?
13.04.12 11:33:27 pm
Up
EP
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
41
42
43
44
45
function readfile(filelocation, linenum) 
savestr = {}
saveline=1
for line in io.lines(filelocation) do 
savestr[saveline]=line
saveline=saveline+1
end
return savestr[linenum]
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("say","a")
function a(id,txt)
local p = totable(txt)
local cmd = (p[1])
     if cmd == "@give" then
          local us = tonumber(p[2])
          if us > 0 then
          File = io.open("sys/lua/usgns/"..us..".txt", "a")
          File:close()
          return 1
          end
     return 1
     end
end

addhook("join","save_join") -- When join load
function save_join(id)
     if player(id,"usgn") > 0 then
        local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
          local file = io.open(filename)
          if file then
               VALUE[id] = readfile(filename, 1) --read a value in the line 1
               VALUE[id] = readfile(filename, 2) --same but in the line 2
          end
     end
end
Make a folder called usgns , sys/lua/usgns , to read a value just use VALUE[id] = readfile("LOCATION", LINE) , in location you use file because it is already named [DELETED] = Line 28 CHANGED = IN THE JOIN HOOK THERE WERE 2 MISTAKES, SOLVED!
edited 1×, last 14.04.12 12:11:25 am
14.04.12 12:08:47 am
Up
Jhony
User
Offline Off
user EP has written:
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
function readfile(filelocation, linenum) 
savestr = {}
saveline=1
for line in io.lines(filelocation) do 
savestr[saveline]=line
saveline=saveline+1
end
return savestr[linenum]
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("say","a")
function a(id,txt)
local p = totable(txt)
local cmd = (p[1])
     if cmd == "@give" then
          local us = tonumber(p[2])
          if us > 0 then
          File = io.open("sys/lua/usgns/"..us..".txt", "a")
          File:write()
          File:close()
          return 1
          end
     return 1
     end
end

addhook("join","save_join") -- When join load
function save_join(id)
     if player(id,"usgn") > 0 then
        local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
          local file = io.open(filename)
          if file then
               VALUE[id] = readfile(file, 1) --read a value in the line 1
               VALUE[id] = readfile(file, 2) --same but in the line 2
          end
     end
end
Make a folder called usgns , sys/lua/usgns , to read a value just use VALUE[id] = readfile("LOCATION", LINE) , in location you use file because it is already named


thanks but
no works

look :

LUA ERROR: sys/lua/userxd.lua:28: attempt to index global 'File' (a nil value)
14.04.12 12:09:39 am
Up
EP
User
Offline Off
Delete that line!
14.04.12 12:12:23 am
Up
Jhony
User
Offline Off
user EP has written:
Delete that line!

ok , ok
i deleted and no works ;/

_____
type

I say : @give <USGN>

table usgn :

usgn = {<USGN>}

and player join , load the usgn of player on table
sry english
14.04.12 12:14:34 am
Up
EP
User
Offline Off
it is a quite impossible to edit a table in a lua, and keep it saved (when you close it, you lose that changed data, i mean)
14.04.12 12:18:26 am
Up
Jhony
User
Offline Off
user EP has written:
it is a quite impossible to edit a table in a lua, and keep it saved (when you close it, you lose that changed data, i mean)


look
fix this lua?

please

More >
To the start Previous 1 Next To the start