Hi!
I'd like to get some idea how to do this:
When the player join to the server he must be register before he can play so ex:
!register Ron_Weasley
it's saves his usgn and his name (Ron_Weasley) then how can i load it, and write it to my hudtxt?
(authorize names by usgn id)
tried with this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook("say","SaveRPname")
function SaveRPname(id,txt,name)
if txt==("!register <name>")
	then
	local usgn = GetUsgn(id);
	if usgn > 0 then
		file = io.open(path .. "saves/" .. name	.. ".txt", "w");
		if file then
			file:write(tostring(Player[id].name .. "\n"));
			end
			io.close(file);
			return true;
		else
			
			return false;
		end
	end
end
edited 3×, last 19.10.13 12:10:05 pm
Admin/mod comment
Title was ungrammatical (revised). /KK Ron_Weasley? Why not Harry_Potter? 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
addhook("say","SaveRPname")
function SaveRPname(id,txt,name)
	if txt:find("!register %S+")==1 then -- You're need to compare it with 1 to make sure if he/she doesn't type it at middle of text(e.x.: lol !register AuahDark)
		local name=txt:sub(11)
		local usgn = GetUsgn(id);
		if usgn > 0 then
			local file=io.open(path.."saves/"..name..".txt","r")
			if file then	-- check if the file already exist
				return 1
			end
			file = io.open(path.."saves/"..name..".txt","w");
			if file then
				file:write(tostring(Player[id].name.."\n"));
				file:close()
			end
			return 1
		end
	end
end
It's just for the join MikuAuahDark has written
Spoiler 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
addhook("say","SaveRPname")
function SaveRPname(id,txt,name)
	if txt:find("!register %S+")==1 then -- You're need to compare it with 1 to make sure if he/she doesn't type it at middle of text(e.x.: lol !register AuahDark)
		local name=txt:sub(11)
		local usgn = GetUsgn(id);
		if usgn > 0 then
			local file=io.open(path.."saves/"..name..".txt","r")
			if file then	-- check if the file already exist
				return 1
			end
			file = io.open(path.."saves/"..name..".txt","w");
			if file then
				file:write(tostring(Player[id].name.."\n"));
				file:close()
			end
			return 1
		end
	end
end
It's just for the
join
got:
LUA ERROR: sys/lua/admins.lua:135: attempt to index local 'txt' (a nil value)
sorry, it was another error
but i have new
LUA ERROR: sys/lua/admins.lua:148: attempt to call global 'GetUsgn' (a nil value)
local usgn = GetUsgn(id); (it's by offline server )
but i got another error: nil value you need to create GetUsgn() function first before using it, i think you're already create it. huh MikuAuahDark has written
you need to create GetUsgn() function first before using it, i think you're already create it. huh
Sorry, i am wrong..
this is the error:
LUA ERROR: sys/lua/admins.lua:302: attempt to index local 'txt' (a nil value) and again, where is line 302?
1
if txt:find("!register %S+")==1 then
anyway
in this line "11" means max. character ?
"11" mean where to start to sub. Example:
1
2
3
txt="!register Miku_AuahDark"
dark=txt:sub(11)
-- "dark" now is "Miku_AuahDark"
And it seems to be strange if txt is nil because it's placed on second parameter. maybe try to delete the third parameter at line 2(on my code)
try to debug it. Put this after line 2
and see if it's output nil at console Spoiler MikuAuahDark has written
"11" mean where to start to sub. Example:
1
2
3
txt="!register Miku_AuahDark"
dark=txt:sub(11)
-- "dark" now is "Miku_AuahDark"
And it seems to be strange if
txt is nil because it's placed on second parameter. maybe try to delete the third parameter at line 2(on my code)
try to debug it. Put this after line 2
and see if it's output
nil at console
ahh okey,
now i get a new error -.-"
LUA ERROR: sys/lua/admins.lua:303: attempt to index local 'txt' (a nil value)
303 line: local name=txt:sub(11) and what the debug code says? it's nil or something like a text?(the debug message can be seen just above LUA ERROR) TheAnonymus, sorry for the kidding. Anyway i am trying to find one save system by pressing f2 for save and load. It is offline, and it will save somewhere in cs2d folder. And it will load the map where you been, position, enemy you killed, the mission you done. TheUnrealGamerz has written
TheAnonymus, sorry for the kidding. Anyway i am trying to find one save system by pressing f2 for save and load. It is offline, and it will save somewhere in cs2d folder. And it will load the map where you been, position, enemy you killed, the mission you done.
I have that system which save your last position, when you exit, then load when jo join..