Forum

> > CS2D > Scripts > [Solved] Hat code now broken!
Forums overviewCS2D overview Scripts overviewLog in to reply

English [Solved] Hat code now broken!

25 replies
Page
To the start Previous 1 2 Next To the start

old Re: [Solved] Hat code now broken!

Cure Pikachu
User Off Offline

Quote
You tried the revised version above? Seems that works on my own dedicated server. Even had 2 CS2D processes connected to said server to test things out.
(Even though shutting it down gives me EXCEPTION_ACCESS_VIOLATION, but that's besides the point)

old Re: [Solved] Hat code now broken!

cs2d_is_a_Gem
User Off Offline

Quote
I'm using this
More >


It does not work for me, I tested the code on 2 computers.

old Re: [Solved] Hat code now broken!

Cure Pikachu
User Off Offline

Quote
user cs2d_is_a_Gem has written
I tested the code on 2 computers.

2 computers? Quick check: Does both of them have the files?
gfx/hat/devil.png
gfx/hat/skull.png
gfx/hat/Soldado ct.png
gfx/hat/Soldado tt.png
gfx/hat/captain america hat by spike.png

Because if one of them doesn't, you'll need to add these to server-transfer.

old Re: [Solved] Hat code now broken!

cs2d_is_a_Gem
User Off Offline

Quote
when joining the game without hat and leaving the game my data is saved in 0 as if I had never selected a hat.

I do not understand why the code is working correctly for you.
edited 1×, last 10.05.18 05:10:41 am

old Re: [Solved] Hat code now broken!

Cure Pikachu
User Off Offline

Quote
user cs2d_is_a_Gem has written
when joining the game aparesco without hat and leaving the game my data is saved in 0 as if I had never selected a hat.

Well I did remove the "save/load from file" portion of the script when I ran my own test.
After factoring in that portion... Well I replaced the join and leave functions with this:
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
addhook("leave","savedata")
function savedata(id,reason)
	if player(id,"usgn") > 0 then
		local f = assert(io.open("sys/lua/hats/saves/"..player(id,"usgn")..".txt","w"))
		f:write(tostring(currenthat[id]))
		f:close()
	end
	if hatimg[id] then
		freeimage(hatimg[id])
	end
	hatimg[id] = nil
	currenthat[id] = nil
end

addhook("join","loaddata")
function loaddata(id)
	local loaded = false
	if player(id,"usgn") > 0 then
		local f = io.open("sys/lua/hats/saves/"..player(id,"usgn")..".txt","r")
		if f ~= nil then
			for line in f:lines() do
				if line then
					currenthat[id] = tonumber(line)
					loaded = true
					break
				end
			end
			f:close()
		end
	end
	if not loaded then
		currenthat[id] = 0
	end
end
Just realised that you forgot a slash in either one of those
io.open
functions.
edited 2×, last 11.05.18 09:10:29 am
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview