Forum

> > CS2D > Scripts > New save system
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch New save system

15 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt New save system

Marcell
Super User Off Offline

Zitieren
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
3× editiert, zuletzt 19.10.13 12:10:05

Admin/Mod Kommentar

Title was ungrammatical (revised). /KK

alt Re: New save system

MikuAuahDark
User Off Offline

Zitieren
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

alt Re: New save system

Marcell
Super User Off Offline

Zitieren
user MikuAuahDark hat geschrieben
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)

alt Re: New save system

Marcell
Super User Off Offline

Zitieren
user MikuAuahDark hat geschrieben
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

alt Re: New save system

Marcell
Super User Off Offline

Zitieren
user MikuAuahDark hat geschrieben
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)

alt Re: New save system

Marcell
Super User Off Offline

Zitieren
user MikuAuahDark hat geschrieben
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)

alt Re: New save system

MikuAuahDark
User Off Offline

Zitieren
"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

alt Re: New save system

Marcell
Super User Off Offline

Zitieren
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)

alt Re: New save system

MikuAuahDark
User Off Offline

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

alt Re: New save system

TheUnrealGamerz
User Off Offline

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

alt Re: New save system

Marcell
Super User Off Offline

Zitieren
user TheUnrealGamerz hat geschrieben
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..
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht