Forum

> > CS2D > Scripts > Attack2(id,mode)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Attack2(id,mode)

17 replies
To the start Previous 1 Next To the start

old Attack2(id,mode)

Anders4000
User Off Offline

Quote
Does anyone know what the parameter "mode" in the function Attack2 do? There is no explanation in the LUA/info.txt file (:

- Anders4000

old Re: Attack2(id,mode)

DC
Admin Off Offline

Quote
numeric values which express the mode/state of the weapon. either the current mode or the mode you are about to switch to. I'm not sure.

for silenced weapons:
0 - unsilenced
1 - silenced

for sniper weapons:
0 - unzoomed
1 - zoom level 1
(2 - zoom level 2 - if available)

laser:
0 - green
1 - next color
2 - next color
...

and so on. no guarantee. better test it with a print or something

old Re: Attack2(id,mode)

Anders4000
User Off Offline

Quote
DC, i really need a way to find out if a player rightclicks or leftclicks with the knife... Do you think there is a way to do this?

Well.. I tried this:
1
2
3
4
5
6
7
8
9
10
11
12
13
rightclick = {0,0,0.....}

function attack2(id)
	rightclick[id] = 1
end

function attack(id)
	rightclick[id] = 0
end

function OnKill(Killer)
	--code
end

Don't worry, the making of the rightclick table was made with an arrayinit... And the functions was added as hooks. Just made you a quick example.

old Re: Attack2(id,mode)

JONY
User Off Offline

Quote
Anders4000, I would do it the other way: addhook to "hit" and check the damage (and weapon) - that's how you determine if it's right or left click. Then check if player(victim,"health")-damage is more or less than 0 - that's how you determine whether player dies or not.
J.

Edit:
here's the code (I dont know exact damage of left click and right click from knife):
1
2
3
4
5
6
7
8
9
10
addhook("hit","check")
function check(id,source,weapon,hpdmg)
	if (weapon == 50) --was the hit made by knife?
		if (hpdmg<50) and (player(id,"health")-hpdmg)<1 then
			--'source' hit 'id' with LEFT click and 'id' dies
		else if (hpdmg>50) and (player(id,"health")-hpdmg)<1 then
			--'source' hit 'id' with RIGHT click and 'id' dies
		end
	end
end
edited 2×, last 14.01.11 10:26:02 pm

old Re: Attack2(id,mode)

EngiN33R
Moderator Off Offline

Quote
Yet I don't think he needs to check whether damage has been done or not, and if so, anders's code is good.

old Re: Attack2(id,mode)

Anders4000
User Off Offline

Quote
No. Both leftclick and rightclick has 100 dmg. But i want left click to plus an int with 2 and rightclick to plus it with 1, to fix a bug (:

old Re: Attack2(id,mode)

JONY
User Off Offline

Quote
left and right click have different damages, dude... unless you changed it with lua of course.

old Re: Attack2(id,mode)

JONY
User Off Offline

Quote
That's the best I can think of:
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
local left={}
for i=1,32 do
	left[i]=true
end

addhook("attack","change1")
function change1(id)
	left[i]=true
end

addhook("attack2","change2")
function change2(id)
	left[i]=false
end

addhook("kill","check")
function check(killer,victim,weapon,)
	if (weapon==50) then
		if (left[killer] == true) then
			--'VICTIM' WAS KILLED WITH LEFT CLICK
		else
			--'VICTIM' WAS KILLED WITH RIGHT CLICK
		end
	end
end

EDIT:
lol, I did it the same way you wanted didnt see it before

old Re: Attack2(id,mode)

Anders4000
User Off Offline

Quote
Okay, i've done enough testing to be able to point out, that my killhook gets called before my attackhook. Therefore, if i click the leftmouse once, and then kill somebody with rightclick afterwards, then the code for leftclick will be executed.

My attackhooks are written before my Killhook. But that doesn't help.

Anyway i can change this? Or solve this problem?

old Re: Attack2(id,mode)

Cure Pikachu
User Off Offline

Quote
1
2
addhook("attack","change1",-2)
addhook("attack2","change2",-1)
Hope it works
edited 1×, last 17.01.11 03:07:15 pm

old Re: Attack2(id,mode)

Anders4000
User Off Offline

Quote
If i do this following will that change the order then?
1
2
3
addhook("attack","change1",-2)
addhook("attack2","change2",-1)
addhook("kill","OnKill")

old Re: Attack2(id,mode)

JONY
User Off Offline

Quote
info.txt has written
Priority is only important if there is more than one function attachted to the same hook!
Default is 0, higher numbers = higher priority, lower numbers (also negative) = lower priority.
The attached function with the HIGHEST priority is the LAST function which will be executed.
Moreover CS2D will take the return value of this function (if there is any)!
In most cases you will just omit the priority parameter (yes, it is [optional])!


I think you should do this (although priority is only when there are 2 functions to the same hook):
1
2
3
addhook("attack","change1",1)
addhook("attack2","change2",1)
addhook("kill","OnKill",0)

old Re: Attack2(id,mode)

KimKat
GAME BANNED Off Offline

Quote
Is it possible to perhaps attach a "attack2" to a weapon without a alternative attack. Such as M3, when you right click it will shoot grenades at enemy or similar. Would be funny.

old Re: Attack2(id,mode)

JONY
User Off Offline

Quote
Shoot grenades with right click (I made it a while ago and it works only for single player):
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
addhook("join","setforall")
function setforall(id)
	parse("bind mouse2 \"attack2;say !shoot_grenade\"")
end

addhook("say","bob")
function bob(id,m)
	if (m=="!shoot_grenade") then
		parse("equip "..id.." 49")
		parse("setweapon "..id.." 49")
		parse("attack")
		timer(10,"stripthismadafaka",tostring(id),1)
	end
	return 1
end

addhook("attack","sda")
function sda(id)
	bob(id,"!shoot_grenade")
end

function stripthismadafaka(lol)
	local id = tonumber(lol)
	parse("strip "..id.." 49")
end

addhook("leave","unbind")
function unbind(id)
	parse("bind mouse2 \"attack2\"")
end

old Re: Attack2(id,mode)

Vectarrio
User Off Offline

Quote
Unfortunately, I made test-script with attack2, and it works only with weapons which use this alt. attack (usp,m4a1,famas,laser,e.t.c.)

old Re: Attack2(id,mode)

Anders4000
User Off Offline

Quote
As Kimkat said, it's only for multiple functions within a hook.

Anything else i could try?
I bet shall just tell people that they have to use rightclick and that mouse1 will not give extra ammo, and then just release this...
Or maybe you can use leftclick for faster knifing, if you just want a kill but not ammo
Anyways, you probably don't understand me

Anyone else knows what i could do to fix this bug?
- Anders4000
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview