Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 2262 263 264338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Snake_Eater
User Off Offline

Quote
@Flacko THX I LOVE YOU

look at this I wanted to creat a specialrandomscript....

1
2
3
4
5
6
7
8
9
function rndm(...)
local window = {...}
return window[math.random(1,#window)]
end

addhook ("second","ssa")
function ssa()
msg (""..rndm(100,200,300).."")
end


So you can get a random get a random from 100,200 or 300 and not between this numbers

old Re: Lua Scripts/Questions/Help

RyceR
User Off Offline

Quote
Plz make for me save and load script for 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
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end
level=initArray(32)
exp=initArray(32)

function level_hud(id)
     parse('hudtxt2 '..id..' 1 "©000100255Level: '..level[id]..' " 13 117')
end

function exp_hud(id)
     parse('hudtxt2 '..id..' 2 "©000100255Exp: '..exp[id]..'/8 " 13 129')
end

addhook("kill","ms_kill")
function ms_kill(id)
     exp[id]=exp[id]+1
     exp_hud(id)
     if exp[id] == 8 then
          exp[id]=0
          level[id]=level[id]+1
          msg2(id,"©000255000Level up!@C")
          exp_hud(id)
          level_hud(id)
     end
end

addhook("spawn","ms_spawn")
function ms_spawn(id)
     level_hud(id)
     exp_hud(id)
end
I sure very need it. Thank you in advance!

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
ive tryed to do it but it gives me an error

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
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end
level=initArray(32)
exp=initArray(32)

addhook("ms100","ms_hud")
function ms_hud()
	for id = 1,32 do
		if (player(id,"exists")) then
			parse('hudtxt2 '..id..' 1 "©000100255Level: '..level[id]..' " 13 117')
			parse('hudtxt2 '..id..' 2 "©000100255Exp: '..exp[id]..'/8 " 13 129')
		end
	end
end

addhook("kill","ms_kill")
function ms_kill(id)
     exp[id]=exp[id]+1
     exp_hud(id)
     if exp[id] == 8 then
          exp[id]=0
          level[id]=level[id]+1
          msg2(id,"©000255000Level up!@C")
     end
end

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

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

addhook("spawn","save_spawn") -- When spawn load
function save_spawn(id)
	if (player(id,"usgn")>0) then
		for line in io.lines("sys/lua/saves/"..player(id,"usgn")..".txt") do
			line = line:split()
			local exp = tonumber(line[1])
			local level = tonumber(line[2])
			level[id]=level
			exp[id]=exp
		end
	else
		msg2(id,"Failed to load")
	end
end

addhook("join","save_join") -- When join load
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 exp = tonumber(line[1])
			local level = tonumber(line[2])
			level[id]=level
			exp[id]=exp
		end
	end
end

it gives me this error

LUA ERROR: sys/lua/server.lua:75: attempt to call method 'split' (a nil value)

old .YeaH.

FiiD
User Off Offline

Quote
Hey HaRe...I need your help why you the PRO...so can you explain me why this script dont works???


1
2
3
4
5
6
addhook("hit","freeze")
function freeze(id,source,weapon,hpdmg,apdmg)
if wpn.id.knife then 
	parse("speedmod "..id.." -100") 
    end
end

Just if you got time...

Edit:I dont placed the ends so...it do it alone...
edited 1×, last 22.09.10 09:12:04 pm

old Re: Lua Scripts/Questions/Help

Snake_Eater
User Off Offline

Quote
easy

1
2
3
4
5
6
addhook("hit","freeze")
function freeze(id,source,weapon,hpdmg,apdmg)
if weapon==50 then
     parse("speedmod "..id.." -100")
end
end

old Re: Lua Scripts/Questions/Help

RyceR
User Off Offline

Quote
@HaRe Saves in your script work, but error is 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
addhook("spawn","save_spawn") -- When spawn load
function save_spawn(id)
     if (player(id,"usgn")>0) then
          for line in io.lines("sys/lua/saves/"..player(id,"usgn")..".txt") do
               line = line:split()
               local exp = tonumber(line[1])
               local level = tonumber(line[2])
               level[id]=level
               exp[id]=exp
          end
     else
          msg2(id,"Failed to load")
     end
end

addhook("join","save_join") -- When join load
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 exp = tonumber(line[1])
               local level = tonumber(line[2])
               level[id]=level
               exp[id]=exp
          end
     end
end

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
MSek has written
@HaRe Saves in your script work, but error is 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
addhook("spawn","save_spawn") -- When spawn load
function save_spawn(id)
     if (player(id,"usgn")>0) then
          for line in io.lines("sys/lua/saves/"..player(id,"usgn")..".txt") do
               line = line:split()
               local exp = tonumber(line[1])
               local level = tonumber(line[2])
               level[id]=level
               exp[id]=exp
          end
     else
          msg2(id,"Failed to load")
     end
end

addhook("join","save_join") -- When join load
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 exp = tonumber(line[1])
               local level = tonumber(line[2])
               level[id]=level
               exp[id]=exp
          end
     end
end


yeah i know it works, the line = line:split() has an error and idk what it is

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
The error is that split is not defined.
Look for lee's string library that include the string.split() function.
Or just use this one instead
1
2
3
4
5
6
7
8
9
function string.split(text,delimiter)
	local buff = {}
	delimiter = delimiter or "%s"
	delimiter = "[^"..delimiter.."]+"
	for w in string.gmatch(text,delimiter) do
		table.insert(buff,w)
	end
	return buff
end

old Re: Lua Scripts/Questions/Help

Jynxxx
User Off Offline

Quote
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
function Array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

rp_license = Array(32,false)
rp_license2 = Array(32,0)
rp_money = Array(32,0)

addhook("join","loadcash2")
function loadcash2(id)
if rp_license2[id]==1 then
rp_license[id]=true
end
if (player(id,"usgn") > 0) then
     local usgn, i = player(id,"usgn")
     if (usgn > 0) then
          local f = (io.open('sys/lua/license/'..player(id,"usgn")..'.txt','r'))
          if f then               
		msg2(id,'')
               for line in f:lines() do
                    i = 1
                    if (i == 1) then
                         rp_license2[id] = tonumber(line)
                    else
                         break
                    end
               end
               f:close()
               i = 1
          else
               msg2(id,'')
          end
     else
          msg2(id,'')
     end
end
if (player(id,"usgn") > 0) then
     local usgn, i = player(id,"usgn")
     if (usgn > 0) then
          local f = (io.open('sys/lua/saves/'..player(id,"usgn")..'.txt','r'))
          if f then               
		msg2(id,'©000255001Load Successfull!@C')
               for line in f:lines() do
                    i = 1
                    if (i == 1) then
                         rp_money[id] = tonumber(line)
                    else
                         break
                    end
               end
               f:close()
               i = 1
          else
               msg2(id,'We are sorry, but failed to load save!@C')
          end
     else
          msg2(id,'Please Check Your U.S.G.N. Account Settings!@C')
     end
end
end

addhook("leave","save2")
function save2(id)
if rp_license2[id]==1 then
rp_license[id]=true
end
if rp_license[id]==true then
rp_license2[id]=1
end
if (player(id,"usgn") > 0) then
f = assert(io.open('sys/lua/license/'..player(id,"usgn")..'.txt','w'))
f:write(rp_license2[id])
f:close()
msg2(id,'')
else
msg2(id,'')
end
if (player(id,"usgn") > 0) then
f = assert(io.open('sys/lua/saves/'..player(id,"usgn")..'.txt','w'))
f:write(rp_money[id])
f:close()
msg2(id,'©000255001Save Successfull!@C')
else
msg2(id,'©255000000Failed to Save!@C')
end
end

old Re: Lua Scripts/Questions/Help

Snake_Eater
User Off Offline

Quote
@Flacko look at this pls

1
2
3
4
5
6
7
8
9
10
11
12
13
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

Is it good too or are there any bugs???

old Re: Lua Scripts/Questions/Help

Bierbuikje
User Off Offline

Quote
Are there some codes to define the kills and deaths of a player? I want them for if you say 'top' it shows the top 3 killers and top 3 deaths. But with which code can I ask for how much deaths a player has?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Snake: It's ok, but you can make it even shorter
1
2
3
4
5
6
7
8
9
10
11
function string.split(text,b)
	local cmd = {}
	if not b then
		b = "%s"
	end
	b = "[^"..b.."]+"
	for o in string.gmatch(text,b) do
		table.insert(cmd,o)
	end
	return cmd
end

This way you skip the b = b thing which is useless.

old Re: Lua Scripts/Questions/Help

TDShuft
User Off Offline

Quote
how to find where are the nil value ( my script has 1600 lines )
and how to fix it ??
its just say :
LUA ERROR: Attempt to call a nil value

edit: i got all correctly but i think this is the damage :

addhook("say","wtfb")
function wtfb()
     if string.sub(txt,1,1)==[[!]] then
          return 1
     elseif string.sub(txt,1,1)=="@" then
          return 1
     end
end
edited 1×, last 22.09.10 04:24:01 am

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
I think this happens when CS2D tries to call a Lua function that is nil.
Check that you have correctly typed all the addhooks and timers.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
--Case 1
addhook("kill","foo")
function bar(id,killer,wpn) --wrong name
parse("setmoney "..killer.." 16000")
end

--Case 2
timer(2000,"foo","hello",1)
function bar(str) --Wronga name again
print(str)
end

old Re: Lua Scripts/Questions/Help

Snake_Eater
User Off Offline

Quote
@Flacko

can you explain me the meaning of "^" and "+" in the script pls?

1
2
3
4
5
6
7
8
9
10
11
function string.split(text,b)
     local cmd = {}
     if not b then
          b = "%s"
     end
     b = "[^"..b.."]+"
     for o in string.gmatch(text,b) do
          table.insert(cmd,o)
     end
     return cmd
end

old .YeaH.

FiiD
User Off Offline

Quote
Hey Snake_Eater...the script you gave me dont works...thanks that you tried to help me but it dont works...can be something other wrong now on my script...Im not sure...I hope someone can help me...
To the start Previous 1 2262 263 264338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview