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 2132 133 134338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Zanahoria
User Off Offline

Quote
I think it would be impossible to do what you said.
I do not know much of Lua's, I'm a newbie

PD: CAN SOMEBODY ANSWER MY QUESTION?

Sorry for my English

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Alright, This is my first script and im not to good at this, so here it goes. I want to make a script that locks you out if you try to join a team I don't want someone to try(test). So heres the script.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
team.p = initArray(32)

addhook("team","tAdmin")
function tAdmin(id,team,look)
local i
	for i = 1,32 do
if not (player(id,"usgn") == 00000) then
	if (player(i,"exists") then
		teamchange = (look i 1)
		if (teamchange == true) then
		return 1
		else
		return 0
		end
	end
end
alright, I just want to know what's wrong, I don't completely understand the array, and I'm just not that good. Just want approval of also the look hook, Im not to sure how to use that, so I just guessed.

old Re: Lua Scripts/Questions/Help

Deatherr
User Off Offline

Quote
Flacko has written
Deatherr has written
I have a lua for my Town([DS] Town) server. If a "Give Money". You say "!give <id> <money>". It works but people been saying something like "!give 10 -16000" And when they say that they steal/bug money off of people! and even if they don't have that much the person still gets the money so i'm asking for a small/big lua that if the player uses (-) in there "!give" command their money will be set to 0.

Ok, post the script I gave you before so we can fix it


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
function toTable(t,match)
     local cmd = {}
     if not match then
          match = "[^%s]+"
     else
          match = "[^"..match.."]+"
     end
     for word in string.gmatch(t, match) do
          table.insert(cmd, word)
     end
     return cmd
end
addhook("say","give_money_cmd")
function give_money_cmd(id, text)
     local ptxt = toTable(text)
     if ptxt[1] == "!give" and #ptxt == 3 then
          local rcvp = tonumber(ptxt[2])
          local rcvm = tonumber(ptxt[3])
          if player(rcvp,"exists") then
               if player(id,"money") >= rcvm then
                    if player(rcvp,"money") + rcvm <= 16000 then
                         parse("setmoney "..id.." "..player(id,"money")-rcvm)
                         parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
                    elseif player(rcvp,"money") < 16000 then
                         rcvm = 16000 - player(rcvp,"money") --Here
                         parse("setmoney "..id.." "..player(id,"money")-rcvm)
                         parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
                    end
               end
          end
     end
end

Also can you make a lua that give money in a area?

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

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

Eh, Is that what you use to setup a table, and a question for exactly what tables do, I get that that table has how to record text, but Im curious, is a table a data structure? Or is it something else that im blanking on

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Deather
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
function toTable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end
	return cmd
end

addhook("say","give_money_cmd")
function give_money_cmd(id, text)
	local ptxt = toTable(text)
	if ptxt[1] == "!give" and #ptxt == 3 then
		local rcvp = tonumber(ptxt[2])
		local rcvm = math.abs(tonumber(ptxt[3]))
		if player(rcvp,"exists") then
			if player(id,"money") >= rcvm then
				if player(rcvp,"money") + rcvm <= 16000 then	
					parse("setmoney "..id.." "..player(id,"money")-rcvm)
					parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
				elseif player(rcvp,"money") < 16000 then
					rcvm = 16000 - player(rcvp,"money") --Here
					parse("setmoney "..id.." "..player(id,"money")-rcvm)
					parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
				end
			end
		end
	end
end

@Homer, yes, tables are data structures that may contain many values inside it, like an array in C/C++.
Tables can have numers, strings, booleans, functions or even more tables inside it.
The function you quoted recieves a string and returns a table with the string splitted in words.
This is done through the function string.gmatch, it will return a string starting at the beggining of the string you passed it. The returning string will be returned when the funcion finds the delimiter you supplied it with. Then you put that returned string (word) into our table, using table.insert, and this is done for each time the gmatch function finds the delimiter (and/or the end of the string).
Finally you return the table containing all the words and you are ready to use it.

old Re: Lua Scripts/Questions/Help

Deatherr
User Off Offline

Quote
Flacko has written
@Deather
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
function toTable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end
	return cmd
end

addhook("say","give_money_cmd")
function give_money_cmd(id, text)
	local ptxt = toTable(text)
	if ptxt[1] == "!give" and #ptxt == 3 then
		local rcvp = tonumber(ptxt[2])
		local rcvm = math.abs(tonumber(ptxt[3]))
		if player(rcvp,"exists") then
			if player(id,"money") >= rcvm then
				if player(rcvp,"money") + rcvm <= 16000 then	
					parse("setmoney "..id.." "..player(id,"money")-rcvm)
					parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
				elseif player(rcvp,"money") < 16000 then
					rcvm = 16000 - player(rcvp,"money") --Here
					parse("setmoney "..id.." "..player(id,"money")-rcvm)
					parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
				end
			end
		end
	end
end

@Homer, yes, tables are data structures that may contain many values inside it, like an array in C/C++.
Tables can have numers, strings, booleans, functions or even more tables inside it.
The function you quoted recieves a string and returns a table with the string splitted in words.
This is done through the function string.gmatch, it will return a string starting at the beggining of the string you passed it. The returning string will be returned when the funcion finds the delimiter you supplied it with. Then you put that returned string (word) into our table, using table.insert, and this is done for each time the gmatch function finds the delimiter (and/or the end of the string).
Finally you return the table containing all the words and you are ready to use it.

i you even change it o.o

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Flacko has written
@Blazz: Lol, that's sick

You mean poor? ]'=

Anyway, what about this?
I made weird snow script + wind...hmm...LOL! Even thought there is already snow

Screen:
IMG:https://img192.imageshack.us/img192/4746/screen1vm.th.png


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
--------------------------------------------------------
-- Some Tricks By Blazzing
-- Blazz Library: 16th - Snowy Day!
-- 2009/12/01 - v1.2
--------------------------------------------------------

snow = {["y"] = {},["x"] = {}, ["size"] = {}, ["move"] = {}, ["pos"] = {}, ["speed"] = {}, ["img"] = {}}
hooks = {[[startround]],[[always]]}
block = nil
snow_count = 340
snow_wind = 0

local hook
for hook = 1, #hooks, 1 do
	addhook(hooks[hook],[[blazz_]]..hooks[hook])
end

function blazz_startround()
	local id
	math.randomseed(os.time())
	block = image([[gfx/splash.bmp]],0,0,2)
	imagepos(block,320,240,0)
	imagecolor(block,0,0,0)
	for id = 1, snow_count, 1 do
		blazz_snow_set(id)
		snow.img[id] = image([[gfx/sprites/snowflake.bmp]],0,0,2)
		imagepos(snow.img[id],snow.x[id],snow.y[id],0)
		imagecolor(snow.img[id],255,255,255)
		imageblend(snow.img[id],1)
		imagealpha(snow.img[id],0.9)
		imagescale(snow.img[id],snow.size[id],snow.size[id])
	end
end

function blazz_always()
	local id, n
	snow_wind = snow_wind + 3
	if (snow_wind > 360) then snow_wind = snow_wind - 360 end
	for id,n in pairs(snow.img) do
		snow.y[id] = snow.y[id] + snow.speed[id]
		snow.x[id] = snow.x[id] + (math.sin(math.rad(snow_wind + snow.pos[id])) * snow.move[id])
		imagepos(snow.img[id],snow.x[id],snow.y[id],0)
		if (snow.y[id] > 490) then blazz_snow_set(id) end
	end
end

function blazz_snow_set(id)
	snow.x[id] = math.random(10,630)
	snow.y[id] = math.random(-480,0)
	snow.size[id] = (math.random(5,10) / 10)
	snow.pos[id] = math.random(1,45)
	snow.speed[id] = math.random(1,2)
	snow.move[id] = math.random(2,3)
end

blazz_startround()
edited 1×, last 08.01.10 08:11:35 pm

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Umm, I still need help with the script I posted, Sorry to interupt, but, I fixed some of the things(I forgot to even try it. >.>) but I still can't get the looky thing to work.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@Flacko,
Sorry, I misunderstanded you, my fail

@Homer, you want only to see your mistakes.? Here you are...
I BOLDED them. Look at spoiler with some comments.

Spoiler >

I found 5 mistakes.
edited 1×, last 09.01.10 12:24:57 am

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Thanks, but those are the ones I fixed.. And I purposely left the USGN number out, and The return, they said to return the look value on the info.txt.
It says wether it lets them continue or it doesn't let them choose a team. It gives me an error message still.
And, I also asked how to use the look part of the hook team. If you wanted to know what the error message was, it was complaining that it got a nil value from player instead of what it expected, never had this problem before. Lol, I would take the finished lua, I don't really care about the game, I just want to learn lua, So I'll take the complete script blazzing.
edited 1×, last 08.01.10 11:44:38 pm

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
I want it so that only a certain person with a certain USGN can join a certain team(lol, so many certains). And I want to know what does what. But, I think I fail at lua pretty bad.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
You should use CS2D timer functions (after hook) because of team hook - parsing "maket,ct" doesn't works.
To the start Previous 1 2132 133 134338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview