Forum

> > CS2D > Scripts > [SOLVED] Score system w/ hp reward
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch [SOLVED] Score system w/ hp reward

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt [SOLVED] Score system w/ hp reward

olieo
User Off Offline

Zitieren
Basically this whole thing has turned into a huge mess and i've gone through several versions that work and that don't work. someone please help

Spoiler >


I have specific values for each levels exp/score value.

ATM the main problem is the HUD not working because of a nil value error for leveldis2 and leveldis
1× editiert, zuletzt 18.05.15 04:37:05

alt Re: [SOLVED] Score system w/ hp reward

olieo
User Off Offline

Zitieren
I did do that at the start and managed to cause problems for myself idk how, I'll give it another shot though. Any other ideas on how to improve it?

EDIT: got it working.

EDIT2: so new problem, every time i level up another player on the map gets my level and vice versa, exp stays the same because the script just reads out the score of each player, not sure how to fix this one...

Spoiler >


I also have rank linked to a few buy menus on the map and whenever i try to buy from them i have to pick up money to increase my score then do it otherwise it wont work and will say my level is someone elses...

Any help would be appreciated
4× editiert, zuletzt 17.05.15 07:00:40

alt Re: [SOLVED] Score system w/ hp reward

Talented Doge
User Off Offline

Zitieren
The code is too long.
I will use this to setscore instead.
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
Karma = {}
dir = "sys/lua/data/"

addhook("kill", "_k")
addhook("join", "_j")
addhook("leave", "_l)

function _k(k)
	Karma[k] = Karma[k] + 5
	parse("setscore "..k.." "..Karma[k])
end

function _j(id)
	USGN[id] = player(id, "usgn")
	if USGN[id] > 0 then
	file:open(dir..USGN[id]..".txt", r)
	Karma[id] = file:read("*n")
	file:close()
end

function _l(id)
	if USGN[id] > 0 then
	file:open(dir..USGN[id]..".txt", w)
	file:write(Karma[id])
	file:close()
end

Separate your code so that I can read it.

alt Re: [SOLVED] Score system w/ hp reward

Talented Doge
User Off Offline

Zitieren
Separate them like:

Suppose there is addhooks and function in your file, just separate them into two or more files, e.g i make them func.lua and hook.lua

In func.lua:
1
2
3
function _k(id)
	-- something here
end

In hook.lua:
1
addhook("kill", _k")

After you separated them, write this in server.lua:
1
2
dofile("sys/lua/hook.lua")
dofile("sys/lua/func.lua")

After these the file is separated.

This is just an example, you may separate the file in any ways you like to. Separating the code is important in order to let people read it more comfortable, and to yourself it does so.

alt Re: [SOLVED] Score system w/ hp reward

olieo
User Off Offline

Zitieren
@user Talented Doge:

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
addhook("join", "loadscore")
addhook("leave", "savescore")
addhook("kill","killmsg")
addhook("die","scoreloss")
addhook ("walkover","moneyisexp")
addhook("spawn","setlevel")

Karma = {}
dir = "sys/lua/scores/"

function loadscore(id)
     USGN[id] = player(id, "usgn")
     	if USGN[id] > 0 then
     		file:open(dir..USGN[id]..".txt", r)
     		Karma[id] = file:read("*n")
     		file:close()
	end
end

function savescore(id)
     	if USGN[id] > 0 then
     		file:open(dir..USGN[id]..".txt", w)
     		file:write(Karma[id])
     		file:close()
	end
end

function killmsg(id)
	msg2(id,"©000000255+1 EXP")
	setlevel(id)
end

function scoreloss(id)
	parse ("setscore "..id.." "..player(id,"score")-10)
	msg2(id,"©255000000-10 EXP")
	setlevel(id)
end

function moneyisexp(id,type)
	if (type==66) then
		msg2(id,"©000000255+1 EXP")
		parse ("setscore "..id.." "..player(id,"score")+1)
		setlevel(id)
	end
	if (type==67) then
		msg2(id,"©000000255+5 EXP")
		parse ("setscore "..id.." "..player(id,"score")+5)
		setlevel(id)
	end
	if (type==68) then
		msg2(id,"©000000255+10 EXP")
		parse ("setscore "..id.." "..player(id,"score")+10)
		setlevel(id)
	end
end

function setlevel(id)
	score = player(id,"score")
	name = player(id,"name")
	
		if (score < 8 ) then
			nextlevelexp = 8	
			playerlevel = 0
		end

		if (score > 8 ) then
			if (score < 17 ) then
				nextlevelexp = 17
				playerlevel = 1
				levelhealth = playerlevel + 100
					if player(id,"maxhealth")<levelhealth then
						parse("setmaxhealth "..id.." "..levelhealth.."")
						msg2(id,"©000255000Level up!@C")
					end
			end
		end
		if (score > 17 ) then
			if (score < 27 ) then
				nextlevelexp = 27
				playerlevel = 2
				levelhealth = playerlevel + 100
					if player(id,"maxhealth")<levelhealth then
						parse("setmaxhealth "..id.." "..levelhealth.."")
						msg2(id,"©000255000Level up!@C")
					end
			end
		end
		if (score > 27 ) then
			if (score < 38 ) then
				nextlevelexp = 38
				playerlevel = 3
				levelhealth = playerlevel + 100
					if player(id,"maxhealth")<levelhealth then
						parse("setmaxhealth "..id.." "..levelhealth.."")
						msg2(id,"©000255000Level up!@C")
					end
			end
		end
	showexplevel(id)
end

function showexplevel(id)
	parse('hudtxt2 '..id..' 16 "©000178238EXP: '..score..'/'..nextlevelexp..'" 330 440')
	parse('hudtxt2 '..id..' 17 "©000178238Level: '..playerlevel..'" 330 456')
end

Ive tided it up, added your save code and just left four of the levels in there to give you an idea of how I'm doing it.

getting the error:
"unable to index global USGN a nil value"

I think the other problem is with how I set up "playerlevel" and "nextlevelexp" not sure how to set it up right.

EDIT: i fixed it myself, anyone having the same issues read this tutorial: http://cs2d.wikia.com/wiki/Lua_Tutorial_2
10× editiert, zuletzt 18.05.15 04:37:50
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht