Forum

> > CS2D > Scripts > Disable friendly-fire(and own) on turrets
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Disable friendly-fire(and own) on turrets

5 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Disable friendly-fire(and own) on turrets

SkullFace
User Off Offline

Zitieren
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

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

SkullFace
User Off Offline

Zitieren
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.
2× editiert, zuletzt 22.11.23 22:10:07

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

Cure Pikachu
User Off Offline

Zitieren
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
1× editiert, zuletzt 26.11.23 16:39:22
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht