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 2152 153 154338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
Yes, that won't print hi (as intended)
You don't need to use parenthesis, you might want to use them when you are using various "or"s and "and"s so you won't mess up.

alt Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Zitieren
Hey, I can't find math.round, so I guess I just have to do it some way else, How would I do it so that it finds a decimal point then gets rid of everything else after the ".".

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
You can use math.floor or math.ceil.
Or you can try something like this:
1
2
3
4
5
6
7
8
function math.round(n)
	a = math.floor(n) + 0.5
	if a > n then
		return math.floor(n)	
	elseif a <= n then
		return math.ceil(n)
	end
end

This would round 1.5 to 2
1.3 to 1
4.7 to 5
etc.

alt Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Zitieren
Thanks, I thought math.floor did something else

Alright, I have another question, Can you return something on multiple hooks like..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("say","hi")
function hi(id,txt)
if (txt == "!Hi") then
print("memememememe")
return 1
end
end
addhook("say","hi2")
function hi2(id,txt)
if (txt == "!Hi2") then
print("ememememememe")
return 1
end
end
Alright, is this legal? Cause it isn't returning both. How supposedly could I do this?
1× editiert, zuletzt 29.01.10 01:24:40

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
You should use one function per hook.
Use
1
2
3
4
5
if txt=="!Hi" then
	--Stuff
elseif txt=="!Hi2" then
	--Stuff
end
Instead.

alt Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Zitieren
Nvm, Well, I want to remove a value from a certain position, Like
table = {1,2}
function Masc()
remove.table(table[1])
end
Shouldn't it remove the 1? and have the 2 replace as 1?

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Zitieren
1
2
table_num = {1,4,2,5}
table.remove([b]table_num, 2[/b])
You should check list of Lua commands, I noticed you haven't read any table tutorial.
1× editiert, zuletzt 29.01.10 12:46:41

alt Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Zitieren
Waw.. www.lua.org/manual/5.1 .. i Really don't understand anything!

But i got more for your script SenSidethink.. - If you want it (;
Here is the code for my KpD hud
1
2
3
4
5
6
7
8
9
10
11
if player(id,"deaths") == 0 and player(id,"score") > 0 then
	KpD = player(id,"score")
elseif player(id,"deaths") == 0 then
	KpD = 0
else
	KpD = tostring(player(id,"score")/player(id,"deaths"))
	if string.len(KpD) > 4 then
		KpD = string.sub(KpD,1,4)
	end
end
parse('hudtxt2 '..id..' 7 "©000255000KpD: '..KpD..' " 5 157')		--Remember that this is my position (5 157) use your own!
I just wanted to be able to see my KpD before i was dead first time..
Fx. If i had 5 kills and 0 deaths, then my KpD would just be 0.
So what this actually does is that it shows what your KpD would be after your first death...
Fx. Now. If i have 5 kills and 0 deaths, my KpD will be 5.

Not easy to understand, sorry But i hope you like it (;

----------------------------------------------------------------------------------

I'm have a question. I think it have been asked before, but i didn't saw the answer.
Can i add a hook in another hook?
Because.. I'm trying to add a "Knife-kills:" hudtxt.
This is the code i got for now:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("kill","akd_hud_kill")
function akd_hud_kill(killer,weapon)

	-- Knife-Kills
	KK = 0
	if (weapon==50) then
		KK = KK + 1
		parse('hudtxt2 '..killer..' 5 "©000255000Knife-kills: '..KK..' " 5 170')
	end
	parse('hudtxt2 '..killer..' 5 "©000255000Knife-kills: '..KK..' " 5 170')

end

But with this code the hudtxt first shows on first knife-kill..
So i think i will put this hook in an "always" hook.
Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
addhook("always","akd_hud")
function akd_hud()

addhook("kill","akd_hud_kill")
function akd_hud_kill(killer,weapon)

	-- Knife-Kills
	KK = 0
	if (weapon==50) then
		KK = KK + 1
		parse('hudtxt2 '..killer..' 5 "©000255000Knife-kills: '..KK..' " 5 170')
	end
	parse('hudtxt2 '..killer..' 5 "©000255000Knife-kills: '..KK..' " 5 170')

end

end

Can i do that?
- And i think there is some bugs (: If you see one -> Tell me please
7× editiert, zuletzt 29.01.10 20:03:14

alt ?

DRoNe
User Off Offline

Zitieren
Is this script possible? if i want push button in menu, and he triggers sv_fow to 1 only for concrete player wich push it?

alt Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Zitieren
DRoNe hat geschrieben
Is this script possible? if i want push button in menu, and he triggers sv_fow to 1 only for concrete player wich push it?


Sure (:
- But i can't script menus (;

alt Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Zitieren
DRoNe hat geschrieben
and if player say for example !NOFOG?


Sure!

...I dont know the code for te fog...
but here is some code you need:
1
2
3
4
5
6
addhook("say","YOUR_NAME_HERE")
function YOUR_NAME_HERE(id,txt)
	if (txt=="!NOFOG") then
		--The fog code here. (:
	end
end

alt Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Zitieren
Ohh.. yea (:

Complete code:
1
2
3
4
5
6
addhook("say","YOUR_NAME_HERE")
function YOUR_NAME_HERE(id,txt)
	if (txt=="!NOFOG") then
		parse("sv_fow 0") --"fow" means "Fog of war"
	end
end

Another way i would make it:
1
2
3
4
5
6
7
8
9
10
addhook("say","YOUR_NAME_HERE")
function YOUR_NAME_HERE(id,txt)
	if (txt=="!FOG") then
		if (sv_fow==0) then
			parse("sv_fow 1") --"fow" means "Fog of war"
		else
			parse("sv_fow 0")
		end
	end
end
Here in my way..
If you type: "!FOG" then:
if the fow is set to 0 it will be set to 1
or if the fow is set to 1 it will be set to 0.

Very basic (:

alt Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Zitieren
@blazzingxx I read the tutorial, partially, I look at what I need to, But since the lua gave me a help that had [] brackets, I thought they were needed.
Zum Anfang Vorherige 1 2152 153 154338 339 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht