Forum

> > CS2D > Scripts > Disable friendly-fire(and own) on turrets
Forums overviewCS2D overview Scripts overviewLog in to reply

English Disable friendly-fire(and own) on turrets

5 replies
To the start Previous 1 Next To the start

old Disable friendly-fire(and own) on turrets

SkullFace
User Off Offline

Quote
My goal is to disable accidental damage on turrets. Since the mod I'm trying to create makes turrets very weak in HP, so sometimes my own gunfire damages and kills turrets that are offscreen.
I know I can disable friendly fire with cs2d cmd mp_killteambuildings but I don't want to damage it by myself.

1
2
3
4
5
6
7
8
9
10
11
12
13
--FRIENDLY FIRE ON TURRET
addhook("objectdamage","turretDamageFriendly")

function turretDamageFriendly(oid,damage,player)

	if damage > 0 then 	--if damage is higher than 0
		if object(oid,"type") == 7 then 	--if dyn. object id is 7 (turret)
			if player(id,"team") == 2 then 	--if it is CT player damaging
				return 1 --don't damage building
			end
		end
	end
end

old Re: Disable friendly-fire(and own) on turrets

SkullFace
User Off Offline

Quote
Yes, sorry for confusion. My goal is to disable friendly to buildings from self and other players. Excluding opposing team. I have a way of removing buildings if they need to be removed.
edited 2×, last 22.11.23 10:10:07 pm

old Re: Disable friendly-fire(and own) on turrets

Cure Pikachu
User Off Offline

Quote
The existing script has most of it covered ye so...
Also BTW object type 7 according to this is a dispenser, if you want standard turret you want 8.
Also fixed an error with your parameter for player ID.
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("objectdamage","turretDamageFriendly")
function turretDamageFriendly(oid,damage,pl)
	if damage > 0 then	-- if damage is higher than 0
		local ot = object(oid,"type")
		if ot == 8 or ot == 11 or ot == 12 then	-- if object type is 8/11/12 (turrets)
			if pl > 0 then	-- check if damage caused by player (before doing team check)
				if math.min(object(oid,"team"),2) == math.min(player(pl,"team"),2) then
					return 1
				end
			end
		end
	end
end
edited 1×, last 26.11.23 04:39:22 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview