Forum

> > CS2D > Scripts > Disable friendly fire from CT turrets(?)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Disable friendly fire from CT turrets(?)

11 replies
To the start Previous 1 Next To the start

old Disable friendly fire from CT turrets(?)

Casper-
User Off Offline

Quote
I've ran into a problem, I'm running a script that disables friendly fire from (blue) team turrets and it works perfectly... as long as the player id (owner) of that turret doesn't change to opposing team (or even no owner of the turret). Then the friendly fire script doesn't work.

Image:


This is how it worked originally :
1
2
3
4
...
elseif player(victim,"team")==2 and weapon == 253 then 
return 1
...

My other attempts :
1
2
3
4
5
6
7
8
9
10
11
12
13
elseif player(source,"team")>=0 and player(victim,"team")==2 and weapon == 253 then
return 1 
...
local ot = object(oid,"team")
elseif ot==2 and player(victim,"team")==2 and weapon == 253 then
return 1 
...
local ot = object(oid,"type")
elseif ot==12 and player(victim,"team")==2 then
return 1
...
elseif player(source,"team")==2 and player(victim,"team")==2 and weapon == 253 then
return 1

old Re: Disable friendly fire from CT turrets(?)

Casper-
User Off Offline

Quote
So initially without script, friendly fire from turrets (accidental fire when turrets target the enemy and friendly is caught in turrets crossfire) teammates get damaged. My script prevented that.

However, when a player left/disconnected, the player ID (owner) of the building has no owner or switches to enemy team, as you see in picture, then it completely avoids my script and continues to do damage when crossfire happens, killing teammates in process.

If the owner of the CT turret is CT, friendly fire script works.
If the owner of the CT turret is T (or has no owner), friendly fire script doesn't work.

old Re: Disable friendly fire from CT turrets(?)

Bowlinghead
User Off Offline

Quote
Your provided code is missing some details. What is
weapon
for example?I am assuming that you use the cs2d lua hook hit hook?
What I dont understand is, that you dont even check for the owner of the turret (in your first original code). So the turrets team doesnt even matter.
Are you sure that you dont have other functions addhooked' to the hit function with a higher priority (and thus overwriting your 'return 1')?

old Re: Disable friendly fire from CT turrets(?)

Casper-
User Off Offline

Quote
Spoiler >

Yeah, there were 2 hit hooks and it was overriding something so I edited it.
Now it works, thank you very much!

This results in total turret immunity even from T turret, but since it's a PVE gamemode, it wont hurt to have it like this.

old Re: Disable friendly fire from CT turrets(?)

Bowlinghead
User Off Offline

Quote
I´m still a bit skeptical if your code works as intended
1
2
3
4
5
6
7
8
9
if player(victim,"team")==1 and weapon == 255 then -- BARBED WIRE FREEZE
	-->> Always true, no need to double check weapon here
	if weapon == 255 then
        	parse("speedmod "..victim.." -100")
	-->> Condition never true here because weapon is always 255 because of top condition
        elseif weapon <= 253 then --ALL WEAPON SLOW DOWN
        	parse("speedmod "..victim.." "..(zSPDmax-15).."")
	end
end

And naming the object parameter 'object' will potentially result in bugs when you want to use the cs2d cs2d lua cmd object function inside your hit function.
1
2
addhook("hit","weaponDamage")
function weaponDamage(victim,source,weapon,hpdmg,apdmg,rawdmg,object)

old Re: Disable friendly fire from CT turrets(?)

Casper-
User Off Offline

Quote
Thanks for pointing that out, re-edited it.
Spoiler >

old Re: Disable friendly fire from CT turrets(?)

Bowlinghead
User Off Offline

Quote
Your bot-code (line 13) will never get executed, unless the bot is a VIP and
unless you use VIPs, you can skip the CT check entirely.
No CT Check + better bot code >

But you probably only want CT bots to not get damaged by creatures:
No CT Check + only CT bot code >

old Re: Disable friendly fire from CT turrets(?)

Casper-
User Off Offline

Quote
This gave me a better perspective on how things work in code. Thank you very much! Will apply the first code since I need bots to not slow down by creatures, since bots ignore them completely.

old Re: Disable friendly fire from CT turrets(?)

Bowlinghead
User Off Offline

Quote
Quote
This gave me a better perspective on how things work in code. Thank you very much

∗ I dislike elseif
In my opinion, you should treat Luas "elseif" as "switch case" (known from other popular programming languages) only. In my opinion, my "only CT Check + only CT bot code" doesnt highlight the "this section is for CT only" stuff quite enough and isnt good readable code. Most of the time you can reach your goal using "if" and "else" seperatly in a more readable manner.
I hope you see what I mean with the following code examples.
elseif example >

∗ Reduce CS2D API calls
Advanced topic: Another thing to mention regarding perfomance is reducing the amount of CS2D API calls. (Some info here).
Here is your original re-edited code (your 3rd thread answer, 4th thread post submit) edited to have less API calls (note: it doesnt have all the other bugfixes we discussed earlier):
Less API calls >
edited 2×, last 30.12.23 04:58:36 am

old Re: Disable friendly fire from CT turrets(?)

Gaios
Reviewer Off Offline

Quote
Here's some OOP example
Spoiler >

old Re: Disable friendly fire from CT turrets(?)

Bowlinghead
User Off Offline

Quote
@user Gaios:
Your code doesnt work. You have to addhook functions via string (unless you use proxy hooks like in here, infos: cs2d lua cmd addhook ). Stop spreading hope
More >


But where is the point in OOP when you only have 1 single instance anyway?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview