Forum

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

English Rank Script Error

3 replies
To the start Previous 1 Next To the start

old Rank Script Error

apex2d
User Off Offline

Quote
Sup. I got a script and it got some problems
Problem: There's no error at logs
maybe syntax error but I don't know what is code that caused this error

Problem--> When I kill the xp stays at 0 instead of going to a bigger value

main.lua
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
------Rank Lua------
----ByDeathliger----
--Copyright © 2016--
dofile("sys/lua/money.lua")
dofile("sys/lua/save.lua")

function array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

function totable(t,match)
	local cmd = {}
	if not match then match = "[^%s]+" end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end 
	return cmd 
end

function rj_msg(clr,txt)
	msg(string.char(169)..""..clr..""..txt)
end

function rj_msg2(id,clr,txt)
	msg2(id,string.char(169)..""..clr..""..txt)
end

function hudtext(tid,color,txt,x,y)
    local toprint = (string.char(169)..""..color.." "..txt) 
    parse('hudtxt '..tid..' "'..toprint..'" '..x.." "..y) 
end

function hudtext2(id,tid,color,txt,x,y)
    local toprint = (string.char(169)..""..color.." "..txt)
    parse('hudtxt2 '..id..' '..tid..' "'..toprint..'" '..x.." "..y)
end

_statshud = function(id)
    for id = 1,32 do
	    if player(id,"exists") then
		    hudtext2(id,1,"192192192","Level : "..rj_level[id].."/"..rj_maxlevel[id],275,426)
			hudtext2(id,2,"192192192","EXP   : "..rj_exp[id].."/"..rj_maxexp[id],275,441)
			hudtext2(id,3,"192192192","Rank : "..rj_rank[id],275,456)
			_ranklist(id)
		end
	end
end

_checkexp = function(id)
    for id = 1,32 do
	    if rj_exp[id] >= rj_maxexp[id] then
		    rj_level[id] = rj_level[id]+1
			rj_maxexp[id] = rj_maxexp[id]+30
			rj_rankimg[id] = rj_rankimg[id]+1
			rj_exp[id] = 0
			_checkrankimg(id)
	    end
	end
end

_checkrankimg = function(id)
    for id = 1,32 do
	    if player(id,"health") == 0 then
		    if rj_img[id] ~= nil then
		        freeimage(rj_img[id])
			    rj_img[id] = nil
			end
		    rj_img[id] = image("gfx/deathliger/ranks/"..rj_rankimg[id]..".png",331,145, 2, id)
		end
	end
end

_rankimg = function(id)
    if rj_img[id] ~= nil then
        freeimage(rj_img[id])
	    rj_img[id] = nil
	end
    rj_img[id] = image("gfx/deathliger/ranks/"..rj_rankimg[id]..".png",331,145, 2, id)
end

_freeimage = function(id)
    if rj_img[id] ~= nil then
        freeimage(rj_img[id])
	    rj_img[id] = nil
	end
end

_ranklist = function(id)
    if rj_level[id] == 1 then
	    rj_rank[id] = "Silver 1"
	elseif rj_level[id] == 3 then
	    rj_rank[id] = "Silver 2"
	elseif rj_level[id] == 5 then
	    rj_rank[id] = "Silver 3"
	elseif rj_level[id] == 7 then
	    rj_rank[id] = "Silver 4"
	elseif rj_level[id] == 8 then
	    rj_rank[id] = "Silver 5"
	elseif rj_level[id] == 9 then
	    rj_rank[id] = "Silver Elite Master"
	elseif rj_level[id] == 10 then
	    rj_rank[id] = "Gold Nova 1"
	elseif rj_level[id] == 13 then
	    rj_rank[id] = "Gold Nova 2"
	elseif rj_level[id] == 15 then
	    rj_rank[id] = "Gold Nova 3"
	elseif rj_level[id] == 17 then
	    rj_rank[id] = "Gold Nova Master"
	elseif rj_level[id] == 18 then
	    rj_rank[id] = "Master Guardian 1"
	elseif rj_level[id] == 19 then
	    rj_rank[id] = "Master Guardian 2"
	elseif rj_level[id] == 20 then
	    rj_rank[id] = "Master Guardian Elite"
	elseif rj_level[id] == 23 then
	    rj_rank[id] = "Distinguished Master Guardian"
	elseif rj_level[id] == 25 then
	    rj_rank[id] = "Legendary Eagle"
	elseif rj_level[id] == 27 then
	    rj_rank[id] = "Legendary Eagle Master"
	elseif rj_level[id] == 28 then
	    rj_rank[id] = "Supreme Master First Class"
	elseif rj_level[id] == 30 then
	    rj_rank[id] = "Global Elite"
	end
end

rj_level = array(32,1)
rj_maxlevel = array(32,30)
rj_exp = array(32,0)
rj_maxexp = array(32,25)
rj_rank = array(32,"Unranked")
rj_rankimg = array(32,1)
rj_img = array(32,nil)
usgnids = array(32,0)

function string_split(str,pattern)
     local entry = {}
     for str in string.gmatch(str,pattern) do
          if str ~= "" then
               table.insert(entry,str)
          end
     end 
     return entry
end

addhook("join","_rjoin")
_rjoin = function(id)
    set_flags(id)
	
    rj_level[id] = 1
	rj_maxlevel[id] = 30
    rj_exp[id] = 0
	rj_maxexp[id] = 25
    rj_rank[id] = "Unranked"
    rj_rankimg[id] = 1
	rj_img[id] = nil 
	_freeimage(id)
	usgnids[id] = 0
--	for _, i in pairs(player(0,"table")) do
	    --if player(i,"usgn") == player(id,"usgn") and i~=id then
		  --  parse("kick "..id)
--		end
	--end
	usgnids[id] = player(id,"usgn")
	if usgnids[id] == 0 then
	rj_msg2(id,"255000000","Please register a U.S.G.N. account at http://www.unrealsoftware.de/ and make sure that you are logged in!")
		rj_msg2(id,"255000000","You Cannot Rank UP Without Your USGN Logged In.")
    else
	    rj_msg2(id,"255000000","Rank Script By DeathLiger")
	end   
end

addhook("leave","_rleave")
_rleave = function(id)
    refresh_user(id)
    --rj_level[id] = 1
	--rj_maxlevel[id] = 25
    --rj_exp[id] = 0
	--rj_maxexp[id] = 50
    --rj_rank[id] = "Unranked"
    --rj_rankimg[id] = 1
	--rj_img[id] = nil
	_freeimage(id)
	--usgnids[id] = 0
end

addhook("ms100","_rms100")
_rms100 = function(id)
    for id = 1,32 do
	    if player(id,"exists") then
		    if player(id,"health") == 0 then
			    _statshud(id)
				_checkexp(id)
			end
		end
	end
end

addhook("spawn","_rspawn")
_rspawn = function(id)
    _rankimg(id)
	image("gfx/deathliger/ranks/rank_info.png", 320, 140, 2, id)
end

addhook("kill","_rkill")
_rkill = function(kil,vic,wpn)
    if rj_level[kil] < rj_maxlevel[kil] then
	    if rj_exp[kil] > rj_maxexp[kil] then
		    rj_exp[kil] = rj_exp[kil]+10
		end
	end
end

--	http://gamebanana.com/members/1314658

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
function refresh_user(id)
     local usgn = player(id,"usgn")
     local path = saves_folder..usgn..".txt"
     if not is_file(path) then
	 file = io.open(path,"w")
	 file : write("level="..rj_level[id].."\n")
	 file : write("rexp"..rj_exp[id].."\n")
	 file : write("maxexp="..rj_maxexp[id].."\n")
	 file : write("rankimg="..rj_rankimg[id].."\n")
	 file : close()
          print("Your account number "..usgn.." has been saved.")
     else
          print("Account Number "..usgn.." does not exist in the database. creating a new one")
     end
end

function create_user(id)
     local usgn = player(id,"usgn")
     local path = saves_folder..usgn..".txt"
     if not is_file(path) then
          file = io.open(path,"w")
          file : write("level="..rj_level[id].."\n")
          file : write("rexp="..rj_exp[id].."\n")
          file : write("maxexp="..rj_maxexp[id].."\n")
          file : write("rankimg="..rj_rankimg[id].."\n")
          file : close()
          print("Account number "..usgn.." was created successfully.")
     else
          print("Account number "..usgn.." already exists in the database. Ignoring")
     end
end

function is_file(filename)
     local file = io.open(filename)
     if file then
          io.close(file)
          return true
     end
     return false
end

function set_flags(id)
local usgn = player(id,"usgn")
local name = player(id,"name")
local path = saves_folder..usgn..".txt"

    if is_file(path) then
		local file = io.open(path,"r")
		local temp = {}
        for line in file:lines() do
			local temp = string_split(line,"[^=]*")
			    if temp[1] == "level" then rj_level[id] = tonumber(temp[1]) end
				if temp[2] == "rexp" then rj_exp[id] = tonumber(temp[2]) end
				if temp[3] == "maxexp" then rj_maxexp[id] = tonumber(temp[3]) end
				if temp[4] == "rankimg" then rj_rankimg[id] = tostring(temp[4]) end
				end
			file : close()
			print("Your Account With Number "..usgn.." Has Been Loaded.")
    elseif usgn ~= 0 then
	     create_user(id)
         msg2(id,"	Account Number "..usgn.." has been created!")
		else
		    print("Save file not found!")
	 end
end	
	--if usgnids[id]~=0 then

Thanks mate

old Re: Rank Script Error

THEMUD
User Off Offline

Quote
It's simply because you didn't put the hudtxt that shows your rank in a synchronized hook.
So it will just show up the first value of the variable.
The solution is to put it in the ms100 or second hook, but I recommend the ms100 hook.

So just set the hook and its function with the content like below:
1
2
3
4
5
6
7
addhook("ms100", "_ms100")
function _ms100()
	for _, id in ipairs(player(0, "tableliving"))
		do
		parse("hudtxt2 "..id.." 1 \""..rj.exp[id].."\" 100 100 0");
	end
end

old Re: Rank Script Error

GeoB99
Moderator Off Offline

Quote
@user THEMUD: The problem is not because of this, check the code carefully. hudtxt already exists there in the code.

In my humble opinion, the problem seems to be on cs2d lua hook kill hook (210 line) with these two if statements. I'd rather remove them for now and keep the 214 line which adds 10 of experience every time you kill an enemy.

old Re: Rank Script Error

apex2d
User Off Offline

Quote
@user GeoB99:


Problems right now after zxc's fix

and then image disappears when the server roundrestart

reconnect = players save are gone but it got server save
edited 3×, last 12.02.16 10:22:26 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview