Forum

> > CS2D > Scripts > Xp needed for next level algoritm
Forums overviewCS2D overview Scripts overviewLog in to reply

English Xp needed for next level algoritm

4 replies
To the start Previous 1 Next To the start

old Xp needed for next level algoritm

Avo
User Off Offline

Quote
I always have got the same problem: how to create function with algoritm of xp needed for next level...

It's my idea, but I'm interesting if it can be done by another (easier) solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
lvl=array(32,1)
xp=array(32,0)
nlvlxp=array(32,0)
up=200
function next_lvlxp(id)
	nlvlxp[id]=0
	for i=1,lvl[id] do
		nlvlxp[id]=nlvlxp[id]*up+up*10+nlvlxp[id]
	end
	if xp[id]>nlvlxp[id] then
		lvl[id]=lvl[id]+1
		msg2(id,"Level up!@C")
		next_lvlxp(id)
	end
end
Have you got any ideas?

old Re: Xp needed for next level algoritm

TimeQuesT
User Off Offline

Quote
Just som Simple gayassshit (only one player example)
-->

1
2
3
4
5
6
7
8
9
10
11
12
13
iConstLevelXp = 100;
iNextLevelXp = 100;
iCurrentXp = 0;
iLevel = 1;

function vIncreaseLevel() //you can add id parameters here if you're using tables/arrays
	iCurrentXp = iCurrentXp + 10;
	if (iCurrentXp>=iNextLevelXp) then
		iLevel = iLevel + 1;
		iNextLevelXp = (iNextLevelXp + (iNextLevelXp*0.15) + iConstLevelXp);
		//Adds 15% + 100 constant xp add.
	end
end

edit sample:
Player got 100XP
-->
Yay LevelUp !
-->
Now he needs 215xp to gain a new level.

old Re: Xp needed for next level algoritm

Jhony
User Off Offline

Quote
Fun Script :

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
level=initArray(32)
exp=initArray(32)
asd=initArray(32)

function string.split(text,b)
local cmd = {}
if b then
b = b
else
b = "%s"
end
b = "[^"..b.."]+"
for o in string.gmatch(text,b) do
table.insert(cmd,o)
end
return cmd
end

addhook("ms100","ms_hud")
function ms_hud()
     for id = 1,32 do
          if (player(id,"exists")) then 		
	       asd[id]=123*level[id]+1	               		
               parse('hudtxt2 '..id..' 48 "©000255000Server Level: '..level[id]..' " 13 117')
               parse('hudtxt2 '..id..' 49 "©000255000Server Exp: '..exp[id]..'/'..asd[id]..' " 13 129')
	  end	 		
      end
end

addhook("objectkill","objectkill")
function objectkill(id,player)
if exp[player] < asd[player] then 
exp[player]=exp[player]+15
end	
if exp[player] == asd[player] or exp[player] > asd[player] then
exp[player]=0
level[player]=level[player]+1
msg2(player,"©000255000Level up!@C")
parse("sv_sound2 "..id.." levelup.wav")
msg("©255075000"..player(id,"name").." reached "..level[player].." level!")
end
end

addhook("kill","ms_kill")
function ms_kill(id)
if exp[id] < asd[id] then 
exp[id]=exp[id]+20
end	
if exp[id] == asd[id] or exp[id] > asd[id] then
exp[id]=0
level[id]=level[id]+1
msg2(id,"©000255000Level up!@C")
parse("sv_sound2 "..id.." levelup.wav")
msg("©255075000"..player(id,"name").." reached "..level[id].." level!")
end
end

addhook("spawn","pl_spawn")
	function pl_spawn(id)
		if level[id] < 4 then
			id=image("gfx/flare2.bmp",0,0,132+id)
			imagecolor(id,255,255,0)
			imageblend(id,1)
			imagealpha(id,0.5)
		elseif level[id] >=4 and level[id] <7 then
			id=image("gfx/soldier.bmp",0,0,132+id)
			imagecolor(id,255,100,255)
			imageblend(id,1)
			imagealpha(id,0.5)
		elseif level[id] >=7 and level[id] <11 then
			id=image("gfx/nkiller.bmp",0,0,132+id)
			imagecolor(id,100,100,100)
			imageblend(id,1)
			imagealpha(id,0.5)
		elseif level[id] >=11 and level[id] < 16 then
			id=image("gfx/vkiller.bmp",0,0,132+id)
			imagecolor(id,255,0,255)
			imageblend(id,1)
			imagealpha(id,0.5)
		elseif level[id] >=16 and level[id] < 21  then
			id=image("gfx/boss.bmp",0,0,132+id)
			imagecolor(id,0,255,255)
			imageblend(id,1)
			imagealpha(id,0.5)
		elseif level[id] >=21 then
			id=image("gfx/TDT.bmp",0,0,132+id)
			imagecolor(id,255,0,0)
			imageblend(id,1)
			imagealpha(id,0.5)
		end		
end

addhook("spawn","spawn")
function spawn(id)
if level[id] > 4 and level[id] < 10 then
			id=image("gfx/vkillerc.png",1,0,100+id)
			imageblend(id,0)
			imagealpha(id,0.5)
		elseif level[id] >= 10 and level[id] < 15 then
			id=image("gfx/bossc.bmp",1,0,100+id)
			imageblend(id,0)
			imagealpha(id,0.5)
		elseif level[id] >= 15 then
			id=image("gfx/tdtc.png",1,0,100+id)
			imageblend(id,0)
			imagealpha(id,0.5)	 
		end
end

addhook("leave","save_leave")
function save_die(id)
     if (player(id,"usgn")>0) then
          io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
          io.write(exp[id].." "..level[id])
          io.close()
     end
end

addhook("die","save_die")
function save_die(id)
     if (player(id,"usgn")>0) then
          io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
          io.write(exp[id].." "..level[id])
          io.close()
     end
end

addhook("join","save_join")
function save_join(id)
     if (player(id,"usgn")>0) then
          for line in io.lines("sys/lua/saves/"..player(id,"usgn")..".txt") do
               line = line:split()
               local ms_exp = tonumber(line[1])
               local ms_level = tonumber(line[2])
               level[id]=ms_level
               exp[id]=ms_exp
          end
     end
end

change the imagens , for your options
create a past in ("sys/lua")
nome of past : saves
enjoy
sry inglish
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview