English LeveL and EXP SCRIPT

22 replies
Goto Page
To the start Previous 1 2 Next To the start
07.07.17 11:42:46 pm
Up
Jedediastwo
User
Offline Off
IMG:https://s9.postimg.org/hdn7bv8i7/image.png

The EXP Multiplier don't work
When kill, only receive +100 exp
Code:
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
Code:
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
08.07.17 08:34:07 am
Up
Baloon
GAME BANNED
Offline Off
Code:
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
08.07.17 02:23:47 pm
Up
apex2d
User
Offline Off
user Baloon
He wanted to save progress
Eat Sleep Conquer Repeat. www.Radeon2D.forumid.net
08.07.17 03:24:59 pm
Up
Fraizeraust
Moderator
Offline Off
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.
08.07.17 03:32:00 pm
Up
JeeewNazi
User
Offline Off
@user Fraizeraust: 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.
08.07.17 03:40:38 pm
Up
Fraizeraust
Moderator
Offline Off
@user JeeewNazi: 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.
08.07.17 03:53:40 pm
Up
JeeewNazi
User
Offline Off
@user Fraizeraust: 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?
08.07.17 04:00:40 pm
Up
Masea
Super User
Offline Off
@user JeeewNazi:
Code:
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 Fraizeraust'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 (12)
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
08.07.17 04:15:15 pm
Up
JeeewNazi
User
Offline Off
@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
Code:
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?
08.07.17 04:25:22 pm
Up
Masea
Super User
Offline Off
@user JeeewNazi: 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.
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
08.07.17 04:32:44 pm
Up
JeeewNazi
User
Offline Off
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.
08.07.17 04:34:42 pm
Up
Masea
Super User
Offline Off
user JeeewNazi has written:
Who gives a shit about players without usgn id.
I do since they're the most of the CS2D players.
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
08.07.17 04:37:07 pm
Up
JeeewNazi
User
Offline Off
@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.
08.07.17 04:44:51 pm
Up
Masea
Super User
Offline Off
user JeeewNazi 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?
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
08.07.17 04:50:21 pm
Up
JeeewNazi
User
Offline Off
@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.
08.07.17 05:13:15 pm
Up
Masea
Super User
Offline Off
user JeeewNazi 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.
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
08.07.17 05:16:58 pm
Up
JeeewNazi
User
Offline Off
Thanks for your help. if that was the purpose lol.
09.07.17 08:34:09 pm
Up
Jedediastwo
User
Offline Off
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.
09.07.17 08:59:53 pm
Up
VaiN
User
Offline Off
@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 (12) to work, everything should be in a single table, not dozens of separate tables. I'd recommend switching things to something like this example:
Code:
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:
Code:
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
09.07.17 10:20:09 pm
Up
_Yank
User
Offline Off
@user JeeewNazi: 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