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 2133 134 135338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
your_usgn = 0 --Here you put your usgn account
team_u_wanna_join = 0 --Here you put the team you want to be able to join

addhook("team","homer_team")
function homer_team(p,team)
	if team == team_u_wanna_join then --If this player wants to join your team
		if player(p,"usgn") ~= your_usgn then --check if it's using ur usgn
			return 1 --if not, we don't change the team
		end
	end
end

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Eh, thanks Alright, So why isn't there an else return 0, but could I use elif usgn == my_usgn then it doesn't do it. Thus, my confusion. Oh, I see, the look thing isn't a calling method, it's a built in passive thingy(Sorry, but I don't know what else to call anything). Thanks and it works flacko.

Alright, Sorry if im a nuisance, but, what is the beginning initailizing of the array for. Like this.
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end
Is it used for tables? or something?

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Usually a table looks like that:
1
table = {0,0,0,0,0,0,0,0,0,0,0}
Instead of that we can use this function:
1
2
3
4
5
6
7
8
9
[spoiler]function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end[/spoiler]

table = initArray(10)

old Please help.

KINGGOLDrus
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
356. if (rpg_item_type[pl_inv1[id]]==2) then
357. 	pl_inv[id]=pl_inv[id]','..tostring(pl_inv1[id])..
358.	i[id]=i[id]+1
		if (i[id]==9) then
			i[id]=i[id]+1
			pl_inv[id]=pl_inv[id]',Next >>'
		end
		if (i[id]==18) then
			i[id]=i[id]+1
			pl_inv[id]=pl_inv2[id]',Back <<'
		end
end
ERROR: unexpected symbol near "="
1
358.	i[id]=i[id]+1
Please, help me! I'm enmeshed in code.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
1
pl_inv[id]=pl_inv[id]',[b]'..tostring(pl_inv1[id])..[/b]
Wrong string concatenation...
Probably it should look like this:
1
pl_inv[id]=pl_inv[id]..","..pl_inv1[id]

There shouldn't be any problems about strings in this case.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@BLACK, I already said what nil means. (three times)

Valuable is equal nil when it's not existing.

Blazzingxx has written
Nope, nil valuable means value doesn't exist.
It means you haven't declared your value.

Like (Nil Comparing Example):
1
2
3
4
5
6
7
8
9
if (value == nil) then -- Check If Value [b]Doesn't[/b] Exist
	print("Value Doesn't Exist")
end

value = 5 -- Value Is Now equal 5

if (value ~= nil) then -- Check Value If It's [b]Does[/b] Exist
	print("Value Exist! and equal "..value)
end

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
mat5b has written
I'm doing a cool teamwork script called the (CAN) AllyMod.
Many brand new gameplay features come with it, like trading, teamworking, and many more!
Here's a small screen of the progress:
http://i50.tinypic.com/15dm7lz.png
That reminds me of Medal of Honor: Allied Assault, you could perhaps even add icons from MoH: AA using lua image instead of hudtxt. I'd love to see MoH: AA 2D.

In example...
Spoiler >
edited 1×, last 09.01.10 02:44:13 pm

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Eh, I hate to ask this of you, but could you show me how to use a table, like an example, cause I get what tables do, but I don't know how to apply them.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
1
2
3
4
5
your_table = {"Cool","Bad","Good"} -- Table

for i = 1, #your_table do -- Loop
	print(your_table[i].." = your_table["..i.."]")
end

It's going to print out:
1
2
3
Cool = your_table[1]
Bad = your_table[2]
Good = your_table[3]

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Oh so like a table is like an array in C++ or whatever, it looks like an array that I know from somewhere else, Thanks. Now, not to annoy you at all, how do you record text, like to see what a person says, like for example if a person says
!say 5555
it would type 5555.
How do you record a persons input.
And thanks for the help blazzing.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
There is many ways how to make that.
In all case we have to use say hook text parameter.

It's the way by using sub.string function. Try "!say hey hey hey"
1
2
3
4
5
6
7
addhook("say","say_func") -- Adding Hook

function say_func(p,t) 
	if (string.sub(t, 1, 4) == "!say") then -- Checking If First 4 Letters Equal "!say"
		msg(player(p,"name").." says: "..string.sub(t, 5, #t)) -- Shows All Text After "!say "
	end
end

old Re: Lua Scripts/Questions/Help

YellowBanana
BANNED Off Offline

Quote
Table isn't the same as a c++ array.
A c++ array can hold hold the same primitive types.
A Lua table can hold strings integers and other tables. Lua tables probably work with pointers.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
addhook("second", "heal")
function heal()
	for i = 1 , 32, 1 do
		if player(i,"exists") then
			parse("sethealth "..i.." "..player(i, "health")+3)
		end
	end
end

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
YellowBanana has written
Table isn't the same as a c++ array.
A c++ array can hold hold the same primitive types.
A Lua table can hold strings integers and other tables. Lua tables probably work with pointers.


no, Lua doesn't have pointer driven tables as Lua uses dynamic memory management, which not only defeats the purpose of pointers, but also renders it unusable as &pointer = &pointer + 1 in Lua would give you a completely arbitrary memory location (which could even be just a part of another data type), therefore Lua omits pointers altogether.

old Re: Lua Scripts/Questions/Help

memo
COMMUNITY BANNED Off Offline

Quote
need help with this script its D-H new mod but i have this bug with the credits so any one know how to fix it ...

Spoiler >


need help here !
edited 1×, last 09.01.10 09:54:34 pm

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Thanks yellow, and blazzing, Sorry, but I have another question xD, Im curious about what the string.sub(t,1,4) does. Like what is it's function really. And why are the arguments t,1,4? Thanks for all your help

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Yea, that's some comparing.
1
2
3
4
t = "Word"
string.sub(t, 1, 1) = "W"
string.sub(t, 2, 2)  = "o"
string.sub(t, 3, 4)  = "rd"
To the start Previous 1 2133 134 135338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview