Nexus Modding > Scripting
Scripting Pt2
The Old Dragon:
As the old scripting thread has gotten quite fat and wedged itself in the depths, I thouhgt i'd strt a new one with this query...
I have a number of weapons in a list' when one of them fires it triggers a 'Fired' event. What I want to do is place a specific value variable on one of these weapons for future reference, just to make things awkward, these weapons are all the same device type.
Can anyone think of a way to ensure the same weapon is picked each time one of them fires?
SetN();, GetN(); or PickN(); don't seem to help, I suspect that Nexus places the firing weapon at Index 0, which in turn makes the list order different each time it is drawn up.
If anyone has any thoughts, please give it a go. Till then, I'll be bashing my head against a brick wall >:(
Mularac:
I had a bit of a problem there, too, as devices objects can't seem to implement new instance variables like ships.
Could we see some of the code? What is it done on the fire event?
The Old Dragon:
Hi Mul,
Certainly can, what I've got so far is largely based on some of Arparso's scripting to do with burst weaponry and is for craft with groups of fixed, forward firing weapons.
By arranging the weapons into lists by weapon type and owner, you can create a list to record the variables against. Although all the weapons in a group fire, Nexus only seems to register it as one shot... even though each weapon triggers the 'fired' rule that does the work and should therefore be a recorded.
--- Code: --- ////////////////
//M:BurstFire2//
////////////////
MACHINE "BurstFire2"
/////////////
//S:Default//
/////////////
STATE Default
RULE event In
:action
//Select all burst fire capable weapons weapons in the scene and apply a fire request.
StrikeWeapons:=GetFreeSel();
Select(StrikeWeapons,S.device&S.working&InSet(S.this,99));
ExecList(StrikeWeapons,RequestFiredEvent(S.this, 1));
//Now we need to do some filtering, select all weapons to a ship first.
ExecList(StrikeWeapons,
//Pick a weapon, then find any other burst weapons of that type on it's owner.
E.Weap:=Pick(StrikeWeapons);
E.Weapons:=GetFreeSel();
SelectDevices(E.Weapons,E.Weap:owner,S.devtype=E.Weap:devtype);
//Next, add the first one to a group list...
AddItem(WeaponGroup,E.Weap);
Debug("Selected weapon is ",E.Weap);
//Now remove these from the Strike Weapons list
ExecList(E.Weapons,RemoveItem(StrikeWeapons,S.this));
);
//Create a list for recording the shots remaining.
BurstRounds:=GetFreeSel();
Dim(BurstRounds,AllNumOf(WeaponGroup));
//And another for target recall.
BurstTargets:=GetFreeSel();
Dim(BurstTargets,AllNumOf(WeaponGroup));
:end //end action
END //end rule
RULE event Fired
condition InSelection(WeaponGroup,E.location)
:action
//Locate this weapons entry on the group list, along with it's burst count list.
E.Index:=IndexOf(WeaponGroup,E.Location);
E.BurstCount:=GetN(BurstRounds,E.Index);
Debug("Weapon firing is ",E.location);
//If none remain, calculate burst size.
if(E.BurstCount=0,
//Find out which weapon it is and add a random value to the total count.
ChooseFirst(
E.Location:devType=#weap_h_s_laser,
E.ShotCount:=(Round(RND(5,8)));
);
Debug("ShotCount for ",E.Location, " is ",E.shotcount);
//Now add to the burstcount
E.BurstCount:=E.BurstCount+E.ShotCount;
//Then record the results.
SetN(BurstRounds,E.Index,E.BurstCount);
,
//If there are still shots to fire, do so and reduce the count by one...
E.BurstCount:=E.BurstCount-1;
SetN(BurstRounds,E.Index,E.BurstCount);
//Last shot fired...?
If(E.BurstCount=0,
//Store current target for later use.
SetN(BurstTargets,E.Index,E.location:target);
//Disable weapon.
LocalEvent(DisableBurstWeapon,E.dev:=P.Location);
);
);
:end //end action
END //end rule
RULE event DisableBurstWeapon
condition InSelection(WeaponGroup,E.dev)
:action
//Disable all weapons from group in question.
E.WIndex:=GetFreeSel();
SelectDevices(E.WIndex,E.dev:owner,S.devtype=E.dev:devtype);
ExecList(E.WIndex,EnableDevice(S.this, 0));
:end //end action
END //end rule
END //end state
END //end machine
--- End code ---
Mularac:
I don't seem to understand what you're doing here...
You're only looking to have one fire event triggered by one weapon per ship?
And no, not every weapon triggers the fire event. Keep in mind that you're sorting through all the fire events being called to only "answer" the one that meets the condition: InSelection(WeaponGroup,E.location), so only one weapon per ship (the one that was added to the weaponGroup list) would trigger the fire event.
The Old Dragon:
In my first attempts, the fired was triggered by any weapon belonging to set 99. What was happening is that number of shots was being fired by all weapons from a ship (let's just say it had two weapons in this case),there would be a brief pause and firing would recommence due to the second weapon.
What I'd originally wanted was when a '99' weapon fired, Nexus would find any other of that type from that owner and then calculate how many shots based on weapon type and number of weapons. All the weapons in the group would then fire this number of shots between them.
Unfortunately, it ended up calculating a burst of shots for the first weapon and all weapons in the group would fire this number of times, then do the same for the second weapon and then the third, etc.
The only way to do what I want (kind of) so far has been to have the burst sequence triggered by one weapon in the group.
Navigation
[0] Message Index
[#] Next page
Go to full version