Forum

> > CS2D > General > Prevent turrets from damaging each other
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Prevent turrets from damaging each other

4 replies
To the start Previous 1 Next To the start

old Prevent turrets from damaging each other

bratwurst
User Off Offline

Quote
I have just noticed that when I build a turret on my server, it will damage my other turrets if a player running between the turrets creates crossfire. Is there a way to disable this?

old Re: Prevent turrets from damaging each other

DC
Admin Off Offline

Quote
aww.. forgot about that.. too bad. I guess it doesn't work then...

I was thinking about checking the weapon which did the damage, because turrets have the internal weapon id 253 but objectdamage does not have a weapon parameter...

I can only think of another, pretty complicated and dirty solution: check if it is possible that it was the player who did the damage on the turret by checking the rotation and position of the player. it probably was one of the turrets if the player is far away/not looking at the turret which has been hit.

or: check if the turret which has been hit is created by the same player and return 1 in this case (side effect: players can't damage their own turrets at all). you could extend that so only Ts can damage CT turrets and vice versa...

old Re: Prevent turrets from damaging each other

MasterAsp
User Off Offline

Quote
Okay thanks, that's what I was thinking to do.

Here's the code that works for it, but a lot of problems such as, grenades (if you don't look at the building your destroying with them) don't damage them(I don't know how to fix it) and if your looking at the object when the turret is shooting then it damages the the object.
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("objectdamage", "blockdamage")
function blockdamage(type2, damage, id)
	if (tonumber(player(object(type2,"player"),"team")) ~= 0) then
		if (player(id,"exists")) then
			x = player(id,"x")
			y = player(id,"y")
			if not (math.abs(math.rad(player(id,"rot")) - math.atan2(y-object(type2,'y'),x-object(type2,'x') - (math.pi/2)%(math.pi*2))) <= 1.6) then
				return 1
			end
		end
	end
	return 0
end
edited 1×, last 26.12.10 04:12:32 am
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview