Forum

> > CS2D > Scripts > Lua Question - Knife Kill Hook
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Question - Knife Kill Hook

16 replies
To the start Previous 1 Next To the start

old Lua Question - Knife Kill Hook

Anders4000
User Off Offline

Quote
Hello! (:

I've made a kill where a variable get increased by 1 and equip some things, when you kill one with knife. (if weapon is knife)
But it only works when i rightclick with the knife, and there is no errors in console, any ideas?
Here is the script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
parse("mp_wpndmg knife 100")
parse("mp_wpndmg_z1 knife 100")
BulletsPos		= "50 65"
Bullets = Array(game("sv_maxplayers"),StartingBullets)

addhook("kill","OnKill")
function OnKill(killer)
	Bullets[killer] = Bullets[killer] + 1
	parse("equip "..killer.." 3")
	parse("setweapon "..killer.." 3")
	parse('hudtxt2 '..killer..' 4 "©000255000Bullets: '..Bullets[killer]..'" '..BulletsPos)
	for b = 1, game("sv_maxplayers"), 1 do
		if Lives[b] == 0 then
			if #player(0,"tableliving") == 1 then
				AutoSpec(killer)
				NextMap()
			end
		end
	end
end

Only posted the importent code...
Tell me if it's not enough.

Thanks in advance!
- Anders4000
edited 1×, last 06.01.11 06:11:19 pm

old Re: Lua Question - Knife Kill Hook

Geez
GAME BANNED Off Offline

Quote
== EDIT 11.01.2011 ==

Moved to another topic.


Original post:
More >
edited 1×, last 11.01.11 08:09:56 pm

old Re: Lua Question - Knife Kill Hook

Anders4000
User Off Offline

Quote
@Headhunter, my idea is that i want 1 more bullet when i kill someone with knife, or any weapon. But if i knife, it only works if i rightclick...

@Qrchack, I could make it, but it will be when i'm done with my One in the Chamber mod.
So if you don't wanna wait, ask Blazzing, maybe he want some work (:

You could ask out loud on the Script forum too
edited 1×, last 06.01.11 09:39:15 pm

old Re: Lua Question - Knife Kill Hook

Banaan
User Off Offline

Quote
I have the feeling that this is not all of the (for this problem) important code. The thing where it goes wrong, the weapon checking, is not included in the snippet you posted. So we can't help you.

old Re: Lua Question - Knife Kill Hook

Anders4000
User Off Offline

Quote
There is no weapon check
Cus it's the deagle and knife that gives extra bullet, everything else is stripped on spawn (:
So there is no need for a weaponcheck..

Sry i made wrong @s in my last post :p

old Re: Lua Question - Knife Kill Hook

Lee
Moderator Off Offline

Quote
Anders4000 has written
That doesn't matter, there is no check code!


If you still want to have only knife-2 trigger the event, this is how:

1
2
3
4
5
6
7
8
9
10
11
12
13
att2 = {}
addhook("attack2", "att2_on")
function att2_on(id) att2[id] = true end

addhook("attack", "att2_off")
function att2_off(id) att2[id] = false end

addhook("kill", "knife2_kill")
function knife2_kill(id, v, w)
	if w == 50 and att2[id] then
		-- Code to give bullets and etc
	end
end

old Re: Lua Question - Knife Kill Hook

Lee
Moderator Off Offline

Quote
Anders4000 has written
Sorry man, I think you can't understand me I want Knife1 to work with my hook. Hook only get executed on Knife2 but i want it on Knife1 too!


That's impossible, either you're doing something wrong or you've used the wrong hooks.

old Re: Lua Question - Knife Kill Hook

Anders4000
User Off Offline

Quote
Lol.. So it's not possible to have an event executed on a simple knife kill, Hmm s:
That sucks?
Gonna try to make a new script only with Killhook now, and see if i can get that working.

EDIT:
I fixed it. When you hold down mousekey1 you automaticly fire 1 shot when you get the pistol equiped. So i have to give the player 2 shots instead of 1 when he kill with knife.
It will be a problem though. Cus if the player kills 1 with knife he automaticly gets the pistol equiped, fires 1 shot, and the other now know where he is if they listen. He will still have 1 shot left though, because he gets 2 bullets for the knife kill with mouse1.

Confusing i know, sorry
- Anders4000

Ps. Thanks for the post with the kill1 or kill2 hooks Lee, I will be using them, so the player only get 1 bullet when "Rightclick Knifing" (:

EDIT2:
Ohh x.x Things just still don't wanna work :p
edited 4×, last 08.01.11 04:15:23 pm

old Re: Lua Question - Knife Kill Hook

KimKat
GAME BANNED Off Offline

Quote
Perhaps this Lua script works...
1
2
3
4
5
6
7
8
9
10
addhook("kill","kill_event")
function kill_event(killer,victim,weapon,x,y)
	if (player(killer,"exists")) then
		if(weapon == 50) then
			-- code
		end
	elseif (player(victim,"exists")==false) then
		-- do nothing
	end
end
This Lua script will check if the killer exists then also checks if the killer has weapon knife equipped and then the code will execute. But if there is no victim on kill script will do nothing, in example; if the victim leaves server or something. This will work using both attack(left click) and attack2(right click).

I am not entirely sure it works but my logic tells me it will. Lol.

old Re: Lua Question - Knife Kill Hook

Anders4000
User Off Offline

Quote
Hah, i've just f*cked it all up, everything is a mess and now bullets starts to count down and such when i knife with leftclick

If there is a kind person who has no life, go ahead and look through my code

More >


PS. DC get those tabing errors fixed, and allowed more than 1 space in a row in [ code ] tags (:
(Gonna keep remind you untill you fix it xD)
edited 2×, last 10.01.11 03:16:04 pm

old Re: Lua Question - Knife Kill Hook

DannyDeth
User Off Offline

Quote
Anders4000 has written
@Qrchack, I could make it, but it will be when i'm done with my One in the Chamber mod.
So if you don't wanna wait, ask Blazzing, maybe he want some work (:

A: Blazz doesn't have that much spare time, he is already working on 2 projects ( last time I checked, that is ).
B: It isn't that complex, lol. You don't need some expert to do it for you.

old Re: Lua Question - Knife Kill Hook

Anders4000
User Off Offline

Quote
DannyDeth has written
Anders4000 has written
@Qrchack, I could make it, but it will be when i'm done with my One in the Chamber mod.
So if you don't wanna wait, ask Blazzing, maybe he want some work (:

A: Blazz doesn't have that much spare time, he is already working on 2 projects ( last time I checked, that is ).
B: It isn't that complex, lol. You don't need some expert to do it for you.


Heh.. Blazzing is just the only moddername I remember (: Could have told him to just ask another 1... But I didn't :s


∗√ EDIT:

What does the parameter "mode" do in the function Attack2 do? There is no explanation in the info.txt file (:
edited 1×, last 12.01.11 08:14:24 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview