Forum

> > CS2D > Scripts > Rank
Forums overviewCS2D overview Scripts overviewLog in to reply

English Rank

2 replies
To the start Previous 1 Next To the start

old Rank

Defqon ONE
User Off Offline

Quote
Anyone can make a lua script w\ patents of EUA type:Captain,Major,Corporal..etc and EXP?You maked tell me

Thanks

old Re: Rank

sheeL
User Off Offline

Quote
user Defqon ONE has written
Anyone can make a lua script w\ patents of EUA type:Captain,Major,Corporal..etc and EXP?You maked tell me

Thanks


Like 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
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
addhook("join","_join") --Loads user data from rankfolder
addhook("kill","_kill") --Adds 1 to the users table, and if the rank is different after adding 1 it will message indicating the new rank
addhook("leave","_leave") --Saves user data to rankfolder
addhook("team","_team") --Indicates rank

rankfolder="sys/lua/ranks/" --Where kills are saved

tRanks={ --EDIT 
     ["TR Patents of EUA"]=0,
     ["TR Captain"]=10,
     ["TR Major"]=310,
     ["TR Corporal"]=320,
     ["TR Guerriler"]=330,
     --["Name of Rank"]=Number of Kills--
}

ctRanks={ --ranks
     ["CT Patents of EUA"]=0,
     ["CT Captain"]=10,
     ["CT Major"]=310,
     ["CT Corporal"]=320,
     ["CT Guerriler"]=330,
     --["Name of Rank"]=Number of Kills--
}

teams={
     "TR", --Terrorist
     "CT", --Counter-Terrorist
}

users={} --users[id] is the number of kills

function _join(id) --Loads user data from rankfolder
     if player(id,"usgn")~=0 then --Only if you have a usgn
          users[id]=tonumber(loaddata(rankfolder..player(id,"usgn")..".txt")) or 0 --If you don't have data, place your kill start to 0
     end
end

function _kill(killer,victim) --Adds 1 to the users table, and if the rank is different after adding 1 it will message indicating the new rank
     if player(killer,"usgn")~=0 then --Only if you have a usgn
          users[killer]=users[killer]+1 --add 1 kill
          if torank(users[killer]-1,player(killer,"team"))~=torank(users[killer],player(killer,"team")) then --if you rank is different
               msg(string.char(169).."255255255"..player(killer,"name").." is now rank: "..torank(users[killer],player(killer,"team")).."!") --show the message
          end
     end
end

function _leave(id) --Saves user data to rankfolder
     if player(id,"usgn")~=0 then --Only if you have a usgn
          savedata(rankfolder..player(id,"usgn")..".txt",users[id]) --save function
     end
end

function _team(id,team) --Indicates rank
     if player(id,"usgn")~=0 then --Only if you have a usgn
          if torank(users[id],team) then --If the rank is not nil or false
               msg(string.char(169).."255255255Player ("..player(id,"name")..") ("..torank(users[id],team)..") JOINS ("..teams[team]..")") --show the rank
          end
     end
end

function savedata(path,data) --simple save function
     file=io.open(path,"w") --open the path
     file:write(data) --write data
     file:close() --close path
end

function loaddata(path) --simple load function
     file=io.open(path,"r") --read path
     if not file then return false end --if path does not exist return false
     local data=file:read("*all") --set data as the read data
     file:close() --close path
     return data --return the loaded file data
end

function torank(kills,team) --turn the number of kills to the rank
     if team==1 then
          ranks=tRanks
     else
          ranks=ctRanks
     end
     local final=false --if a rank is not found, false is returned
     local kill=-1 --the rank is accumulative, so the best rank is returned
     for rankname,rank in pairs(ranks) do --loop through all the ranks
          if kills>=rank and rank>kill then --if you have more kills than the rank, and the rank is better than your current rank
               kill=rank --set your current rank
               final=rankname --set your final rank
          end
     end
     return final --return it
end

P.S = Create a Folder Name : Ranks in lua [SYS/LUA/RANKS]
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview