March 29, 2024, 11:50:28

Author Topic: Scripting Pt2  (Read 16251 times)

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Scripting Pt2
« on: January 12, 2012, 14:52:34 »
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  >:(
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Scripting Pt2
« Reply #1 on: January 13, 2012, 03:54:10 »
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?

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Scripting Pt2
« Reply #2 on: January 13, 2012, 23:32:29 »
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: [Select]
  ////////////////
 //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
   
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Scripting Pt2
« Reply #3 on: January 14, 2012, 05:50:07 »
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.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Scripting Pt2
« Reply #4 on: January 14, 2012, 09:33:18 »
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.
Better to look the fool by asking, then prove them right with ignorance.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Scripting Pt2
« Reply #5 on: January 16, 2012, 19:38:33 »
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...?
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Scripting Pt2
« Reply #6 on: January 18, 2012, 18:04:05 »
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: [Select]
// 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

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.
« Last Edit: January 18, 2012, 18:10:15 by Mularac »

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Scripting Pt2
« Reply #7 on: January 18, 2012, 18:21:16 »
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.


Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Scripting Pt2
« Reply #8 on: January 18, 2012, 19:35:14 »
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: [Select]
23 23 M 60 71 72 73  ; // weapon generator

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?
« Last Edit: January 18, 2012, 20:03:21 by The Old Dragon »
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Scripting Pt2
« Reply #9 on: January 18, 2012, 21:38:47 »
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.

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.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Scripting Pt2
« Reply #10 on: January 18, 2012, 23:33:36 »
That's true, though without the random factor and always firing the same sized burst, it wouldn't look right to me. But either way, the code that I've got now works quite well for what I'm after.

Time for the next puzzle   :D
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Scripting Pt2
« Reply #11 on: January 19, 2012, 02:53:01 »
about that "m" thing... I've got no idea.

Here's what the manaul says about deviceslots:

Quote from: Nexus modding Manual
11.4.3   DeviceSlots
>   slotx..sloty – set1 set2 set3 … ;
Ordering sets to slots that are located on the model.

No M. I'm drawing a blanc here... friggin' nexus...

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Scripting Pt2
« Reply #12 on: February 02, 2012, 00:13:01 »
Hmmm, me neither...

Anyway, next question. does anyone know where/how Nexus associates command button textures with the order button panel?
I've got the tooltips text to change correctly and I know how to put the actual command where I want it, unfortunately it won't use the new command textures that I've made. Just uses the yellow disc with a 'c' in the middle...
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Scripting Pt2
« Reply #13 on: February 02, 2012, 02:16:42 »
We've done it on WB, by doing this:
-Go to the folder "textures\icons\commands" (create it if you don't have it)
- Then simply add the textures for on and off with these two names:

- command_<command's name>_on.tex and command_<command's name>_off.tex.

Example: If you have a command named "JumpPointOut" it would be:
- command_JumpPointOut_on.tex
- command_JumpPointOut_off.tex

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Scripting Pt2
« Reply #14 on: February 02, 2012, 09:05:58 »
Thanks for pointing me in the right direction, Mularac  ;D

I'd already got the textures ready and correctly named, needed to look through the War Begins folders to figure out that the problem was in the Mod_Commands.ini though. A little renaming later and we're all good to go.

Cheers once more!
Better to look the fool by asking, then prove them right with ignorance.