December 21, 2024, 17:52:55

Author Topic: Scripting Issues  (Read 103385 times)

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #25 on: December 11, 2009, 02:18:39 »
well, I sorted it out. Sort of. Just prevented that the wreck could be fired upon, thus, you were never capable of destroying it :P
as for your problem:
are you doing some campaign scripting? Because if you are, then you're problem is a real easy one. Instead of giving them a GetSceneObj, you could call them with the uGet("name_of_the_ship") command, and check whatever you need to check.

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #26 on: December 11, 2009, 02:20:50 »
Oh, don't use a tick rule for that. Nexus indeed has a special event for exploding ships, called "Exploding" :P

Code: [Select]
           RULE event Exploding
                :action
                    Debug("Oh my god!", E.ship, "is exploding");
                :end
            END

If you only want to watch a particular ship, check if E.ship is the one you wanted to keep an eye on as a :condition like so:

Code: [Select]
           RULE event Exploding
                :condition E.ship = WatchedShip
                :action
                    Debug("Oh my god!", E.ship, "is exploding");
                :end
            END

... or if you want to watch a selected group of ships (you previously added to a list) ...

Code: [Select]
           RULE event Exploding
                :condition InSelection(E.ship, MyListOfWatchedShips)
                :action
                    Debug("Oh my god!", E.ship, "is exploding");
                :end
            END

And btw.: Nexus also "works" with wrecked ships, but you can't use SelectShips() for that, because SelectShips(condition) is nothing different than Select(s.ship & condition)... it even states that in the manual. Since s.ship is only ever true for not-wrecked ships, SelectShips will never ever return a wrecked one. Use plain old Select(s.wreck) for that... ;)

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #27 on: December 11, 2009, 14:37:20 »
Ahh, thanks Arparso... another tidbit learned  :thumbup:

@Mularac...

Always doing campaign stuff these days, recently finished the 'general' scenes that the player can visit. Now moving onto background events, this should be fun...
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #28 on: December 20, 2009, 16:45:29 »
I got a question, how do you select all the devices belonging to a given set? just like you did with the shields, but with sets. I've managed to do when working with a single device, but when it comes to set it still eludes me... (not a priority, though)

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #29 on: December 20, 2009, 23:37:06 »
With the 'InSet' condition is how I normally do it.

Code: [Select]
SelectDevices(1,InSet(S.this,25));
Where the second number dictates the set you're looking for.

If you want to collect them from multiple ships, then you'll need to create a list of those ships first and place the SelectD command within an 'execlist' command.
Better to look the fool by asking, then prove them right with ignorance.

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #30 on: December 21, 2009, 00:29:30 »
Or you can use the plain Select() command, if you want to gather the devices from all ships:

Code: [Select]
Select(1, s.device & InSet(S.this,25));

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #31 on: December 21, 2009, 02:20:46 »
great, thanks. Arpaso, I take it that it can also be used in the SelectEx command, right?
EDIT: yep, it can.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #32 on: January 02, 2010, 17:06:15 »
Well, after a little break (been playing Dragon Age) I'm back to working on N:TAA again.

As such I've run into a couple rather annoying bugs.

The first of which is that one of the scenes has a space station that it shouldn't have (belongs in another scene), thing is there's no mention of it except in the files where it's supposed to be. All I can think of at the mo is that both scenes are within the same asteroid field, though I've not seen this before...

The second being more of an annoyance as it doesn't interfere with gameplay. When a strikecraft leaves a hidden ship, the hidden ship comes up as an 'unidentified object' in the tactical display. I can get it to disappear again within a few seconds, but I'd prefer if it doesn't show up at all.Anyone got some different ideas on how to keep it hidden?
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #33 on: January 02, 2010, 20:31:42 »
about the first one, how did you set that station, by the solar system editor or using something else?

