Space Engineers

Space Engineers

Froid's WeaponCore Rotor Turret Script
 This topic has been pinned, so it's probably important
Sigmund Froid  [developer] 23 Aug, 2020 @ 5:38am
Bugs and Issues Discussion
Post your bugs and issues here.

Bugs not to report:
  • The script says x Vanilla Weapons installed, but I only have x WC Weapons on the turret
    ->Seems like the script sometimes has problems aquiring the WC weapons and then lists some of them as Vanilla Weapons. Reload usually fixes the issue. Feel free to post bugged grids with modlist here for me to investigate.
Last edited by Sigmund Froid; 4 Oct, 2020 @ 5:59am
< >
Showing 1-15 of 52 comments
Natomic 15 Dec, 2020 @ 11:24am 
So I have the issue of it showing x vanilla when I only have WC weapons (it shows 1 vanilla and 4 WC, I only have 4 WC). Interestingly it also seems to mess with the firing code, looking through `AimAtTarget(Vector3D)` I guess it goes down the wrong path somewhere. I managed to fix it and get it firing by adding `StaticVanilla.Clear()` at the top of `AimAtTarget(Vector3D)`. I would love to know if there is a cleaner way around this or a better place to put that call. Its on a DS that I can't easily restart :).

Also currently it will only actually target something if I set it as the WC main target, it isn't picking up stuff from the WC turrets.
Last edited by Natomic; 15 Dec, 2020 @ 11:59am
Sigmund Froid  [developer] 15 Dec, 2020 @ 11:36am 
Thanks for your report. I'll look into it. Might be a bug left from the merge to the new API.
Natomic 15 Dec, 2020 @ 12:48pm 
Ok I did some debugging and I _think_ the issue is its picking the wrong designator. I got it to print the name of the designator (with `CustomName`) and it was selecting a weapon which was both off and out of range. Moving into range and turning it on has fixed it. Perhaps changing `Designator = WC_DIRECTORS[0];` to `Designator = WC_DIRECTORS.First(<test if it can hit its target>)` would fix it? (I think api.IsTargetAligned can be used but not sure how to get the weaponId).

Also the extra vanilla weapon has now vanished after deleting the group and recreating so I may have set that up wrong or something (or thats what a reload does ?).
Natomic 15 Dec, 2020 @ 2:08pm 
I've managed to get it selecting a working designator by
modifying the code in `getDesignators` as follows:
Originally posted by TheGoldKnight23:
Designator = null;
distance2Turret = Single.MaxValue;
temp.Clear();
bGroup.GetBlocksOfType<IMyLargeTurretBase>(temp,b=>b.CustomName.Contains(DesignatorNameTag));
if(temp.Count!=0){
this.Designator = temp[0];
distance2Turret = (Designator.Position - Azimuth.Position).Length();
foreach(IMyTerminalBlock t in temp){
if((t.Position - Azimuth.Position).Length()<distance2Turret){
Designator = t;
distance2Turret = (t.Position - Azimuth.Position).Length();
}
}
}
var designatorCandidates = WC_DIRECTORS.Where(d => {
long? id = api.GetWeaponTarget(d, 0)?.EntityId;
if (id != null) {
return api.IsTargetAligned(d, (long)id, 0) && ((IMyFunctionalBlock)d).Enabled;
} else {
return false;
}
}
).ToList();
designatorCandidates.Sort((lhs, rhs) => ((lhs.Position - Azimuth.Position).Length() - (rhs.Position - Azimuth.Position).Length()));

Designator = designatorCandidates.Any() ? designatorCandidates[0] : null;
It is working for me, switching to an in range designator when the current one goes out of range or is turned off and selects the closest when it has to rechoose (the designator does not update if a closer one is made valid unless the current one is invalidated).

Edit:
Getting a null exception here so I guess setting designator to null _after_ it has been not null messes stuff up... not sure I know how to fix that, but hopefully its helpful to you anyway.

Cannot reproduce that exception, it seems fine when losing the target and switching targets.
Last edited by Natomic; 15 Dec, 2020 @ 2:32pm
Sigmund Froid  [developer] 8 Jan, 2021 @ 11:11am 
I'll apply your changes in the next days, I haven't had the time last month. Thanks for your help. I'm still relatively new to C# so I was unaware of the Where function for Lists.
Natomic 9 Jan, 2021 @ 10:26am 
Just a heads up, I'm still getting an exception while using that code. I can't get it to consistently repro but I have to recompile it every few minutes or so while in combat so theres _something_ up there. I'm not sure if it's caused by my changes or a problem in my setup but I suspect the former.
Sigmund Froid  [developer] 6 Feb, 2021 @ 3:11am 
Originally posted by Sigmund Froid:
I'll apply your changes in the next days
Well that aged well. The problem with your code was mostly that getDesignators was designed to avoid that the designator is ever null so I didn't check for that anymore afterwards. the update is out now
Kaito  [developer] 26 Apr, 2021 @ 7:45pm 
Can't get it to work. It throws an exception the moment it finds my group, or if it finds a vanilla designator. I'm not sure how I could copy paste the stack trace, but you'll have to excuse me for not typing it all out. Abbreviated stack trace transcript below:

Object reference not set to an instance of an object, at isTargetAligned, PbIsTargetAligned, isTargetAligned, getDesignators.

Anything I can do to help debug this?
Kaito  [developer] 26 Apr, 2021 @ 8:11pm 
Line 272, you need to check that id is not 0 in addition to not being null.
Kaito  [developer] 26 Apr, 2021 @ 8:25pm 
The conditional on line 400 does not consider DIRECTOR, and getDesignators does not consider DIRECTORS, so it will never use vanilla designators for targets.
Kaito  [developer] 26 Apr, 2021 @ 9:01pm 
Fixed it by passing DIRECTOR down frorm AttemptVanillaTargetting.

Do you have a git repo or something?
Sigmund Froid  [developer] 27 Apr, 2021 @ 2:09am 
1. No I don'T have a git (yet). 2. I'll implement it, thanks for your effort. It seems I haven't tested it with vanilla designators in the last updates as it isn't the main purpose of this script.
Kaito  [developer] 27 Apr, 2021 @ 4:49am 
My entire reason is using the MA Designator Turret, as there is no dedicated WC designator, and that one is apparently used in StarCore.... Somehow.

I've got some more work I'd like to do on the script now that I'm mildly familiar. Let me know if you get it on GitHub or whatever repo hosting you prefer.

Also, where did you hear that DDS would add WC support? I saw no mention of it. I figure you don't want to put too much effort into this, since you expect it to he deprecated soon.
Last edited by Kaito; 27 Apr, 2021 @ 5:10am
Sigmund Froid  [developer] 27 Apr, 2021 @ 6:43am 
Well when I wrote that this script was new and I'd been contacted if I could write a similiar add on like my whip's turret ai slaving script wc addon. When I contacted the author of DDS on his setup guide about the matter he told me he's working on it. From there my script was mostly for personal use but as DDS yet has to push a update supporting WC (I suspect the vast amount of edge cases and setup would bloat the script), I kept updating this as issues arised. On the note of your issue: I haven't been able to fix it yet; maybe I'm just missing the point. I assume you set DIRECTORS static and run the code used to find the best WC turret again over DIRECTORS or are you just replacing null as value for Designator with DIRECTORS[0]?
Sigmund Froid  [developer] 27 Apr, 2021 @ 7:04am 
ok nevermind it works now. I guess my old testing world just got borked by the update.
< >
Showing 1-15 of 52 comments
Per page: 1530 50