Nexus Modding > Scripting
Scripting Pt2
The Old Dragon:
Something else I'm struggling a little with... the availSuppForDevices command, from what does it calculate this?
If applied to a ship (i.e. M.Ship:availSuppForDevices;), it comes back with the amount of power left for devices such as ecm, scanners, etc. Despite my tinkering in various area's of the tacticstypes, this figure doesn't want to change on my test ship.
Just wondering if anyone out there could shine some light on it...?
Mularac:
About your first question altoghether, I still don't know why you don't use this burst fire code.
I've tried with multiple devices in one ship and it worked fine...
--- Code: ---// This machine is meant for handling several weapons' burst fire mode. Original idea and code by Mularac,
// moved into a whole new level by Old Dragon and efficiently re-coded by Arparso.
// Edited to fit the War Begins Mod by Mularac
MACHINE "Burst"
STATE Default
// Initialization
//
// Select all burst fire devices, put them into the BurstWeapons-selection and
// prepare supporting arrays storing the remaining burst shots and targetted ships
RULE event In
:action
// select all burst fire weapons
BurstWeapons := GetFreeSel();
Select(BurstWeapons, s.device & (s.devType=#burst_pbeam | s.devType=#AFRailgun | s.devType=#AFRailgunL | s.devType=#heavy_railgun)); // expandable with additional burst weapon types
ExecList(BurstWeapons,
Debug("requesting fire event for", s.this, "on", s.this:owner);
RequestFiredEvent(s.this, 1);
);
// prepare array for remaining burst shots
RemainingBurstShots := GetFreeSel();
Dim(RemainingBurstShots, AllNumOf(BurstWeapons));
// prepare array for burst weapon targets
BurstTargets := GetFreeSel();
Dim(BurstTargets, AllNumOf(BurstWeapons));
:end
END
// Fire Event
//
// A burst weapon has fired, initialize burst strength and count subsequent shots,
// disable weapon after burst
RULE event Fired
condition InSelection(BurstWeapons,E.location)
:action
// Debug(e.Location, "on", e.Location:owner, "fired at", e.Location:target);
// get index of fired weapon in selection
E.index := IndexOf(BurstWeapons, e.Location);
// get the remaining burst shots of fired weapon
E.remainingBurstShots := GetN(RemainingBurstShots, E.index);
// if 0 burst shots remain, this marks the start of a new burst
if(E.remainingBurstShots = 0,
// calculate burst length, depending on weapon type
ChooseFirst(
E.Location:devType=#burst_pbeam,
E.remainingBurstShots := 2;
,E.Location:devType=#AFRailgun,
E.remainingBurstShots := Round(Rnd(10,18))
,E.Location:devType=#AFRailgunl,
E.remainingBurstShots := Round(Rnd(18,28))
, E.location:devType=#heavy_railgun,
E.remainingBurstShots := 4
);
// save burst length in array
SetN(RemainingBurstShots, E.index, E.remainingBurstShots);
// Debug("Initialized burst with", E.remainingBurstShots, "shots");
, //else
// remaining burst shots was greater than 0 - continue burst fire
E.remainingBurstShots := E.remainingBurstShots - 1;
// save remaining burst length in array
SetN(RemainingBurstShots, E.index, E.remainingBurstShots);
// Debug(E.remainingBurstShots, "burst shots remaining");
// this was the last shot?
If(E.remainingBurstShots = 0,
// store current target for later use
SetN(BurstTargets, E.index, E.location:target);
// disable weapon
LocalEvent(DisableBurstWeapon, E.dev := P.Location);
);
);
:end
END
// Disable Burst Weapon
//
// a full burst was finished... weapon gets disabled for a certain period of time
RULE event DisableBurstWeapon
condition InSelection(BurstWeapons,E.dev)
:action
EnableDevice(E.dev, 0);
Debug("Burst weapon", e.dev,"getting ready for new burst");
ChooseFirst(
E.dev:devType=#burst_pbeam,
Timer(EnableBurstWeapon, 5, e.dev:=p.dev);
,E.dev:devType=#AFRailgun,
Timer(EnableBurstWeapon, Rnd(0.6,1.2), E.dev:=P.dev);
,E.dev:devType=#AFRailgunl,
Timer(EnableBurstWeapon, Rnd(0.3,0.8), E.dev:=P.dev);
, E.dev:devType=#heavy_railgun,
Timer(EnableBurstWeapon, Rnd(0.8,1.2), E.dev:=P.dev);
);
:end
END
// Enable burst weapon
//
// Weapon has recharged - enable it and continue fire at old target, if possible
RULE event EnableBurstWeapon
condition E.dev:device&IsValid(E.dev)&InSelection(BurstWeapons,E.dev)
:action
EnableDevice(E.dev, 1);
E.index := IndexOf(BurstWeapons, e.dev);
// get old target from array
E.target := GetN(BurstTargets, E.index);
// if target is still valid, continue fire...
If(IsValid(E.target),
TargetWeapon(E.dev, E.target);
,
// else remove old target from array
SetN(BurstTargets, E.index, 0);
);
:end
END
Rule event LongRangeArrived
:action
// New ship has arrived
//
// check, if the new ship carries burst weapons
// ... if it does, add those weapons to the BurstWeapon-selection and expand supporting arrays
// select new burst weapons, if there are any
Debug("...........", e.ship);
E.NewBurstWeapons := GetFreeSel();
SelectDevices(E.NewBurstWeapons, E.ship, s.devType=#heavy_railgun | s.devType=#AFRailgun | s.devType=#AFRailgunL);
E.count := AllNumOf(E.NewBurstWeapons);
// yeah, there is at least one new burst weapon in the scene
If(E.count > 0,
// expand BurstWeapon-selection to make room for the additional weapons
E.oldCount := AllNumOf(BurstWeapons);
Dim(BurstWeapons, E.oldCount + E.count);
// now add each new weapon to the BurstWeapon-selection and request a fire event
E.index := 0;
ExecList(E.NewBurstWeapons,
Debug("requesting fire event for", s.this, "on", s.this:owner);
RequestFiredEvent(s.this, 1);
// add new weapon to selection
SetN(BurstWeapons, E.oldCount + E.index, s.this);
E.index := E.index + 1;
);
// expand arrays for burst weapon targets and remaining burst shots
Dim(BurstTargets, E.oldCount + E.count);
Dim(remainingBurstShots, E.oldCount + E.count);
);
DeleteSelect(E.NewBurstWeapons);
:end
END
END
END
--- End code ---
It's been edited to fit the WB mod, but all you need to do is change the according devicetypes to the ones you'll be using.
Mularac:
As for question nÂș 2:
A did a quick test and found out this: (tested on regular Arparso's Nexus Skirmisher mod)
An escort cruiser (noah) completely vanilla gives returns a value of 25 when reading the :availSuppForDevices attribute. However, if you were to increase the power to support devices to a maximum, the value would be 75 (until you ran out of reserve power, of course). This number is not affected by how many support devices are being used, it's just the net output value.
After a quick search, I changed the "EnergyOutput" value of that ship's generator device, "supp_mSGen", from 50 to 100.
The value of the :availSuppForDevices was now 75 and 175 depending, respectibly. I'm pretty sure that's not the only value that affects that number, but so far is the only one I could found. Hope this helps.
The Old Dragon:
Thanks Mularac,
That's got it; sometimes, another mind on the job is required :)
Although I dare say other things will also affect it, the reserve energy appears to be taken from the 'EnergyOutput' of the support generators minus the 'SupportIn' of the shipclass.
My main reason I've been rewriting/tinkering with the burstfire code was for the use of certain models. With their weapons being fixed/forward firing, I wanted them to fire similar sized bursts. Looked a bit odd with one weapon firing three shots while it's neighbour fired seven.
Edit:
Slightly different area with this one. The following is an entry from the TacticsBase.Ini...
--- Code: --- 23 23 M 60 71 72 73 ; // weapon generator
--- End code ---
First two numbers represent which 'slots' on the actual model will be used, last three numbers (varies depending on entry; siege weapons only have one, support has eight) represent which sets can use this slot.
What I'm curios about is what does the 'M' stand for and why is it only on some entries? Also, the number that follows it, what does that represent?
Mularac:
--- Quote from: Old Dragon ---My main reason I've been rewriting/tinkering with the burstfire code was for the use of certain models. With their weapons being fixed/forward firing, I wanted them to fire similar sized bursts. Looked a bit odd with one weapon firing three shots while it's neighbour fired seven.
--- End quote ---
I.. don't think I know what you're refering to, there. With the current burst code both weapons should fire similar bursts, identical if you remove the random part.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version