and as for the second one, I know it's not the best programming, but how about a 0.01 tick rule with the hideship command in it?

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #34 on: January 03, 2010, 10:05:23 »
About the 'mystery' station,  in the scene where it's supposed to be I've added it via the 'AddLocation' command as it's held in the Stations.sobj file also included it's 'position'  data in the scene. As for the scene where it's not supposed to be, there's no call that I can find or mention of it anywhere  ?(

With the 'hidden ship', I've included commands to transfer the squadron to it's destination and to hide the launching ship as soon as each one launches. So it should remain hidden at all times.
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #35 on: January 08, 2010, 04:28:14 »
A question, is it possible to detect when a fighter wing is completely destroyed? I tried witht the co_devicedestroyed, but it didn't work. Any ideas?

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #36 on: January 08, 2010, 12:13:52 »
You can recognize bombers of the same wing by checking for the same launcherWeapon. All it then comes down to is counting the surviving wingmates in the event a bomber has been shot down. If there are none left, the squad obviously has been destroyed.

Try this:

Code: [Select]
// runs for all exploding bombers and checks, if the whole squad has been destroyed
    RULE event Exploding
        condition E.ship:bomber
        :action
            E.BombersInSameSquad := GetFreeSel();            
            Select(E.BombersInSameSquad, S.bomber & S.launcherWeapon = E.ship:launcherWeapon & S.this != E.ship);
            If(AllNumOf(E.BombersInSameSquad) = 0,
                Debug("Squadron destroyed")
            );
        :end
    END

/edit:
Just noticed a problem with the above code: if a bomber wing is currently docking and, lets say, the last one is being shot down while his mates already have docked... then the script above will think the whole squadron has been destroyed, because it doesn't count docked wingmates.

/edit2:
Doh! Even simpler solution: Just check the "count" variable of the launcherWeapon of the exploding bomber - this will give you the remaining amount of bombers in that wing (including the currently exploding one). No need to use stupid selections this time ;)

Code: [Select]
// runs for all exploding bombers and checks, if the whole squad has been destroyed
    RULE event Exploding
        condition E.ship:bomber
        :action
            // count all remaining bombers in bomber wing
            // (this includes the currently exploding bomber!)
            If(E.ship:launcherWeapon:count = 1,
                Debug("Squadron destroyed")
            );
        :end
    END

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #37 on: January 08, 2010, 20:50:24 »
Just a quick question, sure I've seen the answer somewhere. Just can't seem to find it now.

How do you select the slowest ship in a group?
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #38 on: January 08, 2010, 22:20:13 »
you're right, that sounds oddly familiar to me...

yeah, I know now it's from the skirmisher's AI:

if(AllNumOf(AIFleetL1)>0, m.AITeam_leader:=PickMax(AIFleetL1, 1 / s.this:tGetMaxVelocity()), ChangeState(noTeam1,0)); //slowest ship is AI leader

So, it seems you can do that with the tGetMaxVelocity() command, the exact way this command works seems to elude me... perhaps you can knock more sense out of it :)

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #39 on: January 08, 2010, 22:54:51 »
Not that hard to explain, I guess. Let's assume, we've got a bunch of ships selected in MyFleet:

Selecting the fastest ship would be easy:
PickMax(MyFleet, s.this:tGetMaxVelocity());

It's like sorting the list by maximum speed and then picking the fastest one using PickMax. Sadly, there's no PickMin function, so you have to invert the sorting. You could do that by simply negating the maximum speed:
PickMax(MyFleet, -s.this:tGetMaxVelocity());

DeSade (who wrote the Skirmisher's AI) chose to divide 1 by the maximum speed, which also works well:
PickMax(MyFleet, 1/s.this:tGetMaxVelocity())

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #40 on: January 08, 2010, 23:06:07 »
Thanks guys, I thought it was along those lines, just didn't know how to factor in the speed condition.
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #41 on: February 10, 2010, 21:29:02 »
Is is there a way to mimic a "for" command in the BlackRuler scriptim system? I desperately need one for the piece of coding I'm working on.
here's the original idea, it's rather simple... and easy, if I could just use a bloody for...:
I need to collect each weapon in a separete variable, like this, for instance: e.norm_weap1, e.heavy_weap3 and such. I'm dealing with both an unknown ammount of weapons (from 0 to 7) and an unknown type of devicetype for each set. My only information is that the ships carries 2 slots for normal weapons, 2 for heavy, 2 specials and one for artillery (for now it's just an other heavy, but I'll find the way to set it apart). Don't mind the flaks.

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #42 on: February 10, 2010, 22:03:46 »
Nexus doesn't know a for-loop, but it knows while-loops and both are pretty much interchangeable. For example:

Code: [Select]
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Index is {0}", i);
}

... might be written in Nexus scripting as:

Code: [Select]
E.index := 0;
while(E.index < 10,
Debug("Index is", E.index);
E.index := E.index + 1;
);

I'm not sure, if you need it here, though. Why do you need the weapons in seperate variables? Why not just put them in a selection / in an array?

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #43 on: February 10, 2010, 22:45:49 »
I need it because in one mission the player has to choose wich weapon it wants to fix or not, in a dialog. And each dialog is connected to the weapon in question, and that weapon can only be connected to the game via a variable.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #44 on: February 13, 2010, 22:04:29 »
I've got a question.. for the past few days I've been trying to select two different devicetypes (supp_bsgen and supp_res) with the selectdevices rules, so that they may be activated with the enbladevice command. (and no, enabling them with two separate SelectDevices commands doesn't count). Or, in other words, I need to put those devices into a variable useful for the EnableDevice command.
Somehow, writing
Code: [Select]
SelectDevices(1, m.*ship*, s.this:Devtype=#supp_BsGen & s.this:Devtype=#supp_res);
doesn't work, and writing a list and using the additem command doesn't work either... here's the rule I'm working with atm:

Code: [Select]
SelectDevices(1, m.ac,  InSet(s.this,66));
Execlist(1,
debug(s.this);
dev:=s.this;
Debug(dev);
);
SelectDevices(2, m.ac, InSet(s.this,65));
Execlist(2,
debug(s.this);
addItem(dev, s.this);
Debug(dev);
);
Debug("----------------The devices are:", dev);
E.time:=250;
m.pgen:=1;
ChangeState(countdown, dev:=dev; E.time:=p.time);


In the countdown state all that is there is a "EnableDevice(dev, 1);"

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #45 on: February 13, 2010, 23:14:09 »
Try this as your selection instead...

Code: [Select]
SelectDevices(1, m.*ship*, s.this:Devtype=#supp_BsGen | s.this:Devtype=#supp_res);
Your original condition is asking for an item that is both a supp_BsGen and a supp_res. Clearly an imposibility.
This new line asks for an item that is either of those devices.
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #46 on: February 14, 2010, 00:00:21 »
you're right, that was stupid from my end. But that way wouldn't work either, as the rule will settle with the first one of those two that is true, so the output would only be one device, not the both of them.

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #47 on: February 14, 2010, 00:57:48 »
How so? SelectDevices selects all devices matching its criteria, not just a single one, so Dragon's line will make selection 1 include all devices of types #supp_BsGen and #supp_res on that particular ship.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #48 on: February 14, 2010, 01:50:58 »
well... with the debug commands I tracked the variables down to this:

This is the code:
Code: [Select]
SelectDevices(1, m.ac,  InSet(s.this,66)| InSet(s.this,42));
Execlist(1,
debug("1",s.this);
dev:=s.this;
Debug("2",dev);
);

Debug("----------------The devices are:", dev);

and this is what the console gave me:

Code: [Select]
       1  shield/HybridShieldMk3
        2  shield/HybridShieldMk3
        1  device/supp_res
        2  device/supp_res
        ----------------The devices are:  device/supp_res

funny, eh? The selectdevices did indeed select both ones, I was wrong about that one too, but when the "dev" variable left the execlist command it only stayed with the first one, so when I tried it only one of the devices got enabled, hence my previous post. Most peculiar indeed.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
(No subject)
« Reply #49 on: February 14, 2010, 10:12:08 »
The reason that Nexus is only giving you the one debug line  instead of three is because the last 'debug' command is outside of the 'execlist' command.

 If you were to place it within the  parenthesis  (you know, the '()' that surround this little explanation ) then the debug line would fire for each device and as in a circumstance like this, Nexus collects up the various items that fulfill the criteria and puts them in a list. Then it'll take the first item and run through any commands in the execlist that are applicable and when it's done, Nexus puts down item one and picks up item two, executes the commands,puts it down,item three, etc.  You get the idea.

Then it'll proceed with the rest of the command. But as the 'dev' variable can only store one value, only the last run through of the previous 'execlist' command will be recorded.

So this is how I believe it should have read...

Code: [Select]
SelectDevices(1, m.ac,  InSet(s.this,66)| InSet(s.this,42));
Execlist(1,
debug("1",s.this);
dev:=s.this;
Debug("2",dev);
        Debug("----------------The devices are:", dev);
);
Better to look the fool by asking, then prove them right with ignorance.