Forum

> > CS2D > Scripts > Attack2(id,mode)
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Attack2(id,mode)

17 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Attack2(id,mode)

Anders4000
User Off Offline

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

- Anders4000

alt Re: Attack2(id,mode)

DC
Admin Off Offline

Zitieren
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

alt Re: Attack2(id,mode)

Anders4000
User Off Offline

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

alt Re: Attack2(id,mode)

JONY
User Off Offline

Zitieren
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
2× editiert, zuletzt 14.01.11 22:26:02

alt Re: Attack2(id,mode)

EngiN33R
Moderator Off Offline

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

alt Re: Attack2(id,mode)

Anders4000
User Off Offline

Zitieren
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 (:

alt Re: Attack2(id,mode)

JONY
User Off Offline

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

alt Re: Attack2(id,mode)

JONY
User Off Offline

Zitieren
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

alt Re: Attack2(id,mode)

Anders4000
User Off Offline

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

alt Re: Attack2(id,mode)

Cure Pikachu
User Off Offline

Zitieren
1
2
addhook("attack","change1",-2)
addhook("attack2","change2",-1)
Hope it works
1× editiert, zuletzt 17.01.11 15:07:15

alt Re: Attack2(id,mode)

Anders4000
User Off Offline

Zitieren
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")

alt Re: Attack2(id,mode)

JONY
User Off Offline

Zitieren
info.txt hat geschrieben
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)

alt Re: Attack2(id,mode)

KimKat
GAME BANNED Off Offline

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

alt Re: Attack2(id,mode)

JONY
User Off Offline

Zitieren
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

alt Re: Attack2(id,mode)

Vectarrio
User Off Offline

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

alt Re: Attack2(id,mode)

Anders4000
User Off Offline

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