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 2150 151 152338 339 Next To the start

old Re: Lua Scripts/Questions/Help

SenSidethink
User Off Offline

Quote
That doesnt work too..
The first line
1
if wp == 34 or 35 then
is checking if u use a "Sniper".

So..
1
2
3
4
5
6
7
8
9
if wp == 34 or 35 then
 	xxx
else
	if random < 6 then
		hpdmg = critdmg
		parse("sethealth "..i.." "..player(i,"health")-hpdmg)
		return 1
	end
end
Shoud be right.

Problem is that CS2D means the Error is in Line 100,
thats the start off:
1
2
3
4
5
6
addhook("select","RandomCritMode")
funtion RandomCritMode(i,itemtype,mode)
     if itemtype == 34 or itemtype == 35 then
          smode = mode
     end
end
in my Script.

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
I go test script for you

I will bring the results back

Results are back:

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
-----------------------
-- RANDOM CRIT --
-----------------------
local smode = 0
addhook("hit","RandomCrit")
function RandomCrit(i,s,wp,hpdmg,apdmg)
critdmg = hpdmg * 2
random = math.random(1,100)
if wp == 34 or 35 then
     if random < 21 then
          if smode == 0 then
               hpdmg = critdmg
               parse("sethealth "..i.." "..player(i,"health")-hpdmg)
               return 1
          end
     end
     if random < 31 then
          if smode == 2 then
               hpdmg = critdmg
               parse("sethealth "..i.." "..player(i,"health")-hpdmg)
               return 1
          end
     end

     if random < 41 then
          if smode == 3 then
               hpdmg = critdmg
               parse("sethealth "..i.." "..player(i,"health")-hpdmg)
               return 1
          end
     end
     elseif random < 6 then
          hpdmg = critdmg
          parse("sethealth "..i.." "..player(i,"health")-hpdmg)
          return 1
     end
end

addhook("select","RandomCritMode")
[b]function[/b] RandomCritMode(i,itemtype,mode)
if itemtype == 34 or itemtype == 35 then
smode = mode
end
end

It seems you...

spelled "function" as "funtion"

old Re: Lua Scripts/Questions/Help

SenSidethink
User Off Offline

Quote
LOL, thanks.
*facetokeyboard* >_<

But one new Problem..
if u kill someone with a Crit now,
it doest raise ur kills

Its because of the -health command..
the game things a explotion or something
killed it

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
im sure you can use

parse("explosion "..player(i,"x").." "..player(i,"y").." 1 1 "..s)

after the sethealth

just so you can get a "kill"

old Re: Lua Scripts/Questions/Help

SenSidethink
User Off Offline

Quote
1
2
3
4
5
6
7
hpdmg = critdmg
			if player(i,"health") < hpdmg then
				customkill(s, item(wp,"name"), i)
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
			return 1

Shoud work right?

Ignore it.. i am sleepy
Forget parse() and so.

Edit:
When i use it with parse and everythink i still dont
get a "customkill" when i 1hit someone with a crit.

I have this atm
1
2
3
4
5
6
7
8
hpdmg = critdmg
			if player(i,"health") < hpdmg then
				parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
				parse("sv_sound \"DK/headshot.wav\"")
				msg(player(s,"name").." made a Headshot!")
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
But why its not allways a "Headshot" if u kill someone
with a crit?
edited 3×, last 28.01.10 03:33:45 am

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
By your definition of a critical hit, every time that a person is killed, it will automatically be a critical hit... is that how you intended it?

old Re: Lua Scripts/Questions/Help

SenSidethink
User Off Offline

Quote
Its part of this.

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
57
58
59
60
61
62
63
64
65
66
67
68
69
-----------------------
-- RANDOM CRIT --
-----------------------
addhook("hit","RandomCrit")
function RandomCrit(i,s,wp,hpdmg,apdmg)
critdmg = hpdmg * 2
random = math.random(1,100)
if wp == 34 or 35 then
	if random < 21 then
		if smode == 0 then
			hpdmg = critdmg
			if player(i,"health") < hpdmg then
				parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
				parse("sv_sound \"DK/headshot.wav\"")
				msg(player(s,"name").." made a Headshot!")
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
			return 1
		end
	end
	if random < 31 then
		if smode == 2 then
			hpdmg = critdmg
			if player(i,"health") < hpdmg then
				parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
				parse("sv_sound \"DK/headshot.wav\"")
				msg(player(s,"name").." made a Headshot!")
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
			return 1
		end
	end
	if random < 41 then
		if smode == 3 then
			hpdmg = critdmg
			if player(i,"health") < hpdmg then
				parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
				parse("sv_sound \"DK/headshot.wav\"")
				msg(player(s,"name").." made a Headshot!")
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
			return 1
		end
	end
else
	if random < 6 then
		hpdmg = critdmg
		if player(i,"health") < hpdmg then
			parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
			parse("sv_sound \"DK/headshot.wav\"")
			msg(player(s,"name").." made a Headshot!")
		else
			parse("sethealth "..i.." "..player(i,"health")-hpdmg)
		end
		return 1
	end
end
return 0
end

addhook("select","RandomCritMode")
function RandomCritMode(i,itemtype,mode)
     if itemtype == 34 or itemtype == 35 then
          smode = mode
     end
end

I think its only a little "bug" in my head..
Someone see why its not allways a Headshot when
u kill someone with a crit?

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
See where the event stopped propagating towards the next condition by adding msg()s to debug the script. For example, if the test case expects a headshot with weapons 34 or 35, then place a

msg(player(i, "name").." deals "..hpdmg.." from a total of " .. player(i, "health"))

into the scope above the customkill condition, if that fails to trigger, then add in a different log to the scope above that one, and so on, until you reach the scope of the function

old Re: Lua Scripts/Questions/Help

SenSidethink
User Off Offline

Quote
I think i got it.
The Error was in:
1
if player(i,"health") < hpdmg then

Needs to be:
1
if player(i,"health") < hpdmg or player(i,"health") == hpdmg then


Can someone please test this:
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-----------------------
-- RANDOM CRIT --
-----------------------
addhook("hit","RandomCrit")
function RandomCrit(i,s,wp,hpdmg,apdmg)
critdmg = hpdmg * 2
random = math.random(1,100)
if wp == 34 or 35 then
	if random < 21 then
		if smode == 0 then
			hpdmg = critdmg
			if player(i,"health") < hpdmg or player(i,"health") == hpdmg then
				parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
				parse("sv_sound \"DK/headshot.wav\"")
				heads=heads+1
				msg(player(s,"name").." made a Headshot!@C")
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
			return 1
		end
	end
	if random < 31 then
		if smode == 2 then
			hpdmg = critdmg
			if player(i,"health") < hpdmg or player(i,"health") == hpdmg then
				parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
				parse("sv_sound \"DK/headshot.wav\"")
				heads=heads+1
				msg(player(s,"name").." made a Headshot!@C")
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
			return 1
		end
	end
	if random < 41 then
		if smode == 3 then
			hpdmg = critdmg
			if player(i,"health") < hpdmg or player(i,"health") == hpdmg then
				parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
				parse("sv_sound \"DK/headshot.wav\"")
				heads=heads+1
				msg(player(s,"name").." made a Headshot!@C")
			else
				parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			end
			return 1
		end
	end
else
	if random < 6 then
		hpdmg = critdmg
		if player(i,"health") < hpdmg or player(i,"health") == hpdmg then
			parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
			parse("sv_sound \"DK/headshot.wav\"")
			heads=heads+1
			msg(player(s,"name").." made a Headshot!@C")
		else
			parse("sethealth "..i.." "..player(i,"health")-hpdmg)
			return 1
		end
	end
end
return 0
end

addhook("select","RandomCritMode")
function RandomCritMode(i,itemtype,mode)
     if itemtype == 34 or itemtype == 35 then
          smode = mode
     end
end

Edit: Ignore the "heads =" and so

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
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
math.randomseed(os.time())
math.random(1, 100)

function critHit(i, s, wp, hp)
	if player(i,"health") <= hp then
		parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
		parse("sv_sound \"DK/headshot.wav\"")
		msg(player(s,"name").." made a Headshot!")
	else
		parse("sethealth "..i.." "..player(i,"health")-hp)
	end
	return 1
end

addhook("hit", "RandomCrit")
function RandomCrit(i,s,wp,hpdmg,apdmg)
	local critdmg = hpdmg * 2
	local random = math.random(100)
	if wp == 34 or 35 then
		if (random < 21 and smode == 0) or (random < 31 and smode == 2) or (random < 41 and smode == 3) then
			return critHit(i,s,wp,critdmg)
		end
	elseif random < 6 then
		return critHit(i,s,wp,critdmg)
	end
	return 0
end

addhook("select","RandomCritMode")
function RandomCritMode(i,itemtype,mode)
	if itemtype == 34 or itemtype == 35 then
		smode = mode
	else
		smode = nil
	end
end

old Re: Lua Scripts/Questions/Help

SenSidethink
User Off Offline

Quote
Thanks very much.

Edited it a bit for my Server:
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
-----------------------
-- RANDOM CRIT --
-----------------------
addhook("hit", "RandomCrit")
function RandomCrit(i,s,wp,hpdmg,apdmg)
	local critdmg = hpdmg * 2
	local random = math.random(100)
	if wp == 34 or 35 then
		if (random < 21 and smode == 0) or (random < 31 and smode == 2) or (random < 41 and smode == 3) then
			return RandomCritHit(i,s,wp,critdmg)
		end
     elseif wp > 0 and wp < 41 then
		if random < 6 then
			return RandomCritHit(i,s,wp,critdmg)
		end
	end
	return 0
end

addhook("select","RandomCritMode")
function RandomCritMode(i,itemtype,mode)
	if itemtype == 34 or itemtype == 35 then
		smode = mode
	else
		smode = 0
	end
end

function RandomCritHit(i, s, wp, hp)
	if player(i,"health") <= hp then
		parse('customkill '..s..' "'..itemtype(wp,'name')..'" '..i)
		parse("sv_sound \"DK/headshot.wav\"")
		msg(player(s,"name").." made a Headshot!")
		heads=DK.ut.heads[s]
		heads=heads+1
		DK.ut.heads[s]=heads
	else
		parse("sethealth "..i.." "..player(i,"health")-hp)
	end
	return 1
end

Problem:
i made this line:
1
elseif wp > 0 and wp < 41 then
But can still crit with a knife
Someone kill me if i didnt just saw something -.-
6am here ^^'

old Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Quote
Hi guys! I'm new at using lua-script, and i just have a question:
How can i Give other players weapons when they spawn? (:

I've got this code but i dont work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
addhook("spawn","akd_weaponmod_spawn")
function akd_weaponmod_spawn(id)			-- Do i need the "id" here?
for (i = 1, 32, 1) do
	if (player(i, "exists")) then
		-- Remove Glock
		parse("strip "..i.." 2")

		-- Remove USP
		parse("strip "..i.." 1")

		-- Equip P90
		parse("strip "..i.." 20")

		-- Leftclick knife-dmg to 25
		parse("mp_wpndmg knife 25")

		-- Rightclick knife-dmg to 10
		parse("mp_wpndmg_z1 knife 10")
	end
end
end

What is wrong? (:

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Once again, please insert
1
2
math.randomseed(os.time()) 
math.random(100)
back into the code. If you haven't noticed yet, math.random(100) will generate the same sequence of random numbers unless you seed it with the current time.

Also, you did not declare the global table DK yet, therefore you will not be able to achieve the customkill effect.

Insert into the global scope (outside of all functions)
1
DK = { ut = { heads = {} } }

Also please change
1
2
3
heads=DK.ut.heads[s] 
		heads=heads+1 
		DK.ut.heads[s]=heads
to
1
2
if not DK.ut.heads[s] then DK.ut.heads[s] = 0 end
		DK.ut.heads[s] = DK.ut.heads[s] + 1

You will also need to create a leave hook to reset the DK.ut.heads[player] given that the variable player contains the ID of the player who've left.

Quote
Problem:
i made this line:

1
elseif wp > 0 and wp < 41 then

But can still crit with a knife


That's impossible.

Anders4000 has written
Hi guys! I'm new at using lua-script, and i just have a question:
How can i Give other players weapons when they spawn? (:

I've got this code but i dont work:
...
1
2
3
4
5
6
7
8
function akd_weaponmod_spawn(id)               -- Do i need the "id" here? 
for (i = 1, 32, 1) do 
		...
		-- Equip P90 
		parse("strip "..i.." 20") 
		...
end
end


You're using the wrong sets of logic. The spawn hook is called every time that a player is spawned, therefore, each time a player spawns, every single player in the server gets their weapons stripped...

Also, the command for equiping weapons is equip id wpn

Change to
1
2
3
4
5
6
7
function akd_weaponmod_spawn(i) 
	-- remove the for and the if statement that follows
	...
	-- Equip P90 
	parse("equip "..i.." 20") 
	...
end

old Re: Lua Scripts/Questions/Help

Anders4000
User Off Offline

Quote
SenSidethink has written
The DK Table is there, just not deaclared in
the Crit Func

Fixed the Randomseed thing,
my only Problem is..

I dont know why, but i still CAN crit with
a knife

Screen:
http://b83.img-up.net/Screen17nys.jpg

Done with a Knife and some Bots..
at the Upper right u see the "Customkills" too


On the picture..
What is the lua-script up left corner saying your KpD?
I could use that very much dude! o:
- Is it uploaded? (: Then send me a link

And guys..? In the top right corner there is a image of a knife instead of the dustom text saying "knife" (There is also the "costom text" Haha) How do i make that? o:
Is that what SenSidethink is working on? (;

old Re: Lua Scripts/Questions/Help

SenSidethink
User Off Offline

Quote
The KpD Hud is simply this:

1
2
3
4
5
6
7
8
9
if 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')
To the start Previous 1 2150 151 152338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview