Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Lua Scripts/Questions/Help

6.770 Antworten
Seite
Zum Anfang Vorherige 1 214 15 16338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Zitieren
Admin hat geschrieben
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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Zitieren
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.

alt Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Zitieren
LinuxGuy hat geschrieben
Jonzku777 hat geschrieben
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

alt Re: Lua Scripts/Questions/Help

Alpha Beta
User Off Offline

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

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

alt geschlossen Re: Lua Scripts/Questions/Help

Dark M
User Off Offline

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

Admin/Mod Kommentar

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

alt Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Zitieren
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!
1× editiert, zuletzt 14.06.09 17:15:16

alt Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Zitieren
TheKilledDeath hat geschrieben
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?
1× editiert, zuletzt 14.06.09 18:03:46

alt Re: Lua Scripts/Questions/Help

wups
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Zitieren
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?
Zum Anfang Vorherige 1 214 15 16338 339 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht