Forum

> > CS2D > Scripts > How to use steamid instead of usgn
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to use steamid instead of usgn

9 replies
To the start Previous 1 Next To the start

old How to use steamid instead of usgn

Denisgrad
User Off Offline

Quote
Okay so I looked at this page http://www.cs2d.com/help.php?luacat=player&luacmd=player and it says that steamid returns a number (of steam id).

So here is a script right here which loads usgn ID to save progress (level and exp) and when i replace "usgn" with "steamid" the script fails to work.

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
function cod_team_load(id)
         if cod_1_set[id]==1 then
                 cod_1_set[id] = 0
                 if (player(id,"usgn") > 0) then
                        cod_msg2(id,3,'Logged in with: '..player(id,"usgn")..'@C')
                        local usgn = player(id, "usgn")
                        open = io.open('sys/lua/codsaves/'..player(id,"usgn")..'.txt','r')
                        if (open ~= nil) then
                                cod_msg2(id,2,'Your Files found!@C')
                                for line in io.lines('sys/lua/codsaves/'..player(id,"usgn")..'.txt','r') do
                                        local parses = totable(line)
                                        if (tonumber(parses[1]) > 0) then
                                                cod_xp[id] = tonumber(parses[1])
                                                start_check_lvl(id)
                                                open:close()
                                        end
                                end
                        else
                                cod_msg2(id,4,'No Files found!@C')
                                cod_xp[id] = 0
                        end
                else
                        cod_txt2(id,5,4,'No Unreal Software account!',3,415,0)
                end
                if cod_xp[id] == 0 or (player(id,"usgn") < 1) then
                        cod_xp[id] = 0
                        cod_nxp[id] = 100
                        cod_lvl[id] = 1
                end

When I start my server it gives the following error. That I am comparing a number to a string. Sorry I am new to scripting, last time I scripted was 5 years ago and I wasnt good anyways.

1
2
3
4
[01:44:17] LUA ERROR: sys/lua/cod_gamemode.lua:2423: attempt to compare number with string
[01:44:17]  -> sys/lua/cod_gamemode.lua:2423: in function 'cod_team_load'
[01:44:17]  -> sys/lua/cod_gamemode.lua:717: in function <sys/lua/cod_gamemode.lua:694>
[01:44:17]  -> in Lua hook 'team', params: 1, 1, 1

old Re: How to use steamid instead of usgn

G3tWr3ck3d
User Off Offline

Quote
@user SQ: I am using this saving
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
function zp_player_sv(p)
	if (player(p,"usgn") > 0) and (player(p,"steamid") == "0") then
		f = assert(io.open(zp_dir..'data/'..player(p,"usgn")..'.txt','w'))
		f:write(set_player_val(p,1)..'\n'..set_player_val(p,2))
		f:close()
	elseif (player(p,"steamid") ~= "0") and (player(p,"usgn") == 0) then
		f = assert(io.open(zp_dir..'data/'..player(p,"steamid")..'.txt','w'))
		f:write(set_player_val(p,1)..'\n'..set_player_val(p,2))
		f:close()
	elseif (player(p,"steamid") ~= "0") and (player(p,"usgn") > 0) then
		f = assert(io.open(zp_dir..'data/'..player(p,"steamid")..'.txt','w'))
		f:write(set_player_val(p,1)..'\n'..set_player_val(p,2))
		f:close()
	end
end

function zp_player_ld(p)
	local usgn = player(p,"usgn")
	local steamid = player(p,"steamid")
	if (usgn > 0) and (steamid == "0") then
		f = io.open(zp_dir..'data/'..usgn..'.txt','r')
	elseif (steamid ~= "0") and (usgn == 0) then
		f = io.open(zp_dir..'data/'..steamid..'.txt','r')
	elseif (steamid ~= "0") and (usgn > 0) then
		f = io.open(zp_dir..'data/'..steamid..'.txt','r')
		if (f ~= nil) then
			zp_msg2(p,3,'Your Save File Found!@C')
			local i = 0
			local s = 0
			local c = 0
			for line in f:lines() do
				i = i + 1
				if (i < 3) then set_player_stata(p,i,tonumber(line)) end
			end
			while set_player_val(p,1) >= c and s < zp_lvl_max do
				s = s + 1
				c = c +zp_lvl_ratio * s
			end
			if (s > zp_lvl_max) then i = zp_lvl_max end
			set_player_stata(p,3,s)
			set_player_stata(p,4,c)
			f:close()
		else
			zp_msg2(p,1,'Failed To Load Save!@C')
		end
	end	
	if (set_player_val(p,1) == nil or set_player_val(p,1) < 1 or usgn < 1) then
		zp_player_reset(p)
	end
end

And it saves my steamid, but when I join it won't load, in the steam data file shows 05 instead of adding spaces(I think the script wont read it like that)

old Re: How to use steamid instead of usgn

SQ
Moderator Off Offline

Quote
Create your own function to return ID of the player you want.
Just use this instead of usgnid or steamid's. This will return unique ID that is enough to identify user. No need to separate them into different types of users.
1
2
3
4
5
6
7
8
9
function playerUserID(id)
	if ( player(id, "usgn") > 0 ) then
		return( player(id, "usgn") )
	end
	if ( player(id, "steamid") ~= "0" ) then
		return( tonumber(player(id, "steamid")) )
	end
	return(0)
end

old Re: How to use steamid instead of usgn

Talented Doge
User Off Offline

Quote
The above can be simplified into the following:
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
dir = "sys/lua/data/"
val1, val2 = 123, "abc"
addhook("join", "_join")

function determine(p)
	if player(p, "steamid") ~= "0" then return "steamid"
	elseif player(p, "usgn") > 0 then return "usgn"
	else return "error" end
end

function load_player(p)
	local c = determine(p)
	if c == "error" then showsomeerror(p)
	else
		local file = io.open(dir..player(p, c)..".txt", "r")
		if not file then msg2(p, "YOUR FILE IS NOT FOUND, CREATING A NEW ONE!") save_player(p)
		else
			local a, b = file:read("*l"), file:read("*l")
			file:close()
			return a, b
		end
	end
end

function save_player(p)
	local c = determine(p)
	if c == "error" then showsomeerror(p)
	else
		local file = io.open(dir..player(p, c)..".txt", "w")
		file:write(val1.."\n"..val2)
		file:close()
	end
end

function showsomeerror(p)
	msg2(p, "YOU ARE NOT LOAGGED IN TO USGN NOR STEAM! YOUR STATS WILL NOT BE SAVED!")
end

function _join(p)
	print(load_player(p))
end

The save file
131785.txt
contains the following content:
1
2
123
abc

The message printed in console on join(suppose that you already created your own file):
1
123	abc
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview