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 214 15 16338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
Admin has written
Need Help in how to script smthing like:

!m4a1 the m4a1 apears for you please help


1
2
3
4
5
6
7
8
9
10
11
12
if sample==nil then sample={} end
sample.say={}

addhook("say","sample.say.say")
function sample.say.say(id,msg)

	-- Give M4A1
	if (msg=="!m4a1") then
	parse("equip "..id.." "..32)
	return 1
	end
end

this is only give you that weapon

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Hey, is there a way to ''Chain'' Lua menus?
This doesn't work, I press button 1 but the other menu doesn't appear (Or maybe it appears but it closes inmediatly)

1
2
3
4
5
6
7
8
addhook("menu","flacko.rpg.menu")
function flacko.rpg.menu(id,title,button)
	if(title=="MAIN MENU") then
		if(button==1) then
			flacko.rpg.weaponsl1(id)
		end
	end
end

old Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Quote
I think i know all the "Basics" in lua, but the biggest problem for me is to visualize what i am doing.

Other hard thing for me with coding itself is that i don`t know what i must do first inorder to do something to it.

For example, if i want to make a menu...I don`t know do i have to make the menu-base, menu buttons or what i need to make first...

*EDIT*And the hooks, is it just about logic to know which hook to use or is there other way i dont get?'

*EDIT2* And, does lua support "java-functions" like "&&" and "|"?

So, does anyone have ideas how can i improve myself, and how have you learned to visualize and know what to do first and so.

old Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Quote
LinuxGuy has written
Jonzku777 has written
I think i know all the "Basics" in lua, but the biggest problem for me is to visualize what i am doing.

same here


That`s why it`s lot easier to use visual basic...but everyone starts to whine if you do

old Re: Lua Scripts/Questions/Help

Alpha Beta
User Off Offline

Quote
Whats wrong at this line?
1
parse("sethealth "..source.." "..player(source,"Health")-30"")

Alternatively I could use 3 times slap ,but it would spam ...
edited 2×, last 14.06.09 11:25:49 am

old closed Re: Lua Scripts/Questions/Help

Dark M
User Off Offline

Quote
How I can create server??? DC contack me. I willl be wrote more mesages

Admin/mod comment

This is the wrong thread for such questions. In addition, there is a FAQ which helps. Just read the Server Problems / Guide / Checklist Thread /TheKilledDeath

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
I can't get this code to work properly, it says the hook doesn't exist.
1
2
3
4
5
6
7
8
addhook("killplayer","lightningstrike.killplayer")
function lightningstrike.killplayer(p,t)
end
if (txt=="!slay") then
     parse("killplayer" "..id..")
msg2(p, "©255255255The lightning has struck against "..player(p,"name").."!")
parse("sv_sound \"sounds/lightningbolt.ogg\"")
end
The command should only be accessed by server and rcon in console and by "say". The command shall slay a player id and play a sound as confirmation.

I want it to work like this
!slay 1 < result >> The lightning has struck against Player!
edited 1×, last 14.06.09 05:15:16 pm

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
Yes, the hook "killplayer" does not exist. It should be "say"
I did some corrections:
1
2
3
4
5
6
7
8
9
addhook("say","lightningstrike.killplayer")
function lightningstrike.killplayer(p,txt)
	if(string.sub(txt,1,5)=="!slay") then
		slayedplayer = string.sub(txt, 7,string.len(txt))
		parse("killplayer "..slayedplayer)
		msg("©255255255The lightning has struck against "..player(slayedplayer,"name").."!")
		parse("sv_sound \"sounds/lightningbolt.ogg\"")
	end
end

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
TheKilledDeath has written
Yes, the hook "killplayer" does not exist. It should be "say"
I did some corrections:
1
2
3
4
5
6
7
8
9
addhook("say","lightningstrike.killplayer")
function lightningstrike.killplayer(p,txt)
	if(string.sub(txt,1,5)=="!slay") then
		slayedplayer = string.sub(txt, 7,string.len(txt))
		parse("killplayer "..slayedplayer)
		msg("©255255255The lightning has struck against "..player(slayedplayer,"name").."!")
		parse("sv_sound \"sounds/lightningbolt.ogg\"")
	end
end
Tried your code but all it does is closes/crashes(can't tell) CS2D.

&& = and
could this work?
if (txt=="!slay&&id")
if (msg=="!slay&&id") do these have same effect?
edited 1×, last 14.06.09 06:03:46 pm

old Re: Lua Scripts/Questions/Help

wups
User Off Offline

Quote
I mean that

&& = or
| = and

From the other language, and in lua it is "and" "or".

if (txt1=="!help") and (txt2=="cs2d") then

do this

end

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
KimKat, you should try this function Leegao posted once.

1
2
3
4
5
6
7
8
function string.split(t,d) --Text and Delimiter
	if not d then d = "[^%s]+" end
	local cmd = {}
	for word in string.gmatch(t,d) do
		table.insert(cmd,word)
	end
	return cmd
end

What this function will do is return a table with the words you supplied in the string t.
If you give another delimiter (d), like "[^,]+", it will return a table with the words separed with comma.

Example:

1
2
3
4
5
6
7
8
9
10
addhook("say","lightningstrike.killplayer")
function lightningstrike.killplayer(p,txt)
	local asd = string.split(txt)
	if(asd[1]=="!slay") then
		local slayedplayer = asd[2]
		parse("killplayer "..slayedplayer)
		msg("©255255255The lightning has struck against "..player(slayedplayer,"name").."!")
		parse("sv_sound \"sounds/lightningbolt.ogg\"")
	end
end

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
addhook("say","player_say")
function player_say(p,txt)
	if (txt=="!slay") then
		parse("killplayer "..p)
		msg("©255255255The lightning has struck against "..player(p, "name").."!")
		parse("sv_sound \"wc3tft_2d/lightningbolt.ogg\"")
	end
end
This works, but all it does is kills myself. I want one that I can use on player id's.

1
2
3
4
5
6
7
8
addhook("say","player_say")
function player_say(p,txt)
	if (txt=="!slay USER") then
		parse("killplayer " "..player(p, "name")..")
		msg("©255255255The lightning has struck against "..player(p, "name").."!")
		parse("sv_sound \"wc3tft_2d/lightningbolt.ogg\"")
	end
end
Could this work?
To the start Previous 1 214 15 16338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview