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 2311 312 313338 339 Next To the start

old Re: Lua Scripts/Questions/Help

VaiN
User Off Offline

Quote
HaRe has written
You cant do this since the luas loades after the USGN SERVERLIST and that


Actually nevermind, it's working fine. I just wasn't waiting long enough for the logs to update I guess. Thanks anyway.

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
@Yasday, Anders4000
There is also a third parameter in the for loop. It is optional and controls the increase of the variable.
1
2
3
for i = 0, 5, 5 do
	print(i);
end
It starts at 0 for the first iteration and increases by 5.

Output has written
0
5

old Re: Lua Scripts/Questions/Help

Yasday
User Off Offline

Quote
debug.getinfo ([thread,] function [, what])

Returns a table with information about a function. You can give the function directly, or you can give a number as the value of function, which means the function running at level function of the call stack of the given thread: level 0 is the current function (getinfo itself); level 1 is the function that called getinfo; and so on. If function is a number larger than the number of active functions, then getinfo returns nil.

The returned table can contain all the fields returned by lua_getinfo, with the string what describing which fields to fill in. The default for what is to get all information available, except the table of valid lines. If present, the option 'f' adds a field named func with the function itself. If present, the option 'L' adds a field named activelines with the table of valid lines.

For instance, the expression debug.getinfo(1,"n").name returns a table with a name for the current function, if a reasonable name can be found, and the expression debug.getinfo(print) returns a table with all available information about the print function.

old make problem

TWBiBi
User Off Offline

Quote
why my lua can't work in cs2d.
who can teach me??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook ("say","maketeam")
function maketeam(p,txt)
   if (txt=="@maket") then
   parse("maket"..id..)
   msg("©032178170" ..player(p,"name").. "used @maket") 
   
   else if (txt=="@makect") then
    parse("makect"..id..)
	msg("©032178170" ..player(p,"name").. "used @makect") 
	 
   else if (txt=="@makespec") then
    parse("makespec"..id..)
    msg("©032178170" ..player(p,"name").. "used @maket") 
    retrun 1
   end
 end

old Re: Lua Scripts/Questions/Help

Chex
User Off Offline

Quote
TWBiBi has written
why my lua can't work in cs2d.
who can teach me??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook ("say","maketeam")
function maketeam(id,txt)
   if (txt=="@maket") then
   parse("maket" ..id)
   msg("©032178170" ..player(id,"name").. "used @maket") 
   
   elseif (txt=="@makect") then
    parse("makect" ..id)
	msg("©032178170" ..player(id,"name").. "used @makect") 
	 
   elseif (txt=="@makespec") then
    parse("makespec" ..id)
    msg("©032178170" ..player(id,"name").. "used @maket") 
    return 1
   end
 end

You spelled return wrong and elseif is one word.
Some '..' spacing problems too.
Might work, idk though.
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
addhook("startround","begin")
function begin()
	local i
	for i=1,32 do
		kills[i]=0
	end
end

addhook("die","resetScore")
function resetScore(id)
kills[id]=0

addhook("objectkill","npcKill")
function npcKill(id,player)
	if id==30 then
		kills[player]=kills[player]+1
			if kills[player]==1 then
				msg( ..player(id,"name").. "has killed his first zombie!@C")
			elseif kills[player]==10 then
				msg( ..player(id,"name").. "is owning!@C")
			elseif kills[player]==25
				msg( ..player(id,"name").. "is wow,just wow.@C")
			end
		end
	end
end
What am I doing wrong?

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
Arcas has written
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
addhook("startround","begin")
function begin()
	for i=1,32 do
		local kills[i]=0
	end
end

addhook("die","resetScore")
function resetScore(id)
kills[id]=0
end

addhook("objectkill","npcKill")
function npcKill(id,player)
	if id==30 then
		kills[player]=kills[player]+1
			if kills[player]==1 then
				msg( ..player(id,"name").. "has killed his first zombie!@C")
			elseif kills[player]==10 then
				msg( ..player(id,"name").. "is owning!@C")
			elseif kills[player]==25
				msg( ..player(id,"name").. "is wow,just wow.@C")
			end
		end
	end
What am I doing wrong?


That's a simple fix

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
@TWBiBi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook ("say","maketeam")
function maketeam(p,txt)
   if (txt=="@maket") then
   parse("maket "..p)
   msg("©032178170 "..player(p,"name").." used @maket") 
   
   elseif (txt=="@makect") then
    parse("makect "..p)
	msg("©032178170  "..player(p,"name").." used @makect") 
	 
   elseif (txt=="@makespec") then
    parse("makespec "..p)
    msg("©032178170 "..player(p,"name").." used @maket") 
    return 1
   end
 end

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
NaN is Not a Number. A value that can't be expressed as a real number.
For example 0/0, math.sqrt(-1), etc.

You can also get an "infinite" value in Lua, CS2D prints this as the string "-1.#INF".
For example 1/0

old Re: Lua Scripts/Questions/Help

Chex
User Off Offline

Quote
CmDark has written
Arcas has written
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
addhook("startround","begin")
function begin()
	for i=1,32 do
		local kills[i]=0
	end
end

addhook("die","resetScore")
function resetScore(id)
kills[id]=0
end

addhook("objectkill","npcKill")
function npcKill(id,player)
	if id==30 then
		kills[player]=kills[player]+1
			if kills[player]==1 then
				msg( ..player(id,"name").. "has killed his first zombie!@C")
			elseif kills[player]==10 then
				msg( ..player(id,"name").. "is owning!@C")
			elseif kills[player]==25
				msg( ..player(id,"name").. "is wow,just wow.@C")
			end
		end
	end
What am I doing wrong?


That's a simple fix

Still not working.
Debug says an error in line 4.

old Re: Lua Scripts/Questions/Help

Fehu
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
addhook("startround","begin")
function begin()
	for id=1,32 do
		kills[id]=0
	end
end

addhook("die","resetScore")
function resetScore(id)
kills[id]=0
end

addhook("objectkill","npcKill")
function npcKill(id,player)
	if id==30 then
		kills[player]=kills[player]+1
			if kills[player]==1 then
				msg(..player(id,"name").. " has killed his first zombie!@C")
			elseif kills[player]==10 then
				msg(..player(id,"name").. " is owning!@C")
			elseif kills[player]==25
				msg(..player(id,"name").. " is wow,just wow.@C")
			end
		end
	end
Fixed... i dont test this

old Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Quote
Yasday has written
yeah thx but i've already know that
reading the reference manual of lua was the first thing i did, lol(not the whole thing)
but maybe for anders it's new
edit// for real newbies^^: http://lua.org/pil/

Well, no. It's not new to me. I've been programming C++, VB, Java, HTML and CSS... Lua too btw. (;

old (AMX2D) not parsing cmds on VPS server

VaiN
User Off Offline

Quote
Well, I just recently got a VPS server and I'm able to get the servers running any everything. But when I try to use the say commands it fails to parse them correctly.

if you type "@" it is replaced with "tru"
likewise "!" is replaced with "fals"

It seem to be a problem with parsing the cmds.cfg file, in the amx2d/core/cmds.lua> cmd_init() function. (I could be wrong, but that's where I'm assuming it's getting the "tru" and "fals" from)

The scripts worked fine on a local ubuntu linux PC i had been hosting the servers on. The VPS OS is ubuntu server, so I doubt it's a formatting issue.

I'm not sure why it would need any changes if it worked before. Any thoughts?

Edit: Got it working. Evidently ubuntu server doesn't require removing the end of line character like ubuntu desktop did.
edited 1×, last 19.11.10 06:26:27 am

old Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Quote
factis699 has written
Guys i need script for snowball
(respawn where he fall)
can u made that i cant


Here is the code for HE:
1
2
3
4
5
6
addhook("projectile","ThrowHE")
function ThrowHE(id,weapon,x,y)
	if (weapon==51) then		--HE is iid 51.
		parse("setpos "..id.." "..x.." "..y)
	end
end
edited 1×, last 19.11.10 01:11:34 pm
To the start Previous 1 2311 312 313338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview