Forum

> > CS2D > Scripts > LeveL and EXP SCRIPT
Forums overviewCS2D overview Scripts overviewLog in to reply

English LeveL and EXP SCRIPT

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

old LeveL and EXP SCRIPT

Jedediastwo
User Off Offline

Quote
IMG:https://s9.postimg.org/hdn7bv8i7/image.png

The EXP Multiplier don't work
When kill, only receive +100 exp
1
2
if exp[id] < asd[id] then 
		exp[id]=exp[id]+100+lvl[od]*12

And when level up, the maximum exp increase +150
asd[id]=150*lvl[id]+15


How do multiplier? like:
When LeveL UP, the maximum exp increase 100*The LeveL+25 (For example, if i am level 2, multiplier 100*2+25)

And when kill, receive stages, like: 50+(Double, triple, maximum 6x bonus), for example: I killed 5 in sequence, 50+(50*5)

And how save the current exp and level in a file and update every 5 minutes the current exp and lvl?

The Full code here
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
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
lvl=initArray(32)
exp=initArray(32)
asd=initArray(32)
sk1=initArray(32)
sk2=initArray(32)
sk3=initArray(32)
h=initArray(32)
hi=initArray(32)
mai=initArray(32)
mo=initArray(32)
t=initArray(32)
am=initArray(32)
dme=initArray(32)
n=initArray(32)
no=initArray(32)
skd=initArray(32)
buss=initArray(32)
quay=initArray(32)
inbuss=initArray(32)
bhor=initArray(32)
tr1=initArray(32)
tr2=initArray(32)

msh = initArray(32)

count=0
cou=0

addhook("ms100","ms_hud")
function ms_hud()
     for id = 1,32 do
          if (player(id,"exists")) then		
	       asd[id]=150*lvl[id]+15
	       hi[id]=310*lvl[id]+1000+am[id]*2000	               		
	       mai[id]=273*lvl[id]+15	
               parse('hudtxt2 '..id..' 45 "©255255255 Player: '..player(id,"name")..' " 0 105')             			               		
               parse('hudtxt2 '..id..' 48 "©255000255 Level: '..lvl[id]..' " 0 125')
               parse('hudtxt2 '..id..' 49 "©255255100 Exp: '..exp[id]..'/'..asd[id]..' " 0 142')
		if h[id]>hi[id] then h[id]=hi[id] end
		if n[id]>3 then n[id]=3 end
		if lvl[id]>150 then lvl[id]=150 end
		if h[id]<0 then h[id]=player(id,"health") end
	if exp[id] == asd[id] or exp[id] > asd[id] and lvl[id]<150 then
		exp[id]=exp[id]-asd[id]
		lvl[id]=lvl[id]+1
		h[id]= hi[id]
		msg2(id,"©000255000LeveL UP!@C")
		msg("©255075000"..player(id,"name").." LeveL UP to "..lvl[id].." !")
	end
	  end	 		
      end
end

addhook("kill","ms_kill")
function ms_kill(id,od)
	if exp[id] < asd[id] then 
		exp[id]=exp[id]+100+lvl[od]*12
	end	
	if exp[id] == asd[id] or exp[id] > asd[id] and lvl[id]<150 then
		exp[id]=exp[id]-asd[id]
		lvl[id]=lvl[id]+1
		h[id]= hi[id]
		msg2(id,"©000255000LeveL UP!@C")
		msg("©255075000"..player(id,"name").." LeveL UP to "..lvl[id].." !")
	end
	mo[id]=mo[id]+37*lvl[od]+125 +45*buss[od]
end

old Re: LeveL and EXP SCRIPT

Baloon
GAME BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
function give_exp(id,expamount)
	exp[id]=exp[id]+expamount
	if exp[id]>=asd[id] then
		lvl[id]=lvl[id]+1
		asd[id]=(100*lvl[id])+25
		msg("©255075000"..player(id,"name").." LeveL UP to "..lvl[id].." !")
	end
end

old Re: LeveL and EXP SCRIPT

GeoB99
Moderator Off Offline

Quote
Here's a sample of how save/load system looks like:
The Code >

According to your question, you want the stats, level and exp points, to be updated every 5 minutes inside a file. Note that it does not include the save function upon leaving the server but I am sure you can do that yourself. You must use cs2d lua hook leave hook for that. I used the cs2d lua hook spawn hook for the load system because I find it much better than join.

By the way, the data will only be saved for players with U.S.G.N. ID otherwise your data will not be preserved.

old Re: LeveL and EXP SCRIPT

Ajmin
User Off Offline

Quote
@user GeoB99: Well if u make a table for usgn and set it to their "usgn id" using player(id, 'usgn') in join hook and further use it everywhere instead of player(id, 'usgn') then i consider the "join" hook much suitable than the "spawn". Moreover i think spawn hook will always reset ur stats to the saved one each time u respawn. i am not accurate tho.

old Re: LeveL and EXP SCRIPT

GeoB99
Moderator Off Offline

Quote
@user Ajmin: He can setup a variable and create a condition-check if the player has spawned for the first time. If so, set that variable to 1 so the piece of code related to load system will get triggered only once.

old Re: LeveL and EXP SCRIPT

Ajmin
User Off Offline

Quote
@user GeoB99: Yes he can do that. Let me say to you one another situation. Most probably save function will be linked to the leave hook.What if the player leaves before spawning? Again we need to make another conditional check. So my suggestion counts?

old Re: LeveL and EXP SCRIPT

Masea
Super User Off Offline

Quote
@user Ajmin:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
players = {}

addhook("spawn","_spawn")
function _spawn(id)
	if not players[id] then players[id] = {} end
end

addhook("leave","_leave")
function _leave(id)
	if players[id] then 
		-- saving...
		players[id] = nil 
	end
end
Something like this, mate.

By the way, user GeoB99's example of saving code is really bad. Do never use that. I got tons of bugs when I was using it. I highly recommend this one: file cs2d [SALT] Save and Load Tables

old Re: LeveL and EXP SCRIPT

Ajmin
User Off Offline

Quote
@user Masea: Ye that way would work. But when u attach the load function with spawn hook u do want to again check if the player is spawned for the first time. So i just said for the sake of commenting (actually) u could use load function with the join hook itself if you using a table for usgn id . That's no big deal.

Otherwise if player leaves quickly before completely joining the server then his stats wont be loaded but at the same time leave hook will be triggered and his stats will be saved to 0.
Once if u use a table for usgn and set it to an individuals usgn id through join hook we can prevent this.
as we have this condition in save function
1
2
3
4
5
6
7
8
9
10
usgn={}

Join hook>> usgn[id]=player(id,"usgn") , load(id)

function load(id)
if usgn[id]>0 then
bla bla bla

function save(id)
If usgn[id]>0 --- usgn id will be set to a different number other than zero only after the player joins completely so there wont be any mess if the player gets fcked and leaves spontaneously without completely joining.
So?

old Re: LeveL and EXP SCRIPT

Masea
Super User Off Offline

Quote
@user Ajmin: What is the purpose of not getting it over and just use cs2d lua hook spawn or cs2d lua hook team hooks instead? These both will work. That way you also have to deal with players who don't have a USGN ID so.

old Re: LeveL and EXP SCRIPT

Ajmin
User Off Offline

Quote
Who gives a shit about players without usgn id. Whatever hooks we use there wont be any difference with players without usgn id.
We can use what ever hooks we need. I really doubt now its useless to argue since our purposes are the same. GL.

old Re: LeveL and EXP SCRIPT

Ajmin
User Off Offline

Quote
@user Masea: So that means u are going to sap usgn and support players without usgn id? I mean u gonna make a new level of load and save system without the requirement of usgn? sounds like i am going to witness a miracle soon. ? Oh fck. I am damn excited.

old Re: LeveL and EXP SCRIPT

Masea
Super User Off Offline

Quote
user Ajmin has written
@user Masea: So that means u are going to sap usgn and support players without usgn id?
No, it really does not mean that. It just means I also support people who don't have a USGN ID just because they're the most ones who join to the servers or at least to my server.

If you'd have ever opened a server and look for people's USGN IDs whenever someone joins to your server, you'll see most of them do not have that. That's really pathetic, but gotta take it easy.

So with your script and with the meaning of what I said, my proposal is more reasonable(see my first post). Got it?

old Re: LeveL and EXP SCRIPT

Ajmin
User Off Offline

Quote
@user Masea: How will u save and load players stats without usgn id requirement? -.-
The only possible way is to create a new account system within the servers. You are going that deep for this simple load and save function? I really admire you for the effort u are taking for the well being of non registered players lol.

old Re: LeveL and EXP SCRIPT

Masea
Super User Off Offline

Quote
user Ajmin has written
@user Masea: How will u save and load players stats without usgn id requirement? -.-
I never said something like that. I came here just to help you and give an example.

old Re: LeveL and EXP SCRIPT

Jedediastwo
User Off Offline

Quote
ajm-sh you can update my code with u idea?

Only the save/load script.

I have try everything, but when the script create the saves file, the script don't load when server join.

old Re: LeveL and EXP SCRIPT

VaiN
User Off Offline

Quote
@user Jedediastwo: had requested assistance with save/load via PM, but I thought I should reply here in case it helps others.

First, for file cs2d [SALT] Save and Load Tables to work, everything should be in a single table, not dozens of separate tables. I'd recommend switching things to something like this example:
1
2
3
4
5
6
stats[id] = {
	lvl=0,
	exp=0,
	asd=0,
	-- ect
}
this way you can just do salt.save(stats[id],"path..") and it will save it all together.

Regarding when to load/save, I myself also had to learn the hard way about accidentally overwriting data on the leave hook.

What I recommend is to still load the data on join, this way players can see their stats even if they don't actually join a team and just spectate. But you'll need a flag to know when they have fully joined or not, as others have recommended.

I might as well give a more complete example here:
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
dms = {} -- data management system
dms.loaded = {} -- track when it's safe to save
dms.savetime = {} -- track time for auto-saving
stats = {} -- stores data for all users
dms.path = "sys/lua/data/"

function dms.default()
	return {
		lvl = 0,
		exp = 0,
		foo = 0,
		bar = 0,
		-- ...
	}
end

for id = 1,32 do
	dms.loaded[id] = false
	dms.savetime[id] = 0
end

function dms.join(id)
	if player(id,"usgn") > 0 then
		local tbl = salt.load(dms.path .. player(id,"usgn") .. ".lua")
		stats[id] = tbl or dms.default()
		dms.loaded[id] = true -- safe to save
		dms.savetime[id] = os.time() + 300 -- 5 minutes ahead
	else
		stats[id] = dms.default()
	end
end
addhook("join",dms.join)

function dms.leave(id)
	if dms.loaded[id] then
		salt.save(stats[id], dms.path .. player(id,"usgn") .. ".lua")
	end
	stats[id] = {}
	dms.loaded[id] = false
	dms.savetime[id] = 0
end
addhook("leave",dms.leave)

function dms.endround()
	for id = 1,32 do
		if dms.loaded[id] then
			salt.save(stats[id], dms.path .. player(id,"usgn") .. ".lua")
		end
	end
end
addhook("endround",dms.endround)

function dms.second()
	for id = 1,32 do
		if dms.loaded[id] then
			if dms.savetime[id] <= os.time() then
				salt.save(stats[id], dms.path .. player(id,"usgn") .. ".lua")	
				dms.savetime[id] = os.time() + 300
			end
		end
	end
end
addhook("second",dms.second)
I may have overlooked something somewhere, but it should give you a good idea of how to handle saving and loading. In the example, it will save data every five minutes if they are logged into USGN, and also at the end of every round, but doesn't change the auto-save timers, so it will remain staggered based on the time they joined the server.

let me know if you have any questions. hope this helps.
edited 1×, last 01.05.18 02:29:03 pm

old Re: LeveL and EXP SCRIPT

_Yank
User Off Offline

Quote
@user Ajmin: Although it might not be the best solution, you can always save the data to the players IP. I do that on my super hero reborn script and it used to work pretty well actually.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview