Forum

> > CS2D > Scripts > New save system
Forums overviewCS2D overview Scripts overviewLog in to reply

English New save system

15 replies
To the start Previous 1 Next To the start

old New save system

Marcell
Super User Off Offline

Quote
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

old Re: New save system

MikuAuahDark
User Off Offline

Quote
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 cs2d lua hook join

old Re: New save system

Marcell
Super User Off Offline

Quote
user MikuAuahDark has written
Spoiler >

It's just for the cs2d lua hook join

got:
LUA ERROR: sys/lua/admins.lua:135: attempt to index local 'txt' (a nil value)

old Re: New save system

Marcell
Super User Off Offline

Quote
user MikuAuahDark has written
Where is line 135?


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

old Re: New save system

MikuAuahDark
User Off Offline

Quote
you need to create GetUsgn() function first before using it, i think you're already create it. huh

old Re: New save system

Marcell
Super User Off Offline

Quote
user 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)

old Re: New save system

Marcell
Super User Off Offline

Quote
user MikuAuahDark has written
and again, where is line 302?

1
if txt:find("!register %S+")==1 then

anyway

in this line "11" means max. character ?
1
local name=txt:sub(11)

old Re: New save system

MikuAuahDark
User Off Offline

Quote
"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
1
print(tostring(txt))
and see if it's output nil at console

old Re: New save system

Marcell
Super User Off Offline

Quote
Spoiler >


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)

old Re: New save system

MikuAuahDark
User Off Offline

Quote
and what the debug code says? it's nil or something like a text?(the debug message can be seen just above LUA ERROR)

old Re: New save system

TheUnrealGamerz
User Off Offline

Quote
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.

old Re: New save system

Marcell
Super User Off Offline

Quote
user 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..
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview